/* Layout: one column, phone-first. Sticky header, fixed sync/finish bar at the bottom.
   Lift cards in logbook order; History is a sub-page with a lift picker over one chart. */
:root {
  --bg: #eceff2;
  --surface: #ffffff;
  --sunk: #f4f6f8;
  --ink: #14181d;
  --muted: #5a646f;
  --line: #d3d9df;
  --accent: #d9a300;      /* competition-plate yellow */
  --accent-ink: #1a1400;
  --accent-text: #7d5e00;
  --beat: #1b7d45;
  --match: #4b6276;
  --below: #b8322a;
  --warn-bg: #fff4d1;
  --band: rgba(217, 163, 0, 0.16);
  --f-display: "Saira Condensed", "Arial Narrow", "Roboto Condensed", sans-serif;
  --f-body: "Public Sans", -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1114; --surface: #171b20; --sunk: #1e2329; --ink: #e8ebee; --muted: #8b96a2;
    --line: #2a3139; --accent: #f2c230; --accent-ink: #1a1400; --accent-text: #f2c230;
    --beat: #3fc07c; --match: #93a9bc; --below: #f0624f; --warn-bg: #2d2610; --band: rgba(242, 194, 48, 0.14);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1114; --surface: #171b20; --sunk: #1e2329; --ink: #e8ebee; --muted: #8b96a2;
  --line: #2a3139; --accent: #f2c230; --accent-ink: #1a1400; --accent-text: #f2c230;
  --beat: #3fc07c; --match: #93a9bc; --below: #f0624f; --warn-bg: #2d2610; --band: rgba(242, 194, 48, 0.14);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { background: var(--bg); color: var(--ink); }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { font-family: var(--f-body); font-size: 15px; line-height: 1.45; margin: 0; -webkit-tap-highlight-color: transparent; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg); }
.wrap {
  max-width: 560px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 0 220px;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Header */
.top {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--bg);
  display: flex; align-items: center; gap: 12px; padding-block: 14px 12px; border-bottom: 1px solid var(--line);
}
.top h1 { font-family: var(--f-display); font-weight: 700; font-size: 26px; letter-spacing: .01em; margin: 0; line-height: 1.05; text-transform: uppercase; text-wrap: balance; }
.top .sub { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.top .grow { flex: 1; min-width: 0; }
.back, .iconbtn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; min-width: 40px; height: 40px; display: grid; place-items: center; flex: none; font-size: 20px; }
.textbtn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; height: 40px; padding: 0 14px; font-weight: 600; font-size: 14px; flex: none; }
.plate { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); box-shadow: inset 0 0 0 7px var(--accent), inset 0 0 0 9px var(--accent-ink), inset 0 0 0 11px var(--accent); flex: none; }

