:root {
  color-scheme: light;
  --bg: #e9edf5;
  --panel: rgba(250, 251, 253, 0.78);
  --panel-solid: #f7f9fc;
  --board: #edf2f8;
  --border: rgba(255, 255, 255, 0.86);
  --text: #24314b;
  --muted: #66738f;
  --accent: #00e6d0;
  --accent-two: #6755ff;
  --danger: #ff6b73;
  --control: rgba(223, 227, 235, 0.72);
  --shadow: 0 25px 80px rgba(58, 71, 99, 0.13);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  transition: color 220ms ease, background 220ms ease;
}

body.dark-mode {
  color-scheme: dark;
  --bg: #080d17;
  --panel: rgba(20, 25, 37, 0.84);
  --panel-solid: #141925;
  --board: #0b111c;
  --border: rgba(173, 188, 221, 0.16);
  --text: #f6f8ff;
  --muted: #8f9bb5;
  --control: rgba(255, 255, 255, 0.055);
  --shadow: 0 25px 80px rgba(0, 0, 0, 0.32);
}

button { font: inherit; }

.ambient {
  position: fixed;
  width: 420px;
  height: 420px;
  border-radius: 50%;
  filter: blur(115px);
  opacity: 0.22;
  pointer-events: none;
}
.ambient--violet { top: -110px; left: -130px; background: #5843e6; }
.ambient--coral { right: -120px; bottom: -100px; background: #e85965; opacity: 0.2; }
.ambient--cyan { right: -220px; bottom: -130px; background: #00dcca; opacity: 0.14; }
.ambient { opacity: 0.09; }
body.dark-mode .ambient { opacity: 0.22; }

.app-shell {
  position: relative;
  z-index: 1;
  width: min(488px, calc(100% - 28px));
  margin: 0 auto;
  padding: 16px 0 28px;
}

.glass-panel {
  border: 1px solid var(--border);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 74px;
  padding: 13px 20px 13px 24px;
  border-radius: 16px;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand__logo { width: 31px; height: 31px; fill: none; stroke: var(--accent); stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 3px 7px rgba(0, 230, 208, 0.3)); }
.brand__logo circle { fill: #ffd550; stroke: none; }
h1 { margin: 0; color: #4871ff; font-size: 19px; font-weight: 800; letter-spacing: -0.03em; }
h1 span { color: var(--accent); }

.scoreboard { display: flex; gap: 22px; }
.score { text-align: center; }
.score span { display: block; margin-bottom: 1px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; }
.score strong { color: var(--accent); font-size: 21px; line-height: 1; }

.game-board {
  margin-top: 12px;
  padding: 0;
  overflow: hidden;
  border-radius: 16px;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--board);
  touch-action: none;
}

canvas { display: block; width: 100%; height: 100%; opacity: 0.94; }

.start-screen, .pause-screen, .game-over {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 28px;
  text-align: center;
  background: rgba(7, 12, 22, 0.66);
  backdrop-filter: blur(3px);
  transition: opacity 180ms ease, visibility 180ms ease;
}
.start-screen,
.pause-screen,
.game-over { background: rgba(235, 241, 248, 0.69); }
body.dark-mode .start-screen,
body.dark-mode .pause-screen,
body.dark-mode .game-over { background: rgba(7, 12, 22, 0.66); }

.start-screen__mark { width: 48px; height: 48px; margin-bottom: 12px; fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.start-screen h2, .pause-screen p, .game-over h2 { margin: 0; letter-spacing: -0.045em; }
.start-screen h2 { font-size: 28px; }
.start-screen > p { margin: 7px 0 18px; color: var(--muted); font-size: 14px; }
.start-screen small { margin-top: 12px; color: var(--muted); font-size: 11px; }

.difficulty { display: flex; gap: 5px; margin-bottom: 18px; padding: 4px; border: 1px solid var(--border); border-radius: 12px; background: var(--control); }
.difficulty__button { min-width: 68px; padding: 7px 9px; border: 0; border-radius: 8px; color: var(--muted); background: transparent; cursor: pointer; font-size: 11px; font-weight: 800; }
.difficulty__button.is-active { color: #082d2a; background: var(--accent); }

.pause-screen { gap: 20px; }
.pause-screen p { font-size: 28px; font-weight: 800; }

.game-over h2 { color: var(--danger); font-size: 29px; font-weight: 900; }
.game-over > p:not(.new-best) { margin: 8px 0 24px; color: var(--muted); font-size: 14px; }
.final-score { min-width: 144px; padding: 17px 22px 19px; border: 1px solid var(--border); border-radius: 13px; background: var(--control); }
.final-score span { display: block; margin-bottom: 9px; color: var(--muted); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }
.final-score strong { color: var(--accent); font-size: 39px; line-height: 1; }
.new-best { margin: 10px 0 0; color: var(--accent); font-size: 12px; font-weight: 800; }
.game-over .button { min-width: 144px; margin-top: 24px; }

.button {
  min-height: 44px;
  padding: 11px 24px;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 800;
  transition: transform 130ms ease, filter 130ms ease;
}
.button--primary { color: #fff; background: linear-gradient(110deg, #0bcaba, #1fc8db 48%, #6755ff); box-shadow: 0 10px 22px rgba(0, 224, 211, 0.2); }
.button:hover { filter: brightness(1.08); transform: translateY(-1px); }

.game-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 66px;
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 16px;
}

.toolbar-button {
  display: grid;
  width: 44px;
  height: 44px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--muted);
  background: var(--control);
  cursor: pointer;
  transition: color 130ms ease, background 130ms ease, transform 130ms ease;
}
.toolbar-button svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.toolbar-button:hover:not(:disabled) { color: var(--accent); background: rgba(0, 230, 208, 0.09); transform: translateY(-1px); }
.toolbar-button:active:not(:disabled) { transform: scale(0.96); }
.toolbar-button:disabled { cursor: not-allowed; opacity: 0.42; }

.button:focus-visible, .toolbar-button:focus-visible, .control:focus-visible, .difficulty__button:focus-visible { outline: 3px solid rgba(0, 230, 208, 0.42); outline-offset: 2px; }
.is-hidden { opacity: 0 !important; visibility: hidden !important; pointer-events: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.mobile-controls { display: none; grid-template: repeat(2, 48px) / repeat(3, 48px); justify-content: center; gap: 7px; margin-top: 12px; }
.control { border: 1px solid var(--border); border-radius: 12px; color: var(--muted); background: var(--panel); font-size: 19px; touch-action: manipulation; }
.control--up { grid-area: 1 / 2; }
.control--left { grid-area: 2 / 1; }
.control--down { grid-area: 2 / 2; }
.control--right { grid-area: 2 / 3; }

@media (max-width: 540px) {
  .app-shell { width: min(100% - 20px, 488px); padding-top: 10px; }
  .topbar { min-height: 66px; padding: 11px 14px; }
  .brand { gap: 7px; }
  .brand__logo { width: 27px; height: 27px; }
  h1 { font-size: 17px; }
  .scoreboard { gap: 13px; }
  .score strong { font-size: 19px; }
  .game-over h2 { font-size: 26px; }
  .mobile-controls { display: grid; }
}

@media (max-width: 380px) {
  .brand__logo { display: none; }
  h1 { font-size: 16px; }
  .scoreboard { gap: 10px; }
  .start-screen { padding: 18px; }
  .difficulty__button { min-width: 58px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; }
}
