/* exercise — teema „rajamärk”
   Põhjamaine välijõusaal: männiroheline, samblikuhall, rajamärgi kollane.
   Ühe julge elemendi reegel: edetabeli rada (päevade kaupa jaotatud riba + kollane lipp). */

:root {
  --pine: #1e3a32;
  --pine-2: #2c5246;
  --lichen: #e7ebe3;
  --paper: #fbfcf8;
  --line: #d3dacf;
  --ink: #17251f;
  --stone: #5f6d65;
  --marker: #f0b323;
  --marker-ink: #6b4b00;
  --moss: #2f7a4a;
  --berry: #a3274a;
  --fill: var(--pine);
  --track: #dde3d8;
  --focus: #1f6fd1;

  --font-body: "Barlow", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-cond: "Barlow Condensed", "Arial Narrow", "Roboto Condensed", system-ui, sans-serif;

  --r-sm: 6px;
  --r-md: 10px;
  --gap: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --pine: #8fc4a8;
    --pine-2: #a9d6bd;
    --lichen: #101815;
    --paper: #18221e;
    --line: #2b3832;
    --ink: #e5ebe4;
    --stone: #93a199;
    --marker: #f2bd3d;
    --marker-ink: #f2bd3d;
    --moss: #6cc48c;
    --berry: #ef7a98;
    --fill: #6fae8c;
    --track: #24302b;
    --focus: #79b2ff;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--lichen);
  color: var(--ink);
  font: 400 17px/1.5 var(--font-body);
  font-feature-settings: "tnum" 0;
  min-height: 100vh;
}

a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

