:root {
  color-scheme: dark;
  --ink: #f7efe1;
  --muted: #b8aa98;
  --paper: #211a16;
  --paper-2: #17120f;
  --line: rgba(255, 242, 218, 0.16);
  --red: #ed4d3d;
  --red-dark: #9e261f;
  --gold: #ffd15a;
  --green: #64d896;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background:
    radial-gradient(circle at 20% 0%, rgba(138, 46, 33, 0.18), transparent 30rem),
    #0d0b09;
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  overscroll-behavior: none;
}

button { font: inherit; }

.game-shell {
  width: min(100%, 1040px);
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 18px max(12px, env(safe-area-inset-bottom));
}

.brand-bar, .footer-note {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand-bar { height: 70px; }
.eyebrow, .kicker { margin: 0; letter-spacing: .18em; text-transform: uppercase; color: var(--red); font-size: 11px; font-weight: 700; }
.brand-bar h1 { margin: 2px 0 0; font-size: 25px; letter-spacing: .06em; line-height: 1; }
.brand-bar h1 span { color: var(--red); }

.icon-button, .close-button {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.04);
  color: var(--ink);
  border-radius: 50%;
  cursor: pointer;
}
.icon-button { width: 42px; height: 42px; }
.close-button { width: 38px; height: 38px; font-size: 25px; line-height: 1; }

.stage {
  position: relative;
  height: min(74vh, 720px);
  min-height: 520px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 24px;
  background:
    linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px),
    radial-gradient(circle at 50% 115%, rgba(211, 63, 45, .22), transparent 48%),
    linear-gradient(180deg, #211a16 0%, #15110e 100%);
  background-size: 32px 32px, 32px 32px, auto, auto;
  box-shadow: 0 24px 80px rgba(0,0,0,.35);
  isolation: isolate;
  touch-action: none;
  user-select: none;
}

.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  opacity: .45;
  background: linear-gradient(110deg, transparent 40%, rgba(255,255,255,.035) 50%, transparent 60%);
}

#gameCanvas { display: block; width: 100%; height: 100%; cursor: crosshair; }

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(24px, 5vw, 64px);
  text-align: center;
  background: linear-gradient(180deg, rgba(21,17,14,.48), rgba(21,17,14,.92));
  backdrop-filter: blur(7px);
}

[hidden] { display: none !important; }

