:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1f2630;
  --line: #2b3340;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #38bdf8;
  --swim: #38bdf8;
  --bike: #f59e0b;
  --run: #22c55e;
  --strength: #a78bfa;
  --tri: #f472b6;
  --rest: #64748b;
  --other: #94a3b8;
  --good: #22c55e;
  --fair: #f59e0b;
  --low: #ef4444;
  --radius: 14px;
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f9; --surface: #ffffff; --surface-2: #eef1f5; --line: #dde3ea;
    --text: #111827; --muted: #5b6573; --rest: #94a3b8; --shadow: 0 1px 2px rgba(15,23,42,.06);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

/* ---- top bar + tabs ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; text-decoration: none; }
.countdown { font-size: 13px; color: var(--muted); text-align: right; }
.countdown b { color: var(--text); font-size: 15px; }

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 9px; font-size: 12px; text-decoration: none; color: var(--muted);
}
.tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabs a.active { color: var(--accent); }

main { max-width: 680px; margin: 0 auto; padding: 14px 16px 24px; display: grid; gap: 14px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* ---- cards ---- */
section.card { scroll-margin-top: 70px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-head h2 { font-size: 15px; letter-spacing: .01em; }
.card-head .muted { font-size: 13px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 420px) { .grid-2 { grid-template-columns: 1fr; } }

.daybar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.daybar h1 { font-size: 22px; }
.daybar .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.iconbtn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); font-size: 18px; display: inline-grid; place-items: center; cursor: pointer;
}
.iconbtn:disabled { opacity: .35; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap;
}
.chip.phase { color: var(--text); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.banner { border-left: 4px solid var(--fair); }

/* ---- sessions ---- */
.sessions { display: grid; gap: 10px; }
.session {
  display: grid; grid-template-columns: 4px 1fr; gap: 12px;
  background: var(--surface-2); border-radius: 12px; padding: 12px 12px 12px 0; overflow: hidden;
}
.session .bar { background: var(--c, var(--other)); border-radius: 0 4px 4px 0; }
.session.done { opacity: .78; }
.session.done .title { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--text) 40%, transparent); }
.session .top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.session .sport { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--c); }
.session .title { font-weight: 600; margin-top: 2px; }
.session .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.session .minimum { font-size: 20px; font-weight: 700; white-space: nowrap; text-align: right; }
.session .minimum small { display: block; font-size: 11px; font-weight: 500; color: var(--muted); }
.session .actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.session .note { margin-top: 8px; font-size: 13px; color: var(--muted); }
.session.race { background: linear-gradient(135deg, color-mix(in srgb, var(--tri) 22%, var(--surface-2)), var(--surface-2)); }
.session.rest .title { color: var(--muted); font-weight: 500; }
.s-swim { --c: var(--swim); } .s-bike { --c: var(--bike); } .s-run { --c: var(--run); }
.s-strength { --c: var(--strength); } .s-tri { --c: var(--tri); } .s-rest { --c: var(--rest); } .s-other, .s-walk { --c: var(--other); }

