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

* { box-sizing: border-box; }

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

body {
  background: #0d1427;
  color: #f4f7fc;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#game-shell {
  display: grid;
  place-items: center;
  background: #0a1020;
}

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

@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(120, 221, 215, 0.28);
  background: rgba(8, 15, 32, 0.84);
  padding: 6px 8px;
}

#hud span, #hud strong { display: block; }
#hud span { color: #a5b8cf; font-size: 9px; font-weight: 800; letter-spacing: 0.08em; }
#hud strong { color: #8eece1; 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(175, 196, 229, 0.38);
  background: rgba(8, 15, 32, 0.9);
  color: #f4f7fc;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

#action-controls button:hover, .result-actions button:hover { background: rgba(52, 137, 162, 0.44); }

#shift-controls {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
}

.shift-button {
  min-width: 174px;
  min-height: 56px;
  border: 1px solid rgba(126, 238, 223, 0.62);
  background: rgba(9, 25, 45, 0.94);
  color: #ecfffb;
  font: inherit;
  cursor: pointer;
}

.shift-button span, .shift-button strong { display: block; }
.shift-button span { color: #a5c7d6; font-size: 10px; font-weight: 800; letter-spacing: 0.11em; }
.shift-button strong { margin-top: 2px; color: #91f4e5; font-size: 16px; letter-spacing: 0.05em; }
.shift-button[data-polarity="1"] { border-color: rgba(255, 202, 111, 0.78); background: rgba(51, 37, 19, 0.94); }
.shift-button[data-polarity="1"] strong { color: #ffd28b; }
.shift-button:active { transform: translateY(1px); }

.panel {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(85%, 470px);
  transform: translate(-50%, -50%);
  border: 1px solid rgba(125, 230, 217, 0.46);
  background: rgba(7, 15, 31, 0.95);
  padding: 25px 28px;
  text-align: center;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.42);
}

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

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

button.primary:hover { background: #c0fff5; }
.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: 82px;
  max-width: min(76%, 420px);
  transform: translateX(-50%);
  border: 1px solid rgba(129, 235, 222, 0.42);
  background: rgba(7, 15, 31, 0.95);
  color: #b9fff4;
  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"] #shift-controls,
body[data-game-state="over"] #hud { opacity: 0.42; }

body[data-game-state="over"] #shift-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; }
  #shift-controls { bottom: 8px; }
  .shift-button { min-width: 164px; min-height: 50px; }
  .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; }
}