h1, h2, h3 { font-family: var(--font-cond); font-weight: 600; line-height: 1.1; margin: 0; letter-spacing: 0.005em; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.fig { font-family: var(--font-cond); font-weight: 600; font-variant-numeric: tabular-nums; }
.muted { color: var(--stone); }

/* ---------------- Ülariba ---------------- */

.topbar {
  background: #1e3a32;
  color: #eef2ea;
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 680px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}

.wordmark {
  font-family: var(--font-cond); font-weight: 700; font-size: 26px; line-height: 1;
  text-decoration: none; letter-spacing: -0.01em;
  display: inline-flex; align-items: center; gap: 8px;
}
/* Rajamärk: kollane triip valgel taustal, nagu matkaraja puutüvel. */
.wordmark::before {
  content: ""; width: 12px; height: 18px; border-radius: 2px;
  background: linear-gradient(#fff 0 30%, #f0b323 30% 70%, #fff 70% 100%);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.15);
}

.topnav { display: flex; align-items: center; gap: 2px; font-size: 15px; }
.topnav a, .topnav button {
  color: #d6e0d8; text-decoration: none; padding: 8px 10px; border-radius: var(--r-sm);
  font: inherit; background: none; border: 0; cursor: pointer; min-height: 40px;
  display: inline-flex; align-items: center;
}
.topnav a:hover, .topnav button:hover { color: #fff; background: rgba(255,255,255,0.08); }
.topnav a[aria-current="page"] { color: #fff; box-shadow: inset 0 -3px 0 #f0b323; border-radius: 0; }
.logout { margin: 0; }

@media (max-width: 560px) {
  .topbar-inner { flex-wrap: wrap; padding-bottom: 0; row-gap: 4px; }
  .topnav {
    flex-basis: 100%; overflow-x: auto; scrollbar-width: none; margin: 0 -8px;
    font-size: 15px;
  }
  .topnav::-webkit-scrollbar { display: none; }
  .topnav a, .topnav button { padding: 8px; white-space: nowrap; }
  .logout { margin-left: auto; }
}

/* ---------------- Leht ---------------- */

.page {
  max-width: 680px; margin: 0 auto;
  padding: 20px 16px calc(48px + env(safe-area-inset-bottom));
}

.page-title { font-size: 34px; margin: 4px 0 18px; }
.section-title { font-size: 22px; margin: 28px 0 10px; }
.count { color: var(--stone); font-weight: 500; }
.crumb { margin: 0; font-size: 15px; color: var(--stone); }
.lead { color: var(--stone); margin: 6px 0 16px; max-width: 60ch; }

.notice {
  margin: 0 0 14px; padding: 10px 14px; border-radius: var(--r-sm);
  background: var(--paper); border-left: 4px solid var(--pine);
}
.notice-ok { border-left-color: var(--moss); }
.notice-error { border-left-color: var(--berry); }

/* ---------------- Nupud ja vormid ---------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  font: 600 16px/1 var(--font-body); text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--stone); }
.btn-primary { background: var(--pine); border-color: var(--pine); color: var(--paper); }
.btn-primary:hover { background: var(--pine-2); border-color: var(--pine-2); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.6; cursor: progress; }

.link-btn {
  background: none; border: 0; padding: 6px 4px; color: var(--berry);
  font: inherit; font-size: 15px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px;
}

label { display: flex; flex-direction: column; gap: 4px; font-size: 15px; font-weight: 500; }
.field-hint { font-weight: 400; color: var(--stone); font-size: 13px; }

input, textarea, select {
  font: 400 17px/1.3 var(--font-body); color: var(--ink);
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 10px 12px; min-height: 44px; width: 100%;
}
input:hover, textarea:hover { border-color: var(--stone); }
input:focus-visible, textarea:focus-visible { border-color: var(--focus); }
textarea { resize: vertical; }
.mono-ish { font-variant-numeric: tabular-nums; letter-spacing: 0.04em; }

.check { flex-direction: row; align-items: center; gap: 10px; font-weight: 500; }
.check input { width: 20px; height: 20px; min-height: 0; accent-color: var(--pine); margin: 0; }

.stack { display: grid; gap: 14px; }
.grid-form { display: grid; gap: 14px; align-items: end; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.span-2 { grid-column: 1 / -1; }
@media (max-width: 480px) { .grid-2 { grid-template-columns: 1fr; } }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 18px; }

.panel {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 18px; margin: 0 0 22px;
}
.panel h2 { font-size: 22px; margin-bottom: 12px; }

.presets { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.presets-label { font-size: 14px; color: var(--stone); margin-right: 2px; }
.chip {
  font: 500 14px/1 var(--font-body); padding: 8px 11px; min-height: 36px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--lichen); color: var(--ink); cursor: pointer;
}
.chip:hover { border-color: var(--stone); }
.chip.is-on { background: var(--pine); color: var(--paper); border-color: var(--pine); }

/* ---------------- Ridade nimekiri (admin) ---------------- */

.rows { list-style: none; margin: 0 0 22px; padding: 0; border-top: 1px solid var(--line); }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 2px; border-bottom: 1px solid var(--line);
}
.row-main { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; min-width: 0; }
.row-name { font-weight: 600; font-size: 18px; }
.row-sub { flex-basis: 100%; font-size: 14px; color: var(--stone); }
.row.is-inactive .row-name { color: var(--stone); }
.tag {
  font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--track); color: var(--ink);
}
.tag-muted { color: var(--stone); }

.row-action summary {
  cursor: pointer; font-size: 15px; color: var(--stone); padding: 8px 4px; list-style: none;
}
.row-action summary::-webkit-details-marker { display: none; }
.row-action summary::after { content: " ▾"; }
.row-action[open] summary { color: var(--ink); }
.inline-form { display: flex; gap: 8px; margin-top: 6px; }
.inline-form input { width: 12rem; }

.people { list-style: none; padding: 0; margin: 0 0 16px; display: flex; flex-wrap: wrap; gap: 8px; }
.people li {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--lichen);
}
.people form { margin: 0; }
.add-people fieldset { border: 0; padding: 0; margin: 0 0 12px; }
.add-people legend { font-weight: 600; margin-bottom: 8px; }
.pick { display: flex; flex-wrap: wrap; gap: 8px; }
.pick-item {
  flex-direction: row; align-items: center; gap: 8px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: var(--r-sm); cursor: pointer; font-weight: 500;
}
.pick-item input { width: 18px; height: 18px; min-height: 0; margin: 0; accent-color: var(--pine); }
.pick-item:has(input:checked) { border-color: var(--pine); box-shadow: inset 0 0 0 1px var(--pine); }

/* ---------------- Kasutaja andmed ---------------- */

.creds h1 { font-size: 28px; }
.creds-block {
  margin: 0 0 16px; padding: 14px 16px; border-radius: var(--r-sm);
  background: var(--lichen); border: 1px dashed var(--stone);
  font: 500 16px/1.6 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  white-space: pre-wrap; word-break: break-all;
}

/* ---------------- Sisselogimine ---------------- */

body.auth { display: grid; place-items: center; }
body.auth .page { width: 100%; max-width: 420px; }
.auth-panel { padding: 8px 0; }
.auth-panel h1 { font-size: 30px; margin: 22px 0 8px; }
.wordmark-lg { font-size: 40px; margin: 0; color: var(--pine); }
.auth-foot { color: var(--stone); font-size: 15px; margin-top: 18px; }

/* ---------------- Tühi olek ja vead ---------------- */

.emptystate { padding: 32px 0; }
.emptystate h1 { font-size: 32px; margin-bottom: 8px; }
.emptystate p { color: var(--stone); max-width: 52ch; }
.err-code { font: 700 72px/1 var(--font-cond); color: var(--marker-ink); margin: 0 0 8px; }

/* ---------------- Võistluse vahekaardid ---------------- */

.tabs {
  display: flex; gap: 4px; overflow-x: auto; margin: -4px -16px 18px; padding: 0 16px;
  scrollbar-width: none; border-bottom: 1px solid var(--line);
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  flex: none; padding: 10px 12px; text-decoration: none; color: var(--stone);
  font-weight: 500; white-space: nowrap; border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--marker); }

