:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #111326;
}

* { box-sizing: border-box; }

html, body, #game-shell { width: 100%; height: 100%; margin: 0; overflow: hidden; }

body {
  background: #111326;
  color: #f6f7ff;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#game-shell {
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 48%, rgba(101, 245, 224, 0.11), transparent 43%),
    linear-gradient(145deg, #0a0b18, #141839 56%, #0d1025);
}

#stage {
  position: relative;
  width: min(100vw, 960px);
  height: min(56.25vw, 540px);
  overflow: hidden;
  background: #111326;
}

@media (orientation: landscape) {
  #stage {
    width: min(177.7778vh, 960px);
    height: min(100vh, 540px);
  }
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  outline: none;
}

#hud {
  position: absolute;
  left: 14px;
  top: 14px;
  display: grid;
  grid-template-columns: repeat(4, minmax(54px, 1fr));
  gap: 7px;
  pointer-events: none;
}

#hud div {
  min-width: 58px;
  border: 1px solid rgba(167, 255, 243, 0.24);
  background: rgba(10, 12, 30, 0.78);
  padding: 6px 8px;
  box-shadow: 0 7px 18px rgba(0, 0, 0, 0.18);
}

#hud span, #hud strong { display: block; }
#hud span { color: #a8b6d9; font-size: 9px; font-weight: 800; letter-spacing: 0.08em; }
#hud strong { color: #9dfff0; font-size: 15px; line-height: 1.05; }

#action-controls {
  position: absolute;
  right: 14px;
  top: 14px;
  display: flex;
  gap: 7px;
}

#action-controls button, .result-actions button {
  min-width: 38px;
  min-height: 38px;
  border: 1px solid rgba(181, 196, 255, 0.36);
  background: rgba(11, 14, 35, 0.86);
  color: #eff2ff;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

#action-controls button:hover, .result-actions button:hover { background: rgba(100, 245, 224, 0.18); }

#touch-controls {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: flex;
  gap: 8px;
}

.direction-button {
  min-width: 94px;
  min-height: 47px;
  border: 1px solid rgba(157, 255, 240, 0.44);
  background: rgba(11, 17, 39, 0.9);
  color: #dffefa;
  font: inherit;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow: inset 0 0 18px rgba(83, 234, 213, 0.08);
}

.direction-button[data-active="true"], .direction-button:active { background: rgba(83, 234, 213, 0.28); transform: translateY(1px); }

.panel {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(85%, 470px);
  transform: translate(-50%, -50%);
  border: 1px solid rgba(161, 255, 241, 0.42);
  background: rgba(9, 12, 29, 0.93);
  padding: 25px 28px;
  text-align: center;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.44), inset 0 0 55px rgba(70, 222, 202, 0.05);
}

.panel.compact { width: min(74%, 300px); }
.panel h1, .panel h2 { margin: 5px 0 12px; color: #f8f9ff; font-size: clamp(24px, 4vw, 38px); }
.panel p { margin: 9px auto; color: #c4cee7; line-height: 1.5; }
.status-label { color: #95ffef !important; font-size: 11px; font-weight: 900; letter-spacing: 0.13em; }
.controls-copy { color: #8fa2c9 !important; font-size: 13px; }
.best-result { color: #f7d481 !important; font-weight: 700; }

button.primary {
  min-height: 45px;
  margin-top: 9px;
  border: 0;
  background: #91ffec;
  color: #081322;
  padding: 0 18px;
  font: inherit;
  font-size: 14px;
  font-weight: 900;
  cursor: pointer;
}

button.primary:hover { background: #c4fff6; }
.result-actions { display: flex; justify-content: center; gap: 8px; margin-top: 15px; }
.result-actions .primary { margin-top: 0; }
.result-actions button[hidden] { display: none; }

#toast {
  position: absolute;
  left: 50%;
  bottom: 22px;
  max-width: min(76%, 420px);
  transform: translateX(-50%);
  border: 1px solid rgba(150, 255, 239, 0.36);
  background: rgba(6, 9, 22, 0.92);
  color: #b9fff5;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 800;
  text-align: center;
  pointer-events: none;
}

body[data-game-state="ready"] #hud,
body[data-game-state="ready"] #action-controls,
body[data-game-state="ready"] #touch-controls,
body[data-game-state="over"] #hud { opacity: 0.42; }

body[data-game-state="over"] #touch-controls { pointer-events: none; opacity: 0.2; }

@media (max-width: 640px) {
  #hud { left: 8px; top: 8px; gap: 4px; }
  #hud div { min-width: 46px; padding: 4px 5px; }
  #hud span { font-size: 7px; }
  #hud strong { font-size: 12px; }
  #action-controls { right: 8px; top: 8px; gap: 4px; }
  #action-controls button { min-width: 34px; min-height: 34px; }
  #touch-controls { left: 8px; right: 8px; bottom: 8px; justify-content: space-between; }
  .direction-button { min-width: 43%; min-height: 45px; }
  .panel { padding: 18px 16px; }
  .panel h1, .panel h2 { font-size: 24px; }
  .panel p { font-size: 13px; }
}

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