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

* {
  box-sizing: border-box;
}

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

body {
  background: #090d11;
  touch-action: none;
  user-select: none;
}

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

#stage {
  position: relative;
  width: min(100%, calc(100vh * 16 / 9));
  max-height: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #090d11;
}

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

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

button {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid #34414a;
  border-radius: 6px;
  background: rgba(18, 25, 31, 0.96);
  color: #f4f8f6;
  font: inherit;
  font-weight: 850;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:hover,
button:focus-visible {
  border-color: #75f0b5;
  color: #75f0b5;
  outline: none;
}

button:active {
  background: #1b2c2a;
  transform: translateY(1px);
}

button:disabled {
  cursor: default;
  opacity: 0.36;
}

#action-controls {
  position: absolute;
  right: 5.2%;
  top: 64.5%;
  z-index: 3;
  display: flex;
  gap: 8px;
}

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

#touch-controls {
  position: absolute;
  right: 4.4%;
  bottom: 5.5%;
  z-index: 3;
  display: grid;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(2, 46px);
  gap: 6px;
}

#touch-controls button {
  border-color: #465761;
  font-size: 20px;
}

#touch-controls .up {
  grid-column: 2;
  grid-row: 1;
}

#touch-controls .left {
  grid-column: 1;
  grid-row: 2;
}

#touch-controls .down {
  grid-column: 2;
  grid-row: 2;
}

#touch-controls .right {
  grid-column: 3;
  grid-row: 2;
}

.panel {
  position: absolute;
  inset: 50% auto auto 50%;
  z-index: 6;
  width: min(440px, calc(100% - 32px));
  transform: translate(-50%, -50%);
  padding: 24px;
  border: 1px solid #75f0b5;
  border-radius: 8px;
  background: rgba(9, 13, 17, 0.98);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.62);
  text-align: center;
}

.panel[hidden],
#toast[hidden] {
  display: none;
}

.panel .eyebrow {
  margin: 0;
  color: #75f0b5;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  font-weight: 850;
}

.panel h1 {
  margin: 8px 0;
  color: #f4f8f6;
  font-size: 30px;
  letter-spacing: 0;
  line-height: 1.1;
}

.panel p {
  margin: 0;
  color: #aebbc2;
  font-size: 14px;
  line-height: 1.5;
}

.result-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
}

.result-actions button {
  min-width: 150px;
  padding: 0 14px;
}

.result-actions .primary {
  border-color: #75f0b5;
  background: #75f0b5;
  color: #090d11;
}

#toast {
  position: absolute;
  left: 50%;
  bottom: 7%;
  z-index: 8;
  transform: translateX(-50%);
  padding: 9px 14px;
  border: 1px solid #75f0b5;
  border-radius: 5px;
  background: #12191f;
  color: #f4f8f6;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

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

@media (max-width: 700px), (max-height: 390px) {
  button {
    min-width: 30px;
    min-height: 30px;
    border-radius: 4px;
  }

  #action-controls {
    right: 4.7%;
    top: 62.8%;
    gap: 4px;
  }

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

  #touch-controls {
    right: 3.8%;
    bottom: 4%;
    grid-template-columns: repeat(4, 31px);
    grid-template-rows: 31px;
    gap: 4px;
  }

  #touch-controls button {
    font-size: 14px;
  }

  #touch-controls .left {
    grid-column: 1;
    grid-row: 1;
  }

  #touch-controls .up {
    grid-column: 2;
    grid-row: 1;
  }

  #touch-controls .down {
    grid-column: 3;
    grid-row: 1;
  }

  #touch-controls .right {
    grid-column: 4;
    grid-row: 1;
  }

  .panel {
    width: min(360px, calc(100% - 20px));
    padding: 12px;
  }

  .panel .eyebrow {
    font-size: 8px;
  }

  .panel h1 {
    margin: 4px 0;
    font-size: 18px;
  }

  .panel p {
    font-size: 9px;
  }

  .result-actions {
    gap: 6px;
    margin-top: 10px;
  }

  .result-actions button {
    min-width: 104px;
    min-height: 30px;
    padding: 0 8px;
    font-size: 9px;
  }

  #toast {
    bottom: 5%;
    padding: 5px 9px;
    font-size: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  button:active {
    transform: none;
  }
}