/* ---------------- Võistluse päis ---------------- */

.comp-head { margin-bottom: 22px; }
.comp-status {
  display: inline-flex; align-items: center; gap: 7px; margin: 0 0 6px;
  font-size: 14px; font-weight: 600; color: var(--stone);
}
.comp-status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--stone); }
.status-active::before { background: var(--moss); }
.status-upcoming::before { background: var(--marker); }

.comp-title { font-size: clamp(34px, 9vw, 52px); font-weight: 700; line-height: 1; letter-spacing: -0.01em; }
.comp-desc { margin: 10px 0 0; color: var(--stone); max-width: 60ch; }

.facts {
  display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 18px 0 0;
}
.facts div { display: flex; flex-direction: column-reverse; }
.facts dt { font-size: 14px; color: var(--stone); }
.facts dd { margin: 0; font-size: 17px; color: var(--stone); }
.facts .fig { font-size: 30px; color: var(--ink); line-height: 1.05; }
.fig-flag { position: relative; padding-left: 16px; }
.fig-flag::before {
  content: ""; position: absolute; left: 0; top: 0.18em; width: 9px; height: 0.8em;
  background: var(--marker); clip-path: polygon(0 0, 100% 50%, 0 100%);
}
.comp-dates { margin: 10px 0 0; font-size: 14px; color: var(--stone); }

/* ---------------- Sisestus ---------------- */

.logbox {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 16px; margin: 0 0 26px;
}
.logbox-goal h2 { font-size: 22px; }
.goal-line { margin: 4px 0 12px; color: var(--stone); }
.goal-line strong { color: var(--ink); font-family: var(--font-cond); font-size: 20px; font-weight: 600; }
.goal-met { color: var(--moss); font-weight: 600; }

.logform-row { display: flex; gap: 8px; }
.amount {
  flex: 1; min-width: 0; font: 600 34px/1 var(--font-cond); font-variant-numeric: tabular-nums;
  padding: 8px 14px; min-height: 60px; text-align: left;
}
.amount::-webkit-outer-spin-button, .amount::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.amount { -moz-appearance: textfield; appearance: textfield; }
.btn-add { min-height: 60px; padding: 0 26px; font-size: 18px; }

.bumps { display: grid; grid-template-columns: repeat(3, 1fr) 1.3fr; gap: 8px; margin-top: 8px; }
.bump {
  min-height: 52px; border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--lichen); color: var(--ink); cursor: pointer;
  font: 600 22px/1 var(--font-cond); font-variant-numeric: tabular-nums;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.bump:hover { border-color: var(--stone); }
.bump:active { background: var(--track); }
.bump-clear { font: 500 15px/1 var(--font-body); color: var(--stone); }

