:root {
  --bg: #f7f7f5;
  --card: #ffffff;
  --text: #16171a;
  --muted: #6b6f76;
  --border: #e4e4e0;
  --accent: #f5d400;
  --accent-text: #16171a;
  --key: #16171a;
  --key-text: #f5d400;
  --om: #e4e4e0;
  --om-text: #4a4a4a;
  --danger: #c23b3b;
  --radius: 14px;
  --nav-h: 62px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0d0e;
    --card: #17181b;
    --text: #f2f2f0;
    --muted: #9a9ca3;
    --border: #2a2b2f;
    --accent: #f5d400;
    --accent-text: #0d0d0e;
    --key: #f5d400;
    --key-text: #0d0d0e;
    --om: #2a2b2f;
    --om-text: #c7c9cf;
  }
}
:root[data-theme="light"] {
  --bg: #f7f7f5; --card: #ffffff; --text: #16171a; --muted: #6b6f76; --border: #e4e4e0;
  --key: #16171a; --key-text: #f5d400; --om: #e4e4e0; --om-text: #4a4a4a;
}
:root[data-theme="dark"] {
  --bg: #0d0d0e; --card: #17181b; --text: #f2f2f0; --muted: #9a9ca3; --border: #2a2b2f;
  --key: #f5d400; --key-text: #0d0d0e; --om: #2a2b2f; --om-text: #c7c9cf;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
}
a { color: inherit; text-decoration: none; }

#main { max-width: 640px; margin: 0 auto; padding: 16px 16px 40px; }
.page-head h1 { margin: 0; font-size: 26px; letter-spacing: -0.02em; }
.page-head .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.sub { color: var(--muted); font-size: 14px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 22px 2px 8px; font-weight: 700; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card.big { padding: 18px 16px 16px; }

.backlink { display: inline-block; margin-bottom: 10px; color: var(--muted); font-size: 14px; }

.badge { font-size: 11px; font-weight: 800; letter-spacing: 0.04em; padding: 4px 8px; border-radius: 999px; white-space: nowrap; }
.badge-key { background: var(--key); color: var(--key-text); }
.badge-om { background: var(--om); color: var(--om-text); }

.daycard-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.daycard-day { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; }
.daycard-title { margin: 2px 0 10px; font-size: 20px; }
.duration { display: inline-block; background: var(--om); color: var(--om-text); font-weight: 700; font-size: 13px; padding: 6px 10px; border-radius: 8px; margin-bottom: 12px; }

.focustoggle { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.focustoggle label { display: flex; align-items: center; gap: 6px; }

.block { margin: 14px 0; }
.block-h { font-weight: 800; font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 6px; }
.line { font-size: 15px; line-height: 1.5; padding: 3px 0; }
.line.muted { color: var(--muted); }
.line.mistake { color: var(--danger); }
.line.big-target { font-size: 20px; font-weight: 800; color: var(--text); }
.ln-prefix { font-weight: 700; }
.lvl-chip { display: inline-block; }
.lvl-chip.lvl-match { font-weight: 800; background: rgba(245,212,0,0.25); padding: 1px 6px; border-radius: 6px; }
.lvl-sep { margin: 0 6px; color: var(--muted); }
.lvl-tag { font-size: 11px; color: var(--muted); font-weight: 800; }
.ln.lvl-match { font-weight: 700; background: rgba(245,212,0,0.18); padding: 1px 6px; border-radius: 6px; }
.ln-trailing { color: var(--muted); }

.note { background: var(--om); color: var(--om-text); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-top: 10px; }
.harder { margin-top: 10px; font-size: 14px; }
.harder summary { cursor: pointer; font-weight: 700; color: var(--muted); }
.harder p { margin: 8px 0 0; }

.check { display: flex; align-items: center; gap: 8px; margin-top: 16px; font-weight: 700; font-size: 15px; }
.check input { width: 20px; height: 20px; }

.btn { display: block; text-align: center; background: var(--accent); color: var(--accent-text); font-weight: 800; padding: 12px 14px; border-radius: 10px; border: none; font-size: 15px; cursor: pointer; width: 100%; margin-top: 10px; }
.btn.small { display: inline-block; width: auto; padding: 8px 12px; font-size: 13px; margin: 0 6px 6px 0; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.linkbtn { background: none; border: none; color: var(--muted); text-decoration: underline; cursor: pointer; font-size: 13px; padding: 0; }

.restnote { font-weight: 800; font-size: 18px; margin: 6px 0; }

.weekstrip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.stripday { flex: 1; min-width: 40px; text-align: center; padding: 8px 4px; border-radius: 10px; background: var(--card); border: 1px solid var(--border); }
.stripday.today { border-color: var(--accent); border-width: 2px; }
.stripday-label { font-size: 11px; color: var(--muted); font-weight: 700; }
.stripday-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); margin: 6px auto 0; }
.stripday.done .stripday-dot { background: var(--accent); }

.phaseintro { font-size: 14px; color: var(--muted); margin-bottom: 10px; }
.weekrow { display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px; margin-bottom: 8px; }
.weekrow-num { font-weight: 800; width: 34px; flex-shrink: 0; }
.weekrow-mid { flex: 1; min-width: 0; }
.weekrow-title { font-weight: 700; font-size: 15px; }
.weekrow-bar { height: 4px; background: var(--border); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.weekrow-fill { height: 100%; background: var(--accent); }
.weekrow-bar-off { font-size: 13px; color: var(--muted); margin-top: 2px; }
.weekrow-pct { font-size: 13px; color: var(--muted); font-weight: 700; }

.dayrow { display: flex; align-items: center; gap: 10px; padding: 12px 4px; border-bottom: 1px solid var(--border); }
.dayrow.rest { color: var(--muted); }
.dayrow-day { font-weight: 800; font-size: 12px; text-transform: uppercase; width: 36px; flex-shrink: 0; white-space: nowrap; color: var(--muted); }
.dayrow-mid { flex: 1; min-width: 0; }
.dayrow-title { font-weight: 700; font-size: 15px; }
.dayrow-dur { font-size: 13px; color: var(--muted); }
.dayrow.done .dayrow-title { color: var(--muted); }
.tick { color: var(--accent); font-weight: 900; }

.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 700; }
.field.small { margin-bottom: 8px; }
input[type=text], input[type=number], input[type=date], select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 15px; font-family: inherit;
}
.levelpicker { padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); width: 100%; }

