:root {
  color-scheme: dark;
  --ink: #f4f0e9;
  --muted: #9ba0b8;
  --panel: #202541;
  --line: rgba(205, 211, 246, .13);
  --mint: #8af0d0;
  font-family: 'Space Grotesk', 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

body {
  min-height: 100dvh;
  margin: 0;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  color: var(--ink);
  background:
    radial-gradient(ellipse at 50% 0%, rgba(97, 91, 161, .22), transparent 52%),
    #111427;
}

.shell { width: min(100%, 1024px); }
.topbar, .footer { display: flex; align-items: center; justify-content: space-between; }
.topbar { padding: 0 4px 18px; }
.brand { display: inline-flex; gap: 10px; align-items: center; color: var(--ink); text-decoration: none; font-size: 13px; letter-spacing: .16em; font-weight: 600; }
.brand b { color: var(--mint); font-weight: 600; }
.brand-mark { color: #ffd38e; font-size: 20px; text-shadow: 0 0 16px rgba(255, 211, 142, .55); }
.hud { display: flex; gap: 30px; }
.stat { display: grid; gap: 4px; min-width: 76px; text-align: right; font: 500 17px 'DM Mono', monospace; letter-spacing: .04em; }
.stat-label { color: var(--muted); font: 500 9px 'DM Mono', monospace; letter-spacing: .13em; }
.stat.best { color: #aeb7dc; }

.game-frame {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(209, 218, 255, .2);
  border-radius: 16px;
  background: #252747;
  box-shadow: 0 28px 90px rgba(0, 0, 0, .38), 0 2px 0 rgba(255, 255, 255, .05) inset;
  isolation: isolate;
  touch-action: none;
}
canvas { display: block; width: 100%; height: auto; aspect-ratio: 8 / 3; image-rendering: pixelated; touch-action: none; user-select: none; -webkit-user-select: none; }

.screen {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(90deg, rgba(19, 22, 48, .08), rgba(16, 18, 39, .45) 42%, rgba(16, 18, 39, .56));
  transition: opacity .2s ease, visibility .2s ease;
}
.screen.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.screen-card { width: min(390px, 90%); text-align: center; transform: translateY(-4px); }
.screen-icon { display: grid; place-items: center; width: 48px; height: 48px; margin: 0 auto 16px; border: 1px solid rgba(138, 240, 208, .3); border-radius: 14px; color: var(--mint); background: rgba(138, 240, 208, .09); box-shadow: 0 0 32px rgba(138, 240, 208, .11); font-size: 22px; }
.eyebrow { margin: 0 0 10px; color: var(--mint); font: 500 10px 'DM Mono', monospace; letter-spacing: .19em; }
h1 { margin: 0; font-size: clamp(25px, 4vw, 36px); line-height: 1.08; letter-spacing: -.045em; }
.screen-copy { max-width: 330px; margin: 13px auto 20px; color: #c1c4d8; font-size: 14px; line-height: 1.6; }
button { border: 0; border-radius: 8px; padding: 12px 18px; color: #14242c; background: var(--mint); font: 700 13px 'Space Grotesk', sans-serif; cursor: pointer; box-shadow: 0 5px 18px rgba(138, 240, 208, .2); transition: transform .15s ease, filter .15s ease; }
button:hover { transform: translateY(-2px); filter: brightness(1.08); }
button:active { transform: translateY(0); }
button:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
button span { padding-left: 10px; font-size: 17px; vertical-align: -1px; }
.key-hint { margin: 17px 0 0; color: #a5a9c0; font: 500 9px 'DM Mono', monospace; letter-spacing: .12em; }
kbd { border: 1px solid rgba(219, 224, 255, .22); border-bottom-width: 2px; border-radius: 4px; padding: 3px 6px; color: #e3e3ef; background: rgba(255, 255, 255, .06); font: 500 9px 'DM Mono', monospace; }

.footer { padding: 14px 5px 0; color: #9da2b9; font-size: 11px; }
.legend-dot { display: inline-block; width: 7px; height: 7px; margin: 0 7px 1px 0; border-radius: 2px; background: var(--mint); box-shadow: 0 0 9px rgba(138, 240, 208, .7); }
.controls { display: flex; align-items: center; gap: 6px; }
.touch-hint { display: none; }
.divider { margin: 0 4px; color: #606780; }

.touch-duck {
  position: absolute;
  z-index: 3;
  left: 14px;
  top: 14px;
  display: none;
  min-width: 76px;
  min-height: 54px;
  padding: 12px 15px;
  border: 1px solid rgba(190, 250, 231, .5);
  border-radius: 14px;
  color: #d8fff2;
  background: rgba(21, 31, 54, .72);
  box-shadow: 0 4px 18px rgba(0, 0, 0, .2);
  font: 700 11px 'DM Mono', monospace;
  letter-spacing: .12em;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
}
.touch-duck.is-pressed { color: #14242c; background: var(--mint); transform: translateY(1px); }

@media (pointer: coarse), (max-width: 700px) {
  .touch-duck { display: block; }
  .keyboard-hint { display: none; }
  .touch-hint { display: inline; }
}


@media (max-width: 700px) {
  body {
    height: 100dvh;
    min-height: 0;
    padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }
  .shell { width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: center; }
  .topbar { flex: 0 0 auto; padding-bottom: 10px; }
  .hud { gap: 15px; }
  .stat { min-width: auto; font-size: 14px; }
  .stat-label { font-size: 8px; }
  .brand { font-size: 10px; letter-spacing: .1em; }
  .brand-mark { font-size: 17px; }
  .game-frame { border-radius: 11px; }
  .screen-card { transform: none; }
  .screen-icon { width: 38px; height: 38px; margin-bottom: 10px; }
  .screen-copy { margin: 9px auto 14px; font-size: 12px; }
  .key-hint { margin-top: 12px; }
  .footer { align-items: center; gap: 8px; font-size: 9px; }
  .controls { text-align: right; justify-content: flex-end; }
  .game-frame { flex: 0 0 auto; }
}

@media (max-width: 900px) and (orientation: landscape) {
  body {
    height: 100dvh;
    min-height: 0;
    padding: max(5px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(5px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }
  .shell { width: 100%; height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
  .topbar { padding-bottom: 4px; }
  .game-frame { min-height: 0; display: flex; align-items: center; justify-content: center; }
  .game-frame canvas { width: auto; height: auto; max-width: 100%; max-height: 100%; aspect-ratio: 8 / 3; }
  .footer { padding-top: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
