:root {
  color-scheme: dark;
  --bg: #100a12;
  --line: rgba(255, 205, 228, 0.16);
  --text: #fff5fa;
  --muted: #c9adbc;
  --dim: #927887;
  --rose: #ff8fbd;
  --rose-bright: #ff4f9a;
  --rose-soft: #ffd0e2;
  --gold: #ffd184;
  --success: #8ee6b7;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  min-height: 100%;
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 15%, rgba(255, 91, 158, 0.13), transparent 38%),
    radial-gradient(circle at 15% 80%, rgba(132, 68, 125, 0.13), transparent 32%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

button { font: inherit; }

.app {
  position: relative;
  width: min(100%, 500px);
  height: 100dvh;
  min-height: 580px;
  margin: 0 auto;
  padding: calc(12px + var(--safe-top)) 16px calc(12px + var(--safe-bottom));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
  isolation: isolate;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 12px;
}

.title-wrap { min-width: 0; }

h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.2rem, 5vw, 1.55rem);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--rose-soft);
}

.subtitle {
  margin-top: 2px;
  color: var(--dim);
  font-size: 0.76rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.icon-row {
  display: flex;
  gap: 7px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.icon-btn:focus-visible,
.primary-btn:focus-visible,
.hold-btn:focus-visible {
  outline: 3px solid rgba(255, 143, 189, 0.45);
  outline-offset: 3px;
}

.icon-btn[aria-pressed="false"] { color: var(--dim); }

.stage {
  position: relative;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 26px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 34%, rgba(255, 160, 198, 0.16), transparent 29%),
    linear-gradient(180deg, rgba(51, 29, 54, 0.97), rgba(27, 16, 31, 0.98));
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.04);
  touch-action: none;
}

.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(115deg, transparent 28%, rgba(255, 255, 255, 0.035) 48%, transparent 68%),
    radial-gradient(circle at 50% 120%, rgba(255, 86, 154, 0.18), transparent 42%);
  opacity: 0.75;
}

.stage.hot { border-color: rgba(255, 115, 176, 0.34); }
.stage.danger { animation: dangerPulse 0.48s ease-in-out infinite alternate; }
.stage.shake { animation: shake 0.28s ease; }

.character-frame {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px 20px 46px;
}

.character-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
  opacity: 0;
  transition: opacity 0.38s ease, filter 0.35s ease;
  pointer-events: none;
  z-index: 2;
  transform-origin: center 70%;
}

.character-art.ready {
  opacity: 1;
  animation: breathe 3.6s ease-in-out infinite;
}

/* Breathing */
@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.015); }
}

/* Soft jiggle when heat is high */
.character-art.jiggle {
  animation: breathe 3.6s ease-in-out infinite, jiggle 0.9s ease-in-out infinite;
}

@keyframes jiggle {
  0%, 100% { transform: scale(1.012) rotate(0deg); }
  25% { transform: scale(1.018) rotate(0.4deg); }
  75% { transform: scale(1.014) rotate(-0.35deg); }
}

/* Arch when very high heat */
.character-art.arch {
  animation: breathe 3.2s ease-in-out infinite, arch 2.8s ease-in-out infinite;
}

@keyframes arch {
  0%, 100% { transform: scale(1.02) translateY(0); }
  50% { transform: scale(1.028) translateY(-4px); }
}

/* Heat glow + glisten */
.stage.hot .character-art.ready {
  filter: saturate(1.12) brightness(1.06) contrast(1.04);
}

.stage.hot .character-frame::after {
  content: "";
  position: absolute;
  inset: 8% 12% 18% 12%;
  border-radius: 40%;
  background: radial-gradient(circle, rgba(255, 140, 190, 0.22) 0%, transparent 70%);
  pointer-events: none;
  z-index: 3;
  animation: heatPulse 2.4s ease-in-out infinite;
  mix-blend-mode: soft-light;
}

@keyframes heatPulse {
  0%, 100% { opacity: 0.45; transform: scale(1); }
  50% { opacity: 0.75; transform: scale(1.04); }
}

.stage.danger .character-frame::after {
  background: radial-gradient(circle, rgba(255, 80, 140, 0.35) 0%, transparent 70%);
  animation: heatPulse 1.4s ease-in-out infinite;
}

/* Glisten overlay intensity */
.character-art.glisten {
  filter: saturate(1.18) brightness(1.08) contrast(1.05);
}

.fallback-character {
  position: relative;
  width: min(56%, 220px);
  aspect-ratio: 0.55;
  z-index: 1;
  transition: transform 0.35s ease, filter 0.35s ease, opacity 0.25s ease;
  filter: saturate(calc(1 + var(--stage-index, 0) * 0.06));
}

.character-art.ready + .fallback-character { opacity: 0; }

