/* kmwo design tokens. Dark first. With no saved choice, light follows the
   system setting; a choice from the account menu sets data-theme on <html>
   (theme.js) and wins over the system. The light block appears twice
   because CSS can't share one block between a media query and a selector. */
:root {
  --bg: #0b0d10;
  --surface: #14171c;
  --surface-2: #1c2027;
  --line: rgba(255, 255, 255, .07);
  --line-strong: rgba(255, 255, 255, .14);
  --fg: #f2f4f7;
  --muted: #8a94a3;
  --lift: #5b8cff;
  --ride: #2dd4a7;
  --accent: #5b8cff;
  --accent-2: #8b6bff;
  --on-accent: #fff;
  --danger: #ff6b6b;
  --nudge: #ffc15e;
  --shadow: 0 1px 0 rgba(255, 255, 255, .04) inset, 0 8px 24px rgba(0, 0, 0, .35);
  --radius: 18px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f3f4f7;
    --surface: #ffffff;
    --surface-2: #f0f2f6;
    --line: rgba(15, 20, 30, .08);
    --line-strong: rgba(15, 20, 30, .16);
    --fg: #10141b;
    --muted: #5d6675;
    --lift: #2f66f0;
    --ride: #0c9a78;
    --accent: #2f66f0;
    --accent-2: #6a4cf0;
    --danger: #d43c3c;
    --nudge: #9a5b00;
    --shadow: 0 1px 2px rgba(15, 20, 30, .05), 0 8px 24px rgba(15, 20, 30, .06);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --line: rgba(15, 20, 30, .08);
  --line-strong: rgba(15, 20, 30, .16);
  --fg: #10141b;
  --muted: #5d6675;
  --lift: #2f66f0;
  --ride: #0c9a78;
  --accent: #2f66f0;
  --accent-2: #6a4cf0;
  --danger: #d43c3c;
  --nudge: #9a5b00;
  --shadow: 0 1px 2px rgba(15, 20, 30, .05), 0 8px 24px rgba(15, 20, 30, .06);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { background: var(--bg); }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.45 var(--font); font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
}
main { max-width: 560px; margin: 0 auto; padding: calc(20px + env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom)); }
h1 { font-size: 1.75rem; line-height: 1.15; letter-spacing: -.02em; margin: 0; font-weight: 800; }
h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; margin: 28px 4px 10px; }
h3 { font-size: 1rem; margin: 0; font-weight: 700; letter-spacing: -.01em; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.error { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); padding: 10px 12px; border-radius: 12px; }
.eyebrow { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; margin: 0 0 4px; }
svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* buttons and inputs */
button { font: inherit; color: inherit; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; cursor: pointer; transition: transform .12s ease, background .15s ease, opacity .15s; }
button:active { transform: scale(.97); }
button:disabled { opacity: .55; cursor: default; }
button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--on-accent);
  border: 0; padding: 15px 22px; font-weight: 700; border-radius: 14px;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 35%, transparent);
}
button.danger { background: transparent; color: var(--danger); border-color: transparent; }
button.link { border: 0; background: none; color: var(--accent); padding: 6px 2px; font-weight: 600; font-size: .88rem; }
.iconbtn { width: 42px; height: 42px; padding: 0; display: grid; place-items: center; border-radius: 50%; background: var(--surface); color: var(--muted); }
input, select, textarea {
  font: inherit; color: inherit; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 11px 12px; width: 100%; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
input[type=number] { -moz-appearance: textfield; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card p { margin: 6px 0; }

/* sign-in gate */
main.center { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; padding-bottom: 24px; }
.brand { width: 72px; height: 72px; border-radius: 20px; margin-bottom: 8px; box-shadow: 0 12px 32px color-mix(in srgb, var(--accent) 30%, transparent); }
main.center h1 { font-size: 2.2rem; }
main.center .primary { margin-top: 14px; min-width: 240px; }

/* top bar */
.top { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 18px; }
.back { display: inline-flex; align-items: center; gap: 4px; text-decoration: none; font-weight: 600; font-size: .92rem; margin-bottom: 14px; }

/* home: Next up hero */
.hero {
  display: block; position: relative; overflow: hidden; color: #fff; text-decoration: none;
  border-radius: 24px; padding: 20px; margin-bottom: 8px;
  background: linear-gradient(140deg, #3b6cff 0%, #7a5cff 100%);
  box-shadow: 0 16px 40px rgba(70, 90, 255, .35);
}
.hero.ride { background: linear-gradient(140deg, #10b98a 0%, #1aa3c4 100%); box-shadow: 0 16px 40px rgba(16, 185, 138, .3); }
.hero.done { background: linear-gradient(140deg, #3a3f4b, #23272f); box-shadow: none; }
.hero::after {
  content: ""; position: absolute; right: -60px; top: -60px; width: 200px; height: 200px; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 255, 255, .22), transparent);
}
.hero-top { display: flex; justify-content: space-between; align-items: center; }
.hero .eyebrow { color: rgba(255, 255, 255, .8); margin: 0; }
.pill { font-size: .78rem; font-weight: 700; padding: 5px 10px; border-radius: 999px; background: rgba(255, 255, 255, .2); backdrop-filter: blur(6px); }
.hero-kind { font-size: 2.6rem; font-weight: 800; letter-spacing: -.03em; line-height: 1.05; margin: 14px 0 6px; }
.hero p { margin: 0; color: rgba(255, 255, 255, .88); font-size: .95rem; max-width: 34ch; }
.hero-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; font-size: .85rem; font-weight: 600; }
.hero-foot .cta { display: inline-flex; align-items: center; gap: 6px; background: #fff; color: #1b1f2a; padding: 9px 14px; border-radius: 999px; }
.meter { height: 6px; border-radius: 999px; background: rgba(255, 255, 255, .22); margin-top: 14px; overflow: hidden; }
.meter i { display: block; height: 100%; background: #fff; border-radius: inherit; transition: width .4s ease; }

/* calendar */
.cal { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 10px 6px; box-shadow: var(--shadow); }
.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 4px; }
.grid.head { text-align: center; font-size: .7rem; color: var(--muted); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; margin-bottom: 6px; }
.wk { font-size: .68rem; color: var(--muted); font-weight: 600; margin: 8px 6px 4px; letter-spacing: .04em; white-space: pre; }
.wk.cur { color: var(--fg); }
.cell {
  aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border-radius: 12px; color: inherit; text-decoration: none; position: relative; transition: background .15s;
}
.cell:hover { background: var(--surface-2); }
.cell b { font-size: .95rem; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1; }
.cell small { position: absolute; top: 3px; font-size: .55rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.cell .dot { width: 6px; height: 6px; border-radius: 50%; background: transparent; }
.cell.lift .dot { background: var(--lift); }
.cell.ride .dot { background: var(--ride); }
.cell.off b { color: var(--muted); font-weight: 500; }
.cell.past:not(.done) b { color: var(--muted); }
.cell.missed .dot { background: transparent; box-shadow: inset 0 0 0 1.5px var(--muted); }
.cell.done { background: color-mix(in srgb, var(--lift) 18%, transparent); }
.cell.done.ride { background: color-mix(in srgb, var(--ride) 18%, transparent); }
.cell.done .dot { display: none; }
.cell .tick { width: 14px; height: 14px; stroke-width: 3; color: var(--lift); }
.cell.ride .tick { color: var(--ride); }
.cell .short { font-size: .55rem; font-weight: 700; color: var(--muted); line-height: 1; }
.cell.today { box-shadow: inset 0 0 0 2px var(--fg); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; justify-content: center; margin: 12px 0 0; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .dot { width: 8px; height: 8px; border-radius: 50%; }
.legend .dot.lift { background: var(--lift); } .legend .dot.ride { background: var(--ride); }
.legend .dot.missed { box-shadow: inset 0 0 0 1.5px var(--muted); }

/* day log */
.seg { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; gap: 4px; margin: 18px 0 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.seg button { border: 0; border-radius: 10px; padding: 11px; background: transparent; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface-2); color: var(--fg); box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }
.seg button.on[data-kind=lift] { color: var(--lift); }
.seg button.on[data-kind=ride] { color: var(--ride); }
.check { display: flex; align-items: center; gap: 10px; margin: 10px 2px; cursor: pointer; }
.toggle-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin: 0 0 12px; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.field > span { font-size: .78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.ex-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.target { font-size: .78rem; font-weight: 700; color: var(--lift); background: color-mix(in srgb, var(--lift) 14%, transparent); padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.nudge { color: var(--nudge); background: color-mix(in srgb, var(--nudge) 12%, transparent); font-weight: 600; padding: 8px 10px; border-radius: 10px; margin: 8px 0 4px !important; }
.setgrid { display: grid; grid-template-columns: 2.2em 1fr 1fr; gap: 8px 10px; align-items: center; margin-top: 12px; }
.setgrid .colhead { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; text-align: center; }
.setgrid .n { font-size: .8rem; color: var(--muted); font-weight: 700; }
.stepper { display: grid; grid-template-columns: 36px 1fr 36px; align-items: center; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.stepper button { border: 0; border-radius: 0; background: transparent; padding: 0; height: 42px; font-size: 1.15rem; color: var(--muted); }
.stepper button:active { background: var(--line); transform: none; }
.stepper input { border: 0; background: transparent; padding: 8px 0; border-radius: 0; box-shadow: none; min-width: 0; }
.settools { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.settools .check { margin: 0 0 0 auto; font-size: .85rem; }
.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.savebar > div { max-width: 528px; margin: 0 auto; display: flex; gap: 10px; }
.savebar .primary { flex: 1; }

/* plan */
.phases { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0 10px; }
.phase { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.phase span { display: block; font-size: .72rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.phase strong { font-size: 1.05rem; }
.phase em { display: block; font-style: normal; color: var(--muted); font-size: .8rem; }
.exlist { list-style: none; padding: 0; margin: 12px 0 0; counter-reset: ex; }
.exlist li { counter-increment: ex; display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); font-weight: 600; }
.exlist li::before { content: counter(ex); width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; font-size: .8rem; background: color-mix(in srgb, var(--lift) 16%, transparent); color: var(--lift); }
.kindtag { display: inline-flex; align-items: center; gap: 8px; }
.kindtag::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--lift); }
.kindtag.ride::before { background: var(--ride); }
.rules .rule { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.rules .rule:first-child { border-top: 0; padding-top: 0; }
.rules .rule svg { flex: none; color: var(--accent); margin-top: 2px; }
.rules .rule p { margin: 0; color: var(--muted); }
.rules .rule strong { color: var(--fg); display: block; margin-bottom: 2px; }
.card ul { margin: 8px 0 0; padding-left: 18px; color: var(--muted); }
.card li { margin: 4px 0; }

/* progress */
.ringcard { display: flex; align-items: center; gap: 18px; }
.ring { width: 104px; height: 104px; flex: none; position: relative; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .track { fill: none; stroke: var(--surface-2); stroke-width: 10; }
.ring .fill { fill: none; stroke: url(#ringgrad); stroke-width: 10; stroke-linecap: round; transition: stroke-dashoffset .6s ease; }
.ring .lbl { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; line-height: 1.1; }
.ring .lbl strong { font-size: 1.6rem; font-weight: 800; letter-spacing: -.02em; }
.ring .lbl span { font-size: .72rem; color: var(--muted); }
.tiles { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); }
.tile strong { font-size: 1.45rem; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .axis { stroke: var(--line-strong); stroke-width: 1; }
.chart .goal { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 4; }
.chart .tick { fill: var(--muted); font-size: 10px; font-family: var(--font); }
.chart .val { fill: var(--fg); font-size: 11px; font-weight: 700; font-family: var(--font); }
.chart .bar { fill: var(--accent); }
.chart .bar.full { fill: url(#bargrad); }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: url(#areagrad); }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart-note { min-height: 1.3em; margin: 8px 0 0 !important; }
details { margin-top: 8px; }
summary { cursor: pointer; color: var(--muted); font-weight: 600; }
table { border-collapse: collapse; width: 100%; margin-top: 8px; }
th, td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
th { color: var(--muted); font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; }

/* splash (splash.js): a full-screen cover drawn with pseudo-elements on
   <html>, so it exists from the first paint, before <body> is parsed. */
html.splash::before, html.splash::after { position: fixed; z-index: 1000; pointer-events: none; transition: opacity .3s ease; }
html.splash::before {
  content: ""; inset: 0;
  background: radial-gradient(120% 70% at 50% 40%, color-mix(in srgb, var(--accent) 22%, var(--bg)) 0%, var(--bg) 70%);
}
html.splash::after {
  content: "kmwo"; left: 50%; top: 50%; width: 200px; margin: -80px 0 0 -100px;
  padding-top: 108px; text-align: center; color: var(--fg);
  font: 800 1.9rem/1 var(--font); letter-spacing: -.03em;
  background: url("icon.svg") top center / 88px 88px no-repeat;
  animation: splash-pop .6s cubic-bezier(.2, .9, .3, 1.2) both;
}
html.splash body { overflow: hidden; }
html.splash-out::before, html.splash-out::after { opacity: 0; }
@keyframes splash-pop {
  0% { opacity: 0; transform: scale(.82); }
  100% { opacity: 1; transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  html.splash::after { animation: none; }
}

/* account menu (menu.js) */
.account { position: relative; flex: none; }
.avatar {
  width: 42px; height: 42px; padding: 0; border-radius: 50%; border: 0; display: grid; place-items: center;
  font-weight: 700; font-size: .9rem; letter-spacing: .02em; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent);
}
.avatar[aria-expanded="true"] { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 20; min-width: 248px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 16px; padding: 6px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .35); transform-origin: top right; animation: menu-in .14s ease-out;
}
@keyframes menu-in { from { opacity: 0; transform: scale(.96) translateY(-4px); } }
.menu-head { padding: 10px 12px 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu-head strong { display: block; font-size: .95rem; }
.menu-head span { display: block; font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.menu-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: transparent; border: 0; border-radius: 10px; padding: 11px 12px; font-weight: 500; font-size: .92rem; color: var(--fg);
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); outline: none; }
.menu-item:active { transform: none; }
.menu-item svg { color: var(--muted); flex: none; }
.menu-item .grow { flex: 1; }
.menu-item.danger { color: var(--danger); }
.menu-item.danger svg { color: var(--danger); }
.switch { width: 40px; height: 24px; border-radius: 999px; background: var(--line-strong); position: relative; flex: none; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .2s; }
.menu-item[aria-checked="true"] .switch { background: var(--accent); }
.menu-item[aria-checked="true"] .switch::after { transform: translateX(16px); }
.navrow { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.navrow .back { margin-bottom: 0; }

/* bottom tabs */
.tabs {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 5;
  display: flex; gap: 4px; padding: 6px; border-radius: 22px;
  background: color-mix(in srgb, var(--surface) 82%, transparent); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--line-strong); box-shadow: 0 10px 30px rgba(0, 0, 0, .3);
}
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 84px; padding: 7px 10px; border-radius: 16px; color: var(--muted); text-decoration: none; font-size: .7rem; font-weight: 600; }
.tabs a.on { color: var(--fg); background: var(--surface-2); }
.tabs a.on svg { color: var(--accent); }
