:root {
  --bg: #0f1115;
  --card: #181b22;
  --card2: #20242d;
  --line: #2b303b;
  --text: #f2f4f8;
  --muted: #8b93a3;
  --accent: #ff6b35;
  --accent2: #ff9f1c;
  --c-green: #3ddc84;
  --c-blue: #3fa7ff;
  --c-yellow: #ffd23f;
  --c-orange: #ff8c32;
  --c-red: #ff4d4d;
  --c-muted: #5b6475;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  min-height: 100dvh;
  padding-top: calc(56px + var(--safe-t));
  padding-bottom: calc(72px + var(--safe-b));
  overscroll-behavior-y: none;
}
body.fullscreen { padding-top: var(--safe-t); padding-bottom: var(--safe-b); }
body.fullscreen .topbar, body.fullscreen .tabbar { display: none; }

h1 { font-size: 26px; margin: 8px 0 12px; letter-spacing: -0.02em; }
h2 { font-size: 18px; margin: 24px 0 10px; color: var(--muted); font-weight: 600; }
h3 { margin: 0 0 8px; }
a { color: inherit; text-decoration: none; }
small { display: block; color: var(--muted); font-size: 13px; }
p { margin: 8px 0; }
.muted { color: var(--muted); }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 12px; }
.row.gap { gap: 10px; margin: 10px 0; }
.hint { color: var(--muted); font-size: 13px; }
.label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; margin-bottom: 4px; }
.page { max-width: 640px; margin: 0 auto; padding: 8px 16px 24px; }
.back { display: inline-block; color: var(--muted); padding: 6px 0; }
.empty { color: var(--muted); text-align: center; padding: 28px 12px; background: var(--card); border-radius: var(--radius); }

