:root {
  --bg: #08080e;
  --panel: #14141f;
  --accent: #f4d03f;
  --accent2: #e8788a;
  --text: #e8e6d8;
  --dim: #8a8a9a;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Press Start 2P', 'Courier New', ui-monospace, monospace;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hidden {
  display: none !important;
}

#hud {
  width: 100%;
  max-width: 560px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  font-size: 13px;
  flex-wrap: wrap;
}

.hud-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.hud-label {
  color: var(--dim);
  font-size: 10px;
  text-transform: uppercase;
}

#battery-bar {
  width: 90px;
  height: 10px;
  border: 2px solid var(--dim);
  border-radius: 3px;
  padding: 1px;
}

#battery-fill {
  height: 100%;
  background: #3ecf5a;
  width: 100%;
  transition: width 0.3s linear;
}

#battery-box.low #battery-fill {
  background: #e04f4f;
  animation: blink 0.6s steps(2) infinite;
}

body.reduce-motion #battery-fill,
body.reduce-motion #battery-box.low #battery-fill,
body.reduce-motion #toast {
  animation: none;
}

@keyframes blink {
  50% { opacity: 0.4; }
}

.hud-btn {
  margin-left: auto;
  background: var(--panel);
  color: var(--text);
  border: 2px solid var(--dim);
  border-radius: 4px;
  font-family: inherit;
  font-size: 14px;
  padding: 4px 10px;
  cursor: pointer;
}

.hud-btn + .hud-btn {
  margin-left: 0;
}

#stage {
  position: relative;
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  min-height: 0;
}

#game {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 448 / 496;
  background: #0e0e15;
  border: 2px solid #1e2033;
  border-radius: 4px;
}

#dpad {
  position: absolute;
  left: 12px;
  bottom: 12px;
  width: 150px;
  height: 150px;
  opacity: 0.55;
}

.dpad-btn {
  position: absolute;
  width: 50px;
  height: 50px;
  background: var(--panel);
  color: var(--text);
  border: 2px solid var(--dim);
  border-radius: 8px;
  font-size: 16px;
  touch-action: none;
}

.dpad-up { left: 50px; top: 0; }
.dpad-down { left: 50px; bottom: 0; }
.dpad-left { left: 0; top: 50px; }
.dpad-right { right: 0; top: 50px; }

#btn-turbo {
  position: absolute;
  right: 16px;
  bottom: 24px;
  width: 74px;
  height: 74px;
  border-radius: 50%;
  background: rgba(217, 79, 79, 0.75);
  border: 2px solid #ffb0b0;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  touch-action: none;
}

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--bg);
  padding: 20px;
  text-align: center;
  z-index: 10;
  overflow-y: auto;
}

.screen.overlay {
  background: rgba(8, 8, 14, 0.88);
}

.screen h2 {
  color: var(--accent);
  font-size: 24px;
  letter-spacing: 2px;
  text-shadow: 3px 3px 0 #3a3010;
}

.logo {
  image-rendering: pixelated;
  width: min(336px, 80vw);
}

.subtitle {
  color: var(--accent2);
  font-size: 13px;
  letter-spacing: 1px;
}

.branding {
  color: var(--text);
  font-size: 12px;
}

.marquee {
  width: min(448px, 92vw);
  image-rendering: pixelated;
}

.story {
  max-width: 440px;
  font-size: 11px;
  line-height: 1.8;
  color: var(--dim);
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.menu-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 100%;
}

.rounds-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.rounds-label {
  font-size: 13px;
  color: var(--accent);
  min-width: 110px;
}

.btn {
  background: var(--panel);
  color: var(--text);
  border: 2px solid var(--accent);
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  padding: 12px 18px;
  cursor: pointer;
  box-shadow: 0 3px 0 #3a3010;
}

.btn:active {
  transform: translateY(2px);
  box-shadow: none;
}

.btn.primary {
  background: var(--accent);
  color: #1a1505;
  font-weight: bold;
}

.btn.small {
  font-size: 11px;
  padding: 10px 12px;
}

.credits {
  font-size: 10px;
  color: var(--dim);
}

.flavor {
  font-size: 13px;
  line-height: 1.8;
  color: var(--text);
  max-width: 440px;
}

.stats {
  font-size: 13px;
  line-height: 2;
  color: var(--accent);
}

.win-title {
  color: var(--accent2) !important;
}

.howto {
  max-width: 480px;
  font-size: 12px;
  line-height: 1.9;
  text-align: left;
  color: var(--text);
}

.howto p {
  margin-bottom: 12px;
}

.board {
  list-style: none;
  font-size: 13px;
  min-width: min(360px, 86vw);
}

.board li {
  display: flex;
  gap: 10px;
  padding: 7px 4px;
  border-bottom: 1px solid #22222f;
}

.board .rank {
  color: var(--accent);
  width: 28px;
  text-align: right;
}

.board .name {
  flex: 1;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board .pts {
  color: var(--dim);
}

.board .board-note {
  color: var(--dim);
  font-size: 11px;
  justify-content: center;
}

.name-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.name-form label {
  font-size: 11px;
  color: var(--dim);
}

.name-form input {
  font-family: inherit;
  font-size: 16px;
  background: var(--panel);
  border: 2px solid var(--accent);
  border-radius: 6px;
  color: var(--text);
  padding: 10px;
  width: min(260px, 70vw);
  text-align: center;
}

#toast {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 2px solid var(--accent);
  border-radius: 6px;
  color: var(--accent);
  font-size: 12px;
  padding: 10px 16px;
  z-index: 20;
  animation: pop 0.2s ease-out;
}

@keyframes pop {
  from { transform: translateX(-50%) scale(0.7); opacity: 0; }
  to { transform: translateX(-50%) scale(1); opacity: 1; }
}

.gate-error {
  color: #e8788a;
  font-size: 12px;
}

.shake {
  animation: shake 0.35s linear;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

@media (max-width: 480px) {
  #hud {
    font-size: 11px;
    gap: 8px;
    padding: 6px 8px;
  }
  #battery-bar {
    width: 64px;
  }
  .screen h2 {
    font-size: 18px;
  }
  .btn.small {
    font-size: 10px;
    padding: 9px 9px;
  }
  .story {
    display: none;
  }
}