.onboarding h2 { margin-top: 0; }

.tablewrap { overflow-x: auto; margin-bottom: 12px; border: 1px solid var(--border); border-radius: 12px; }
.mtable { border-collapse: collapse; width: 100%; font-size: 13px; }
.mtable th, .mtable td { padding: 8px 10px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--border); }
.mtable thead th { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.mtable tr.me { background: rgba(245,212,0,0.15); font-weight: 800; }

.segtabs { display: flex; gap: 6px; margin: 10px 0 16px; }
.segtab { flex: 1; text-align: center; padding: 9px 6px; border-radius: 9px; background: var(--card); border: 1px solid var(--border); font-size: 13px; font-weight: 700; color: var(--muted); }
.segtab.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.stationnav { display: flex; justify-content: space-between; margin-top: 14px; font-weight: 700; }

.logentry-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.felt { font-size: 12px; background: var(--om); color: var(--om-text); padding: 2px 8px; border-radius: 999px; }
.logentry-actions { margin-top: 8px; font-size: 13px; color: var(--muted); }
.benchtabs { display: flex; flex-wrap: wrap; }
.benchform { margin-top: 10px; }
.qc-result { font-size: 22px; font-weight: 800; margin-top: 8px; }

.racedaybox .block-h { margin-top: 12px; }

/* modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.modal { background: var(--card); width: 100%; max-width: 640px; border-radius: 16px 16px 0 0; padding: 20px; max-height: 85vh; overflow-y: auto; }
.modal h2 { margin-top: 0; }
.modal-actions { display: flex; gap: 10px; margin-top: 10px; }
.modal-actions .btn { margin-top: 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px); transform: translate(-50%, 10px);
  background: var(--key); color: var(--key-text); padding: 10px 16px; border-radius: 999px;
  font-weight: 700; font-size: 14px; opacity: 0; transition: opacity 0.2s, transform 0.2s; z-index: 60; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* bottom nav */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; height: var(--nav-h);
  background: var(--card); border-top: 1px solid var(--border);
  display: flex; padding-bottom: env(safe-area-inset-bottom, 0px); z-index: 40;
}
.navbtn {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; background: none; border: none; color: var(--muted); font-size: 11px; font-weight: 700; cursor: pointer; font-family: inherit;
}
.navbtn .navicon { font-size: 20px; line-height: 1; }
.navbtn.active { color: var(--text); }
.navbtn.active .navicon { filter: none; }

@media (min-width: 700px) {
  #main { padding-top: 24px; }
}
