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

* { box-sizing: border-box; }

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

body {
  background: #07181c;
  color: #f0fff7;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#game-shell { display: grid; place-items: center; background: #07181c; }

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

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

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
}

#game-canvas:focus-visible { outline: 3px solid #f7d46a; outline-offset: -3px; }

button {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid rgba(97, 231, 208, 0.72);
  border-radius: 6px;
  background: #12353b;
  color: #f0fff7;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:hover, button:focus-visible { border-color: #f7d46a; color: #fff3ba; outline: none; }
button:active { background: #1e5259; transform: translateY(1px); }
button.primary { border-color: #f7d46a; background: #f7d46a; color: #102126; }

#hud {
  position: absolute;
  inset: 18px 156px auto 22px;
  z-index: 3;
  display: flex;
  gap: 24px;
  pointer-events: none;
}

#hud div { min-width: 68px; }
#hud span, #hud strong { display: block; letter-spacing: 0; }
#hud span {
  color: #9bc8c0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  font-weight: 800;
}
#hud strong { margin-top: 2px; color: #f0fff7; font-size: 20px; line-height: 1; }
#best-value { color: #f7d46a; }

#action-controls {
  position: absolute;
  top: 16px;
  right: 18px;
  z-index: 4;
  display: flex;
  gap: 8px;
}

#action-controls button { font-size: 13px; }

.panel {
  position: absolute;
  inset: 50% auto auto 50%;
  z-index: 7;
  width: min(440px, calc(100% - 32px));
  transform: translate(-50%, -50%);
  padding: 24px;
  border: 1px solid #61e7d0;
  border-radius: 8px;
  background: rgba(7, 24, 28, 0.97);
  text-align: center;
}

.panel.compact { width: min(340px, calc(100% - 32px)); }
.panel[hidden], #toast[hidden] { display: none; }
.status-label {
  margin: 0;
  color: #61e7d0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  font-weight: 850;
}
.panel h1, .panel h2 {
  margin: 8px 0;
  color: #f0fff7;
  font-size: 30px;
  letter-spacing: 0;
  line-height: 1.1;
}
.panel p { margin: 0; color: #c7ded8; font-size: 14px; line-height: 1.5; }
.panel .controls-copy, .panel .best-result { margin-top: 8px; color: #f7d46a; }
.panel > .primary, .result-actions { margin-top: 20px; }
.panel > .primary { min-width: 178px; padding: 0 16px; }
.result-actions { display: flex; justify-content: center; gap: 10px; }
.result-actions button { min-width: 156px; padding: 0 14px; }
.result-actions #share-result-button { min-width: 44px; padding: 0; font-size: 13px; }

#touch-controls {
  position: absolute;
  right: 20px;
  bottom: 16px;
  z-index: 5;
  display: grid;
  justify-items: center;
  gap: 5px;
}

.control-row { display: grid; grid-template-columns: repeat(3, 46px); gap: 5px; }
#touch-controls > .direction-button { width: 46px; }
.direction-button, .rotate-button {
  min-width: 46px;
  min-height: 42px;
  padding: 0 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 9px;
}
.rotate-button { font-size: 10px; }

#toast {
  position: absolute;
  left: 50%;
  bottom: 22px;
  z-index: 9;
  transform: translateX(-50%);
  margin: 0;
  padding: 9px 14px;
  border: 1px solid #f7d46a;
  border-radius: 5px;
  background: #1f4548;
  color: #f0fff7;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

@media (max-width: 640px) {
  #hud { inset: 10px 116px auto 12px; gap: 10px; }
  #hud div { min-width: 42px; }
  #hud span { font-size: 7px; }
  #hud strong { font-size: 14px; }
  #action-controls { top: 8px; right: 10px; gap: 5px; }
  #action-controls button { min-width: 34px; min-height: 34px; }
  #touch-controls { right: 8px; bottom: 8px; gap: 3px; }
  .control-row { grid-template-columns: repeat(3, 34px); gap: 3px; }
  #touch-controls > .direction-button, .direction-button, .rotate-button { min-width: 34px; min-height: 32px; font-size: 7px; }
  .rotate-button { font-size: 8px; }
  .panel { padding: 16px; }
  .panel h1, .panel h2 { font-size: 22px; }
  .panel p { font-size: 12px; }
  .panel > .primary { min-width: 152px; }
  #toast { bottom: 8px; max-width: calc(100% - 16px); font-size: 10px; }
}

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