/* Prism Peak Rally interface.
   Tokens come straight from the accepted screen designs: a bright festival
   palette by default, and the night variant of the same layout when the system
   asks for a dark theme. Every screen is one full-size layer inside #ui-layer,
   so the race stays visible under the overlays that are meant to show it. */

:root {
  color-scheme: light dark;

  --bg: #ddf7f2;
  /* The card screens sit on their own background, a shade away from the sky the
     title and the race are drawn on: #DDF7F2 against #A7E7EA by day and #0D2830
     against #102A39 at night, which is what the screen designs specify. */
  --bg-panel: #ddf7f2;
  --sky: #a7e7ea;
  --surface: #fff8dd;
  --surface-sunk: #ddf7f2;
  --highlight: #fff1b8;
  --ink: #17343c;
  --muted: #4d6267;
  --border: #17343c;
  --accent: #f05a3c;
  --accent-ink: #0b252c;
  --danger: #8a2d20;
  --ready: #4fae68;
  --pending: #f6c64e;
  --road: #344b52;
  --verge: #fff8dd;
  --disabled: #cbd8c9;
  --scrim: rgba(23, 52, 60, 0.68);

  --radius: 18px;
  --radius-small: 12px;
  --border-width: 4px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #102a39;
    --bg-panel: #0d2830;
    --sky: #102a39;
    --surface: #173f48;
    --surface-sunk: #102f37;
    --highlight: #463e2e;
    --ink: #fff8dd;
    --muted: #b8d6d2;
    --border: #79d8c8;
    --accent: #ff8068;
    --danger: #ffb0a0;
    --road: #17272e;
    --verge: #fff8dd;
    --disabled: #3c5a5c;
    --scrim: rgba(11, 37, 44, 0.74);
  }
}

body, html {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--sky);
  font-family: system-ui, 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  color: var(--ink);
}

#game-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

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

#ui-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: 24px;
  background: var(--bg);
  pointer-events: auto;
  transition: opacity 0.3s;
}

.screen.hidden {
  display: none;
  opacity: 0;
}

.screen.active {
  display: flex;
  opacity: 1;
}

/* Overlays keep the frozen race readable behind them. */
.screen.overlay {
  background: var(--scrim);
}

/* Screens above own their own hidden state; this is for everything else that is
   shown conditionally, such as the wrong-way alert and the support guide. */
.hidden:not(.screen) {
  display: none;
}

/* Screens whose content is one large card, aligned to the top on short
   viewports so a long panel scrolls instead of overflowing. */
.panel-screen {
  background: var(--bg-panel);
  justify-content: flex-start;
  overflow: auto;
}

/* The title card is the one full screen that is not a card screen and is not
   the race, so it keeps the sky the designs put behind it. */
#screen-title {
  background: var(--sky);
}

/* --- Panels ------------------------------------------------------------- */

.panel {
  background: var(--surface);
  border: 6px solid var(--border);
  border-radius: 24px;
  box-sizing: border-box;
  max-height: 100%;
  max-width: 1100px;
  overflow: auto;
  padding: 28px 32px;
  width: 100%;
}

.panel-title {
  max-width: 620px;
}

.panel-dialog {
  max-width: 760px;
}

.panel-head {
  align-items: center;
  display: flex;
  gap: 20px;
  justify-content: space-between;
  margin-bottom: 18px;
}

.panel h2 {
  font-size: 2.1rem;
  margin: 0 0 6px;
}

.panel h3 {
  margin: 0 0 6px;
}

.rule {
  border: none;
  border-top: 3px solid var(--border);
  margin: 18px 0;
}

.columns {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
}

.columns > * {
  flex: 1 1 320px;
  min-width: 0;
}

.row-between {
  display: flex;
  justify-content: space-between;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85rem;
}

.eyebrow {
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 4px;
  margin: 0;
  text-transform: uppercase;
}

.game-title {
  font-size: 3.6rem;
  letter-spacing: 4px;
  margin: 0 0 8px;
  text-transform: uppercase;
}

.subtitle {
  color: var(--muted);
  margin: 0 0 22px;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 16px 0 0;
  max-width: 560px;
}

/* --- Controls ----------------------------------------------------------- */

button {
  background-color: var(--surface-sunk);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius-small);
  color: var(--ink);
  cursor: pointer;
  font-size: 1.05rem;
  font-weight: 800;
  margin: 6px;
  padding: 14px 26px;
  pointer-events: auto;
  text-transform: uppercase;
  transition: transform 0.1s, background-color 0.2s;
}

