/* KTOOL Live: the app's instrument palette. Near-black water, one teal accent, red only for
   "live" and stale. Built to be read in sunlight on a phone at the club as well as on a big screen. */
:root {
  --night: #0b1117;
  --card: #111921;
  --panel: #131b23;
  --border: #26313b;
  --text: #e8eef2;
  --soft: #b8c3cc;
  --muted: #7d8a96;
  --teal: #00b2a9;
  --teal-deep: #0e2a2a;
  --red: #ff5a4e;
  --amber: #f5a524;
  --mark: #f5e663;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --topbar: 56px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--night);
  color: var(--text);
  font: 14px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, select, input { font: inherit; color: inherit; }
.num, .clock-value, .fleet .sog, .fleet .cog, .fleet .age, .replay-time { font-variant-numeric: tabular-nums; }

/* Brand */
.brand { display: flex; align-items: center; gap: 8px; flex: none; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center;
  background: var(--teal); color: #04211f; font-weight: 800; font-size: 16px;
}
.brand-word { font-weight: 800; letter-spacing: 0.12em; font-size: 15px; }
.brand-live {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--soft); font-size: 11px; font-weight: 700; letter-spacing: 0.1em;
}
.brand-live .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.brand-live.is-live { color: var(--text); border-color: #4a1619; background: #2a1513; }
.brand-live.is-live .dot { background: var(--red); animation: pulse 1.6s ease-in-out infinite; }
.brand-live.is-replay { color: #04211f; background: var(--teal); border-color: var(--teal); }
.brand-live.is-replay .dot { background: #04211f; }
@keyframes pulse { 50% { opacity: 0.35; } }
.brand-large .brand-mark { width: 40px; height: 40px; font-size: 22px; border-radius: 10px; }
.brand-large .brand-word { font-size: 22px; }

/* Plain pages */
.page-plain { display: grid; place-items: center; min-height: 100%; padding: 24px 16px; }
.plain { max-width: 420px; }
.plain h1 { font-size: 26px; margin: 28px 0 8px; }
.plain p { color: var(--soft); margin: 0 0 10px; }
.plain .soft { color: var(--muted); }

/* Live page */
.page-live { overflow: hidden; }
.topbar {
  height: var(--topbar); display: flex; align-items: center; gap: 16px; padding: 0 16px;
  background: var(--card); border-bottom: 1px solid var(--border); position: relative; z-index: 1000;
}
.regatta-name { flex: 1; min-width: 0; font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clock { text-align: right; flex: none; line-height: 1.1; }
.clock-value { font-size: 22px; font-weight: 800; }
.clock-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.clock.soon .clock-value { color: var(--amber); }
.clock.racing .clock-value { color: var(--teal); }

.layout { position: absolute; top: var(--topbar); left: 0; right: 0; bottom: 0; display: flex; }
.map { flex: 1; min-width: 0; background: #0a1520; }
.panel {
  width: 340px; flex: none; display: flex; flex-direction: column;
  background: var(--panel); border-left: 1px solid var(--border);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 14px 8px; }
.panel-title { font-weight: 700; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--soft); }
.count { color: var(--muted); margin-left: 4px; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented button { background: none; border: 0; padding: 4px 8px; font-size: 12px; color: var(--muted); cursor: pointer; }
.segmented button.on { background: var(--teal-deep); color: var(--teal); }

.fleet-columns, .fleet li {
  display: grid; grid-template-columns: 14px 1fr 56px 44px 44px; gap: 8px; align-items: center; padding: 0 14px;
}
.fleet-columns { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.fleet-columns .num, .fleet .num { text-align: right; }
.fleet { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.fleet li { min-height: 46px; border-bottom: 1px solid rgba(38, 49, 59, 0.6); cursor: pointer; }
.fleet li:hover { background: rgba(255, 255, 255, 0.03); }
.fleet li.followed { background: var(--teal-deep); }
.fleet li.stale { color: var(--muted); }
.fleet .swatch { width: 12px; height: 12px; border-radius: 3px; }
.fleet .who { min-width: 0; }
.fleet .sail { font-weight: 700; }
.fleet .boat { color: var(--soft); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.fleet li.stale .boat { color: var(--muted); }
.fleet .sog { font-weight: 700; font-size: 16px; }
.fleet .age { color: var(--muted); font-size: 12px; }
.fleet li.stale .age { color: var(--red); }
.fleet .gpx { color: var(--muted); font-size: 11px; text-decoration: none; margin-left: 6px; }
.fleet .gpx:hover { color: var(--teal); }
.empty { color: var(--muted); padding: 16px 14px; font-size: 13px; }
.panel-foot { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border); }

.btn {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; color: var(--text); font-weight: 600; font-size: 13px;
}
.btn:hover { border-color: var(--teal); }
.btn-icon { width: 36px; padding: 7px 0; }

/* Map objects */
.leaflet-container { background: #0a1520; font-family: var(--font); }
.leaflet-control-attribution { background: rgba(11, 17, 23, 0.75) !important; color: var(--muted) !important; }
.leaflet-control-attribution a { color: var(--soft) !important; }
.leaflet-bar a { background: var(--card); color: var(--text); border-color: var(--border); }
.boat-icon { position: relative; }
.boat-icon .hull { position: absolute; left: 0; top: 0; width: 26px; height: 26px; transform-origin: 13px 13px; }
.boat-icon .label {
  position: absolute; left: 22px; top: -4px; white-space: nowrap; font-size: 11px; font-weight: 700;
  padding: 1px 5px; border-radius: 4px; background: rgba(11, 17, 23, 0.82); color: var(--text);
  border: 1px solid var(--border);
}
.boat-icon.stale .hull { opacity: 0.45; }
.boat-icon.followed .label { border-color: var(--teal); color: var(--teal); }
.leaflet-tooltip.mark-label {
  background: rgba(11, 17, 23, 0.85); border: 1px solid #5c5520; color: var(--mark);
  font-weight: 700; font-size: 11px; border-radius: 4px; box-shadow: none; padding: 1px 5px;
}
.leaflet-tooltip.mark-label::before { display: none; }

/* Replay bar */
.replay {
  position: absolute; left: 16px; right: 356px; bottom: 16px; z-index: 1000;
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: rgba(17, 25, 33, 0.95); border: 1px solid var(--border); border-radius: var(--radius);
}
.replay input[type="range"] { flex: 1; accent-color: var(--teal); }
.replay-time { font-weight: 700; min-width: 72px; text-align: center; }
.replay select { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 6px; }

/* Phones: map on top, fleet below. */
@media (max-width: 760px) {
  :root { --topbar: 52px; }
  .topbar { gap: 10px; padding: 0 12px; }
  .brand-word { display: none; }
  .regatta-name { font-size: 15px; }
  .clock-value { font-size: 19px; }
  .layout { flex-direction: column; }
  .map { flex: 1 1 58%; }
  .panel { width: auto; flex: 1 1 42%; max-height: 42%; border-left: 0; border-top: 1px solid var(--border); }
  .panel-head { padding: 8px 12px 6px; }
  .fleet-columns, .fleet li { padding: 0 12px; grid-template-columns: 12px 1fr 52px 40px 40px; }
  .fleet li { min-height: 42px; }
  .replay { left: 8px; right: 8px; bottom: calc(42% + 8px); flex-wrap: wrap; }
}
