/* Detroit Dash — v1.0 minimal styles.
   TODO(v1.0): pull in a Summit-ish web font + brand palette where trivial (§7).
   Keep it minimal for v1: reset, center the canvas, basic HUD. No parallax/particles. */

/* Minimal reset */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0b1d33;        /* deep navy */
  --fg: #f0f6ff;        /* light tint */
  --accent: #ff6b35;    /* orange */
  color-scheme: dark;
}

/* Day variant — page frame matches the daytime skyline (v1.3). */
body[data-daynight="day"] {
  --bg: #bcd8ec;
  --fg: #0f2f47;
}

html,
body {
  height: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, sans-serif; /* TODO(v1.0): swap for brand font (§7). */
  display: flex;
  overflow: hidden; /* game is a fixed surface; no page scroll */
}

/* The shell fills the viewport and centers a fixed-size HUD + hint with the
   canvas taking the leftover height — so the whole game fits in both
   orientations (v3.4). */
#game {
  position: relative; /* anchor for overlays (§5) */
  margin: 0 auto;
  width: 100%;
  max-width: 900px;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding-top: max(1rem, env(safe-area-inset-top));
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
}

/* HUD — score, streak, puzzle number (§5, §7). Fixed-size row, never wraps. */
#hud {
  width: 100%;
  flex: 0 0 auto;
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  font-variant-numeric: tabular-nums;
  font-size: clamp(0.9rem, 3vw, 1.1rem);
}

/* Puzzle label truncates so a long "· PLAYTEST" tag never forces h-scroll. */
#hud-puzzle {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#hud-score,
#hud-streak {
  flex: 0 0 auto;
  white-space: nowrap;
}

/* HUD icon buttons — 44x44 tap targets (v3.4). */
#mute-btn,
#stats-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
  padding: 0;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.85;
}

#mute-btn:hover,
#stats-btn:hover {
  opacity: 1;
}

/* Flex-grow track that owns the leftover height and centers the canvas. */
#stage-wrap {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Canvas — letterboxed to fit BOTH width and height so the full 16:9 field
   (runner at the bottom included) is always visible in any orientation. */
#stage {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 16 / 9;
  background: #0e2440;
  border-radius: 8px;
  touch-action: manipulation; /* prevent double-tap zoom eating jump input */
}

#hint {
  flex: 0 0 auto;
  opacity: 0.88;
  font-size: clamp(0.8rem, 2.5vw, 0.95rem);
}

/* Result-screen overlay — full-screen modal centered on the viewport (§5). */
#result {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(9, 22, 40, 0.86); /* dim the game behind the card */
}

#result[hidden] {
  display: none;
}

.result-card {
  width: 100%;
  max-width: 360px;
  max-height: 100%;
  overflow-y: auto; /* Share/Replay stay reachable on short landscape (v3.4) */
  background: #0e2440;
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 1.5rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  /* Overlay cards are always dark surfaces — force light text so day-theme
     (dark --fg for the light page frame) never washes them out (v3.3). */
  color: #f0f6ff;
}

.result-card h2 {
  font-size: 1.1rem;
  font-weight: 600;
  opacity: 1;
}