.backdate { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.backdate label { font-size: 15px; }
.backdate input { width: auto; }
.hint { font-size: 13px; color: var(--stone); margin: 10px 0 0; }

.logform.has-pending .amount { border-color: var(--marker); box-shadow: 0 0 0 1px var(--marker); }

/* ---------------- Edetabel ---------------- */

.board-title { font-size: 26px; margin: 0 0 12px; }
.empty { color: var(--stone); }

.racers { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.racer {
  display: grid; grid-template-columns: 44px 1fr; gap: 4px 10px;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 14px 16px 14px 10px;
}
.racer.is-me { border-color: var(--pine); box-shadow: inset 4px 0 0 var(--pine); }
.racer.is-inactive { opacity: 0.55; }

.racer-rank {
  font: 700 34px/1 var(--font-cond); font-variant-numeric: tabular-nums;
  color: var(--stone); text-align: center; padding-top: 2px;
}
.racer:first-child .racer-rank { color: var(--marker-ink); }

.racer-body { min-width: 0; }
.racer-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.racer-name { font-weight: 600; font-size: 18px; overflow-wrap: anywhere; }
.you {
  font-size: 12px; font-weight: 600; color: var(--pine); border: 1px solid currentColor;
  border-radius: 999px; padding: 1px 7px; vertical-align: 2px; margin-left: 4px;
}
.racer-score { white-space: nowrap; }
.racer-score .fig { font-size: 30px; line-height: 1; }
.racer-score .of { color: var(--stone); font-size: 15px; }

/* Rada: üks lõik iga võistluspäeva kohta. Päevade vahed joonistatakse täidise peale. */
.trail {
  position: relative; height: 14px; margin: 10px 0 8px; border-radius: 3px;
  background: var(--track);
}
.trail::after {
  content: ""; position: absolute; inset: 0; border-radius: 3px; pointer-events: none;
  background-image: linear-gradient(to right, transparent calc(100% - 2px), var(--paper) calc(100% - 2px));
  background-size: calc(100% / var(--days, 1)) 100%;
}
.trail-fill {
  position: absolute; inset: 0 auto 0 0; border-radius: 3px; background: var(--fill);
}
.is-done .trail-fill { background-color: var(--moss); }
.trail-flag {
  position: absolute; z-index: 1; top: -6px; bottom: -4px; width: 2px; margin-left: -1px;
  background: var(--ink);
}
.trail-flag::after {
  content: ""; position: absolute; top: 0; left: 2px; width: 11px; height: 9px;
  background: var(--marker); clip-path: polygon(0 0, 100% 50%, 0 100%);
}

.racer-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; font-size: 15px; color: var(--stone);
}
.pct { font-family: var(--font-cond); font-weight: 600; font-size: 18px; color: var(--ink); font-variant-numeric: tabular-nums; }
.delta { font-weight: 600; }
.delta-ahead { color: var(--moss); }
.delta-behind { color: var(--berry); }
.badge-done { color: var(--moss); font-weight: 600; }
.ago { margin-left: auto; font-size: 14px; }

.today {
  display: grid; grid-template-columns: auto auto 1fr auto; align-items: center; gap: 10px;
  margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); font-size: 15px;
}
.today-label { color: var(--stone); white-space: nowrap; }
.today-fig { font: 600 20px/1 var(--font-cond); font-variant-numeric: tabular-nums; }
.today-meter { height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; min-width: 40px; }
.today-meter span { display: block; height: 100%; background: var(--marker); }
.today-left { color: var(--stone); white-space: nowrap; font-variant-numeric: tabular-nums; }
.today-met .today-meter span { background: var(--moss); }
.today-met .today-left { color: var(--moss); font-weight: 600; }

.legend { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--stone); margin: 14px 0 0; max-width: 62ch; }
.legend-flag { flex: none; width: 10px; height: 9px; margin-top: 4px; background: var(--marker); clip-path: polygon(0 0, 100% 50%, 0 100%); }

@media (max-width: 400px) {
  .racer { grid-template-columns: 30px 1fr; padding-left: 8px; }
  .racer-rank { font-size: 26px; }
  .racer-score .fig { font-size: 26px; }
  .bumps { grid-template-columns: repeat(3, 1fr); }
  .bump-clear { grid-column: 1 / -1; min-height: 40px; }
}

@media (prefers-reduced-motion: no-preference) {
  .trail-fill { transition: width 400ms ease-out; }
}
