/* style.css — mobile-first, Estonian flag palette, light + dark */
:root {
  --blue: #0072CE; --blue-dark: #005ba6; --blue-soft: #e6f1fb; --blue-line: #b9d7f3;
  --ink: #111111; --text: #111111; --muted: #5b6470; --bg: #ffffff; --surface: #f4f6f9; --line: #e2e6ec;
  --est-bg: #f2f7fd; --warn: #b45309; --warn-bg: #fff4e0; --ok: #1a7f37; --danger: #b42318;
  --pill-live: #1a7f37; --pill-live-bg: #e6f6ea; --pill-fin: #5b6470; --pill-fin-bg: #eceff3; --pill-up: #0072CE; --pill-up-bg: #e6f1fb; --pill-wait: #8a94a3; --pill-wait-bg: #f1f3f6;
  --tab-h: 58px; --gutter: 16px; --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.06);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --text: #f2f4f7; --muted: #9aa3ae; --bg: #111111; --surface: #1b1f25; --line: #2c323b;
    --blue-soft: #12283d; --blue-line: #1f4a73; --est-bg: #14202c; --warn: #f5b04b; --warn-bg: #3a2a10;
    --pill-live: #5dd07e; --pill-live-bg: #12301b; --pill-fin: #aab3bf; --pill-fin-bg: #262b33; --pill-up: #6db3f2; --pill-up-bg: #12283d; --pill-wait: #8a94a3; --pill-wait-bg: #20252c;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px));
  overflow-x: hidden;
}
a { color: var(--blue); text-decoration: none; }
button { font: inherit; }
h1, h2, h3 { margin: 0; font-weight: 700; }
h2 { font-size: 15px; letter-spacing: .02em; text-transform: uppercase; color: var(--muted); margin: 20px 0 8px; }
h3 { font-size: 16px; }
.muted { color: var(--muted); }
.empty { color: var(--muted); padding: 12px 0; margin: 0; }
[hidden] { display: none !important; }

