:root {
  --bg-deep: #13252c;
  --bg-mid: #1a353f;
  --amber: #f0a04b;
  --teal: #3db8a0;
  --cream: #e8f0f2;
  --danger: #e85d4c;
  --panel: rgba(18, 36, 42, 0.92);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --font-display: "Nunito", system-ui, sans-serif;
  --font-ui: "Space Grotesk", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 20% 0%, #2a4a55 0%, transparent 50%),
    radial-gradient(ellipse at 90% 100%, #3a2e1c 0%, transparent 45%),
    linear-gradient(160deg, var(--bg-deep), var(--bg-mid));
  color: var(--cream);
  font-family: var(--font-ui);
  touch-action: none;
  user-select: none;
}

#app {
  height: 100%;
  max-width: 1100px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  gap: 8px;
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand-mark {
  display: block;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(1.4rem, 4vw, 2rem);
  letter-spacing: 0.04em;
  color: var(--amber);
  line-height: 1;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}

.brand-sub {
  font-size: 0.78rem;
  opacity: 0.7;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.stats {
  display: flex;
  gap: 14px;
  align-items: center;
}

.stat {
  text-align: right;
}

.stat-label {
  display: block;
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.55;
}

.stat-value {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.35rem;
  color: var(--teal);
}

.speed-value {
  color: var(--amber);
  transition: color 0.2s, text-shadow 0.2s;
}

.speed-value.hot {
  color: #ff6b4a;
  text-shadow: 0 0 12px rgba(255, 107, 74, 0.45);
}

.speed-max {
  font-size: 0.7em;
  opacity: 0.55;
  font-weight: 700;
  margin-left: 1px;
}

.lives {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
  min-height: 1.4rem;
  align-items: center;
}

.life {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: var(--danger);
  box-shadow: 0 0 0 2px rgba(232, 93, 76, 0.25);
  transition: transform 0.2s, opacity 0.2s;
}

.life.gone {
  opacity: 0.2;
  transform: scale(0.7);
}

.stage-wrap {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
}

#game {
  width: 100%;
  height: 100%;
  max-height: min(72vh, 640px);
  object-fit: contain;
  border-radius: 18px;
  box-shadow: var(--shadow);
  background: #0d1a1f;
  display: block;
}

.touch-pad {
  display: none;
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.touch-pad .zone {
  pointer-events: auto;
  position: absolute;
  width: 42%;
  height: 38%;
  border: 0;
  background: transparent;
  color: rgba(232, 240, 242, 0.35);
  font-family: var(--font-ui);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
}

.touch-pad .zone span {
  font-size: 1.1rem;
  font-weight: 700;
}

.touch-pad .zone small {
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.touch-pad .tl { top: 6%; left: 4%; }
.touch-pad .tr { top: 6%; right: 4%; }
.touch-pad .bl { bottom: 8%; left: 4%; }
.touch-pad .br { bottom: 8%; right: 4%; }

.hint {
  text-align: center;
  font-size: 0.78rem;
  opacity: 0.65;
  min-height: 1.4em;
}

.hint p { margin: 0; }

.mobile-hint { display: none; }

kbd {
  display: inline-block;
  padding: 1px 6px;
  margin: 0 2px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  font-size: 0.75rem;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 16, 20, 0.72);
  backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 20;
  opacity: 1;
  transition: opacity 0.25s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.panel {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid rgba(61, 184, 160, 0.25);
  border-radius: 22px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
  text-align: center;
  animation: rise 0.45s ease;
}

@keyframes rise {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.panel h1 {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 2.1rem;
  color: var(--amber);
}

.panel p {
  margin: 0 0 18px;
  line-height: 1.45;
  opacity: 0.85;
  font-size: 0.95rem;
}

.legend {
  list-style: none;
  margin: 0 0 22px;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  text-align: left;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  background: rgba(255, 255, 245, 0.04);
  border-radius: 12px;
  padding: 6px 8px;
}

.legend img {
  width: 42px;
  height: 42px;
  object-fit: cover;
  border-radius: 10px;
  background: #d8dee0;
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 14px 32px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.05rem;
  color: #1a2a30;
  background: linear-gradient(180deg, #ffc06a, var(--amber));
  cursor: pointer;
  box-shadow: 0 8px 0 #b36d28, 0 12px 24px rgba(0, 0, 0, 0.35);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.btn:hover { transform: translateY(-1px); }
.btn:active {
  transform: translateY(4px);
  box-shadow: 0 3px 0 #b36d28, 0 6px 12px rgba(0, 0, 0, 0.3);
}

.ending {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(ellipse at 50% 20%, rgba(240, 160, 75, 0.28), transparent 55%),
    rgba(6, 18, 24, 0.88);
  backdrop-filter: blur(10px);
  opacity: 1;
  transition: opacity 0.4s ease;
}

.ending.hidden {
  opacity: 0;
  pointer-events: none;
}

.ending-card {
  width: min(640px, 100%);
  text-align: center;
  animation: ending-rise 0.7s ease;
}

@keyframes ending-rise {
  from { transform: translateY(24px) scale(0.97); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.ending-scene {
  position: relative;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  aspect-ratio: 3 / 2;
  background: #1a3038;
}

.ending-scene img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ending-card h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  color: var(--amber);
}

.ending-card p {
  margin: 0 0 16px;
  opacity: 0.88;
  line-height: 1.45;
}

.board-block {
  margin: 0 0 18px;
  text-align: left;
}

.board-title {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--teal);
}

.board-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  max-height: 180px;
  overflow: auto;
}

.board-list li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  font-size: 0.88rem;
}

.board-list .rank {
  font-family: var(--font-display);
  font-weight: 800;
  color: var(--amber);
}

.board-list .nick {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-list .meta {
  opacity: 0.65;
  font-size: 0.78rem;
  white-space: nowrap;
}

.board-list li.me {
  background: rgba(61, 184, 160, 0.18);
  box-shadow: inset 0 0 0 1px rgba(61, 184, 160, 0.35);
}

.board-empty {
  margin: 0;
  font-size: 0.82rem;
  opacity: 0.55;
}

.board-empty.hidden,
.nick-form.hidden,
.ending-board.hidden {
  display: none;
}

.nick-form {
  margin: 0 0 8px;
  text-align: left;
}

.nick-form label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.65;
}

.nick-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.nick-form input {
  flex: 1 1 160px;
  min-width: 0;
  border: 1px solid rgba(61, 184, 160, 0.35);
  border-radius: 12px;
  padding: 12px 14px;
  font-family: var(--font-ui);
  font-size: 1rem;
  color: var(--cream);
  background: rgba(8, 20, 26, 0.85);
  outline: none;
}

.nick-form input:focus {
  border-color: var(--amber);
  box-shadow: 0 0 0 3px rgba(240, 160, 75, 0.2);
}

.nick-submit {
  padding: 12px 18px;
  box-shadow: 0 5px 0 #b36d28, 0 8px 16px rgba(0, 0, 0, 0.3);
}

.nick-submit:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #b36d28, 0 4px 10px rgba(0, 0, 0, 0.28);
}

.nick-hint {
  margin: 8px 0 0 !important;
  font-size: 0.78rem !important;
  opacity: 0.55 !important;
}

.ending-board {
  margin-top: 8px;
}

.ending-board .btn {
  margin-top: 14px;
  width: 100%;
}

.pause-overlay {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(6, 18, 24, 0.72);
  backdrop-filter: blur(8px);
  opacity: 1;
  transition: opacity 0.2s ease;
}

.pause-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.pause-panel {
  width: min(360px, 100%);
  text-align: center;
  background: var(--panel);
  border: 1px solid rgba(61, 184, 160, 0.25);
  border-radius: 20px;
  padding: 28px 22px;
  box-shadow: var(--shadow);
  animation: rise 0.3s ease;
}

.pause-panel h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 1.8rem;
  color: var(--amber);
}

.pause-panel p {
  margin: 0 0 18px;
  opacity: 0.85;
  line-height: 1.4;
}

@media (max-width: 720px), (pointer: coarse) {
  .desktop-hint { display: none; }
  .mobile-hint { display: block; }
  .touch-pad { display: block; }
  #game { max-height: min(68vh, 560px); }
}