.result-score {
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.result-stats {
  display: flex;
  justify-content: center;
  gap: 2rem;
}

.result-stats dt {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.8;
}

.result-stats dd {
  font-size: 1.2rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

#share-btn {
  margin-top: 0.25rem;
  padding: 0.7rem 1.2rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #0b1d33;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

#share-btn:hover {
  filter: brightness(1.1);
}

/* Dev-mode replay button — outlined, secondary to Share. */
.result-replay {
  margin-top: 0.25rem;
  padding: 0.7rem 1.4rem;
  border: none;
  border-radius: 8px;
  background: #2e86de; /* filled blue — bright, distinct from the orange Share */
  color: #ffffff;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.result-replay:hover {
  filter: brightness(1.1);
}

.result-share-status {
  min-height: 1.2em;
  font-size: 0.85rem;
  opacity: 0.95;
}

.result-countdown {
  font-size: 0.9rem;
  opacity: 0.9;
  font-variant-numeric: tabular-nums;
}

/* --- v1.3: result polish + stats overlay + a11y --------------------------- */

.result-card {
  animation: result-pop 0.28s ease-out;
}

@keyframes result-pop {
  from { transform: scale(0.94); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.result-badge {
  color: #ffd166;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}

.result-breakdown {
  font-size: 0.85rem;
  opacity: 0.92;
  margin-top: -0.25rem;
}

.result-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
  margin-top: 0.25rem;
}

.result-secondary {
  padding: 0.7rem 1.1rem;
  border: 1px solid #54a0ff;
  border-radius: 8px;
  background: rgba(46, 134, 222, 0.28); /* filled blue tint — colorful, not dark */
  color: #eaf3ff;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}

.result-secondary:hover {
  background: rgba(46, 134, 222, 0.45);
}

/* Stats overlay — centered card over the dimmed canvas, like the result. */
#stats {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(9, 22, 40, 0.86);
}

#stats[hidden] {
  display: none;
}

.stats-card {
  width: 100%;
  max-width: 380px;
  max-height: calc(100vh - 2rem);
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  /* Brighter surface (v3.4) — light #f0f6ff text stays ~10.7:1 (AA). */
  background: #1a3a5c;
  border: 1px solid rgba(240, 246, 255, 0.22);
  border-radius: 12px;
  padding: 0 1.5rem 1.5rem;
  animation: result-pop 0.24s ease-out;
  color: #f0f6ff;
}

/* Sticky header keeps the close ✕ pinned at the top while the card scrolls. */
.stats-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 -1.5rem;
  padding: 1.1rem 1.5rem 0.75rem;
  background: #1a3a5c;
  border-bottom: 1px solid rgba(240, 246, 255, 0.14);
}

.stats-head h2 {
  font-size: 1.2rem;
}

#stats-close {
  border: none;
  background: transparent;
  color: #f0f6ff; /* stay light in BOTH themes (var(--fg) is dark in day) */
  font-size: 1.2rem;
  cursor: pointer;
  opacity: 0.8;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

#stats-close:hover {
  opacity: 1;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem 0.5rem;
  margin: 1rem 0 1.25rem;
}

.stats-grid dt {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.8;
}

.stats-grid dd {
  font-size: 1.1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stats-card h3 {
  font-size: 0.9rem;
  opacity: 0.92;
  margin-bottom: 0.5rem;
}

.stats-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.stats-list li {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  background: rgba(240, 246, 255, 0.08); /* reads on the brighter card (v3.4) */
  font-variant-numeric: tabular-nums;
}

.stats-empty {
  justify-content: center !important;
  opacity: 0.85;
}

/* Cosmetic skins picker in the stats overlay (v3.1). */
.skins-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.skin-swatch {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid rgba(240, 246, 255, 0.18);
  border-radius: 8px;
  background: rgba(240, 246, 255, 0.08);
  color: #f0f6ff; /* light in both themes on the dark card (v3.4) */
  font-size: 0.82rem;
  cursor: pointer;
  text-align: left;
}

.skin-swatch:hover:not(:disabled) {
  background: rgba(240, 246, 255, 0.1);
}

.skin-selected {
  border-color: var(--accent);
  background: rgba(255, 107, 53, 0.18);
  font-weight: 700;
}

.skin-locked {
  opacity: 0.75;
  cursor: default;
}

.skin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
}

.skin-dot-none {
  border: 1px dashed rgba(240, 246, 255, 0.5);
  background: transparent;
}

/* Leaderboard panel inside the result card (v2.0). */
.result-board {
  width: 100%;
  margin-top: 0.25rem;
  border-top: 1px solid rgba(240, 246, 255, 0.12);
  padding-top: 0.75rem;
}

.result-board h3 {
  font-size: 0.85rem;
  opacity: 0.8;
  margin-bottom: 0.4rem;
}

.board-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  text-align: left;
}

.board-list li {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  padding: 0.25rem 0.5rem;
  border-radius: 5px;
  font-variant-numeric: tabular-nums;
}

.board-me {
  background: rgba(255, 107, 53, 0.22);
  font-weight: 700;
}

.board-empty,
.board-status {
  opacity: 0.88;
  font-size: 0.85rem;
  text-align: center;
}

.board-rank {
  margin-top: 0.4rem;
  font-size: 0.85rem;
  opacity: 0.95;
  font-weight: 600;
}

/* Visible keyboard focus for all controls (a11y). */
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Respect reduced-motion — kill card/stat entrance animations. */
@media (prefers-reduced-motion: reduce) {
  .result-card,
  .stats-card {
    animation: none;
  }
}
