:root {
  --bg: #f6f7f4; --card: #fff; --text: #1c2420; --muted: #66716a; --line: #e2e6e0;
  --accent: #2f7d4f; --accent-ink: #fff; --accent-soft: #e6f2ea;
  --ok: #2e9e5b; --due: #d98e04; --over: #d9372b;
  --ok-soft: #e3f4ea; --due-soft: #fdf1d6; --over-soft: #fbe4e1;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.05);
  --inset: 18px;   /* space between a card's edge and its text */
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131714; --card: #1c211d; --text: #e8ece9; --muted: #98a39c; --line: #2c342e;
    --accent: #4bb377; --accent-ink: #0c1a11; --accent-soft: #203428;
    --ok-soft: #1b3325; --due-soft: #3a2f12; --over-soft: #3d1c19;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
body:has(dialog[open]) { overflow: hidden; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
p { margin: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); } .small { font-size: .875rem; }
[hidden] { display: none !important; }

/* chrome */
/* header matches the Haf-Clip site: black bar, cream wordmark, white tagline, underlined nav */
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 16px; background: #141414; position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; text-decoration: none; }
.wordmark { font-family: "Archivo Black", "Arial Black", "Helvetica Neue", system-ui, sans-serif; font-weight: 900; font-size: 1.35rem; color: #f5eeec; white-space: nowrap; display: inline-flex; flex-direction: column; align-items: center; line-height: 1.05; }
.wordmark small { font-size: 0.55em; color: #fff; }
.nav { display: none; gap: 4px; }
.btn.strava-btn { background: #fc4c02; border-color: #fc4c02; color: #fff; font-weight: 600; }
.btn.strava-btn:hover { background: #e34402; border-color: #e34402; }
.danger-text { color: var(--over); }
.nav a { padding: 8px 12px; color: #fff; text-decoration: none; font-weight: 500; }
.nav a:hover, .nav a[aria-current] { text-decoration: underline; text-underline-offset: 4px; }
.count { background: var(--accent); color: var(--accent-ink); border-radius: 99px; font-size: .75rem; padding: 1px 7px; margin-left: 2px; }
.tabs { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
.tabs a { flex: 1; text-align: center; padding: 8px 0 7px; color: var(--muted); text-decoration: none; font-size: .75rem; }
.tabs a .ico { display: block; font-size: 1.25rem; line-height: 1.2; }
.tabs a[aria-current] { color: var(--accent); font-weight: 600; }
@media (min-width: 720px) {
  .nav { display: flex; } .tabs { display: none; }
  body { padding-bottom: 40px; }
}
main { max-width: 980px; margin: 0 auto; padding: 16px; }
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.stack > * + * { margin-top: 14px; }
.section-title { margin: 22px 0 8px; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.back { display: inline-block; margin-bottom: 8px; text-decoration: none; color: var(--muted); font-size: .9rem; }

/* cards & buttons */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 14px var(--inset); }
.btn { font: inherit; font-weight: 500; padding: 9px 14px; min-height: 40px; border-radius: 9px; border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--over); border-color: var(--over); background: transparent; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.sm { padding: 5px 10px; min-height: 32px; font-size: .875rem; }
.linkbtn { font: inherit; background: none; border: 0; color: var(--accent); cursor: pointer; padding: 8px 0; font-weight: 500; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* status */
.pill { display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 9px; border-radius: 99px; white-space: nowrap; }
.pill.overdue { background: var(--over-soft); color: var(--over); }
.pill.due { background: var(--due-soft); color: var(--due); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.none { background: var(--line); color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--line); }
.dot.overdue { background: var(--over); } .dot.due { background: var(--due); } .dot.ok { background: var(--ok); }
.bar { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
.bar.due i { background: var(--due); } .bar.overdue i { background: var(--over); }

/* home */
.summary { display: flex; align-items: center; gap: 12px; padding: 16px var(--inset); }
.summary .big { font-size: 1.25rem; font-weight: 700; }
.summary.overdue { border-color: var(--over); } .summary.due { border-color: var(--due); }
.row { display: flex; align-items: center; gap: 12px; padding: 12px var(--inset); cursor: pointer; }
.row + .row { border-top: 1px solid var(--line); }
.row:hover { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.row .sub { color: var(--muted); font-size: .875rem; overflow: hidden; text-overflow: ellipsis; }
.row .end { display: flex; align-items: center; gap: 8px; flex: none; }
@media (max-width: 520px) { .row { flex-wrap: wrap; } .row .end { width: 100%; justify-content: space-between; padding-left: 22px; } }
.bikes { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.bikecard { padding: 16px var(--inset); display: flex; flex-direction: column; gap: 10px; cursor: pointer; }
.bikecard:hover { border-color: var(--accent); }
.bikecard .top2 { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.bikecard .btns { display: flex; gap: 8px; }
.empty { text-align: center; padding: 36px 20px; }
.empty h2 { margin-bottom: 6px; } .empty p { margin-bottom: 16px; color: var(--muted); }

/* bike page */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 10px; scrollbar-width: none; }
.chips a { padding: 6px 14px; border: 1px solid var(--line); border-radius: 99px; text-decoration: none; color: var(--text); white-space: nowrap; background: var(--card); font-size: .9rem; }
.chips a[aria-current] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.group { margin-top: 12px; overflow: hidden; }
.group-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px var(--inset); background: color-mix(in srgb, var(--accent-soft) 40%, var(--card)); border-bottom: 1px solid var(--line); list-style: none; cursor: pointer; }
.group-head::-webkit-details-marker, .group-head::marker { display: none; content: ""; }
.group-head .l { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; row-gap: 2px; }
.group-head .l h3 { flex: none; }
.group-head .chev { color: var(--muted); font-size: .7rem; flex: none; transition: transform .15s ease; }
.group:not([open]) .group-head { border-bottom: 0; }
.subhead { padding: 12px var(--inset) 4px; font-size: 1rem; font-weight: 700; color: var(--text); }
.subhead:not(:first-child) { border-top: 1px solid var(--line); margin-top: 4px; }
.group[open] .group-head .chev { transform: rotate(90deg); }
/* a side within a group (Front Wheel / Rear Wheel): collapsible, lighter than the group header */
.zone-sub + .zone-sub { border-top: 1px solid var(--line); }
.zone-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px var(--inset); font-weight: 700; list-style: none; cursor: pointer; }
.zone-head::-webkit-details-marker, .zone-head::marker { display: none; content: ""; }
.zone-head .chev { color: var(--muted); font-size: .7rem; transition: transform .15s ease; }
.zone-sub[open] > .zone-head .chev { transform: rotate(90deg); }
.zone-sub[open] > .zone-head { border-bottom: 1px solid var(--line); }
.group .empty-note { padding: 12px var(--inset); color: var(--muted); font-size: .9rem; }
.group-foot { padding: 0 var(--inset); border-top: 1px solid var(--line); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--card); }
.seg button { font: inherit; padding: 7px 16px; border: 0; background: transparent; color: var(--muted); cursor: pointer; min-height: 38px; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin: 6px 0 4px; }
details.card:not(.group) summary { padding: 12px var(--inset); cursor: pointer; font-weight: 600; }
details.card .row { cursor: default; }
summary { outline: none; }

/* diagram view */
.viz { display: grid; gap: 12px; margin-top: 8px; }
@media (min-width: 860px) { .viz { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); align-items: start; } .viz-art { position: sticky; top: 70px; } }
.viz-art { overflow: hidden; }
svg.bk { display: block; width: 100%; height: auto; aspect-ratio: 800 / 470; color: var(--text); touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.bk .frame, .bk .fork, .bk .shock, .bk .coil, .bk .thin, .bk .tire, .bk .rim, .bk .rotor, .bk .spoke { fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; }
.bk .frame { stroke-width: 9; opacity: .9; } .bk .frame.head { stroke-width: 14; } .bk .frame.thin2 { stroke-width: 6; }
.bk .frame.saddle { stroke-width: 12; } .bk .frame.grip { stroke-width: 12; opacity: 1; }
.bk .tire { stroke-width: 15; opacity: .82; } .bk .rim { stroke-width: 3; opacity: .45; } .bk .spoke { stroke-width: 1.2; opacity: .3; }
.bk .thin { stroke-width: 3.5; opacity: .75; }
.bk .rotor { stroke-width: 3; stroke-dasharray: 5 3.5; opacity: .6; }
.bk .solid { fill: currentColor; opacity: .85; }
.bk .fork { stroke: var(--accent); stroke-width: 11; }
.bk .shock { stroke: var(--accent); stroke-width: 10; } .bk .coil { stroke: var(--accent); stroke-width: 17; stroke-dasharray: 3 3.5; opacity: .55; }
.zone { cursor: pointer; outline: none; }
.zone .hit { fill: transparent; stroke: transparent; transition: fill .15s, stroke .15s; }
.zone .hit.line { fill: none; stroke-linecap: round; }
.zone.overdue .hit { fill: color-mix(in srgb, var(--over) 18%, transparent); stroke: color-mix(in srgb, var(--over) 18%, transparent); }
.zone.due .hit { fill: color-mix(in srgb, var(--due) 16%, transparent); stroke: color-mix(in srgb, var(--due) 16%, transparent); }
.zone:hover .hit, .zone:focus-visible .hit { fill: color-mix(in srgb, var(--accent) 30%, transparent); stroke: color-mix(in srgb, var(--accent) 30%, transparent); }
.zone.sel .hit { fill: color-mix(in srgb, var(--accent) 13%, transparent); stroke: color-mix(in srgb, var(--accent) 13%, transparent); }
.zone .hit.line { fill: none; }
.badge { pointer-events: none; }
.badge circle { fill: var(--muted); stroke: var(--card); stroke-width: 2.5; }
.badge text { fill: #fff; font: 700 14px system-ui, sans-serif; }
.badge.ok circle { fill: var(--ok); } .badge.due circle { fill: var(--due); } .badge.overdue circle { fill: var(--over); } .badge.empty circle { fill: var(--muted); opacity: .55; }
.legend { display: flex; gap: 16px; justify-content: center; padding: 8px 12px 12px; font-size: .8rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .dot { width: 9px; height: 9px; }

/* part page */
.meters { display: grid; gap: 14px; }
.meter-top { display: flex; justify-content: space-between; font-size: .9rem; margin-bottom: 4px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.fact .k { color: var(--muted); font-size: .8rem; } .fact .v { font-weight: 600; }
/* suspension tune table: a small spreadsheet-style grid (date + one column per setting) */
.tune-card { overflow: hidden; }
.tune-scroll { overflow-x: auto; }
.tune { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tune th, .tune td { padding: 8px 10px; text-align: center; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tune th + th, .tune td, .tune tbody th + td { border-left: 1px solid var(--line); }
.tune thead th { background: color-mix(in srgb, var(--accent-soft) 40%, var(--card)); font-size: .8rem; font-weight: 600; letter-spacing: .03em; }
.tune thead th:first-child, .tune tbody th { text-align: left; }
.tune tbody th { font-weight: 500; color: var(--muted); }
.tune tbody tr:last-child th, .tune tbody tr:last-child td { border-bottom: 0; }
details.tune-card[open] > summary { border-bottom: 1px solid var(--line); }
.tune .pill { font-size: .75rem; }
.hist { list-style: none; margin: 0; padding: 0; }
.hist li { padding: 11px var(--inset); display: flex; gap: 12px; align-items: flex-start; }
.hist li + li { border-top: 1px solid var(--line); }
.hist .when { color: var(--muted); font-size: .85rem; min-width: 92px; padding-top: 2px; }
.hist .grow { flex: 1; min-width: 0; }
.hist-actions { display: flex; gap: 4px; flex: none; }
.tag { font-weight: 600; }
.notes { white-space: pre-wrap; }

/* dialogs */
dialog { border: 0; padding: 0; border-radius: 16px; background: var(--card); color: var(--text); width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(10,15,12,.55); }
.modal { display: flex; flex-direction: column; max-height: calc(100dvh - 24px); }
.modal > h2 { padding: 18px 20px 4px; }
.modal-body { padding: 8px 20px 14px; overflow-y: auto; display: grid; gap: 12px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 20px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.modal-actions .spacer { margin-right: auto; }
.modal-actions.stacked { flex-direction: column; }
.modal-actions.stacked .btn { width: 100%; }
label.f { display: grid; gap: 4px; font-size: .875rem; font-weight: 500; }
label.f .hint { font-weight: 400; color: var(--muted); }
.fixed-name { font-weight: 600; padding: 9px 0 2px; }
input, select, textarea { font: inherit; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); color: var(--text); width: 100%; min-height: 40px; }
textarea { resize: vertical; min-height: 72px; }
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }
label.check { display: flex; align-items: center; gap: 10px; font-weight: 500; cursor: pointer; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cols3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px 12px; margin: 0; display: grid; gap: 10px; }
legend { font-size: .8rem; font-weight: 600; color: var(--muted); padding: 0 6px; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.presets button { font: inherit; font-size: .85rem; padding: 4px 11px; border-radius: 99px; border: 1px solid var(--line); background: var(--accent-soft); color: var(--text); cursor: pointer; }
details.more summary { cursor: pointer; color: var(--accent); font-weight: 500; font-size: .9rem; }
details.more[open] summary { margin-bottom: 10px; }
details.more > div { display: grid; gap: 12px; }
.detail-group { border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: grid; gap: 10px; }
.divider { display: flex; align-items: center; gap: 10px; margin: 2px 0; color: var(--muted); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }

/* toast */
#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 20; display: grid; gap: 8px; width: min(440px, calc(100vw - 24px)); pointer-events: none; }
@media (min-width: 720px) { #toast { bottom: 24px; } }
.toast { pointer-events: auto; background: #202824; color: #fff; padding: 11px 14px; border-radius: 10px; display: flex; align-items: center; justify-content: space-between; gap: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.3); font-size: .95rem; }
.toast button { font: inherit; background: none; border: 0; color: #8fe0b0; font-weight: 700; cursor: pointer; padding: 4px 6px; }

/* settings */
.setting { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px var(--inset); flex-wrap: wrap; }
.setting + .setting { border-top: 1px solid var(--line); }
.setting .grow { flex: 1; min-width: 200px; }
.setting select { width: auto; min-width: 180px; }
ol.steps { margin: 6px 0 0; padding-left: 20px; } ol.steps li + li { margin-top: 4px; }
code { background: var(--accent-soft); padding: 1px 6px; border-radius: 5px; font-size: .85em; }