/* ---------- Topbar & tabbar ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 20;
  height: calc(56px + var(--safe-t)); padding: var(--safe-t) 12px 0;
  display: flex; align-items: center; gap: 10px;
  background: rgba(15, 17, 21, 0.85); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { flex: 1; font-size: 18px; letter-spacing: -0.01em; }
.brand b { color: var(--accent); }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; border: 0; font-size: 20px;
  display: grid; place-items: center; background: var(--card2); color: #fff; cursor: pointer;
}
.avatar.xl { width: 64px; height: 64px; font-size: 32px; }
.pill {
  display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card);
  color: var(--text); border-radius: 99px; padding: 7px 12px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.ok .dot { background: var(--c-green); box-shadow: 0 0 8px var(--c-green); }
.pill.busy .dot { background: var(--c-yellow); animation: blink 0.8s infinite; }
.pill.off { border-color: var(--accent); }
.pill.off .dot { background: var(--accent); }
@keyframes blink { 50% { opacity: 0.2; } }

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: flex; padding: 6px 4px calc(6px + var(--safe-b));
  background: rgba(15, 17, 21, 0.92); backdrop-filter: blur(12px); border-top: 1px solid var(--line);
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; font-size: 11px; color: var(--muted); padding: 4px; }
.tabbar a span { font-size: 22px; filter: grayscale(1); opacity: 0.7; }
.tabbar a.active { color: var(--text); }
.tabbar a.active span { filter: none; opacity: 1; }

.ride-banner {
  position: fixed; z-index: 19; top: calc(56px + var(--safe-t)); left: 0; right: 0;
  border: 0; background: var(--accent); color: #fff; font-weight: 700; padding: 10px; font-size: 14px;
}

/* ---------- Cards & buttons ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin: 10px 0; border: 1px solid var(--line); display: block; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card2); color: var(--text);
  border-radius: 12px; padding: 12px 16px; font-size: 15px; font-weight: 600; cursor: pointer; text-align: center;
}
.btn small { display: inline; margin-left: 4px; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); border: 0; color: #fff; }
.btn.danger { background: var(--c-red); border: 0; color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger.ghost { background: transparent; color: var(--c-red); border-color: #ff4d4d55; }
.btn.block { display: flex; width: 100%; margin: 10px 0; }
.btn.xl { padding: 16px; font-size: 18px; }
.btn.small { padding: 7px 12px; font-size: 13px; }
.link { background: none; border: 0; color: var(--muted); font-size: 12px; text-decoration: underline; cursor: pointer; }
.icon { background: var(--card2); border: 1px solid var(--line); color: var(--text); width: 36px; height: 36px; border-radius: 10px; font-size: 16px; cursor: pointer; }
.icon.danger { color: var(--c-red); }
.round { width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line); background: var(--card2); color: var(--text); font-size: 22px; cursor: pointer; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--card2); color: #111; }
.tag.warn { background: var(--c-orange); }
.conn-name .tag { color: var(--muted); background: var(--card2); }
.chev { color: var(--muted); font-size: 26px; }

/* ---------- Home ---------- */
.hello { font-size: 24px; }
.conn-card { padding: 12px 14px; }
.conn-empty { display: flex; align-items: center; gap: 12px; }
.bike-ico { font-size: 34px; }
.conn-live { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; }
.conn-live b { font-size: 26px; font-variant-numeric: tabular-nums; }
.conn-live i { font-style: normal; color: var(--muted); font-size: 12px; margin-left: 2px; }
.conn-name { margin-top: 8px; font-size: 13px; color: var(--muted); text-align: center; }
.week { display: flex; gap: 18px; align-items: center; }
.ring { position: relative; flex-shrink: 0; }
.ring-inner { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-inner b { font-size: 24px; line-height: 1; }
.week-stats .kv { font-size: 14px; color: var(--muted); }
.week-stats .kv span { color: var(--text); font-weight: 700; font-size: 16px; }
.streak { margin-top: 6px; font-weight: 600; font-size: 14px; }
.actions-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0; }
.big-action {
  border: 0; border-radius: var(--radius); padding: 18px 14px; text-align: left; color: #fff; cursor: pointer;
  background: linear-gradient(135deg, var(--accent), #e8451a);
}
.big-action.alt { background: linear-gradient(135deg, #3a4150, #262b35); }
.big-action span { font-size: 30px; display: block; }
.big-action b { font-size: 18px; display: block; margin-top: 6px; }
.big-action small { color: #ffffffbb; }
.app-dl { border-color: #3ddc8455; background: linear-gradient(135deg, #10291c, var(--card)); }
.app-dl .chev { color: var(--c-green); font-size: 22px; }
.suggest { cursor: pointer; border-color: #ff6b3555; background: linear-gradient(135deg, #2a1a14, var(--card)); }
.wicon { width: 46px; height: 46px; border-radius: 12px; background: var(--card2); display: grid; place-items: center; font-size: 24px; flex-shrink: 0; }
.wicon.xl { width: 64px; height: 64px; font-size: 34px; }
.ride-row { display: flex; align-items: center; gap: 12px; }
.ride-row b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ride-date { width: 44px; text-align: center; background: var(--card2); border-radius: 10px; padding: 4px 0; }
.ride-date b { font-size: 18px; }
.compl { font-weight: 800; color: var(--c-orange); }
.compl.good { color: var(--c-green); }

/* ---------- Profielen ---------- */
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.profile-card {
  background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 16px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; cursor: pointer;
}
.profile-card.active { border-color: var(--accent); }
.profile-card.add { border-style: dashed; color: var(--muted); }
.welcome, .celebrate { text-align: center; padding: 10px 0; }
.big-emoji { font-size: 64px; }
.form label { display: block; margin: 10px 0; font-size: 13px; color: var(--muted); font-weight: 600; }
.form input, .form select, select, input.num {
  display: block; width: 100%; margin-top: 4px; padding: 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card2); color: var(--text); font-size: 16px; font-family: inherit;
}
select, input.num { width: auto; display: inline-block; margin: 0; padding: 8px 10px; }
input.num { width: 70px; text-align: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 8px; }
.grid4 label { margin: 6px 0 0; }
.grid4 input { padding: 8px; }
details { background: var(--card); border-radius: 12px; padding: 10px 12px; margin: 10px 0; border: 1px solid var(--line); }
summary { cursor: pointer; font-weight: 600; }
.emoji-pick, .color-pick { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.emoji-pick button { width: 42px; height: 42px; font-size: 22px; border-radius: 10px; border: 2px solid transparent; background: var(--card2); cursor: pointer; }
.color-pick button { width: 32px; height: 32px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; }
.emoji-pick .sel, .color-pick .sel { border-color: var(--text); }
.bmi { color: var(--muted); font-size: 14px; margin: 8px 0; }

/* ---------- Workouts ---------- */
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 4px; scrollbar-width: none; }
.chip { padding: 8px 14px; border-radius: 99px; background: var(--card); border: 1px solid var(--line); white-space: nowrap; font-size: 14px; font-weight: 600; }
.chip.sel { background: var(--text); color: var(--bg); }
.workout b { font-size: 17px; }
canvas.wprof { width: 100%; height: 40px; display: block; margin: 10px 0 6px; }
canvas.wprof.big { height: 80px; }
.wmeta { display: flex; gap: 12px; align-items: center; font-size: 13px; color: var(--muted); }
.wd-head { display: flex; gap: 14px; align-items: center; }
.wd-head h1 { margin: 0; }
.wd-head p { color: var(--muted); margin: 4px 0; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(60px, 1fr)); gap: 8px; text-align: center; margin: 14px 0; }
.stat-row b { font-size: 22px; display: block; }
.stat-row.small b { font-size: 18px; }
.offset { display: flex; align-items: center; gap: 10px; }
.off-val { font-size: 22px; min-width: 32px; text-align: center; }
.seg-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.seg-row:last-child { border: 0; }
.lv { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; color: #111; background: var(--c-muted); flex-shrink: 0; }
.lv3, .lv4 { background: var(--c-blue); }
.lv5, .lv6 { background: var(--c-yellow); }
.lv7, .lv8 { background: var(--c-orange); }
.lv9, .lv10, .lv11 { background: var(--c-red); }
.times { color: var(--accent); font-weight: 800; }
.bseg { padding: 10px; }
.bseg-head { display: flex; gap: 6px; }
.bseg-head input { flex: 1; min-width: 0; padding: 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--card2); color: var(--text); font-size: 15px; }
.total { text-align: right; color: var(--muted); }

/* ---------- Live rit ---------- */
.ride { max-width: 640px; margin: 0 auto; padding: 8px 12px 16px; transition: background 0.3s; }
.ride.paused { background: repeating-linear-gradient(45deg, transparent 0 20px, #ffffff06 20px 40px); }
.ride.paused .seg-time, .ride.paused #r-elapsed { opacity: 0.5; }
.ride-top { display: flex; align-items: center; gap: 8px; }
.ride-top b { display: block; font-size: 16px; }
.ride-prof { height: 34px !important; margin: 8px 0 !important; }
.seg-card {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--card); border-radius: var(--radius); padding: 10px 14px; border: 1px solid var(--line);
}
.seg-name { font-weight: 700; font-size: 17px; }
.seg-tip { color: var(--muted); font-size: 13px; }
.seg-time { font-size: 44px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.seg-time.hot { color: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }

.level-card {
  margin: 10px 0; border-radius: 20px; padding: 12px 14px; border: 2px solid var(--line); background: var(--card);
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; transition: border-color 0.2s, background 0.2s;
}
.lv-box { text-align: center; }
.lv-box small { font-weight: 700; letter-spacing: 0.1em; }
.lv-box b { font-size: 72px; line-height: 1; font-weight: 900; font-variant-numeric: tabular-nums; display: block; }
.level-card.free { grid-template-columns: 1fr; }
.level-card.free .lv-box.now { display: none; }
.lv-scale { grid-column: 1 / -1; display: flex; gap: 3px; height: 26px; }
.lv-scale i { flex: 1; border-radius: 5px; background: var(--card2); position: relative; display: grid; place-items: center; font-style: normal; font-size: 11px; color: var(--muted); }
.lv-scale i.fill { background: #3fa7ff55; }
.lv-scale i.cur { background: var(--c-blue); color: #fff; font-weight: 800; }
.lv-scale i.tgt { outline: 3px solid var(--text); outline-offset: -1px; color: var(--text); font-weight: 800; }
.lv-status { grid-column: 1 / -1; text-align: center; font-size: 20px; font-weight: 800; min-height: 26px; }
.level-card.good { border-color: var(--c-green); background: linear-gradient(180deg, #3ddc8422, var(--card)); }
.level-card.good .lv-status, .level-card.good .now b { color: var(--c-green); }
.level-card.bad { border-color: var(--c-red); background: linear-gradient(180deg, #ff4d4d26, var(--card)); animation: alert 1.2s infinite; }
.level-card.bad .lv-status, .level-card.bad .now b { color: var(--c-red); }
.level-card.warn { border-color: var(--c-orange); background: linear-gradient(180deg, #ff8c3222, var(--card)); }
.level-card.warn .lv-status, .level-card.warn .now b { color: var(--c-orange); }
.level-card.unknown .lv-status { color: var(--c-yellow); }
.level-card.neutral .lv-status { color: var(--muted); font-size: 14px; font-weight: 600; }
@keyframes alert { 50% { border-color: #ff4d4d55; } }

.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.metric {
  background: var(--card); border-radius: 14px; padding: 8px 10px; border: 1px solid var(--line); position: relative; overflow: hidden;
  border-bottom: 3px solid var(--zone, var(--line));
}
.metric small { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; }
.metric b { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; display: block; line-height: 1.15; }
.metric i { font-style: normal; color: var(--muted); font-size: 11px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric .zone { font-size: 10px; color: var(--zone); font-weight: 700; }
.metric.ok { border-bottom-color: var(--c-green); }
.metric.low, .metric.high { border-bottom-color: var(--c-orange); }
.metric.low b, .metric.high b { color: var(--c-orange); }
.cad-bar { position: relative; height: 5px; background: var(--card2); border-radius: 3px; margin-top: 4px; }
.cad-bar em { position: absolute; top: 0; bottom: 0; background: #3ddc8466; border-radius: 3px; }
.cad-bar span { position: absolute; top: -3px; width: 4px; height: 11px; margin-left: -2px; background: var(--text); border-radius: 2px; z-index: 1; transition: left 0.4s; }
canvas.spark { width: 100%; height: 44px; display: block; margin: 8px 0; }
.next { text-align: center; color: var(--muted); font-size: 14px; padding: 8px; background: var(--card); border-radius: 12px; }
.next b { color: var(--text); }
.manual-level, .sim-ctrl {
  display: flex; align-items: center; justify-content: center; gap: 12px; margin: 10px 0; padding: 8px;
  border-radius: 12px; background: var(--card); border: 1px dashed var(--line); font-size: 14px;
}
.manual-level b, .sim-ctrl b { font-size: 22px; min-width: 28px; text-align: center; }
.sim-ctrl { border-color: #c74dff66; }
.ride-ctrl { display: flex; gap: 8px; margin-top: 12px; }
.ride-ctrl .btn { flex: 1; }

/* ---------- Samenvatting & historie ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.stat-grid > div { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px; text-align: center; }
.stat-grid b { font-size: 22px; display: block; }
.pr { background: linear-gradient(135deg, #3b2f0b, var(--card)); border-color: #ffd23f66; }
.pr .btn { margin-top: 8px; }
.compliance { display: flex; align-items: center; gap: 12px; }
canvas.chart { width: 100%; height: 160px; display: block; margin-top: 8px; }
canvas.bars { width: 100%; height: 120px; display: block; margin-top: 8px; }
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.legend span::before { content: ''; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.lg-p::before { background: var(--accent); }
.lg-c::before { background: var(--c-green); }
.lg-hr::before { background: var(--c-red); }
.lg-l::before { background: var(--c-blue); }
.zones { display: flex; height: 14px; border-radius: 7px; overflow: hidden; margin: 10px 0 6px; background: var(--card2); }
.zone-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); }
.zone-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.feel small { margin-bottom: 8px; }
.feel-btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.feel-btns button { background: var(--card2); border: 1px solid var(--line); border-radius: 12px; padding: 10px; font-size: 28px; color: var(--text); cursor: pointer; }
.badges { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.badge { text-align: center; opacity: 0.3; filter: grayscale(1); }
.badge.got { opacity: 1; filter: none; }
.badge span { font-size: 30px; display: block; }
.badge small { font-size: 11px; }

/* ---------- Instellingen ---------- */
.setting { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.setting:last-of-type { border-bottom: 0; }
.switch { appearance: none; width: 48px; height: 28px; border-radius: 99px; background: var(--card2); border: 1px solid var(--line); position: relative; cursor: pointer; flex-shrink: 0; transition: background 0.2s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--muted); transition: transform 0.2s, background 0.2s; }
.switch:checked { background: var(--accent); border-color: var(--accent); }
.switch:checked::after { transform: translateX(20px); background: #fff; }
.live-debug { font-size: 13px; color: var(--muted); padding: 8px 0; }
.live-debug b { color: var(--text); }
.log { background: #000; color: #9fe8b0; font-size: 11px; padding: 10px; border-radius: 10px; min-height: 160px; max-height: 50vh; overflow: auto; white-space: pre-wrap; word-break: break-all; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 8px; }
.tbl th, .tbl td { padding: 6px; border-bottom: 1px solid var(--line); text-align: center; }
.tbl th { color: var(--muted); font-weight: 600; }
.steps { padding-left: 20px; color: var(--muted); }
.steps li { margin: 6px 0; }
.calib-level { text-align: center; margin: 20px 0; }
.calib-level b { font-size: 120px; font-weight: 900; line-height: 1; color: var(--accent); }
.progress { height: 10px; background: var(--card2); border-radius: 5px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--c-green); width: 0; transition: width 0.5s; }
.calib-live { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; margin: 16px 0; }
.calib-live b { font-size: 28px; }
.calib-live .hint { grid-column: 1 / -1; }

/* ---------- Modal & toast ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 50; background: #000a; display: grid; place-items: center; padding: 16px; animation: fade 0.15s; }
.modal { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 20px; width: 100%; max-width: 420px; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.modal-actions .btn { flex: 1; }
@keyframes fade { from { opacity: 0; } }
.toast {
  position: fixed; z-index: 60; left: 16px; right: 16px; bottom: calc(84px + var(--safe-b)); margin: 0 auto; max-width: 480px;
  background: #2b303b; color: var(--text); padding: 12px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  box-shadow: 0 8px 24px #0008; transform: translateY(20px); opacity: 0; pointer-events: none; transition: all 0.25s;
}
.toast.show { transform: none; opacity: 1; }
.toast.ok { border-left: 4px solid var(--c-green); }
.toast.error { border-left: 4px solid var(--c-red); }

@media (max-width: 380px) {
  .lv-box b { font-size: 60px; }
  .metric b { font-size: 24px; }
  .seg-time { font-size: 36px; }
}
@media (min-height: 800px) {
  .lv-box b { font-size: 84px; }
}
