:root {
  color-scheme: dark;
  --bg: #07090d;
  --panel: #10141c;
  --panel-2: #171d28;
  --line: #30394a;
  --text: #f5f7fa;
  --muted: #a9b1bf;
  --orange: #ff7a18;
  --orange-light: #ffad5c;
  --cyan: #47d7e8;
  --danger: #ff4d6d;
  font-family: "Courier New", ui-monospace, monospace;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background:
    linear-gradient(rgba(255, 122, 24, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 122, 24, .035) 1px, transparent 1px),
    radial-gradient(circle at 50% 0%, #1b202a 0, var(--bg) 55%);
  background-size: 32px 32px, 32px 32px, auto;
}
button { font: inherit; }
.shell { width: min(1180px, 100%); margin: 0 auto; padding: 18px; }
.topbar, .game-heading, .game-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.topbar { margin-bottom: 18px; }
.brand { display: flex; align-items: center; gap: 12px; letter-spacing: .08em; }
.brand-mark {
  display: grid; place-items: center; width: 46px; height: 46px;
  color: #111; background: var(--orange); border: 2px solid var(--orange-light);
  box-shadow: 6px 6px 0 #552707; font-weight: 900; font-size: 1.5rem;
}
.brand strong, .brand small { display: block; }
.brand small { color: var(--muted); margin-top: 4px; font-size: .75rem; }
.status { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px 18px; color: var(--muted); font-size: .88rem; }
.status strong { color: var(--orange-light); }
.status strong.is-warning { color: var(--danger); text-shadow: 0 0 12px rgba(255,77,109,.65); }
.game-frame { padding: 18px; background: rgba(16, 20, 28, .94); border: 1px solid var(--line); box-shadow: 10px 10px 0 rgba(0,0,0,.35); }
.desktop-notice {
  display: none; max-width: 720px; margin: 48px auto 0; padding: 36px;
  background: rgba(16, 20, 28, .96); border: 2px solid var(--orange); box-shadow: 8px 8px 0 #4f2509;
}
.desktop-notice h1 { font-size: clamp(1.8rem, 7vw, 3rem); }
.desktop-notice p:not(.eyebrow) { color: #d2d7df; font-size: 1rem; line-height: 1.65; }
.desktop-notice .desktop-notice-hint { color: var(--cyan); }
.shell:fullscreen {
  width: 100vw; max-width: none; height: 100vh; padding: 10px;
  overflow: hidden; display: flex; flex-direction: column; background: var(--bg);
}
.shell:fullscreen .topbar { flex: 0 0 auto; margin-bottom: 8px; }
.shell:fullscreen .game-frame {
  min-height: 0; flex: 1 1 auto; padding: 8px; overflow: hidden;
  display: flex; flex-direction: column; border: 0; box-shadow: none;
}
.shell:fullscreen .game-heading { flex: 0 0 auto; margin-bottom: 6px; }
.shell:fullscreen .game-heading { flex-direction: row; align-items: center; }
.shell:fullscreen .game-heading .eyebrow { display: none; }
.shell:fullscreen h1 { font-size: 1.65rem; }
.shell:fullscreen .toolbar button { min-height: 38px; padding: 6px 10px; }
.shell:fullscreen .screen-wrap {
  width: min(100%, calc((100vh - 150px) * 1.6)); height: auto;
  min-height: 0; flex: 0 0 auto; align-self: center; aspect-ratio: 16 / 10;
}
.shell:fullscreen .game-legend,
.shell:fullscreen .game-footer,
.shell:fullscreen .leaderboard { display: none; }
.shell:fullscreen .mobile-controls { flex: 0 0 auto; margin-top: 6px; }
.game-heading { margin-bottom: 14px; }
.eyebrow { margin: 0 0 6px; color: var(--orange-light); font-size: .78rem; letter-spacing: .14em; }
h1, h2 { margin: 0; line-height: 1; }
h1 { font-size: clamp(1.8rem, 5vw, 3.3rem); letter-spacing: .07em; }
h2 { font-size: clamp(1.45rem, 4vw, 2.4rem); }
.toolbar { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.toolbar button {
  min-height: 44px; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); cursor: pointer;
}
.toolbar button { padding: 10px 14px; }
.toolbar button:hover, .toolbar button:focus-visible { border-color: var(--orange); outline: 2px solid transparent; }
.toolbar button:disabled {
  color: #747c89; border-color: #252c38; cursor: not-allowed; opacity: .62;
}
.toolbar button:disabled:hover { border-color: #252c38; }
.screen-wrap { position: relative; overflow: hidden; aspect-ratio: 16 / 10; background: #080b10; border: 2px solid #3b4558; }
canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; touch-action: none; }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(4, 6, 10, .76); backdrop-filter: blur(3px); }
.overlay[hidden] { display: none; }
.game-message {
  position: absolute; top: 14px; left: 50%; z-index: 2; transform: translateX(-50%);
  max-width: calc(100% - 28px); padding: 9px 14px; color: #111;
  background: var(--cyan); border: 2px solid #baf7ff; box-shadow: 4px 4px 0 rgba(0,0,0,.55);
  font-weight: 900; text-align: center; pointer-events: none;
}
.game-message.is-danger { color: #fff; background: var(--danger); border-color: #ffb0be; }
.game-message.is-success { background: var(--orange); border-color: var(--orange-light); }
.game-message[hidden] { display: none; }
.overlay-panel { width: min(620px, 100%); padding: clamp(20px, 4vw, 38px); text-align: center; background: rgba(15, 20, 28, .96); border: 2px solid var(--orange); box-shadow: 8px 8px 0 #4f2509; }
.overlay-panel p:not(.eyebrow) { color: #d2d7df; line-height: 1.6; }
.score-form { margin: 18px auto; text-align: left; }
.score-form[hidden], .score-submit-status[hidden] { display: none; }
.score-form label { display: block; margin-bottom: 8px; color: var(--cyan); font-size: .86rem; font-weight: 900; }
.score-entry { display: flex; justify-content: center; gap: 8px; }
.score-entry input {
  width: 9rem; min-height: 48px; padding: 8px 12px; color: var(--text); background: #080b10;
  border: 2px solid var(--cyan); font: 900 1.35rem/1 "Courier New", monospace; letter-spacing: .14em; text-transform: uppercase;
}
.score-entry input:focus-visible { outline: 2px solid var(--orange-light); outline-offset: 2px; }
.score-entry button {
  min-height: 48px; padding: 8px 16px; color: #071012; background: var(--cyan); border: 2px solid #baf7ff; font-weight: 900; cursor: pointer;
}
.score-entry button:disabled { cursor: wait; opacity: .62; }
.score-form small { display: block; margin-top: 7px; color: var(--muted); font-size: .75rem; }
.score-submit-status { margin: 12px 0; color: var(--cyan) !important; font-weight: 900; }
.primary { min-height: 50px; padding: 12px 22px; color: #16100a; background: var(--orange); border: 2px solid var(--orange-light); font-weight: 900; cursor: pointer; box-shadow: 5px 5px 0 #622d08; }
.primary:hover, .primary:focus-visible { transform: translate(2px, 2px); box-shadow: 3px 3px 0 #622d08; }
.primary:disabled { cursor: wait; opacity: .62; transform: none; box-shadow: 3px 3px 0 #622d08; }
.game-footer { margin-top: 14px; color: var(--muted); font-size: .78rem; letter-spacing: .08em; }
.game-footer span:first-child { color: var(--cyan); }
.game-legend {
  display: flex; flex-wrap: wrap; gap: 10px 22px; margin-top: 12px;
  color: #c7ced9; font-size: .82rem; line-height: 1.45;
}
.game-legend span { display: inline-flex; align-items: center; gap: 8px; }
.game-legend i { width: 12px; height: 12px; flex: 0 0 12px; border: 2px solid rgba(255,255,255,.35); }
.legend-danger { background: var(--danger); }
.legend-bonus { background: var(--cyan); transform: rotate(45deg); }
.legend-checkpoint { background: var(--orange); }
.leaderboard { margin-top: 22px; padding: 18px; background: #0a0e14; border: 1px solid var(--line); }
.leaderboard-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; }
.leaderboard-heading h2 { font-size: 1.3rem; }
.leaderboard-heading > p { margin: 0; color: var(--muted); font-size: .78rem; text-align: right; }
.leaderboard-list {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px 18px;
  margin: 16px 0 0; padding: 0; list-style: none; counter-reset: leaderboard;
}
.leaderboard-list li {
  counter-increment: leaderboard; display: grid; grid-template-columns: 2.2rem 1fr auto; gap: 10px;
  padding: 8px 10px; color: var(--text); background: #111722; border-left: 3px solid var(--cyan);
}
.leaderboard-list li::before { content: counter(leaderboard, decimal-leading-zero); color: var(--muted); }
.leaderboard-list strong { color: var(--orange-light); }
.leaderboard-list .leaderboard-empty { display: block; grid-column: 1 / -1; color: var(--muted); text-align: center; border-left-color: var(--line); }
.leaderboard-list .leaderboard-empty::before { content: none; }
.leaderboard-status { min-height: 1em; margin: 10px 0 0; color: var(--danger); font-size: .78rem; }

@media (hover: none) and (pointer: coarse), (max-width: 820px) {
  body { min-width: 0; }
  .shell { padding: 16px; }
  .topbar { margin-bottom: 24px; }
  .status { display: none; }
  .game-frame { display: none; }
  .desktop-notice { display: block; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