.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 10px; padding: 7px 12px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #04121c; }
.btn.on-done { background: var(--good); border-color: var(--good); color: #052e14; }
.btn.on-partial { background: var(--fair); border-color: var(--fair); color: #2b1a02; }
.btn.on-skipped { background: var(--rest); border-color: var(--rest); color: #fff; }
.btn:disabled { opacity: .5; }
.status-pill { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.status-pill.done { background: color-mix(in srgb, var(--good) 22%, transparent); color: var(--good); }
.status-pill.partial { background: color-mix(in srgb, var(--fair) 22%, transparent); color: var(--fair); }
.status-pill.skipped { background: color-mix(in srgb, var(--rest) 30%, transparent); color: var(--muted); }

.activity {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px;
  background: color-mix(in srgb, var(--c) 10%, var(--surface-2)); font-size: 13px; margin-top: 8px;
}
.activity .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; }
.activity b { font-weight: 600; }

details.gym { margin-top: 10px; }
details.gym summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--strength); }
.exercises { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 8px; }
.exercises li { padding: 8px 10px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); }
.exercises .ex-top { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.exercises .ex-top span { color: var(--strength); white-space: nowrap; }
.exercises .how { font-size: 13px; color: var(--muted); margin-top: 2px; }
.exercises .prog { font-size: 12px; margin-top: 3px; }

/* ---- readiness ---- */
.readiness { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; }
.ring { width: 96px; height: 96px; position: relative; }
.ring svg { width: 96px; height: 96px; transform: rotate(-90deg); }
.ring .val { position: absolute; inset: 0; display: grid; place-items: center; font-size: 28px; font-weight: 800; }
.ring .val small { display: block; font-size: 10px; font-weight: 600; color: var(--muted); text-align: center; margin-top: -4px; letter-spacing: .06em; }
.readiness h3 { font-size: 17px; }
.readiness .advice { color: var(--muted); font-size: 13px; margin-top: 4px; }
.parts { display: grid; gap: 8px; margin-top: 12px; }
.part { display: grid; grid-template-columns: 96px 1fr 34px; gap: 10px; align-items: center; font-size: 13px; }
.part .track { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.part .fill { height: 100%; border-radius: 99px; background: var(--lvl); }
.part .detail { grid-column: 2 / 4; margin-top: -6px; font-size: 12px; color: var(--muted); }
.lvl-good { --lvl: var(--good); } .lvl-fair { --lvl: var(--fair); } .lvl-low { --lvl: var(--low); }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 20px; font-weight: 700; margin-top: 2px; }
.stat .value small { font-size: 12px; font-weight: 500; color: var(--muted); }
.stat svg.spark { display: block; width: 100%; height: 28px; margin-top: 6px; }
.spark path.line { fill: none; stroke: var(--c, var(--accent)); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark circle { fill: var(--c, var(--accent)); }

/* ---- week progress ---- */
.progress-row { display: grid; grid-template-columns: 74px 1fr auto; gap: 10px; align-items: center; font-size: 13px; margin-top: 8px; }
.progress-row .track { height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress-row .fill { height: 100%; background: var(--c); border-radius: 99px; transition: width .4s; }
.big-progress { display: flex; align-items: baseline; gap: 8px; }
.big-progress .value { font-size: 26px; font-weight: 800; }

.kv { display: grid; gap: 8px; font-size: 14px; }
.kv .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

/* ---- week view ---- */
.day-card .day-title { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.day-card .day-title h3 { font-size: 15px; }
.day-card.today { border-color: var(--accent); }
.day-card.past .session:not(.done):not(.rest) { outline: 1px dashed color-mix(in srgb, var(--low) 45%, transparent); }
.compact .session { padding: 10px 10px 10px 0; }
.compact .session .minimum { font-size: 15px; }
.compact .session .actions .btn { padding: 5px 10px; }

/* ---- plan view ---- */
.phase-strip { display: flex; height: 12px; border-radius: 99px; overflow: hidden; margin: 6px 0 4px; }
.phase-strip span { display: block; height: 100%; }
.weeks-list { display: grid; gap: 6px; }
.week-row {
  display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; align-items: center;
  padding: 10px 12px; border-radius: 12px; background: var(--surface-2); text-decoration: none;
}
.week-row.current { outline: 2px solid var(--accent); }
.week-row .wk { font-weight: 800; font-size: 16px; text-align: center; }
.week-row .dates { font-size: 12px; color: var(--muted); }
.week-row .bar { height: 4px; border-radius: 99px; background: var(--line); margin-top: 6px; overflow: hidden; }
.week-row .bar span { display: block; height: 100%; background: var(--good); }
.week-row .race { color: var(--tri); font-size: 12px; font-weight: 700; }
.event { display: grid; grid-template-columns: 64px 1fr; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.event:first-child { border-top: 0; }
.event .when { font-weight: 800; font-size: 13px; }
.event.past { opacity: .5; }

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login { width: min(360px, 100%); display: grid; gap: 12px; text-align: center; justify-items: center; }
.login input {
  width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); font: inherit;
}
.login .btn { width: 100%; padding: 12px; }
.error { color: var(--low); margin: 0; }
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 10px; font-size: 13px; z-index: 20;
}
.exercises .howto { display: inline-block; margin-top: 4px; font-size: 12px; font-weight: 600; color: var(--accent); text-decoration: none; }

/* ---- wide screens: unfolded Galaxy Fold inner screen, tablets, desktop ----
   The folded cover screen keeps the single column above. */
.days { display: grid; gap: 14px; }
@media (min-width: 700px) {
  main { max-width: 1180px; padding: 18px 20px 28px; }
  /* Today + Gym: cards flow down two columns in reading order; headers span both. */
  main.v-today, main.v-gym { display: block; columns: 2; column-gap: 16px; }
  main.v-today > *, main.v-gym > * { break-inside: avoid; margin: 0 0 16px; }
  .span-all { column-span: all; }
  main.v-today .grid-2 { grid-template-columns: 1fr; }
  /* Week: summary on top, days as a grid of cards. */
  .days { grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); align-items: start; }
  /* Plan: phases across the top, events beside the list of weeks. */
  main.v-plan { grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); align-items: start; }
  main.v-plan .plan-phases { grid-column: 1 / -1; }
  main.v-admin { grid-template-columns: 1fr 1fr; align-items: start; }
  main.v-plan .plan-events { position: sticky; top: 70px; }
  .tabs { left: 50%; transform: translateX(-50%); max-width: 640px; border-left: 1px solid var(--line); border-right: 1px solid var(--line); border-radius: 14px 14px 0 0; }
}
@media (min-width: 1100px) {
  main.v-today { columns: 3; }
}

/* Reminders & connections (Plan screen) */
.conn { display: grid; gap: 16px; }
.conn h3 { font-size: 14px; margin: 0 0 4px; }
.conn p { margin: 4px 0; }
.setup summary { cursor: pointer; font-size: 14px; color: var(--accent); margin-top: 6px; }
.setup ol { padding-left: 20px; margin: 8px 0 0; display: grid; gap: 10px; }
.kvs { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 6px 0; padding: 8px 10px; background: var(--surface-2); border-radius: 10px; word-break: break-all; }
.kvs span { color: var(--muted); }
.form { display: grid; gap: 8px; margin-top: 8px; }
.form input { font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); min-width: 0; }
.chip.strava, a.strava { color: #fc5200; }
.chip.keiser { color: #c8102e; }
.btn.strava-btn { background: #fc5200; border-color: #fc5200; color: #fff; text-decoration: none; display: inline-flex; align-items: center; }
.admin .actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
button.chip { font: inherit; font-size: 12px; cursor: pointer; }
.time-edit { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.time-edit input { font: inherit; font-size: 16px; padding: 4px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); color-scheme: light dark; }
.time-edit .btn { padding: 5px 10px; }
.admin h3 { font-size: 14px; margin: 0 0 4px; }
.admin p { margin: 4px 0; }

/* Coach */
.coach h3 { margin: 14px 0 6px; font-weight: 600; }
.coach-summary p { margin: 0 0 8px; line-height: 1.45; }
.proposal { display: grid; gap: 6px; padding: 10px 0; border-top: 1px solid var(--line); }
.proposal .actions { display: flex; gap: 6px; }
.proposal.rejected, .proposal.stale { opacity: .55; }
.niggle { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 4px 0; }
.form.inline { grid-template-columns: 1fr auto; }
.form textarea { font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); resize: vertical; }