.hero-mark {
  position: relative;
  width: 92px;
  height: 92px;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  border: 2px solid var(--red);
  border-radius: 26% 74% 37% 63% / 59% 32% 68% 41%;
  transform: rotate(-8deg);
  color: var(--ink);
  font-family: serif;
  font-size: 45px;
  font-weight: 900;
  box-shadow: inset 0 0 30px rgba(237,77,61,.18), 0 0 35px rgba(237,77,61,.12);
}
.hero-mark span { transform: rotate(8deg); }
.hero-mark i { position: absolute; width: 132px; height: 2px; background: linear-gradient(90deg, transparent, #fff, var(--red), transparent); transform: rotate(-35deg); box-shadow: 0 0 12px #fff; }

.screen h2 { margin: 9px 0 13px; font-size: clamp(34px, 6vw, 62px); line-height: 1.05; letter-spacing: -.04em; }
.intro { width: min(100%, 520px); color: var(--muted); font-size: 14px; line-height: 1.8; margin: 0 0 18px; }
.rules { display: flex; gap: 22px; margin-bottom: 24px; color: #d8cdbd; font-size: 13px; }
.rules span { display: flex; align-items: center; gap: 7px; }
.rule-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.rule-dot.bad { background: var(--red); box-shadow: 0 0 10px var(--red); }
.rule-dot.good { background: var(--gold); box-shadow: 0 0 10px var(--gold); }

.primary-button {
  min-width: 190px;
  border: 0;
  border-radius: 999px;
  padding: 14px 28px;
  color: #fff;
  font-weight: 800;
  letter-spacing: .08em;
  cursor: pointer;
  background: linear-gradient(135deg, #ff6654, var(--red-dark));
  box-shadow: 0 10px 25px rgba(190,48,37,.3), inset 0 1px rgba(255,255,255,.25);
}
.primary-button:hover { transform: translateY(-1px); filter: brightness(1.08); }
.primary-button:active { transform: translateY(1px); }
.text-button { margin-top: 14px; padding: 8px; border: 0; color: var(--muted); background: transparent; text-decoration: underline; text-underline-offset: 4px; cursor: pointer; }

.hud {
  position: absolute;
  inset: 0 0 auto;
  height: 92px;
  display: grid;
  grid-template-columns: 1fr minmax(150px, 260px) 1fr;
  align-items: start;
  gap: 20px;
  padding: 18px 22px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(8,7,6,.72), transparent);
}
.hud-stat span { display: block; font-size: 10px; letter-spacing: .18em; color: var(--muted); }
.hud-stat strong { color: var(--ink); font-size: 29px; line-height: 1; font-variant-numeric: tabular-nums; }
.hud-stat em {
  display: block;
  width: max-content;
  margin-top: 5px;
  padding: 3px 7px;
  border: 1px solid rgba(255,209,90,.25);
  border-radius: 99px;
  color: var(--gold);
  background: rgba(255,209,90,.06);
  font-size: 9px;
  font-style: normal;
  font-weight: 800;
  letter-spacing: .06em;
}
.hud-center { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px 10px; }
.combo-pill { grid-column: 1 / -1; min-height: 18px; text-align: center; color: var(--gold); font-size: 11px; font-weight: 800; letter-spacing: .12em; opacity: 0; transform: translateY(-4px); transition: .15s; }
.combo-pill.active { opacity: 1; transform: translateY(0); }
.time-track { height: 5px; overflow: hidden; border-radius: 9px; background: rgba(255,255,255,.12); }
.time-track span { display: block; width: 100%; height: 100%; transform-origin: left; background: linear-gradient(90deg, var(--red), var(--gold)); }
.hud-center b { font-size: 12px; font-variant-numeric: tabular-nums; }
.lives { justify-self: end; color: var(--red); letter-spacing: .22em; font-size: 16px; text-shadow: 0 0 10px rgba(237,77,61,.6); }
.hud-actions { justify-self: end; display: flex; align-items: center; gap: 12px; pointer-events: auto; }
.pause-button {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255,255,255,.055);
  color: var(--ink);
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
}

.coach {
  position: absolute;
  left: 50%;
  top: 53%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  transform: translate(-50%, -50%);
  color: rgba(255,255,255,.78);
  font-size: 12px;
  letter-spacing: .08em;
  pointer-events: none;
  animation: coach-fade 2.6s both;
}
.coach i {
  width: 78px;
  height: 3px;
  border-radius: 99px;
  background: linear-gradient(90deg, transparent, #fff, var(--red), transparent);
  box-shadow: 0 0 14px var(--red);
  transform: rotate(-32deg);
  animation: coach-swipe .8s ease-in-out infinite alternate;
}
@keyframes coach-swipe { from { translate: -25px 16px; } to { translate: 25px -16px; } }
@keyframes coach-fade { 0%, 72% { opacity: 1; } 100% { opacity: 0; } }

.level-banner {
  position: absolute;
  left: 50%;
  top: 39%;
  z-index: 4;
  display: grid;
  min-width: min(78%, 370px);
  justify-items: center;
  padding: 20px 28px;
  transform: translate(-50%, -50%);
  border-top: 1px solid rgba(255,209,90,.55);
  border-bottom: 1px solid rgba(255,209,90,.55);
  color: var(--ink);
  background: linear-gradient(90deg, transparent, rgba(12,9,7,.92) 18%, rgba(12,9,7,.92) 82%, transparent);
  pointer-events: none;
  animation: level-in 1.5s both;
}
.level-banner span { color: var(--red); font-size: 10px; font-weight: 900; letter-spacing: .24em; }
.level-banner strong { margin: 4px 0; color: var(--gold); font-size: clamp(25px, 5vw, 40px); letter-spacing: .08em; }
.level-banner small { color: var(--muted); font-size: 11px; }
@keyframes level-in {
  0% { opacity: 0; transform: translate(-50%, -40%) scale(.9); }
  15%, 76% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -58%) scale(1.04); }
}

.pause-screen { z-index: 5; }
.pause-mark {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  margin-bottom: 16px;
  border: 1px solid rgba(255,209,90,.45);
  border-radius: 50%;
  color: var(--gold);
  font-size: 22px;
  box-shadow: 0 0 30px rgba(255,209,90,.08);
}
.pause-screen h2 { margin-bottom: 4px; }

.toast {
  position: absolute;
  left: 50%;
  top: 25%;
  transform: translate(-50%, -10px) scale(.9);
  padding: 8px 15px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 999px;
  background: rgba(15,12,10,.82);
  color: var(--ink);
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transition: .18s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
.toast.good { color: var(--gold); border-color: rgba(255,209,90,.4); }
.toast.bad { color: #ff7e70; border-color: rgba(237,77,61,.4); }
.toast.wrong {
  top: 20%;
  max-width: 84%;
  padding: 13px 20px;
  border: 2px solid var(--gold);
  border-radius: 15px;
  color: #241807;
  background: var(--gold);
  box-shadow: 0 0 0 8px rgba(255,209,90,.12), 0 12px 40px rgba(0,0,0,.38);
  font-size: clamp(15px, 3vw, 21px);
}

.stage.danger-flash { animation: danger-flash .42s ease-out; }
@keyframes danger-flash {
  0%, 100% { box-shadow: 0 24px 80px rgba(0,0,0,.35); }
  18% { box-shadow: inset 0 0 0 7px #ffd15a, inset 0 0 90px rgba(255,50,32,.48), 0 24px 80px rgba(0,0,0,.35); }
  42% { translate: -7px 0; }
  58% { translate: 7px 0; }
}

.roster-screen { align-items: stretch; justify-content: flex-start; overflow-y: auto; text-align: left; background: rgba(18,14,12,.96); }
.screen-heading { display: flex; justify-content: space-between; align-items: flex-start; width: 100%; margin-bottom: 18px; }
.screen-heading h2 { margin: 5px 0 0; font-size: clamp(27px, 4vw, 40px); }
.roster-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; width: 100%; }
.roster-item { min-height: 68px; display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.035); }
.roster-item.good { border-color: rgba(255,209,90,.42); background: rgba(255,209,90,.06); }
.roster-icon { flex: 0 0 38px; width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; color: #fff; font-size: 16px; font-weight: 900; box-shadow: inset 0 1px rgba(255,255,255,.25); }
.roster-item b { display: block; font-size: 13px; }
.roster-item small { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.roster-note { align-self: center; color: var(--muted); font-size: 12px; }
.roster-note span { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); }

.end-screen .final-score { margin: 6px 0 24px; }
.final-score span { display: block; color: var(--muted); font-size: 11px; letter-spacing: .18em; }
.final-score strong { display: block; font-size: clamp(62px, 12vw, 108px); line-height: 1; color: var(--gold); font-variant-numeric: tabular-nums; }
.result-grid { display: grid; grid-template-columns: repeat(3, minmax(85px, 130px)); gap: 10px; }
.result-grid div { padding: 12px 8px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,255,255,.035); }
.result-grid span { display: block; color: var(--muted); font-size: 10px; }
.result-grid b { display: block; margin-top: 2px; font-size: 21px; }
.result-line { min-height: 24px; color: var(--muted); font-size: 13px; }

.footer-note { min-height: 42px; color: #756b5e; font-size: 11px; letter-spacing: .06em; }
.footer-note b { color: #a89986; }

@media (max-width: 700px) {
  .game-shell { padding-left: 0; padding-right: 0; padding-top: max(8px, env(safe-area-inset-top)); }
  .brand-bar, .footer-note { padding-left: 14px; padding-right: 14px; }
  .brand-bar { height: 58px; }
  .brand-bar h1 { font-size: 21px; }
  .eyebrow { display: none; }
  .icon-button { width: 38px; height: 38px; }
  .stage { height: calc(100svh - 108px); min-height: 490px; border-left: 0; border-right: 0; border-radius: 18px; }
  .screen { padding: 24px 20px; }
  .screen h2 { font-size: clamp(36px, 12vw, 52px); }
  .hero-mark { width: 76px; height: 76px; font-size: 38px; }
  .intro { font-size: 13px; }
  .rules { gap: 13px; font-size: 12px; }
  .hud { padding: 14px 13px; grid-template-columns: 1fr minmax(115px, 150px) 1fr; gap: 8px; }
  .hud-stat strong { font-size: 24px; }
  .hud-stat em { max-width: 105px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .lives { letter-spacing: .1em; }
  .hud-actions { gap: 7px; }
  .pause-button { width: 29px; height: 29px; }
  .roster-screen { padding: 22px 14px; }
  .roster-grid { grid-template-columns: repeat(2, 1fr); gap: 7px; }
  .roster-item { min-height: 59px; padding: 8px; }
  .roster-icon { flex-basis: 32px; width: 32px; height: 32px; border-radius: 9px; font-size: 13px; }
  .footer-note { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; }
}