/* header */
.top {
  position: sticky; top: 0; z-index: 20; background: var(--blue); color: #fff;
  padding: calc(8px + env(safe-area-inset-top, 0px)) var(--gutter) 8px;
}
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.brand { display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 700; font-size: 17px; }
.brand-badge { background: #fff; color: var(--blue); font-size: 11px; font-weight: 800; padding: 2px 5px; border-radius: 5px; border-bottom: 3px solid var(--ink); letter-spacing: .04em; }
.top-sub { display: flex; gap: 10px; align-items: center; font-size: 12px; margin-top: 4px; min-height: 16px; }
.top-sub .muted { color: rgba(255,255,255,.8); }
.top .warn { background: var(--warn-bg); color: var(--warn); padding: 1px 8px; border-radius: 999px; font-weight: 600; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--surface); color: var(--text); font-size: 13px; font-weight: 600; white-space: nowrap; }
.chip-day { background: rgba(255,255,255,.18); color: #fff; }

/* main */
.view { padding: 8px var(--gutter) 24px; max-width: 720px; margin: 0 auto; }
.section { margin-top: 4px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin: 8px 0; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.card[data-nav] { cursor: pointer; }
.kv { display: flex; gap: 8px; align-items: baseline; margin-top: 8px; font-size: 14px; }
.kv .k { color: var(--muted); min-width: 64px; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.big { font-size: 28px; font-weight: 800; color: var(--blue); }

/* rows */
.list { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.row {
  display: flex; align-items: center; gap: 8px; min-height: 48px; padding: 6px 2px 6px 8px;
  border-bottom: 1px solid var(--line); border-left: 3px solid transparent; color: inherit;
}
.row.followed { border-left-color: var(--blue); }
.row.est { background: var(--est-bg); }
.row.tap { cursor: pointer; }
.row .pos { width: 30px; flex: none; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 600; }
.row .pos.rank { color: var(--text); }
.row .pos.dsq { color: var(--danger); font-size: 12px; }
.row .flag { width: 34px; flex: none; display: flex; flex-direction: column; align-items: center; line-height: 1.1; font-size: 10px; font-weight: 600; color: var(--muted); letter-spacing: .02em; }
.row .flag .em { font-size: 19px; line-height: 1.1; }
.row .main { flex: 1; min-width: 0; }
.row .main .title { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; font-weight: 600; overflow: hidden; overflow-wrap: anywhere; line-height: 1.25; }
.row .main .sub { display: block; color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .right { flex: none; text-align: right; font-variant-numeric: tabular-nums; font-size: 14px; }
.row .right .sub { display: block; color: var(--muted); font-size: 12px; }
.row .time { width: 46px; flex: none; font-weight: 700; font-variant-numeric: tabular-nums; }
.row .res { flex: none; text-align: right; font-variant-numeric: tabular-nums; font-size: 14px; white-space: nowrap; }
.row .res .f { font-weight: 700; }
.row .res .t { color: var(--muted); margin-left: 6px; }
.star { flex: none; width: 40px; height: 44px; border: 0; background: transparent; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer; border-radius: 8px; }
.star[aria-pressed="true"] { color: var(--blue); }
.star:active { background: var(--blue-soft); }

/* pills / badges */
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.pill-live { color: var(--pill-live); background: var(--pill-live-bg); }
.pill-finished { color: var(--pill-fin); background: var(--pill-fin-bg); }
.pill-upcoming { color: var(--pill-up); background: var(--pill-up-bg); }
.pill-not-uploaded { color: var(--pill-wait); background: var(--pill-wait-bg); }
.badge { display: inline-block; padding: 1px 7px; border-radius: 6px; font-size: 11px; font-weight: 700; background: var(--blue-soft); color: var(--blue); white-space: nowrap; }
.badge.team { background: var(--pill-fin-bg); color: var(--pill-fin); }
.badge.reserve { background: var(--pill-wait-bg); color: var(--pill-wait); }
.counts { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

/* day groups */
.day-head { display: flex; align-items: baseline; gap: 8px; margin: 18px 0 6px; }
.day-head .d { font-size: 17px; color: var(--text); text-transform: none; letter-spacing: 0; margin: 0; }

/* round view */
.round-head { padding: 8px 0 4px; }
.round-head h1 { font-size: 20px; }
.round-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 13px; margin-top: 4px; }
.round-msg { margin: 8px 0 0; padding: 8px 10px; background: var(--warn-bg); color: var(--warn); border-radius: 8px; font-size: 13px; }
.seg { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 3px; margin: 10px 0 8px; }
.seg button { flex: 1; min-height: 38px; border: 0; background: transparent; color: var(--muted); font-weight: 600; border-radius: 8px; cursor: pointer; font-size: 14px; }
.seg button[aria-selected="true"] { background: var(--blue); color: #fff; }
.controls { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.controls input[type="search"] { flex: 1; min-width: 140px; }
.toggle { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; font-size: 14px; white-space: nowrap; }
.toggle input { width: 20px; height: 20px; accent-color: var(--blue); }
input[type="search"], input[type="text"] {
  width: 100%; min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text); font: inherit;
}
details.row { display: block; padding: 0; }
details.row summary { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 6px 8px; list-style: none; cursor: pointer; }
details.row summary::-webkit-details-marker { display: none; }
details.row .members { margin: 0; padding: 0 8px 8px 40px; list-style: none; font-size: 13.5px; }
details.row .members li { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; border-top: 1px dashed var(--line); }
details.row .members .rk { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; flex: none; }

/* Eesti */
.pair-runs { margin: 6px 0 0; padding: 0; list-style: none; font-size: 14px; }
.pair-runs li { display: flex; justify-content: space-between; gap: 8px; padding: 5px 0; border-top: 1px solid var(--line); }
.pair-runs .rt { color: var(--muted); font-size: 13px; }
.pair-runs .rv { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }

/* settings */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.chips .chip button { border: 0; background: transparent; color: var(--muted); font-size: 18px; line-height: 1; padding: 0 0 0 4px; cursor: pointer; min-width: 28px; min-height: 28px; }
.addrow { display: flex; gap: 8px; }
.addrow input { flex: 1; text-transform: uppercase; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 8px 16px;
  border-radius: 10px; border: 1px solid var(--blue); background: var(--blue); color: #fff; font-weight: 600; cursor: pointer;
}
.btn.secondary { background: transparent; color: var(--blue); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn[disabled] { opacity: .5; cursor: default; }
.btnrow { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.field { margin: 12px 0; }
.field label { display: block; font-weight: 600; margin-bottom: 4px; }
input[type="range"] { width: 100%; accent-color: var(--blue); }
.status { padding: 10px 12px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); margin: 8px 0; }
.status b.ok { color: var(--ok); }
.status b.bad { color: var(--danger); }
.help { font-size: 14px; color: var(--muted); }
.help ol { padding-left: 20px; margin: 6px 0; }
.help li { margin: 4px 0; }
.rm { border: 0; background: transparent; color: var(--danger); min-width: 44px; min-height: 44px; font-size: 14px; cursor: pointer; }

/* toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + 12px + env(safe-area-inset-bottom, 0px));
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 30; max-width: calc(100vw - 32px);
}

/* tab bar */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex;
  background: var(--bg); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--tab-h); color: var(--muted); font-size: 11.5px; font-weight: 600;
}
.tabs a svg { width: 24px; height: 24px; fill: currentColor; }
.tabs a.active { color: var(--blue); }
.tabs a .tri .t1 { fill: var(--blue); } .tabs a .tri .t2 { fill: var(--ink); } .tabs a .tri .t3 { fill: #fff; stroke: var(--line); stroke-width: .6; }
@media (prefers-color-scheme: dark) { .tabs a .tri .t2 { fill: #2a2f36; } }
.tabs a:not(.active) .tri rect { opacity: .55; }

/* course maps & organiser documents */
.docs{margin:10px 0 4px;display:flex;flex-direction:column;gap:8px}
.mapthumb{display:block;border:1px solid var(--line,#ddd);border-radius:10px;overflow:hidden;background:#fff;text-decoration:none;color:inherit}
.mapthumb img{display:block;width:100%;min-height:120px;max-height:220px;object-fit:contain;background:#fff}
.mapthumb span{display:block;padding:6px 10px;font-size:.85em;color:var(--accent,#0072CE)}
.mapmark{color:var(--accent,#0072CE);white-space:nowrap}
.orglinks{margin:18px 0 8px;font-size:.8em;color:var(--muted)}
.orglinks a.ext{color:var(--muted);text-decoration:underline dotted}
.orglinks a.ext::after{content:" ↗";font-size:.9em}
.lightbox{position:fixed;inset:0;z-index:50;background:rgba(0,0,0,.94);display:flex;flex-direction:column;padding:env(safe-area-inset-top,0) 0 env(safe-area-inset-bottom,0)}
.lightbox .lb-body{flex:1;display:flex;align-items:center;justify-content:center;overflow:auto;touch-action:pinch-zoom}
.lightbox img{max-width:100%;max-height:100%;object-fit:contain;background:#fff}
.lightbox .lb-close{position:absolute;top:calc(env(safe-area-inset-top,0) + 10px);right:12px;width:44px;height:44px;border:0;border-radius:22px;background:rgba(255,255,255,.15);color:#fff;font-size:26px;line-height:44px;cursor:pointer}
.lightbox .lb-title{color:#ddd;font-size:.85em;text-align:center;padding:8px 16px}
body.lb-open{overflow:hidden}
.note{margin:6px 0 10px;padding:10px 12px;border-radius:10px;background:var(--surface);border:1px solid var(--line);font-size:.95em}
.note.warn{border-color:#c9a227}
.btn.small{padding:6px 10px;font-size:.9em;margin-left:6px}
.brand-logo{width:36px;height:36px;border-radius:8px;vertical-align:middle;margin-right:8px;background:#fff;padding:2px;box-sizing:border-box}
.toplink{margin:6px 0 2px;font-size:.95em}
.toplink a{color:var(--accent,#0072CE);text-decoration:none;font-weight:600}
.tabs a span{font-size:.68rem;letter-spacing:-.01em;white-space:nowrap}
.brand span{font-size:.95rem;line-height:1.15;font-weight:700}
@media (max-width:420px){.brand span{font-size:.85rem}}
