:root {
  color-scheme: dark;
  --ink: #21120d;
  --espresso: #351c11;
  --oak-dark: #5f3217;
  --oak: #b86b28;
  --oak-light: #eda94f;
  --cream: #fff0c2;
  --paper: #f8df9c;
  --pink: #ef5b9b;
  --purple: #71348f;
  --blue: #2286c4;
  --green: #67b94a;
  --gold: #ffd34d;
  --shadow: rgba(22, 8, 4, 0.62);
  --stage-ratio: 384 / 684;
}

* { box-sizing: border-box; }

html, body { width: 100%; height: 100%; margin: 0; overscroll-behavior: none; }

body {
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 15%, rgba(242, 168, 75, 0.25), transparent 36%),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.018) 0 2px, transparent 2px 8px),
    #160b07;
  color: var(--cream);
  font-family: "Courier New", ui-monospace, monospace;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button { font: inherit; }

.game-frame {
  width: min(100vw, calc(100vh * 384 / 684));
  height: min(100vh, calc(100vw * 684 / 384));
  padding: max(0px, env(safe-area-inset-top)) max(0px, env(safe-area-inset-right)) max(0px, env(safe-area-inset-bottom)) max(0px, env(safe-area-inset-left));
}

.playfield {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  isolation: isolate;
  background: #2b170e;
  box-shadow: 0 0 0 3px #0f0704, 0 0 0 6px #7c411d, 0 24px 80px #000;
  touch-action: none;
}

.canvas-mount, .canvas-mount canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.canvas-mount canvas { image-rendering: pixelated; image-rendering: crisp-edges; }

.hud {
  position: absolute;
  z-index: 20;
  inset: 7px 7px auto;
  height: 65px;
  display: grid;
  grid-template-columns: 1.15fr .92fr .82fr .72fr auto;
  gap: 4px;
  pointer-events: none;
}

