* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --red-dark: #8e0d13;
  --red-main: #c91820;
  --gold-main: #f3c65f;
  --text: #ffffff;
  --shadow: 0 18px 44px rgba(91, 8, 12, 0.28);
  --page-bg: url("./bg.jpg");
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", Arial, sans-serif;
  color: var(--text);
  background: #b91118;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image: var(--page-bg);
  background-repeat: no-repeat;
  background-position: center center;
  background-size: cover;
}

.app {
  width: min(100%, 460px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 14px;
}

h1 {
  margin: 2px 0 0;
  text-align: center;
  font-size: clamp(23px, 7vw, 34px);
  line-height: 1.16;
  letter-spacing: 0.03em;
  font-weight: 900;
  text-shadow: 0 3px 14px rgba(84, 5, 10, 0.38);
}

.avatar-stage {
  position: relative;
  width: min(100%, 260px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  margin-top: 220px;
  overflow: hidden;
  border-radius: 30px;
  background: rgba(255, 239, 184, 0.9);
  box-shadow: var(--shadow);
  border: 2px solid rgba(255, 237, 165, 0.72);
  touch-action: none;
  user-select: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.controls {
  display: grid;
  gap: 14px;
  align-content: start;
  padding: 14px;
  border-radius: 28px;
  background: rgba(255, 247, 225, 0.15);
  border: 1px solid rgba(255, 239, 184, 0.22);
  box-shadow: 0 14px 38px rgba(82, 7, 10, 0.18);
  backdrop-filter: blur(12px);
}

input[type="range"] {
  width: 100%;
  height: 34px;
  accent-color: var(--gold-main);
}

.frame-list {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.frame-option {
  position: relative;
  display: grid;
  place-items: center;
  padding: 4px;
  aspect-ratio: 1 / 1;
  border: 2px solid transparent;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 8px 18px rgba(84, 5, 10, 0.16);
}

.frame-option img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.frame-option.active {
  border-color: var(--gold-main);
  background: linear-gradient(180deg, #fff7dc, #ffffff);
}

.frame-option.active::after {
  content: "";
  position: absolute;
  right: 5px;
  bottom: 5px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--red-main);
  box-shadow: 0 0 0 2px #fff4cd;
}

.button-row {
  display: grid;
  grid-template-columns: 1.35fr 1fr 1.35fr;
  gap: 9px;
}

.btn {
  min-width: 0;
  height: 48px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #7e0c11;
  font-weight: 900;
  font-size: 15px;
  letter-spacing: 0.02em;
  white-space: nowrap;
  cursor: pointer;
}

.btn input {
  display: none;
}

.btn.primary {
  color: #7e0c11;
  background: linear-gradient(180deg, #ffe78d, #f1ba42);
  box-shadow: 0 10px 22px rgba(80, 8, 10, 0.24);
}

.btn.secondary {
  color: #fff8dc;
  background: rgba(128, 9, 15, 0.62);
  border: 1px solid rgba(255, 236, 168, 0.38);
}

.result-modal {
  position: fixed;
  inset: 0;
  z-index: 99;
  display: none;
  align-items: center;
  justify-content: center;
  padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
}

.result-modal.show {
  display: flex;
}

.result-mask {
  position: absolute;
  inset: 0;
  background: rgba(50, 0, 4, 0.72);
  backdrop-filter: blur(8px);
}

.result-card {
  position: relative;
  z-index: 1;
  width: min(100%, 420px);
  padding: 14px 14px 16px;
  border-radius: 28px;
  background: linear-gradient(180deg, #fff7dc, #ffffff);
  box-shadow: 0 24px 60px rgba(50, 0, 4, 0.42);
  border: 1px solid rgba(255, 230, 150, 0.8);
}

.result-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  border-radius: 20px;
  background: #fff0bd;
  -webkit-touch-callout: default;
  user-select: auto;
}

.result-text {
  margin-top: 12px;
  text-align: center;
  color: #8e0d13;
  font-size: 17px;
  font-weight: 900;
}

.result-close {
  position: absolute;
  right: 10px;
  top: 10px;
  z-index: 2;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  color: #8e0d13;
  background: rgba(255, 244, 205, 0.92);
  font-size: 25px;
  line-height: 1;
  font-weight: 400;
}
