:root {
  color-scheme: dark;
  --cream: #fff5e5;
  --gold: #ffd478;
  --ink: #402039;
  --plum: #24172f;
}
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { background: #33264e; color: var(--cream); font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid #fff7d8; outline-offset: 3px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
#stage, .vignette { position: fixed; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.vignette { pointer-events: none; background: radial-gradient(ellipse at 50% 48%, transparent 28%, rgba(33, 17, 47, .48) 100%); }

#hud { position: fixed; z-index: 2; top: calc(16px + env(safe-area-inset-top)); left: calc(22px + env(safe-area-inset-left)); right: calc(22px + env(safe-area-inset-right)); display: flex; align-items: center; gap: 24px; text-shadow: 0 2px 9px #291326; }
.stat { display: flex; align-items: center; gap: 9px; font-size: 25px; font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat.center, .stat.right { flex-direction: column; gap: 3px; align-items: flex-end; }
.stat.center { margin-left: auto; }
.stat small { font-size: 9px; letter-spacing: .16em; color: #ffecd5; }
.coin-icon { display: grid; place-items: center; width: 32px; height: 32px; border: 2px solid #a86506; border-radius: 50%; background: radial-gradient(circle at 35% 25%, #fff7b3, #ffc832 60%, #d48108); color: #fff5a9; font-size: 20px; box-shadow: 0 0 18px #ffc64080; }
.icon-button { display: grid; place-items: center; width: 46px; height: 46px; padding: 0; border: 1px solid #ffffff80; border-radius: 50%; background: #241a38b8; color: #fff; font-weight: 900; }

.overlay { position: fixed; inset: 0; z-index: 3; display: flex; align-items: safe center; justify-content: center; overflow-y: auto; overscroll-behavior: contain; padding: calc(24px + env(safe-area-inset-top)) calc(20px + env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) calc(20px + env(safe-area-inset-left)); background: linear-gradient(180deg, #21162c88, #3d203d70 50%, #21142cba); }
.panel { flex: none; width: min(440px, 100%); margin: auto; padding: clamp(24px, 5vw, 38px); border: 1px solid #ffe2bd47; border-radius: 24px; background: linear-gradient(155deg, #43283ebd, #231b35db); box-shadow: 0 24px 70px #1f122866, inset 0 1px #fff3dc24; text-align: center; text-shadow: 0 2px 14px #30182c99; }
.eyebrow { margin: 0 0 13px; color: #ffda9c; font-size: 10px; font-weight: 800; letter-spacing: .22em; line-height: 1.5; }
.eyebrow span { padding: 0 3px; color: #ffbf64; }
h1, h2 { font-family: Georgia, "Times New Roman", serif; font-weight: 700; letter-spacing: -.045em; }
h1 { margin: 0; font-size: clamp(51px, 10vw, 79px); line-height: .95; }
h1 span { display: block; color: var(--gold); }
h2 { margin: 0 0 22px; font-size: clamp(43px, 8vw, 60px); line-height: 1; }
.subtitle { margin: 16px 0 24px; color: #ffede2; font-size: 15px; line-height: 1.5; }
.primary, .secondary { display: block; width: min(300px, 100%); min-height: 50px; margin: 12px auto; padding: 13px 20px; border: 1px solid transparent; border-radius: 12px; font-size: 13px; font-weight: 900; letter-spacing: .09em; transition: transform .16s ease, box-shadow .16s ease, background-color .16s ease; }
.primary { background: linear-gradient(180deg, #ffde85, #ffc05b); color: var(--ink); box-shadow: 0 4px 0 #bd793e, 0 10px 25px #1c101c66; }
.primary span, .secondary span { float: right; }
.secondary { background: #fff2e2; color: #402039; }
.primary:not(:disabled):hover, .secondary:hover { transform: translateY(-2px); }
.primary:not(:disabled):active, .secondary:active { transform: translateY(2px); }
.primary:disabled { opacity: .55; filter: saturate(.45); cursor: not-allowed; }
.controls { max-width: 330px; margin: 22px auto 0; color: #fce9dd; font-size: 11px; line-height: 1.7; }
.controls span { color: #e3a982; }
.touch-hint { margin-top: 4px; }
.menu-bottom { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 4px 20px; margin-top: 18px; color: #ffe1b3; font-size: 11px; font-weight: 800; letter-spacing: .12em; }
.menu-bottom b { color: #fff; font-size: 13px; }
.text-button { min-height: 44px; padding: 10px 12px; border: 0; border-radius: 8px; background: transparent; color: #fff8ed; font-size: 11px; font-weight: 850; letter-spacing: .12em; }
.text-button:hover { background: #ffffff16; }
.panel > .text-button { display: block; margin: auto; }
.setting { display: flex; justify-content: space-between; align-items: center; gap: 16px; min-height: 56px; max-width: 300px; margin: 10px auto; padding: 10px 14px; border: 1px solid #ffe2bd26; border-radius: 10px; background: #1e193c88; text-align: left; font-size: 14px; }
.setting input { width: 22px; height: 22px; margin: 0 4px; accent-color: #ffc868; }
.setting select { min-height: 44px; max-width: 50%; padding: 0 28px 0 10px; border: 1px solid #ffe2bd66; border-radius: 8px; background: #342440; color: #fff; }
.result { margin: 0; font-size: clamp(42px, 10vw, 56px); font-weight: 900; line-height: 1.1; font-variant-numeric: tabular-nums; }
.result small { font-size: 10px; letter-spacing: .14em; }
#gameover .subtitle { margin: 8px 0 14px; }
.result-meta { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px 22px; margin: 0 auto 18px; color: #f7d9b2; font-size: 10px; font-weight: 800; letter-spacing: .11em; overflow-wrap: anywhere; }
.result-meta b { color: #fff; }
#power-label, .countdown, .run-hint { position: fixed; z-index: 2; left: calc(12px + env(safe-area-inset-left)); right: calc(12px + env(safe-area-inset-right)); text-align: center; color: #fff0b5; font-weight: 900; text-shadow: 0 2px 8px #271432; pointer-events: none; }
#power-label { top: calc(80px + env(safe-area-inset-top)); font-size: 13px; }
.countdown { top: 42%; font-size: clamp(64px, 18vw, 120px); line-height: 1; }
.run-hint { bottom: calc(88px + env(safe-area-inset-bottom)); font-size: 13px; }
#mobile-controls { position: fixed; z-index: 2; bottom: calc(12px + env(safe-area-inset-bottom)); left: calc(12px + env(safe-area-inset-left)); right: calc(12px + env(safe-area-inset-right)); display: none; justify-content: center; gap: 10px; pointer-events: none; }
#mobile-controls button { pointer-events: auto; width: 48px; height: 48px; border: 1px solid #ffffff99; border-radius: 50%; background: #26203ab3; color: #fff; font-size: 22px; touch-action: manipulation; }
@media (pointer: coarse) { #mobile-controls { display: flex; } }
@media (max-width: 520px) {
  #hud { left: calc(12px + env(safe-area-inset-left)); right: calc(12px + env(safe-area-inset-right)); gap: 10px; }
  .stat { font-size: 19px; }
  .stat small { font-size: 8px; }
  .coin-icon { width: 27px; height: 27px; font-size: 16px; }
}
@media (max-height: 550px) {
  .overlay { padding-top: calc(14px + env(safe-area-inset-top)); padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .panel { padding: 20px 26px; }
  h1 { font-size: 50px; }
  h1 span { display: inline; }
  h2 { margin-bottom: 12px; font-size: 40px; }
  .subtitle { margin: 9px 0 14px; }
  .controls { margin-top: 12px; }
  .touch-hint { margin-top: 2px; }
  .menu-bottom { margin-top: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