button.primary {
  background-color: var(--accent);
  color: var(--accent-ink);
}

button.danger {
  border-color: var(--danger);
  color: var(--danger);
}

button.wide {
  width: 100%;
}

button:hover {
  transform: scale(1.03);
}

button:disabled {
  background-color: var(--disabled);
  cursor: not-allowed;
  opacity: 0.7;
  transform: none;
}

button:focus,
input:focus,
.racer-card:focus {
  outline: 4px solid var(--accent);
  outline-offset: 3px;
}

button:active {
  transform: scale(0.97);
}

.button-row {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.menu-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.menu-row button {
  flex: 1 1 140px;
}

.option-group {
  background: var(--surface-sunk);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}

.option-group legend {
  font-weight: 900;
  letter-spacing: 1px;
  padding: 0 8px;
  text-transform: uppercase;
}

.option {
  align-items: center;
  display: flex;
  gap: 12px;
  margin: 12px 0;
}

.option input[type='range'] {
  flex: 1;
}

.callout {
  background: var(--surface-sunk);
  border: 3px solid var(--border);
  border-radius: var(--radius-small);
  margin-top: 16px;
  padding: 14px 18px;
}

.callout.warning {
  background: var(--highlight);
  border-color: var(--accent);
}

.callout ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.capability-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  list-style: none;
  margin: 18px 0;
  padding: 0;
}

.capability {
  background: var(--surface-sunk);
  border: 3px solid var(--border);
  border-radius: var(--radius-small);
  font-weight: 700;
  padding: 12px 16px;
}

.capability::before {
  background: var(--pending);
  border-radius: 50%;
  content: '';
  display: inline-block;
  height: 10px;
  margin-right: 10px;
  width: 10px;
}

.capability-ready::before {
  background: var(--ready);
}

.capability-missing::before {
  background: var(--accent);
}

.progress {
  background: var(--disabled);
  border: 3px solid var(--border);
  border-radius: 999px;
  height: 22px;
  overflow: hidden;
}

.progress-fill {
  background: var(--accent);
  height: 100%;
  transition: width 0.3s;
  width: 0;
}

.progress-indeterminate {
  animation: sweep 1.4s ease-in-out infinite;
  width: 40%;
}

@keyframes sweep {
  0% { margin-left: 0; }
  50% { margin-left: 60%; }
  100% { margin-left: 0; }
}

.bindings {
  border-collapse: collapse;
  width: 100%;
}

.bindings caption {
  font-weight: 900;
  letter-spacing: 1px;
  padding-bottom: 8px;
  text-align: left;
  text-transform: uppercase;
}

.bindings th,
.bindings td {
  padding: 10px 12px;
  text-align: left;
}

.bindings tr:nth-child(odd) {
  background: var(--surface-sunk);
}

.bindings td {
  font-weight: 900;
  text-align: right;
}

.race-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px 18px;
  margin: 0;
}

.race-card dt {
  color: var(--muted);
  font-weight: 700;
}

.race-card dd {
  font-weight: 900;
  margin: 0;
  text-align: right;
}

.course-sketch {
  border: 4px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
}

/* --- Title record and badges -------------------------------------------- */

.badge {
  align-items: center;
  background: var(--surface);
  border: 3px solid var(--border);
  border-radius: 999px;
  display: flex;
  font-weight: 800;
  gap: 10px;
  padding: 10px 18px;
  position: absolute;
  right: 28px;
  text-transform: uppercase;
  top: 28px;
}

.badge-dot {
  background: var(--pending);
  border-radius: 50%;
  height: 10px;
  width: 10px;
}

.badge[data-state='ready'] .badge-dot {
  background: var(--ready);
}

.badge[data-state='off'] .badge-dot {
  background: var(--accent);
}

.record-card {
  background: var(--highlight);
  border: 3px solid var(--border);
  border-radius: var(--radius);
  box-sizing: border-box;
  margin-top: 24px;
  padding: 16px 22px;
}

.record-card h2 {
  font-size: 1rem;
  letter-spacing: 2px;
  margin: 0 0 8px;
  text-transform: uppercase;
}

.record-card p {
  color: var(--muted);
  margin: 4px 0;
}

/* --- Racer selection ----------------------------------------------------- */

.racers {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
}

.racer-card {
  background: var(--surface-sunk);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius);
  box-sizing: border-box;
  cursor: pointer;
  display: flex;
  flex: 1 1 220px;
  flex-direction: column;
  padding: 16px 18px 20px;
}

.racer-card.selected {
  background: var(--highlight);
  border-color: var(--accent);
}

