:root {
  --bg: #08080a; --card: #131317; --card2: #1a1a20; --line: #26262e; --text: #ececf1; --muted: #9b9ba8;
  --accent: #8fb0ff; --accent-ink: #0b1430; --good: #8fe0b0; --warn: #ffcf8f; --bad: #ff8f8f;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --tabbar: 68px; --radius: 18px;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 16px; line-height: 1.45; }
body { min-height: 100vh; padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 16px); overscroll-behavior-y: none; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: 0.2px; margin: 0 0 8px; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.06rem; }
a { color: var(--accent); }
p { margin: 6px 0; }
.muted { color: var(--muted); } .small { font-size: 0.85rem; } .tiny { font-size: 0.75rem; }
.good { color: var(--good); } .warn { color: var(--warn); } .bad { color: var(--bad); }

/* Sticky app bar: stays at the top while scrolling (back arrow always reachable) */
.appbar { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: 6px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px; min-height: calc(env(safe-area-inset-top) + 60px);
  background: rgba(8, 8, 10, 0.88); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); border-bottom: 1px solid var(--line); }
.appbar h1 { margin: 0; font-size: 1.3rem; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar .back { width: 48px; height: 48px; border-radius: 14px; border: 0; background: transparent; color: var(--accent); display: grid; place-items: center; font-size: 1.6rem; cursor: pointer; margin-left: -6px; }
.appbar .back:active { background: var(--card2); }
.appbar .bar-action { min-height: 44px; }

main { padding: 12px 14px 24px; max-width: 640px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 0 0 12px; }
.card.tone-good { border-color: #2c4a3a; } .card.tone-warn { border-color: #5a4626; } .card.tone-info { border-color: #2a3350; }
.card h3 { margin-bottom: 4px; }
.row { display: flex; align-items: center; gap: 10px; } .row.wrap { flex-wrap: wrap; } .spread { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; } .grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stack > * + * { margin-top: 10px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }

button, .btn { font: inherit; min-height: 48px; padding: 10px 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--card2); color: var(--text); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; }
button:active, .btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 650; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-big { min-height: 60px; font-size: 1.1rem; }
.btn-sm { min-height: 40px; padding: 6px 12px; font-size: 0.9rem; }
button:disabled { opacity: 0.5; }
input, select, textarea { font: inherit; color: var(--text); background: #0f0f13; border: 1px solid var(--line); border-radius: 12px; min-height: 48px; padding: 10px 12px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 10px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chip { text-decoration: none; display: inline-flex; align-items: center; min-height: 40px; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--text); white-space: nowrap; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 4px; margin-bottom: 12px; }
.seg button { min-height: 44px; border: 0; background: transparent; border-radius: 10px; }
.seg button.on { background: var(--card2); color: var(--accent); font-weight: 600; }

/* Bottom tab bar: fixed */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: rgba(12, 12, 15, 0.94); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); border-top: 1px solid var(--line); }
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); text-decoration: none; font-size: 0.75rem; min-height: 56px; }
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a.on { color: var(--accent); }

/* Rings */
.rings { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; text-align: center; }
.ring svg { display: block; margin: 0 auto; }
.ring-bg { stroke: #24242c; } .ring-val { fill: var(--text); font-size: 15px; font-weight: 700; } .ring-sub { fill: var(--muted); font-size: 10px; }
.ring-label { font-size: 0.8rem; margin-top: 2px; } .ring-sub2 { font-size: 0.7rem; color: var(--muted); }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.item { display: flex; align-items: center; gap: 10px; padding: 10px 2px; min-height: 56px; width: 100%; background: none; border: 0; border-radius: 0; text-align: left; color: inherit; text-decoration: none; }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.item .chev { color: var(--muted); font-size: 1.3rem; }
.kpi { font-family: var(--serif); font-size: 1.6rem; font-weight: 600; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 650; background: var(--card2); border: 1px solid var(--line); }
.q-excellent { background: #1d3b2b; color: #8fe0b0; border-color: #2c5a40; } .q-good { background: #243b1d; color: #c4e08f; border-color: #3b5a2c; }
.q-poor { background: #3f311a; color: #ffcf8f; border-color: #5a4626; } .q-bad { background: #401c1c; color: #ff9f9f; border-color: #5a2626; } .q-unknown { color: var(--muted); }
.score-dial { width: 84px; height: 84px; border-radius: 50%; display: grid; place-items: center; font-size: 1.8rem; font-weight: 700; font-family: var(--serif); border: 6px solid; }

/* Training */
.setrow { display: grid; grid-template-columns: 34px 1fr 1fr 56px; gap: 8px; align-items: center; padding: 6px 0; }
.setrow .num { color: var(--muted); text-align: center; font-weight: 600; }
.setrow input { text-align: center; font-size: 1.15rem; min-height: 54px; padding: 6px; }
.setrow .tick { min-height: 54px; padding: 0; font-size: 1.3rem; }
.setrow.done .tick { background: var(--good); color: #0b2a19; border-color: var(--good); }
.setrow.warm .num { color: #666; }
.target { font-size: 0.8rem; color: var(--accent); text-align: center; }
.timer { position: fixed; left: 12px; right: 12px; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 10px); z-index: 55; background: var(--card2); border: 1px solid var(--accent); border-radius: 18px; padding: 10px 14px; display: flex; align-items: center; gap: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.5); }
.timer .t { font-family: var(--serif); font-size: 1.8rem; font-weight: 700; flex: 1; }
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.day { background: var(--card); border: 1px solid var(--line); border-radius: 12px; min-height: 92px; padding: 6px 4px; text-align: center; font-size: 0.72rem; display: flex; flex-direction: column; gap: 3px; align-items: stretch; color: var(--text); }
.day.today { border-color: var(--accent); }
.day .dn { color: var(--muted); font-size: 0.7rem; }
.pill { border-radius: 8px; padding: 2px 3px; background: var(--card2); line-height: 1.2; }
.pill.lift { background: #22305a; color: #cfdcff; } .pill.run { background: #1e3b2d; color: #bfeccc; } .pill.mob { background: #3b2f1e; color: #f1d9b0; } .pill.core { background: #3a1f3b; color: #f0c4f1; } .pill.done { outline: 1px solid var(--good); }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: #22222a; stroke-width: 1; } .chart .axis { fill: var(--muted); font-size: 10px; }
.empty { color: var(--muted); padding: 18px; text-align: center; }

/* Sheets and toasts */
.sheet-wrap { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; }
.sheet { background: var(--card); width: 100%; max-height: 88vh; overflow: auto; border-radius: 22px 22px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 14px); z-index: 90; background: #e9eeff; color: #0b1430; padding: 10px 16px; border-radius: 12px; font-weight: 600; max-width: 90vw; }
video.scan { width: 100%; border-radius: 14px; background: #000; aspect-ratio: 4/3; object-fit: cover; }
.credit { font-size: 0.75rem; color: var(--muted); }
.steps-list li { margin: 6px 0; }
ol.method { padding-left: 20px; } ol.method li { margin-bottom: 8px; }
table.t { width: 100%; border-collapse: collapse; font-size: 0.9rem; } table.t td, table.t th { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; } table.t td.n, table.t th.n { text-align: right; }
.working { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.8rem; background: #0e0e12; border: 1px solid var(--line); border-radius: 12px; padding: 10px; white-space: pre-wrap; }
.tabbar[hidden] { display: none; }