.hair {
  position: absolute;
  left: 50%;
  top: 2%;
  width: 67%;
  height: 35%;
  transform: translateX(-50%);
  border-radius: 50% 50% 42% 42%;
  background: linear-gradient(145deg, #2a1718, #563130 48%, #1d1012);
  box-shadow: 0 9px 22px rgba(0, 0, 0, 0.3);
  z-index: 1;
}

.head {
  position: absolute;
  left: 50%;
  top: 6%;
  width: 42%;
  aspect-ratio: 0.82;
  transform: translateX(-50%);
  border-radius: 48% 48% 45% 45% / 42% 42% 54% 54%;
  background: linear-gradient(145deg, #f6c6bb, #d9958d);
  z-index: 2;
  box-shadow: inset -8px -5px 16px rgba(123, 55, 67, 0.12);
}

.head::before,
.head::after {
  content: "";
  position: absolute;
  top: 47%;
  width: 10%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #4d302c;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.36);
}

.head::before { left: 25%; }
.head::after { right: 25%; }

.body-shape {
  position: absolute;
  left: 50%;
  top: 28%;
  width: 78%;
  height: 67%;
  transform: translateX(-50%);
  border-radius: 38% 38% 25% 25% / 20% 20% 34% 34%;
  background: linear-gradient(150deg, #efb5ac, #ca7f81 72%, #a75e69);
  box-shadow: inset -17px -10px 25px rgba(85, 31, 48, 0.13);
}

.clothing {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  transition: opacity 0.45s ease, transform 0.45s ease;
  z-index: 3;
}

.dress {
  top: 29%;
  width: 82%;
  height: 64%;
  border-radius: 38% 38% 22% 22% / 18% 18% 30% 30%;
  background: linear-gradient(155deg, #f8ecef, #d8c5cf 55%, #a892a0);
  box-shadow: inset -14px -10px 20px rgba(77, 44, 63, 0.14);
}

.top {
  top: 31%;
  width: 68%;
  height: 27%;
  border-radius: 30% 30% 42% 42%;
  background: linear-gradient(145deg, #b96c8a, #713b64);
}

.bottom {
  top: 70%;
  width: 57%;
  height: 17%;
  border-radius: 45% 45% 30% 30%;
  background: linear-gradient(145deg, #b96c8a, #713b64);
}

.fallback-character[data-stage="1"] .dress,
.fallback-character[data-stage="2"] .dress,
.fallback-character[data-stage="3"] .dress,
.fallback-character[data-stage="4"] .dress,
.fallback-character[data-stage="5"] .dress,
.fallback-character[data-stage="6"] .dress,
.fallback-character[data-stage="final"] .dress {
  opacity: 0;
  transform: translateX(-50%) translateY(12px) scale(0.94);
}

.fallback-character[data-stage="3"] .top,
.fallback-character[data-stage="4"] .top,
.fallback-character[data-stage="5"] .top,
.fallback-character[data-stage="6"] .top,
.fallback-character[data-stage="final"] .top {
  opacity: 0;
  transform: translateX(-50%) translateY(8px) scale(0.94);
}

.fallback-character[data-stage="5"] .bottom,
.fallback-character[data-stage="6"] .bottom,
.fallback-character[data-stage="final"] .bottom {
  opacity: 0;
  transform: translateX(-50%) translateY(8px) scale(0.94);
}

.fallback-character[data-stage="final"] {
  transform: scale(1.035);
  filter: saturate(1.3) brightness(1.06);
}

.stage-caption {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 12px;
  z-index: 4;
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  pointer-events: none;
}

.stage-copy {
  min-width: 0;
  max-width: 78%;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(12, 6, 16, 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.4);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}

.stage-name {
  color: var(--rose-soft);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.02rem;
}

.status {
  margin-top: 3px;
  min-height: 2.4em;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.status.success { color: var(--success); }
.status.warning { color: var(--gold); }
.status.danger { color: #ff9cad; }

.progress-dots {
  display: flex;
  gap: 5px;
  flex: 0 0 auto;
  padding-bottom: 4px;
}

.progress-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 1px solid rgba(255, 208, 226, 0.33);
  background: rgba(255, 255, 255, 0.05);
  transition: background 0.25s ease, transform 0.25s ease;
}

.progress-dot.done {
  background: var(--rose);
  border-color: var(--rose);
}

.progress-dot.current {
  transform: scale(1.35);
  background: var(--rose-soft);
  border-color: var(--rose-soft);
}

.controls {
  display: grid;
  gap: 9px;
}

.hud-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.stat {
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.027);
  padding: 7px 9px;
  text-align: center;
}

.stat-label {
  color: var(--dim);
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.stat-value {
  margin-top: 1px;
  color: var(--rose-soft);
  font-size: 0.86rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.meter-block {
  display: grid;
  gap: 5px;
}

.meter-labels {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.73rem;
}

.meter-track {
  position: relative;
  height: 18px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #1b111e;
  box-shadow: inset 0 2px 7px rgba(0, 0, 0, 0.35);
}

.sweet-zone {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 72%;
  width: 18%;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(255, 209, 132, 0.45), rgba(142, 230, 183, 0.62));
  border: 1px solid rgba(255, 232, 186, 0.38);
  transition: left 0.3s ease, width 0.3s ease;
  z-index: 1;
}

.meter-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #8c3c70, var(--rose), var(--rose-bright));
  box-shadow: 0 0 16px rgba(255, 75, 151, 0.48);
  z-index: 2;
  will-change: width;
}

.meter-glint {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  left: 0%;
  transform: translateX(-1px);
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.7);
  z-index: 3;
  will-change: left;
}

.hold-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
}

.side-hint {
  color: var(--dim);
  font-size: 0.68rem;
  line-height: 1.25;
}

.side-hint:last-child { text-align: right; }

.hold-btn {
  position: relative;
  width: 96px;
  height: 96px;
  border: 1px solid rgba(255, 213, 230, 0.34);
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 28%, rgba(255, 255, 255, 0.35), transparent 19%),
    radial-gradient(circle, #ff9bc5, #df4a8e 63%, #983563);
  color: white;
  font-size: 0.83rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  cursor: pointer;
  touch-action: none;
  box-shadow:
    0 9px 22px rgba(220, 62, 133, 0.34),
    inset 0 -9px 18px rgba(103, 26, 68, 0.25),
    inset 0 3px 8px rgba(255, 255, 255, 0.2);
  transition: transform 0.1s ease, filter 0.2s ease, opacity 0.2s ease;
}

.hold-btn::after {
  content: "";
  position: absolute;
  inset: -7px;
  border: 1px solid rgba(255, 143, 189, 0.22);
  border-radius: 50%;
  pointer-events: none;
}

.hold-btn.holding {
  transform: scale(0.92);
  filter: brightness(1.08) saturate(1.12);
}

.hold-btn:disabled {
  opacity: 0.48;
  cursor: default;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-top)) 22px calc(24px + var(--safe-bottom));
  background: rgba(10, 6, 12, 0.86);
  backdrop-filter: blur(10px);
  transition: opacity 0.22s ease, visibility 0.22s ease;
}

.modal.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.modal-card {
  width: min(100%, 390px);
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(48, 28, 51, 0.98), rgba(28, 17, 31, 0.98));
  padding: 24px;
  text-align: center;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
}

.modal-kicker {
  color: var(--rose);
  font-size: 0.69rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.modal h2 {
  margin-top: 7px;
  color: var(--rose-soft);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.72rem;
  font-weight: 600;
}

.modal p {
  margin: 12px auto 0;
  max-width: 320px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.rules {
  margin: 18px 0;
  display: grid;
  gap: 9px;
  text-align: left;
}

.rule {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 0.82rem;
}

.rule-number {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 143, 189, 0.13);
  color: var(--rose-soft);
  font-weight: 800;
}

.primary-btn {
  min-width: 170px;
  border: 0;
  border-radius: 999px;
  padding: 12px 22px;
  background: linear-gradient(90deg, var(--rose), var(--rose-bright));
  color: #2b0e1d;
  font-weight: 850;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(255, 79, 154, 0.24);
}

.secondary-line {
  margin-top: 12px;
  color: var(--dim);
  font-size: 0.7rem;
}

.record-grid {
  margin: 18px 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.record-box {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.025);
}

.record-box small {
  display: block;
  color: var(--dim);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.record-box strong {
  display: block;
  margin-top: 3px;
  color: var(--rose-soft);
  font-size: 1.08rem;
  font-variant-numeric: tabular-nums;
}

.toast {
  position: fixed;
  left: 50%;
  top: calc(70px + var(--safe-top));
  z-index: 20;
  max-width: calc(100vw - 32px);
  transform: translate(-50%, -12px);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 13px;
  background: rgba(31, 18, 34, 0.94);
  color: var(--rose-soft);
  font-size: 0.78rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes dangerPulse {
  from { box-shadow: inset 0 0 0 rgba(255, 79, 105, 0), 0 0 0 rgba(255, 79, 105, 0); }
  to { box-shadow: inset 0 0 24px rgba(255, 79, 105, 0.18), 0 0 18px rgba(255, 79, 105, 0.12); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

@media (max-height: 680px) {
  .app {
    min-height: 520px;
    padding-top: calc(8px + var(--safe-top));
    padding-bottom: calc(8px + var(--safe-bottom));
    gap: 7px;
  }

  .subtitle,
  .side-hint { display: none; }

  .hold-row {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .hold-btn {
    width: 82px;
    height: 82px;
  }

  .stat { padding: 5px 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .character-art.ready,
  .character-art.jiggle,
  .character-art.arch {
    animation: none !important;
  }
}