.racer-card h3 {
  margin: 8px 0 2px;
}

.racer-tagline {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 14px;
}

.racer-stats {
  align-items: center;
  display: grid;
  gap: 8px 12px;
  grid-template-columns: auto 1fr;
  margin: 0;
  width: 100%;
}

.racer-stats dt {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.racer-stats dd {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin: 0;
}

.stat-bar {
  background: var(--disabled);
  border-radius: 4px;
  flex: 1;
  height: 12px;
  overflow: hidden;
}

.stat-bar-fill {
  background: var(--accent);
  display: block;
  height: 100%;
}

.stat-value {
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  min-width: 26px;
  text-align: right;
}

/* --- Race HUD ------------------------------------------------------------ */

#screen-hud,
#screen-countdown {
  background: transparent;
  pointer-events: none;
}

#screen-hud .hud-card,
#screen-countdown .hud-card {
  position: absolute;
}

.hud-card {
  background: var(--surface);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
}

.hud-card strong {
  display: block;
  font-size: 2rem;
  font-variant-numeric: tabular-nums;
}

.hud-label {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.hud-position,
.hud-corner-left {
  left: 32px;
  top: 28px;
}

.hud-lap {
  left: 50%;
  top: 28px;
  transform: translateX(-50%);
}

.hud-lap strong {
  font-size: 1.6rem;
}

.hud-course {
  right: 32px;
  top: 28px;
}

#hud-minimap {
  display: block;
  height: 180px;
  width: 232px;
}

.hud-speed {
  bottom: 32px;
  left: 32px;
}

.hud-speed small {
  color: var(--muted);
  font-size: 0.9rem;
}

.hud-item {
  align-items: center;
  bottom: 32px;
  display: flex;
  gap: 14px;
  right: 32px;
}

.hud-item strong {
  font-size: 1.2rem;
}

.hud-item p {
  margin: 2px 0 0;
}

.item-slot {
  background: var(--surface-sunk);
  border: 3px solid var(--border);
  border-radius: var(--radius-small);
  height: 64px;
  width: 64px;
}

.pill {
  background: var(--surface);
  border: 3px solid var(--border);
  border-radius: var(--radius-small);
  bottom: 30px;
  font-weight: 900;
  left: 50%;
  margin: 0;
  padding: 10px 22px;
  position: absolute;
  text-transform: uppercase;
  transform: translateX(-50%);
}

.pill.alert {
  background: var(--accent);
  bottom: auto;
  color: var(--accent-ink);
  top: 140px;
}

.hud-recover {
  bottom: 30px;
}

#countdown-text {
  animation: pulse 1s infinite;
  color: var(--ink);
  font-size: 8rem;
  margin: 0;
  text-shadow: 4px 4px 0 var(--pending);
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* Reduced motion turns off every decorative animation, and the system setting
   does the same for players who never open the settings screen. */
body.reduced-motion #countdown-text,
body.reduced-motion .progress-indeterminate {
  animation: none;
}

body.reduced-motion button:hover,
body.reduced-motion button:active {
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  #countdown-text,
  .progress-indeterminate {
    animation: none;
  }
}

/* --- Finish and results --------------------------------------------------- */

.finish-banner {
  background: var(--surface);
  border: 8px solid var(--border);
  border-radius: 32px;
  padding: 36px 60px;
  text-align: center;
}

.finish-banner h2 {
  font-size: 4rem;
  margin: 0;
}

#finish-place {
  font-size: 1.8rem;
  font-weight: 900;
  margin: 8px 0 0;
}

#finish-time {
  font-size: 1.4rem;
  font-variant-numeric: tabular-nums;
  margin: 4px 0 20px;
}

.results-table {
  background: var(--surface-sunk);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
}

.result-row {
  align-items: center;
  border-radius: var(--radius-small);
  display: grid;
  gap: 12px;
  grid-template-columns: 44px 1fr auto;
  margin: 8px 0;
  padding: 10px 12px;
}

.result-head {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 900;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.result-row-player {
  background: var(--accent);
  color: var(--accent-ink);
}

.result-place {
  font-weight: 900;
}

.result-time {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.reward-card {
  background: var(--highlight);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius);
  padding: 18px 22px;
}

.reward-card strong {
  display: block;
  font-size: 1.3rem;
}

#progression-stats {
  background: var(--surface-sunk);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius);
  box-sizing: border-box;
  margin-top: 18px;
  padding: 14px 22px;
}

#progression-stats h3 {
  margin: 0 0 8px;
  text-transform: uppercase;
}

.progression-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
}
