:root {
  --bg: #0d0f12;
  --panel: #161a1f;
  --panel2: #1e232a;
  --line: #2a3038;
  --text: #e8ebef;
  --muted: #8b95a1;
  --accent: #ff8a1f;
  --accent-ink: #1a0d00;
  --ok: #3ccf7a;
  --bad: #ff5a5a;
  --cyan: #4cc9f0;
  --radius: 12px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif; }
button, input, select { font: inherit; color: inherit; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 18px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
a { color: var(--cyan); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
[hidden] { display: none !important; }

.top { display: flex; align-items: center; gap: 20px; padding: 10px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: rgba(13,15,18,.95); backdrop-filter: blur(8px); z-index: 10; }
.brand { font-weight: 800; font-size: 18px; }
.brand span { color: var(--accent); font-weight: 600; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav button { background: none; border: 0; padding: 8px 12px; border-radius: 8px; color: var(--muted); cursor: pointer; }
nav button:hover { color: var(--text); background: var(--panel); }
nav button.active { color: var(--text); background: var(--panel2); }
.status { margin-left: auto; font-size: 12px; color: var(--muted); }

main { padding: 20px; max-width: 1400px; margin: 0 auto; }

.btn { background: var(--panel2); border: 1px solid var(--line); padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #3a424d; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 650; }
.btn.primary:disabled { opacity: .4; cursor: default; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn.icon { padding: 4px 8px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

input[type=text], input[type=number], select { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; }
input[type=number] { width: 90px; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; padding: 4px 0; cursor: pointer; }
input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.grid3 { display: grid; grid-template-columns: 240px 280px 1fr; gap: 16px; align-items: start; }
.grid2 { display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .grid3, .grid2 { grid-template-columns: 1fr; } }

.list { display: flex; flex-direction: column; gap: 4px; }
.list .item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.list .item:hover { background: var(--panel2); }
.list .item.sel { background: var(--panel2); border-color: var(--accent); }
.list .item .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .item.hiddenpage .name { color: var(--muted); text-decoration: line-through; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--panel2); color: var(--muted); border: 1px solid var(--line); }
.tag.active { color: var(--ok); border-color: #1e5a39; }

.savebar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.dirty { color: var(--accent); font-size: 12px; }

/* phone preview */
.editor { display: flex; gap: 24px; flex-wrap: wrap; align-items: flex-start; }
.phone { width: 300px; aspect-ratio: 9 / 19.5; background: #000; border-radius: 38px; border: 8px solid #2b2f35; padding: 34px 8px 64px; display: flex; flex-direction: column; position: relative; box-shadow: 0 10px 40px rgba(0,0,0,.5); flex-shrink: 0; }
.phone::before { content: ""; position: absolute; top: 9px; left: 50%; transform: translateX(-50%); width: 84px; height: 22px; background: #1a1c20; border-radius: 12px; }
.phone .pagename { position: absolute; bottom: 40px; left: 0; right: 0; text-align: center; font-size: 11px; color: var(--muted); }
.phone .dots { position: absolute; bottom: 24px; left: 0; right: 0; display: flex; justify-content: center; gap: 5px; }
.phone .dots i { width: 6px; height: 6px; border-radius: 50%; background: #444; }
.phone .dots i.on { background: #fff; }
.screen { flex: 1; display: flex; flex-direction: column; gap: 3px; min-height: 0; }
.prow { display: grid; gap: 3px; flex: 1; min-height: 0; }
.prow.big { flex: 2; }
.slot { background: #15181c; border-radius: 6px; padding: 5px 7px; display: flex; flex-direction: column; justify-content: space-between; cursor: pointer; border: 2px solid transparent; overflow: hidden; min-height: 0; position: relative; }
.slot:hover { border-color: #444b55; }
.slot.sel { border-color: var(--accent); }
.slot .lbl { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot .val { font-weight: 750; font-variant-numeric: tabular-nums; font-size: 26px; line-height: 1; text-align: right; white-space: nowrap; }
.prow.big .slot .val { font-size: 48px; }
.prow.cols1:not(.big) .slot .val { font-size: 34px; }
.slot .unit { font-size: 10px; color: var(--muted); text-align: right; }
.slot.empty .val { color: #333; }
.slot .style { position: absolute; top: 4px; right: 6px; font-size: 9px; color: var(--cyan); text-transform: uppercase; }
.slot svg { width: 100%; height: 60%; }
.zone-power .val { color: #ffd166; }
.zone-heartRate .val { color: #ff6b6b; }
.visual { flex: 1; background: #12161b; border-radius: 6px; overflow: hidden; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; position: relative; }
.visual svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; height: 70px; margin-top: 3px; }
.strip .slot .val { font-size: 18px; }

.slotedit { flex: 1; min-width: 260px; display: flex; flex-direction: column; gap: 12px; }

/* picker */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(760px, 94vw); max-height: 84vh; }
dialog::backdrop { background: rgba(0,0,0,.6); }
.pk-head { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: center; }
.pk-head input { flex: 1; }
.pk-body { padding: 10px 16px 16px; overflow: auto; max-height: calc(84vh - 64px); }
.pk-cat { margin-top: 10px; }
.pk-cat h4 { margin: 8px 0 6px; font-size: 12px; color: var(--muted); }
.pk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px; }
.pk-grid button { text-align: left; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; cursor: pointer; }
.pk-grid button:hover { border-color: var(--accent); }
.pk-grid button.cur { border-color: var(--accent); background: #2a1d10; }
.pk-grid button small { display: block; color: var(--muted); font-size: 11px; }

/* routes */
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 22px; text-align: center; color: var(--muted); cursor: pointer; }
.drop.over { border-color: var(--accent); color: var(--text); }
#map { height: 420px; border-radius: var(--radius); border: 1px solid var(--line); background: #111; }
.elev { width: 100%; height: 120px; margin-top: 10px; }
.stats { display: flex; gap: 22px; margin: 10px 0; flex-wrap: wrap; }
.stat b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }

/* workouts */
table.steps { width: 100%; border-collapse: collapse; }
table.steps th { text-align: left; font-size: 11px; color: var(--muted); font-weight: 500; padding: 4px; }
table.steps td { padding: 3px 4px; border-top: 1px solid var(--line); }
table.steps input[type=number] { width: 70px; }
table.steps input[type=text] { width: 140px; }
.wchart { width: 100%; height: 140px; background: #101317; border-radius: 10px; border: 1px solid var(--line); }

/* settings */
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
table.zones { border-collapse: collapse; margin-top: 6px; }
table.zones td, table.zones th { padding: 4px 14px 4px 0; text-align: left; font-variant-numeric: tabular-nums; }
table.zones th { color: var(--muted); font-weight: 500; font-size: 12px; }
.zdot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* setup / pairing */
.setup { max-width: 460px; margin: 60px auto; }
.setup p { color: var(--muted); }
.code { font: 700 34px/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .18em; }
.qr { background: #fff; padding: 12px; border-radius: 12px; display: inline-block; }
.qr img, .qr svg { display: block; width: 220px; height: 220px; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.5); z-index: 100; }
.toast.err { border-color: var(--bad); }
.empty-state { padding: 40px; text-align: center; color: var(--muted); }
