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

* { box-sizing: border-box; }

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

body {
  background: #100d24;
  color: #fff7ff;
  touch-action: manipulation;
  user-select: none;
}

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

#stage {
  position: relative;
  width: 100vw;
  height: 56.25vw;
  max-width: 100vw;
  max-height: 100vh;
  overflow: hidden;
  background: #100d24;
  touch-action: none;
}

@media (orientation: landscape) {
  #stage {
    width: 177.7778vh;
    height: 100vh;
  }
}

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

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

button {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid #5c487e;
  border-radius: 6px;
  background: #251a44;
  color: #fff7ff;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:hover,
button:focus-visible { border-color: #ffb2e5; color: #ffb2e5; outline: none; }
button:active { background: #3b2a62; transform: translateY(1px); }

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

#hud div { min-width: 78px; }
#hud span,
#hud strong { display: block; letter-spacing: 0; }
#hud span {
  color: #cabfe1;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  font-weight: 800;
}
#hud strong { margin-top: 2px; color: #fff7ff; font-size: 20px; line-height: 1; }
#energy-value { color: #ffd36d; }

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

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

#pad-controls {
  position: absolute;
  left: 50%;
  bottom: 20px;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(3, 104px);
  gap: 10px;
  transform: translateX(-50%);
}

.pad-button {
  display: grid;
  min-width: 0;
  width: 104px;
  height: 58px;
  place-items: center;
  border-color: #ffb2e5;
  background: #30204f;
}
.pad-button span { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }
.pad-button small { color: #cabfe1; font-size: 9px; font-weight: 800; }
.pad-button.left { border-color: #72e2ff; }
.pad-button.middle { border-color: #ffb2e5; }
.pad-button.right { border-color: #b8f48d; }
.pad-button[data-active="true"] { color: #100d24; }
.pad-button.left[data-active="true"] { background: #72e2ff; }
.pad-button.middle[data-active="true"] { background: #ffb2e5; }
.pad-button.right[data-active="true"] { background: #b8f48d; }
.pad-button[data-active="true"] small { color: #100d24; }

.panel {
  position: absolute;
  inset: 50% auto auto 50%;
  z-index: 7;
  width: min(450px, calc(100% - 32px));
  transform: translate(-50%, -50%);
  padding: 24px;
  border: 1px solid #ffb2e5;
  border-radius: 8px;
  background: rgba(16, 13, 36, 0.98);
  text-align: center;
}

.panel.compact { width: min(340px, calc(100% - 32px)); }
.panel[hidden], #toast[hidden], .result-actions button[hidden] { display: none; }
.status-label {
  margin: 0;
  color: #ffb2e5;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  font-weight: 850;
}
.panel h1,
.panel h2 {
  margin: 8px 0;
  color: #fff7ff;
  font-size: 30px;
  letter-spacing: 0;
  line-height: 1.1;
}
.panel p { margin: 0; color: #ddd2ef; font-size: 14px; line-height: 1.5; }
.panel .controls-copy,
.panel .best-result { margin-top: 8px; color: #ffd36d; }
.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: 138px; padding: 0 14px; }
.result-actions #share-result-button { min-width: 44px; padding: 0; font-size: 13px; }
button.primary { border-color: #ffb2e5; background: #ffb2e5; color: #100d24; }

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

body[data-game-state="ready"] #hud,
body[data-game-state="ready"] #action-controls,
body[data-game-state="ready"] #pad-controls,
body[data-game-state="over"] #action-controls,
body[data-game-state="over"] #pad-controls,
body[data-game-state="paused"] #action-controls,
body[data-game-state="paused"] #pad-controls,
body[data-game-state="complete"] #action-controls,
body[data-game-state="complete"] #pad-controls {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

body[data-alert="true"] #energy-value { color: #ff7f99; }

@media (max-width: 700px), (max-height: 390px) {
  button { min-width: 32px; min-height: 32px; border-radius: 4px; }
  #hud { inset: 9px 82px auto 10px; gap: 10px; }
  #hud div { min-width: 44px; }
  #hud span { font-size: 6px; }
  #hud strong { font-size: 12px; }
  #action-controls { top: 8px; right: 8px; gap: 4px; }
  #action-controls button { font-size: 9px; }
  #pad-controls { bottom: 9px; grid-template-columns: repeat(3, 82px); gap: 7px; }
  .pad-button { width: 82px; height: 48px; }
  .pad-button span { font-size: 8px; }
  .pad-button small { font-size: 7px; }
  .panel, .panel.compact { width: min(360px, calc(100% - 20px)); padding: 12px; }
  .status-label { font-size: 8px; }
  .panel h1, .panel h2 { margin: 4px 0; font-size: 18px; }
  .panel p { font-size: 9px; }
  .panel > .primary, .result-actions { margin-top: 10px; }
  .panel > .primary, .result-actions button { min-width: 105px; min-height: 44px; padding: 0 8px; font-size: 9px; }
  .result-actions #share-result-button { min-width: 32px; padding: 0; font-size: 9px; }
  #toast { bottom: 62px; padding: 5px 9px; font-size: 8px; }
}

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