:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #15181c;
  --muted: #646b75;
  --line: #e1e4e8;
  --accent: #d9442b;
  --accent-text: #ffffff;
  --done: #1f8a4c;
  --done-bg: #e8f5ee;
  --started-bg: #fff6e0;
  --radius: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1a1e24;
    --text: #e6e8eb;
    --muted: #9aa2ad;
    --line: #2c323a;
    --accent: #e8553d;
    --done: #4cc47f;
    --done-bg: #16301f;
    --started-bg: #352c14;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: inherit; text-decoration: none; }
h1 { font-size: 1.6rem; margin: 0.25rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.5rem; }
h3 { font-size: 1rem; margin: 0 0 0.5rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.right { text-align: right; }

.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(0.75rem + env(safe-area-inset-top)) 1rem 0.75rem;
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 2;
}
.brand { font-weight: 700; letter-spacing: -0.01em; }
.brand::before { content: "▮━▮ "; color: var(--accent); font-size: 0.8em; }
.mode { color: var(--muted); font-size: 0.9rem; }

.tabs { display: flex; gap: 0.25rem; padding: 0.5rem 1rem 0; background: var(--surface); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a { padding: 0.5rem 0.75rem; border-bottom: 2px solid transparent; color: var(--muted); white-space: nowrap; }
.tabs a.on { color: var(--text); border-color: var(--accent); font-weight: 600; }

main { max-width: 960px; margin: 0 auto; padding: 1rem; }
.back { display: inline-block; color: var(--muted); margin-bottom: 0.5rem; }

.hero { padding: 1.5rem 0 1rem; }
.hero h1 { font-size: 2rem; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; margin-bottom: 0.75rem; display: block;
}
.card.link:hover { border-color: var(--accent); }
.cards.two { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.list { margin: 0.75rem 0 1.25rem; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; }
.grow { flex: 1; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.next { border-color: var(--accent); }
.plain { list-style: none; padding: 0; margin: 0.5rem 0 1rem; }
.plain li { padding: 0.25rem 0; }

/* forms */
input, select, textarea {
  font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 0.5rem 0.6rem; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type="checkbox"] { width: 1.4rem; height: 1.4rem; accent-color: var(--done); }
label { display: block; font-size: 0.9rem; color: var(--muted); margin-bottom: 0.75rem; }
label input, label select, label textarea { margin-top: 0.25rem; color: var(--text); }
form.inline { display: flex; gap: 0.5rem; flex-wrap: wrap; }
form.inline input, form.inline select { flex: 1; min-width: 160px; }
.grid3 { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.num { width: 5rem; text-align: center; }
.title-input { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.5rem; }

button, .btn {
  font: inherit; cursor: pointer; border-radius: 8px; padding: 0.5rem 0.9rem;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  display: inline-block; text-align: center;
}
button:hover, .btn:hover { border-color: var(--muted); }
.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.danger { color: var(--accent); }
.small.btn, .btn.small { padding: 0.3rem 0.6rem; font-size: 0.85rem; }
.big { width: 100%; padding: 0.9rem; font-size: 1.1rem; margin-top: 0.5rem; }
.icon { border: none; background: none; color: var(--muted); padding: 0.25rem 0.5rem; }
.icon:hover { color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: none; border-radius: 0; }
.seg button.on { background: var(--accent); color: var(--accent-text); }

/* progress */
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 0.5rem 0 0.25rem; }
.progress span { display: block; height: 100%; background: var(--done); }

/* week/day grids */
.days { display: grid; gap: 0.5rem; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); margin: 0.5rem 0; }
.day {
  display: flex; justify-content: space-between; gap: 0.5rem; align-items: center;
  padding: 0.6rem 0.75rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
}
.day.done { background: var(--done-bg); border-color: var(--done); }
.day.started { background: var(--started-bg); }
details { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.75rem 1rem; margin-bottom: 0.5rem; }
summary { cursor: pointer; font-weight: 600; }

/* program editor */
.week { padding-bottom: 1rem; }
.day-edit { border-top: 1px solid var(--line); padding: 0.75rem 0; }
.day-name { font-weight: 600; max-width: 360px; }
.table-wrap { overflow-x: auto; margin: 0.5rem 0; }
table { border-collapse: collapse; width: 100%; }
th { text-align: left; font-size: 0.8rem; color: var(--muted); font-weight: 500; padding: 0.25rem; }
td { padding: 0.2rem 0.25rem; vertical-align: middle; }
.week table td:first-child input { min-width: 150px; }
.week table td:nth-child(7) input { min-width: 140px; }

/* session logging */
.pill { background: var(--bg); border: 1px solid var(--line); border-radius: 99px; padding: 0.15rem 0.6rem; font-size: 0.85rem; white-space: nowrap; }
.target { margin: 0.25rem 0 0.5rem; }
.sets td, .sets th { text-align: center; }
.sets .num { width: 100%; max-width: 6rem; }
.sets tr.done input.num { border-color: var(--done); }
.athlete-link { color: var(--accent); }
.week table select { min-width: 6.5rem; }

/* auth & accounts */
.auth { max-width: 420px; margin: 2rem auto; }
.auth h1 { margin-top: 0; }
.auth-tabs { margin: 0.5rem 0 1rem; }
.stack { display: flex; flex-direction: column; gap: 0.25rem; }
.stack label { margin-bottom: 0.5rem; }
.link-btn { border: none; background: none; padding: 0.25rem; color: var(--accent); cursor: pointer; font: inherit; font-size: 0.9rem; }
.link-btn:hover { text-decoration: underline; }
.mode { display: flex; align-items: center; gap: 0.5rem; }
.who { max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 520px) { .who { display: none; } }
.pill.warn { background: var(--started-bg); border-color: transparent; color: var(--text); }
code.invite { font: 600 1.5rem/1 ui-monospace, Menlo, monospace; letter-spacing: 0.15em; padding: 0.5rem 0.75rem; background: var(--bg); border: 1px dashed var(--line); border-radius: 8px; }
.loading { text-align: center; color: var(--muted); padding: 3rem; }
button:disabled { opacity: 0.6; cursor: wait; }

#toast {
  position: fixed; left: 50%; bottom: calc(1rem + env(safe-area-inset-bottom)); transform: translate(-50%, 150%);
  max-width: min(90vw, 480px); padding: 0.75rem 1rem; border-radius: 10px; color: #fff; background: #b3261e;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.2); transition: transform 0.25s; z-index: 10;
}
#toast.ok { background: var(--done); }
#toast.show { transform: translate(-50%, 0); }
.invited { background: var(--done-bg); border-radius: 8px; padding: 0.6rem 0.75rem; margin: 0 0 0.75rem; }
.invite-row { margin-top: 0.75rem; }
