/* Ghost Racer — minimal, light. Styling is deliberately plain for now. */

* { box-sizing: border-box; }

:root {
  --bg: #f7f7f5;
  --ink: #1c1c1c;
  --muted: #6b6b6b;
  --line: #e0e0dc;
  --primary: #1565c0;
  --primary-ink: #fff;
  --danger: #c62828;
  --card: #ffffff;
  --radius: 14px;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  /* honour the notch / safe areas in full screen */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* --- View switching ---------------------------------------------------- */
.view { display: none; height: 100dvh; flex-direction: column; }
body[data-view="home"]      #view-home,
body[data-view="nutrak"]    #view-nutrak,
body[data-view="race"]      #view-race,
body[data-view="spectator"] #view-spectator,
body[data-view="traks"]     #view-traks { display: flex; }

/* --- Buttons ----------------------------------------------------------- */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  padding: 14px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  min-height: 52px;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.small { min-height: 40px; padding: 8px 14px; font-size: .9rem; }
.btn.big { font-size: 1.15rem; font-weight: 600; }
.btn.link { border: none; background: none; color: var(--primary); min-height: auto; padding: 6px; }
.btn:disabled { opacity: .4; cursor: default; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 0; }

/* --- Home --------------------------------------------------------------- */
.home-head { padding: 28px 22px 8px; }
.home-head h1 { margin: 0; font-size: 2.4rem; letter-spacing: -0.5px; }
.home-head h1 span { color: var(--primary); }
.tagline { margin: 6px 0 0; color: var(--muted); }
.home-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 18px 22px 28px;
  align-content: center;
}
.tile {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 1.3rem;
  font-weight: 600;
  border-radius: 20px;
  aspect-ratio: 1 / 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tile:active { transform: scale(.98); }
.app-version { text-align: center; color: var(--muted); font-size: .8rem; padding: 0 0 18px; margin: 0; }

/* --- Bars / panels ----------------------------------------------------- */
.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}
.bar-title { font-weight: 600; }
.back, .add {
  appearance: none; border: none; background: none; font: inherit;
  color: var(--primary); font-size: 1rem; cursor: pointer; padding: 6px;
}
.add { margin-left: auto; }
.panel { padding: 16px; display: flex; flex-direction: column; gap: 12px; background: var(--card); border-top: 1px solid var(--line); }
.status { margin: 0; color: var(--muted); font-size: .95rem; }

.trak-select {
  flex: 1;
  font: inherit;
  font-size: 1rem;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}

/* --- Nu Trak map + crosshair ------------------------------------------- */
.map-wrap { position: relative; flex: 1; }
#nutrak-map { position: absolute; inset: 0; }
.crosshair { position: absolute; inset: 0; pointer-events: none; z-index: 500; }
.crosshair span {
  position: absolute; top: 50%; left: 50%; background: rgba(21,101,192,.9);
}
.crosshair span:nth-child(1) { width: 2px; height: 26px; transform: translate(-50%, -50%); }
.crosshair span:nth-child(2) { width: 26px; height: 2px; transform: translate(-50%, -50%); }

/* Leaflet labelled pins (Nu Trak) */
.nt-pin span {
  display: flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%;
  color: #fff; font-weight: 700; font-size: 13px;
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4);
}

/* --- Stage (canvas map screens) ---------------------------------------- */
.stage { position: relative; flex: 1; overflow: hidden; background: #eef0ee; }
.stage-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }

.race-timer {
  position: absolute; top: 14px; left: 0; right: 0; text-align: center;
  font-size: 2.6rem; font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--ink); text-shadow: 0 1px 0 #fff, 0 0 8px #fff; pointer-events: none;
}
.race-count {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 6rem; font-weight: 800; color: var(--primary);
  text-shadow: 0 2px 0 #fff; pointer-events: none;
}

.hud-bottom {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(247,247,245,.96), rgba(247,247,245,.0));
  display: flex; flex-direction: column; gap: 10px;
}
.splits { list-style: none; margin: 0; padding: 0; font-variant-numeric: tabular-nums; }
.splits li { font-size: .95rem; padding: 2px 0; color: var(--ink); }

.done-card, .empty-card {
  position: absolute; inset: 0; margin: auto; height: max-content;
  max-width: 340px; background: var(--card); border: 1px solid var(--line);
  border-radius: 18px; padding: 22px; text-align: center;
  display: flex; flex-direction: column; gap: 14px; align-self: center;
}
.done-card h2 { margin: 0; }
.big-time { font-size: 2.8rem; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--primary); }

/* --- Race state visibility --------------------------------------------- */
.homing-only, .racing-only, .done-only, .empty-only { display: none; }
#view-race[data-race-state="select"]  .homing-only,
#view-race[data-race-state="homing"]  .homing-only { display: block; }
#view-race[data-race-state="racing"]  .racing-only { display: block; }
#view-race[data-race-state="done"]    .done-only  { display: flex; }
#view-race[data-race-state="empty"]   .empty-only { display: flex; }
#view-race[data-race-state="racing"]  .hud-bottom,
#view-race[data-race-state="select"]  .hud-bottom,
#view-race[data-race-state="homing"]  .hud-bottom { display: flex; }
#view-race:not([data-race-state="racing"]) #race-timer { display: none; }
#view-race:not([data-race-state="countdown"]):not([data-race-state="racing"]) #race-count { display: none; }
#view-race[data-race-state="done"]  .hud-bottom,
#view-race[data-race-state="empty"] .hud-bottom { display: none; }

/* --- Spectator state visibility ---------------------------------------- */
.spec-ready, .spec-norace, .spec-notrak { display: none; }
#view-spectator[data-spec-state="ready"]  .spec-ready  { display: flex; }
#view-spectator[data-spec-state="norace"] .spec-norace { display: flex; }
#view-spectator[data-spec-state="notrak"] .spec-notrak { display: flex; }
#spec-modes.mode-row.spec-ready { display: flex; }

.mode-row { gap: 8px; padding: 12px 14px; background: var(--card); border-bottom: 1px solid var(--line); }
.chip {
  appearance: none; border: 1px solid var(--line); background: var(--bg);
  font: inherit; padding: 8px 16px; border-radius: 999px; cursor: pointer; flex: 1;
}
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* --- Traks list -------------------------------------------------------- */
.traks-list { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.trak-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.trak-card-head h3 { margin: 0 0 4px; font-size: 1.15rem; }
.trak-meta { color: var(--muted); font-size: .85rem; }
.trak-card-actions { display: flex; gap: 8px; margin-top: 12px; }
.trak-card-actions .btn { flex: 1; }
.empty-card { position: static; margin: auto; }
