:root {
  color-scheme: dark;
  --bg: #14130f;
  --surface: #1e1d19;
  --surface-2: #2a2924;
  --border: #3a3832;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #8f8d84;
  --gold: #e8b64c;
  --gold-dim: #7a5f22;
  --xp: #9b6be0;
  --rested: #3987e5;
  --good: #0ca30c;
  --critical: #d03b3b;
  /* family identity, categorical slots in fixed order (dark steps) */
  --f-push: #3987e5;
  --f-legs: #d95926;
  --f-core: #199e70;
  --f-hold: #c98500;
  --f-pull: #d55181;
  --f-cardio: #008300;
  --f-mobility: #9085e9;
  --f-yoga: #e66767;
  /* sequential (heatmap), blue */
  --seq-0: #2a2924;
  --seq-1: #184f95;
  --seq-2: #256abf;
  --seq-3: #3987e5;
  --seq-4: #6da7ec;
  --seq-5: #b7d3f6;
  --con-grey: #8f8d84;
  --con-green: #0ca30c;
  --con-yellow: #e0b400;
  --con-orange: #ec835a;
  --con-red: #e05050;
  --r-common: #c9c8bf;
  --r-uncommon: #4cc94c;
  --r-rare: #5a9cff;
  --r-epic: #b77cff;
  --r-legendary: #ff9a3c;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f4f2ec;
    --surface: #fcfcfb;
    --surface-2: #ecebe5;
    --border: #d9d7cf;
    --text: #0b0b0b;
    --text-2: #52514e;
    --muted: #77756e;
    --gold: #9a6a00;
    --gold-dim: #e9d3a0;
    --xp: #6250d6;
    --rested: #2a78d6;
    --f-push: #2a78d6;
    --f-legs: #eb6834;
    --f-core: #1baf7a;
    --f-hold: #eda100;
    --f-pull: #e87ba4;
    --f-cardio: #008300;
    --f-mobility: #6250d6;
    --f-yoga: #e34948;
    --seq-0: #ecebe5;
    --seq-1: #cde2fb;
    --seq-2: #9ec5f4;
    --seq-3: #5598e7;
    --seq-4: #256abf;
    --seq-5: #0d366b;
    --r-common: #6b6a63;
    --r-uncommon: #1a8a1a;
    --r-rare: #1d5fd1;
    --r-epic: #7a2fd1;
    --r-legendary: #b85a00;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
h2 { font-size: 0.95rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--gold); margin: 22px 0 10px; }
h3 { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; text-transform: none; letter-spacing: 0; font-weight: normal; }
.hidden { display: none !important; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }

main { max-width: 760px; margin: 0 auto; padding: 0 16px 24px; }
.tab { display: none; }
.tab.active { display: block; }

