:root {
  --bg: #070b12;
  --panel: #0b111a;
  --ink: #e8f0f7;
  --muted: #748394;
  --line: #243241;
  --cyan: #64e6e0;
  --orange: #ffb45c;
  --red: #ff6b7a;
}

[data-theme="light"] {
  --bg: #faf8ef;
  --panel: #f1eee7;
  --ink: #3e3934;
  --muted: #8b8177;
  --line: #d8d0c5;
  --cyan: #0288d1;
  --orange: #f77f00;
  --red: #e63946;
}

* { box-sizing: border-box; }

html,body{margin:0;min-height:100%;background:var(--bg);color:var(--ink);font-family:ui-monospace,SFMono-Regular,Consolas,monospace;overscroll-behavior:none}

body {
  display: flex;
  justify-content: center;
}

button, a {
  -webkit-tap-highlight-color: transparent;
}

.page {
  width: min(480px, 100%);
  padding: 18px 15px calc(20px + env(safe-area-inset-bottom));
}

header.topbar {
  min-height: 45px;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

header h1 {
  font-size: 19px;
  letter-spacing: .14em;
  margin: 0;
  white-space: nowrap;
}

header a, header button {
  border: 0;
  background: none;
  color: var(--muted);
  font: 10px inherit;
  letter-spacing: .1em;
  text-decoration: none;
  min-height: 44px;
  cursor: pointer;
  display: flex;
  align-items: center;
}

.header-actions {
  display: flex;
  justify-content: flex-end;
  gap: 11px;
}

.sound.on {
  color: var(--cyan);
}

.game-wrap {
  margin: auto;
  width: 100%;
}

.hud {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 7px;
  margin-bottom: 8px;
}

.hud > div {
  border: 1px solid var(--line);
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: var(--panel);
  font-size: 9px;
  color: var(--muted);
  letter-spacing: .08em;
}

.hud b {
  font-size: 11px;
  color: var(--cyan);
  letter-spacing: .05em;
}

.hud > div:nth-child(2) { text-align: center; }
.hud > div:last-child { text-align: right; }

.screen-frame{
  position: relative;
  width: min(100%, calc((100svh - 190px)*20/27), 480px);
  margin: 0 auto;
  border: 1px solid var(--line);
  background: #111b26;
  box-shadow: 5px 5px #030609;
  line-height: 0;
  touch-action:none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout:none;
}

[data-theme="light"] .screen-frame {
  background: #e6dfd3;
  box-shadow: 5px 5px #d3cab8;
}

.screen-frame canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio:20/27;
  background: #080d15;
  touch-action:none;
}

[data-theme="light"] .screen-frame canvas {
  background: #f7f4ec;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(5, 9, 16, 0.88);
  z-index: 4;
  line-height: 1.3;
}

[data-theme="light"] .overlay {
  background: rgba(245, 241, 232, 0.92);
}

.overlay.hidden {
  display: none;
}

.intro {
  text-align: center;
  padding: 18px;
}

.intro .eyebrow {
  font-size: 9px;
  color: var(--muted);
  letter-spacing: .16em;
  margin: 0 0 6px;
}

.intro h1 {
  font-size: 28px;
  line-height: 1;
  margin: 0 0 8px;
  letter-spacing: .12em;
}

.intro h1 em {
  font-style: normal;
  color: var(--cyan);
}

.intro .hint {
  font-size: 9px;
  color: var(--muted);
  letter-spacing: .08em;
  margin: 0 0 16px;
}

.intro .start {
  border: 0;
  background: var(--cyan);
  color: #06110c;
  font: 700 11px inherit;
  letter-spacing: .12em;
  min-height: 44px;
  padding: 12px 24px;
  box-shadow: 3px 3px #185a75;
  cursor: pointer;
}

[data-theme="light"] .intro .start {
  background: #0288d1;
  color: #fff;
  box-shadow: 3px 3px #01579b;
}

.intro .best {
  font-size: 10px;
  color: var(--muted);
  margin: 12px 0 0;
  letter-spacing: .1em;
}

.intro .best strong {
  color: var(--ink);
}

.mobile-controls {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.mobile-controls button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  min-height: 44px;
  font: 700 12px inherit;
  cursor: pointer;
  touch-action:none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout:none;
}

.mobile-controls button:active {
  background: var(--line);
}

footer {
  margin-top: 14px;
  text-align: center;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: .08em;
  line-height: 1.5;
}

@media (max-width: 480px) {
  .page { padding: 12px 10px max(18px, env(safe-area-inset-bottom)); }
  header.topbar { min-height: 40px; margin-bottom: 10px; }
  header h1 { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0s !important; }
}