.hud__brand, .hud__chip {
  min-width: 0;
  border: 2px solid #1a0d08;
  outline: 1px solid #8c542c;
  background: linear-gradient(#33231c, #180f0b);
  box-shadow: inset 0 0 0 2px #4a2a19, 2px 3px 0 rgba(0,0,0,.45);
  text-align: center;
}

.hud__brand { display: grid; place-content: center; line-height: .9; color: var(--gold); text-shadow: 2px 2px #6d1f35; }
.hud__brand span { font-size: clamp(7px, 2.2vw, 10px); letter-spacing: .04em; }
.hud__brand strong { font-size: clamp(13px, 4.1vw, 19px); }
.hud__chip { display: grid; place-content: center; }
.hud__chip span { color: #e3ad61; font-size: clamp(7px, 2vw, 9px); text-transform: uppercase; }
.hud__chip strong { color: white; font-size: clamp(13px, 4.2vw, 19px); font-variant-numeric: tabular-nums; text-shadow: 2px 2px #000; }
.hud__chip--time strong { color: var(--gold); }
.hud__chip--time.is-low strong { color: #ff6b68; animation: timePulse .48s steps(2, end) infinite; }

.hud__controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; pointer-events: auto; }
.icon-button {
  min-width: 30px;
  min-height: 44px;
  padding: 0;
  border: 2px solid #1b0c08;
  border-radius: 6px;
  color: white;
  background: linear-gradient(#8e4fb1, #56236f);
  box-shadow: inset 0 0 0 2px #b479d0, 2px 3px #130707;
  font-size: clamp(13px, 4vw, 19px);
  cursor: pointer;
}
.icon-button:last-child { background: linear-gradient(#2d9ad0, #17618d); box-shadow: inset 0 0 0 2px #64c4e7, 2px 3px #130707; }
.icon-button:active { transform: translate(1px, 2px); box-shadow: inset 0 0 0 2px rgba(255,255,255,.35); }
.icon-button:focus-visible, .pixel-button:focus-visible, .toggle-button:focus-visible, .target-button:focus-visible { outline: 3px solid white; outline-offset: 2px; }

.dialogue {
  position: absolute;
  z-index: 18;
  top: 82px;
  left: 10px;
  max-width: 200px;
  min-height: 34px;
  padding: 7px 9px;
  border: 2px solid #472614;
  border-radius: 8px 8px 8px 2px;
  background: rgba(255, 240, 194, .96);
  color: #392011;
  font-weight: 700;
  font-size: clamp(10px, 3vw, 13px);
  line-height: 1.2;
  box-shadow: 3px 4px rgba(30,11,5,.45);
  opacity: 0;
  transform: translateY(-5px);
  transition: opacity .15s, transform .15s;
  pointer-events: none;
}
.dialogue.is-visible { opacity: 1; transform: none; }
.dialogue[data-tone="good"] { border-color: #48702d; }
.dialogue[data-tone="oops"] { border-color: #9a3d39; }

.target-layer { position: absolute; z-index: 12; inset: 0; pointer-events: none; }
.target-button {
  position: absolute;
  left: calc(var(--x) / 384 * 100%);
  top: calc(var(--y) / 684 * 100%);
  width: calc(var(--w) / 384 * 100%);
  height: calc(var(--h) / 684 * 100%);
  min-height: 44px;
  border: 0;
  background: transparent;
  color: transparent;
  pointer-events: auto;
  cursor: pointer;
  border-radius: 5px;
}
.target-button:focus-visible, .target-button.is-selected { box-shadow: inset 0 0 0 3px var(--gold), 0 0 12px var(--gold); }

.overlay {
  position: absolute;
  z-index: 50;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 80px 16px 20px;
  background: linear-gradient(rgba(30,13,7,.22), rgba(16,7,4,.78));
  opacity: 0;
  visibility: hidden;
  transition: opacity .18s;
}
.overlay.is-visible { opacity: 1; visibility: visible; }

.panel {
  position: relative;
  width: min(350px, 100%);
  padding: 20px 17px 15px;
  text-align: center;
  border: 4px solid #241008;
  outline: 3px solid #c77a34;
  background:
    linear-gradient(rgba(255,255,255,.035), transparent 2px),
    linear-gradient(#4a2818, #25140e);
  box-shadow: inset 0 0 0 3px #7f4726, 0 12px 0 #130704, 0 18px 36px rgba(0,0,0,.6);
}

.panel__susan {
  display: block;
  width: 116px;
  height: 116px;
  margin: -9px auto 1px;
  object-fit: contain;
  image-rendering: pixelated;
  filter: drop-shadow(3px 4px 0 rgba(26, 9, 5, .68));
  pointer-events: none;
}
.panel__susan[hidden] { display: none; }

.panel__eyebrow { margin: 0 0 5px; color: #f4bd68; text-transform: uppercase; font-size: 10px; font-weight: 700; letter-spacing: .09em; }
.panel__title { margin: 0; color: #fff0d1; font: 900 clamp(25px, 8vw, 36px)/.94 Georgia, serif; text-shadow: 3px 3px #5c153f, -1px -1px #ff8fc3; }
.panel__title span { color: #ffb236; }
.panel__copy { max-width: 290px; margin: 13px auto; color: #f7e1bf; font-size: clamp(11px, 3.3vw, 14px); line-height: 1.45; white-space: pre-line; }
.panel__stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 12px 0; }
.stat-box { padding: 7px 5px; border: 2px solid #2a150d; background: #170d09; color: #dfb16c; font-size: 9px; text-transform: uppercase; }
.stat-box strong { display: block; margin-top: 2px; color: white; font-size: 15px; }
.instruction-strip { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px 9px; margin: 12px 0; color: #e8c994; font-size: 9px; }
.panel__actions { display: grid; gap: 7px; }
.pixel-button, .toggle-button {
  min-height: 44px;
  border: 2px solid #180b07;
  color: #fff4d9;
  background: linear-gradient(#6d3d25, #462313);
  box-shadow: inset 0 0 0 2px #9b5d36, 2px 3px #110704;
  font-weight: 900;
  cursor: pointer;
}
.pixel-button--primary { color: #2a1609; background: linear-gradient(#ffe36a, #e99a2d); box-shadow: inset 0 0 0 2px #fff1a7, 2px 3px #110704; }
.pixel-button:active, .toggle-button:active { transform: translate(1px, 2px); box-shadow: inset 0 0 0 2px rgba(255,255,255,.2); }
.sound-settings { display: flex; justify-content: center; gap: 7px; margin-top: 10px; }
.toggle-button { min-height: 32px; padding: 5px 9px; font-size: 9px; }
.toggle-button[aria-pressed="false"] { opacity: .58; }
.panel__best { margin: 11px 0 0; color: #b99c7c; font-size: 9px; }

.toast {
  position: absolute;
  z-index: 32;
  left: 50%;
  bottom: 80px;
  translate: -50% 10px;
  padding: 8px 13px;
  color: var(--gold);
  background: #160c08;
  border: 2px solid #8a5229;
  font-weight: 900;
  font-size: 13px;
  opacity: 0;
  transition: .18s;
  pointer-events: none;
}
.toast.is-visible { opacity: 1; translate: -50% 0; }
.rotate-note { display: none; }
.sr-only { position: fixed; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@keyframes timePulse { 50% { transform: scale(1.08); } }

@media (orientation: landscape) and (max-height: 620px) {
  .rotate-note {
    display: block;
    position: fixed;
    z-index: 80;
    right: 10px;
    bottom: 8px;
    max-width: 150px;
    margin: 0;
    padding: 6px 8px;
    background: rgba(20,8,5,.85);
    color: #e7bd7c;
    border: 1px solid #84502b;
    font-size: 9px;
    pointer-events: none;
  }
}

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