/* header */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.lvl {
  flex: none; width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 800; font-size: 1.2rem;
  border: 2px solid var(--gold); color: var(--gold); background: var(--surface);
}
.xpwrap { flex: 1; min-width: 0; }
.xpline { display: flex; justify-content: space-between; align-items: center; font-size: 0.85rem; gap: 8px; margin-bottom: 5px; }
.chips { display: flex; gap: 6px; flex: none; }
.chip { background: var(--surface-2); border-radius: 999px; padding: 2px 8px; font-size: 0.8rem; white-space: nowrap; }
.chip.rested { color: var(--rested); }
.xpbar { position: relative; height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
#xpfill, #xprest { position: absolute; top: 0; bottom: 0; left: 0; transition: width 0.5s ease, left 0.5s ease; }
#xpfill { background: var(--xp); border-radius: 5px; }
#xprest { background: var(--rested); opacity: 0.35; }
.icon-btn { flex: none; background: none; border: none; font-size: 1.3rem; padding: 6px; color: var(--text-2); }

/* bottom nav */
.bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom button { background: none; border: none; padding: 8px 0 10px; font-size: 0.75rem; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; }
.bottom button span { font-size: 1.25rem; }
.bottom button.active { color: var(--gold); }

/* quests */
.quests { display: grid; gap: 8px; }
.quest { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center; }
.quest .q-title { font-weight: 600; }
.quest .q-type { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--gold); }
.quest .q-reward { font-size: 0.8rem; color: var(--text-2); text-align: right; }
.quest .bar { grid-column: 1 / -1; }
.quest.done { border-color: var(--gold-dim); }
.quest.done .q-title::before { content: "✔ "; color: var(--good); }
.reroll { background: none; border: 1px solid var(--border); border-radius: 8px; padding: 2px 8px; font-size: 0.75rem; color: var(--text-2); margin-left: 6px; }
.bar { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar > div { height: 100%; background: var(--gold); border-radius: 4px; transition: width 0.4s; }
.bar.xpc > div { background: var(--xp); }

/* recent quick log */
.recent { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.qbtn {
  text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; border-left: 4px solid var(--fam, var(--gold));
}
.qbtn:active { transform: scale(0.97); }
.qbtn b { display: block; font-size: 1.1rem; }
.qbtn span { font-size: 0.8rem; color: var(--text-2); }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.stat { padding: 10px 12px; }
.stat .s-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.stat .s-name { font-size: 0.8rem; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.05em; }
.stat .s-val { font-size: 1.4rem; font-weight: 800; }

/* ladders */
.ladders { display: grid; gap: 8px; }
.ladder { cursor: pointer; }
.ladder .l-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.ladder .pips { display: flex; gap: 3px; margin: 8px 0 6px; }
.ladder .pip { flex: 1; height: 6px; border-radius: 3px; background: var(--surface-2); }
.ladder .pip.on { background: var(--fam); }
.ladder .l-next { font-size: 0.85rem; color: var(--text-2); }
.ladder .l-detail { margin-top: 10px; font-size: 0.85rem; display: grid; gap: 4px; }
.ladder .l-detail div { display: flex; justify-content: space-between; gap: 8px; }

/* elevation */
.elev .big { font-size: 1.6rem; font-weight: 800; }
.elev .bar { margin: 8px 0 4px; }
.elev .bar > div { background: var(--f-cardio); }

/* today */
.today { display: grid; gap: 6px; }
.tset { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--surface); border-radius: 10px; border-left: 4px solid var(--fam); }
.tset .t-name { flex: 1; min-width: 0; }
.tset .t-xp { font-size: 0.85rem; color: var(--text-2); white-space: nowrap; }
.tset .t-del { background: none; border: none; color: var(--muted); font-size: 1rem; padding: 4px 6px; }

/* log tab */
.fam-chips { display: flex; gap: 6px; overflow-x: auto; padding: 14px 0 10px; scrollbar-width: none; }
.fam-chips button { flex: none; border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 8px 14px; }
.fam-chips button.active { border-color: var(--fam); background: color-mix(in srgb, var(--fam) 22%, var(--surface)); }
.exlist { display: grid; gap: 6px; }
.ex-row { display: flex; gap: 6px; }
.ex-row .ex { flex: 1; min-width: 0; }
.ex { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; text-align: left; width: 100%; }
.ex.sel { border-color: var(--gold); }
.ex .e-meta { font-size: 0.8rem; color: var(--text-2); text-align: right; }
.ex .tag { font-size: 0.7rem; padding: 1px 6px; border-radius: 6px; background: var(--surface-2); margin-left: 6px; }
.ex .tag.next { background: var(--gold-dim); color: var(--text); }
.logpanel { grid-template-columns: minmax(0, 1fr); position: sticky; bottom: calc(72px + env(safe-area-inset-bottom)); margin-top: 12px; display: grid; gap: 10px; box-shadow: 0 -8px 24px rgb(0 0 0 / 0.35); }
.lp-head { flex-wrap: wrap; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(60px, 1fr)); gap: 6px; }
.quick button { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 0; font-weight: 700; }
.lp-row { display: flex; align-items: center; gap: 8px; }
.lp-row input, .lp-row select { flex: 1; min-width: 0; font: inherit; font-size: 1.2rem; padding: 8px 10px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; text-align: center; }
.lp-row select { font-size: 1rem; }
.step { width: 48px; height: 44px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); font-size: 1.3rem; }
.lp-timer { display: flex; align-items: center; gap: 12px; justify-content: center; }
#timer-val { font-size: 2rem; font-variant-numeric: tabular-nums; font-weight: 800; }
.btn { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 16px; }
.btn.primary { background: var(--gold); color: #14130f; border-color: var(--gold); font-weight: 700; }
.btn.big { padding: 14px; font-size: 1.1rem; }

/* data */
.heatmap { overflow-x: auto; }
.heatmap svg, .weekly svg { display: block; }
.heatmap rect.cell:hover, .weekly rect.seg:hover { stroke: var(--text); stroke-width: 1.5; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.8rem; color: var(--text-2); margin-bottom: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.records { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.records .r-val { font-size: 1.3rem; font-weight: 800; }
.records .r-lbl { font-size: 0.8rem; color: var(--text-2); }
.history { display: grid; gap: 4px; font-size: 0.9rem; }
.history .h-day { margin-top: 10px; color: var(--gold); font-size: 0.8rem; }
.history .h-row { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--border); }
.axis { fill: var(--muted); font-size: 10px; }
.gridline { stroke: var(--border); stroke-width: 1; }

/* achievements */
.achievements { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.ach { padding: 10px 12px; }
.ach .a-name { font-weight: 700; }
.ach .a-desc { font-size: 0.8rem; color: var(--text-2); margin-top: 2px; }
.ach .a-date { font-size: 0.75rem; color: var(--gold); margin-top: 6px; }
.ach.locked { opacity: 0.45; }
.ach.locked .a-name::before { content: "🔒 "; }
.ach:not(.locked) { border-color: var(--gold-dim); }

/* overlays */
.tooltip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 0.8rem; max-width: 240px; box-shadow: 0 4px 16px rgb(0 0 0 / 0.3); }
.toasts { position: fixed; z-index: 40; top: calc(76px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); display: grid; gap: 6px; width: min(92vw, 420px); }
.toast { background: var(--surface-2); border: 1px solid var(--border); border-left: 4px solid var(--gold); border-radius: 10px; padding: 10px 12px; animation: tin 0.25s ease; box-shadow: 0 6px 20px rgb(0 0 0 / 0.35); }
.toast.xp { border-left-color: var(--xp); }
.toast.ach { border-left-color: var(--gold); }
@keyframes tin { from { opacity: 0; transform: translateY(-8px); } }
.levelup { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: rgb(0 0 0 / 0.55); }
.lu-box { text-align: center; animation: pop 0.5s cubic-bezier(.2, 1.6, .4, 1); }
.lu-small { font-size: 1.1rem; letter-spacing: 0.2em; color: var(--gold); font-weight: 800; }
.lu-num { font-size: 6rem; font-weight: 900; color: var(--gold); text-shadow: 0 0 30px color-mix(in srgb, var(--gold) 60%, transparent); }
@keyframes pop { from { transform: scale(0.3); opacity: 0; } }

dialog { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); width: min(92vw, 400px); }
dialog::backdrop { background: rgb(0 0 0 / 0.5); }
dialog label { display: grid; gap: 4px; margin-bottom: 12px; font-size: 0.9rem; color: var(--text-2); }
dialog label.check { display: flex; align-items: center; gap: 8px; }
dialog input[type=number] { font: inherit; padding: 8px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; }
.empty { color: var(--muted); font-size: 0.9rem; padding: 8px 0; }

/* help */
.help-btn { flex: none; width: 44px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--gold); font-weight: 800; font-size: 1.1rem; }
.lp-head .help-btn, .l-next .help-btn { width: 26px; height: 26px; border-radius: 50%; font-size: 0.85rem; padding: 0; }
.lp-head strong { margin-right: auto; }
.l-next .help-btn { margin-left: 4px; vertical-align: middle; }
#help p { line-height: 1.5; margin: 0 0 12px; }
.help-tip { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
#help a.btn { text-decoration: none; color: var(--text); }

/* difficulty (con) colours, always paired with a text label */
.con { display: inline-block; font-size: 0.7rem; font-weight: 700; padding: 1px 6px; border-radius: 6px; border: 1px solid var(--c); color: var(--c); white-space: nowrap; }
.con-legend { margin: 0 0 10px; }
.con-legend .con { margin-right: 2px; }
.ex { border-left: 4px solid var(--c, var(--border)); }

/* plan */
.plan { display: grid; gap: 8px; }
.pitem { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center; border-left: 4px solid var(--c); }
.pitem .p-name { font-weight: 700; }
.pitem .p-target { font-size: 1.05rem; margin-top: 2px; }
.pitem .p-note { grid-column: 1 / -1; font-size: 0.8rem; color: var(--text-2); }
.pitem .p-act { display: flex; gap: 6px; align-items: center; }
.pitem .p-act .btn { padding: 10px 14px; font-weight: 700; }
.pitem.done { opacity: 0.6; }
.pitem .p-sets { display: flex; gap: 4px; margin-top: 6px; }
.pitem .p-sets i { width: 18px; height: 6px; border-radius: 3px; background: var(--surface-2); }
.pitem .p-sets i.on { background: var(--c); }

/* sections, tiles editing */
.sec.off { display: none; }
.h-row2 { display: flex; justify-content: space-between; align-items: center; }
.h-row2 .reroll { text-transform: none; letter-spacing: 0; }
.qtile { position: relative; }
.qtile .tdel, .qtile .tpin { position: absolute; top: -8px; right: -8px; width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 0.85rem; padding: 0; }
.qtile .tpin { right: 24px; }
.qbtn.add { border-style: dashed; border-left-width: 1px; text-align: center; color: var(--text-2); }
.qbtn.auto { opacity: 0.85; }
.editing .qtile .qbtn { animation: wiggle 0.3s ease-in-out infinite alternate; }
@keyframes wiggle { from { transform: rotate(-0.6deg); } to { transform: rotate(0.6deg); } }
@media (prefers-reduced-motion: reduce) { .editing .qtile .qbtn { animation: none; } }
dialog fieldset { border: 1px solid var(--border); border-radius: 10px; margin: 0 0 12px; padding: 8px 12px 4px; }
dialog legend { color: var(--gold); font-size: 0.85rem; padding: 0 4px; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.checks label { margin-bottom: 8px; }
dialog select { font: inherit; padding: 8px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; }

/* login */
.login { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; background: var(--bg); padding: 16px; }
.login-box { width: min(100%, 360px); display: grid; gap: 4px; }
.login-box h3 { text-align: center; color: var(--gold); }
.login-logo { text-align: center; font-size: 2.5rem; }
.login-box label { display: grid; gap: 4px; margin-bottom: 10px; font-size: 0.9rem; color: var(--text-2); }
.login-box input { font: inherit; padding: 10px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; }
.login-err { color: var(--critical); font-size: 0.9rem; min-height: 1.2em; margin-bottom: 6px; }

/* party */
.party { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 8px; }
.pm { display: grid; gap: 6px; padding: 12px; }
.pm.me { border-color: var(--gold); }
.pm-top { display: flex; justify-content: space-between; align-items: baseline; }
.pm-lvl { font-weight: 800; color: var(--gold); }
.pm-row { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; }
.pm-row .ok { color: var(--ok, var(--con-green)); }
.spark { display: flex; align-items: flex-end; gap: 2px; height: 22px; width: 70px; }
.spark i { flex: 1; background: var(--seq-3); border-radius: 2px 2px 0 0; }
.spark i.zero { background: var(--seq-0); }

/* body log */
.body-card { display: grid; gap: 14px; }
.body-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; align-items: end; }
.body-form label { display: grid; gap: 4px; font-size: 0.8rem; color: var(--text-2); }
.body-form .mood { display: grid; gap: 4px; grid-column: span 2; }
#body-mood { display: flex; gap: 4px; }
#body-mood button { flex: 1; font-size: 1.3rem; padding: 6px 0; background: var(--surface-2, var(--bg)); border: 1px solid var(--border); border-radius: 8px; opacity: 0.55; }
#body-mood button.on { opacity: 1; border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
.body-insights { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.body-insights .wide { grid-column: 1 / -1; }
.body-insights .r-val { font-size: 1.2rem; font-weight: 800; }
.body-card .r-lbl { font-size: 0.8rem; color: var(--text-2); margin-bottom: 4px; }
table.mini { border-collapse: collapse; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
table.mini th, table.mini td { padding: 3px 12px 3px 0; text-align: left; }
table.mini th { color: var(--muted); font-weight: 600; }
.wline { fill: none; stroke: var(--seq-3); stroke-width: 2; stroke-linejoin: round; }
.dot { fill: var(--seq-3); stroke: var(--surface); stroke-width: 1.5; }
.dot:hover { stroke: var(--text); }
.refline { stroke: var(--muted); stroke-dasharray: 4 3; stroke-width: 1; }
.body-form input, .body-form select { font: inherit; font-size: 1rem; padding: 8px; min-width: 0; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; }

/* boss */
.boss { display: grid; gap: 8px; }
.b-top { display: flex; gap: 10px; align-items: center; }
.b-icon { font-size: 2rem; line-height: 1; }
.b-hp > div { background: var(--con-red); }
.b-part { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center; padding: 6px 0; border-top: 1px solid var(--border); }
.b-part > .muted { grid-column: 1; }
.b-part .b-act { grid-column: 2; grid-row: 1 / span 2; display: flex; gap: 6px; align-items: center; }
.b-part.done { opacity: 0.6; }
.b-hist { border-top: 1px solid var(--border); padding-top: 6px; }

/* loot (WoW item quality colours) */
.loot { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.item { padding: 10px 12px; border-left: 3px solid var(--rc); display: grid; gap: 2px; }
.item .i-name { font-weight: 700; color: var(--rc); }
.item .i-meta { color: var(--rc); opacity: 0.85; }
.r-common { --rc: var(--r-common); } .r-uncommon { --rc: var(--r-uncommon); } .r-rare { --rc: var(--r-rare); }
.r-epic { --rc: var(--r-epic); } .r-legendary { --rc: var(--r-legendary); }
b.r-common, b.r-uncommon, b.r-rare, b.r-epic, b.r-legendary { color: var(--rc); }
.loot-hint { grid-column: 1 / -1; }
.pm-title { font-weight: 500; font-size: 0.8rem; color: var(--gold); }