.banner { margin-top: 12px; background: var(--warn-bg); border: 1px solid var(--accent); color: var(--ink); border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.banner.err { border-color: var(--below); }

/* Session list */
.week-label { margin: 22px 0 8px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; font-weight: 600; }
.sessions { display: grid; gap: 8px; }
.srow { display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; width: 100%; }
.srow .dno { font-family: var(--f-display); font-weight: 700; font-size: 30px; line-height: 1; text-align: center; }
.srow .dname { font-weight: 600; display: block; }
.srow .meta { font-size: 12px; color: var(--muted); }
.pill { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; padding: 4px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill.planned { border-color: var(--accent); color: var(--accent-text); }
.pill.done { border-color: var(--beat); color: var(--beat); }

/* Lift cards */
.lifts { display: grid; gap: 12px; margin-top: 14px; }
.lift { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: grid; gap: 12px; }
.lhead { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; }
.ord { font-family: var(--f-display); font-weight: 700; font-size: 15px; width: 28px; height: 28px; border-radius: 8px; background: var(--sunk); display: grid; place-items: center; color: var(--muted); }
.lift.logged .ord { background: var(--ink); color: var(--surface); }
.lname { font-family: var(--f-display); font-weight: 600; font-size: 21px; line-height: 1.1; text-wrap: balance; }
.lname .setno { color: var(--muted); font-size: 16px; }
.ltags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; font-size: 12px; color: var(--muted); }
.ltags .rule { color: var(--accent-text); font-weight: 600; }
.ltags .added { color: var(--accent-text); }
.setup { font-size: 13px; color: var(--muted); background: var(--sunk); border-radius: 8px; padding: 8px 10px; }

.ref { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.refbox { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.refbox.tgt { border-color: var(--accent); }
.refbox .k { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-weight: 600; }
.refbox .v { font-family: var(--f-display); font-weight: 600; font-size: 24px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.refbox .v small { font-size: 14px; color: var(--muted); font-weight: 500; }
.refbox .e { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.inputs.bw { grid-template-columns: 1fr; }
.step { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--sunk); }
.step button { border: 0; background: transparent; font-size: 24px; font-weight: 500; min-height: 58px; touch-action: manipulation; }
.step button:active { background: var(--line); }
.step .field { display: grid; text-align: center; align-content: center; border-left: 1px solid var(--line); border-right: 1px solid var(--line); background: var(--surface); }
.step label { font-size: 10px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); font-weight: 600; }
.step input { border: 0; background: transparent; width: 100%; text-align: center; font-family: var(--f-display); font-weight: 700; font-size: 28px; line-height: 1; color: var(--ink); padding: 0 0 4px; font-variant-numeric: tabular-nums; }
.step input::placeholder { color: var(--muted); opacity: .45; }

.verdict { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; min-height: 32px; }
.aim { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.aim b { color: var(--ink); font-weight: 600; }
.chip { font-family: var(--f-display); font-weight: 700; font-size: 16px; letter-spacing: .06em; text-transform: uppercase; padding: 3px 12px; border-radius: 8px; border: 2px solid currentColor; white-space: nowrap; }
.chip.sm { font-size: 13px; padding: 1px 7px; border-width: 1.5px; }
.chip.beat { color: var(--beat); } .chip.match { color: var(--match); } .chip.below { color: var(--below); } .chip.info { color: var(--muted); }

.extras { display: flex; flex-wrap: wrap; gap: 6px; }
.extras .tog { flex: 0 1 auto; white-space: nowrap; }
.tog { min-height: 44px; border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 6px 11px; font-size: 13px; color: var(--muted); }
.tog[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.tog.pain[aria-pressed="true"] { background: var(--below); border-color: var(--below); color: #fff; }
.tog.add { margin-left: auto; color: var(--ink); }
textarea, .search { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font: inherit; font-size: 16px; background: var(--sunk); color: var(--ink); }
textarea { resize: vertical; min-height: 64px; }

.addlift { width: 100%; border: 1.5px dashed var(--line); background: transparent; border-radius: 14px; padding: 14px; font-weight: 600; color: var(--muted); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: grid; gap: 10px; }
.panel h2 { font-family: var(--f-display); font-weight: 600; font-size: 18px; text-transform: uppercase; letter-spacing: .04em; margin: 0; }
.picklist { display: grid; gap: 2px; max-height: 50vh; overflow-y: auto; }
.picklist .grp { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-weight: 600; padding: 10px 2px 4px; }
.pick { display: flex; justify-content: space-between; gap: 10px; text-align: left; border: 0; background: transparent; padding: 10px 4px; border-bottom: 1px solid var(--line); width: 100%; }
.pick span:last-child { color: var(--muted); font-size: 12px; white-space: nowrap; }
.pick:disabled { opacity: .45; }

/* History */
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--sunk); border: 1px solid var(--line); border-radius: 10px; padding: 3px; margin-top: 14px; }
.seg button { border: 0; background: transparent; border-radius: 8px; padding: 8px; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 12px 0 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.lchip { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 12px; font-size: 13px; white-space: nowrap; }
.lchip.key { font-weight: 600; }
.lchip[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.chartcard { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 10px 6px; margin-top: 8px; }
.chartcard h2 { font-family: var(--f-display); font-weight: 600; font-size: 18px; margin: 0 4px 2px; }
.chartcard .cap { font-size: 12px; color: var(--muted); margin: 0 4px 6px; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 10px; font-family: var(--f-body); font-variant-numeric: tabular-nums; }
.chart .band { fill: var(--band); }
.chart .area { fill: var(--ink); opacity: .05; }
.chart .line { fill: none; stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.main { stroke: var(--ink); }
.chart .line.alt { stroke: var(--accent); }
.chart .line.dashed { stroke-dasharray: 4 4; }
.chart .pt.main { fill: var(--ink); } .chart .pt.alt { fill: var(--accent); }
.chart .pt.end { stroke: var(--surface); stroke-width: 2; }
.chart .endlabel { paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; fill: var(--ink); font-family: var(--f-display); font-weight: 700; font-size: 14px; }
.chart-empty { color: var(--muted); padding: 30px 4px; text-align: center; margin: 0; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin: 0 4px 4px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; background: var(--ink); }
.legend i.alt { background: var(--accent); } .legend i.band { height: 10px; background: var(--band); border: 1px solid var(--accent); }
.tablewrap { overflow-x: auto; margin-top: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; font-variant-numeric: tabular-nums; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; padding: 10px 10px 6px; white-space: nowrap; }
td { padding: 9px 10px; border-top: 1px solid var(--line); white-space: nowrap; }
td.n, th.n { text-align: right; }
td .pos { color: var(--below); } td .neg { color: var(--beat); }
.muted { color: var(--muted); }

/* Bottom bar */
.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--surface); border-top: 1px solid var(--line);
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-top: 10px; padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
}
.bar .in { max-width: 560px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.bar .prog { flex: 1; min-width: 0; }
.bar .count { font-family: var(--f-display); font-weight: 700; font-size: 20px; font-variant-numeric: tabular-nums; }
.bar.kb { display: none; }
button.sync { border: 0; background: transparent; padding: 2px 0; text-align: left; width: 100%; }
.sync { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; min-width: 0; }
.sync .synctext { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--beat); flex: none; }
.dot.pending { background: var(--accent); } .dot.off { background: var(--below); }
.finish { border: 0; border-radius: 12px; background: var(--accent); color: var(--accent-ink); font-family: var(--f-display); font-weight: 700; font-size: 18px; text-transform: uppercase; letter-spacing: .05em; padding: 12px 18px; flex: none; }
.finish.confirm { background: var(--ink); color: var(--surface); }
.finish:disabled { opacity: .5; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* This week (list screen) */
.wcard { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.wcard .srow { border: 0; border-radius: 0; }
.keys { padding: 0 12px 12px 68px; display: grid; gap: 6px; font-size: 13px; }
.keyrow { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 10px; align-items: baseline; }
.keyrow .kname { font-weight: 600; min-width: 0; }
.keyrow .rule { color: var(--accent-text); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.keyrow .ktgt { font-family: var(--f-display); font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; text-align: right; }
.keyrow .klast { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.keyrow .chip { justify-self: end; }
.krest { color: var(--muted); font-size: 12px; line-height: 1.5; border-top: 1px solid var(--line); padding-top: 6px; }
.krest .muted { font-variant-numeric: tabular-nums; }

/* Rest timer (top of the bottom bar) */
.rest { position: relative; max-width: 560px; margin: 0 auto 10px; border-radius: 12px; background: var(--sunk); border: 1px solid var(--line); overflow: hidden; }
.rest-fill { position: absolute; inset: 0; background: var(--band); transform-origin: left; transform: scaleX(0); }
.rest-row { position: relative; display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 12px; }
.rest-time { font-family: var(--f-display); font-weight: 700; font-size: 30px; line-height: 1; font-variant-numeric: tabular-nums; min-width: 2.6em; }
.rest-meta { flex: 1; min-width: 0; display: grid; }
.rest-label { font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rest-len { border: 0; background: transparent; padding: 0; text-align: left; font-size: 12px; color: var(--muted); text-decoration: underline dotted; text-underline-offset: 3px; }
.rest-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; min-width: 44px; min-height: 44px; padding: 0 8px; font-weight: 600; font-size: 13px; }
.rest.go { background: var(--accent); border-color: var(--accent); }
.rest.go .rest-time, .rest.go .rest-label, .rest.go .rest-len { color: var(--accent-ink); }
.rest.go .rest-fill { display: none; }
@media (prefers-reduced-motion: no-preference) { .rest.go { animation: restpulse 1s ease-in-out 3; } }
@keyframes restpulse { 50% { filter: brightness(1.12); } }
