/* ============ Tokens ============ */
:root {
  --bg: #EFEDE8;          /* soft warm off-white */
  --card: #FFFFFF;
  --soft: #F5F4F0;
  --line: #E7E4DD;
  --ink: #1C1A45;         /* deep indigo */
  --ink-2: #4A4870;
  --muted: #8E8CA0;
  --navy: #1C1A45;        /* icon color on pastel tiles, same in both themes */

  /* pastels (tiles, pins, highlights) */
  --mint: #BFE6D1;
  --lav: #D8D0FB;
  --butter: #FADB8E;
  --pink: #F5CEF1;
  --sky: #B3D2FB;
  --none: #E9E7EE;

  /* tinted pills */
  --mint-bg: #DDF2E6; --mint-fg: #2F6B4E;
  --lav-bg: #ECE8FE;  --lav-fg: #5A47C9;
  --butter-bg: #FDF0C9; --butter-fg: #86610F;
  --danger: #C0392B; --danger-bg: #FBE3E0;

  --shadow: 0 1px 2px rgba(28, 26, 69, .04), 0 12px 32px -14px rgba(28, 26, 69, .14);
  --shadow-sm: 0 1px 2px rgba(28, 26, 69, .06), 0 4px 12px -6px rgba(28, 26, 69, .12);
  --font: 'Outfit', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111220; --card: #1B1C2C; --soft: #242538; --line: #2E2F45;
    --ink: #EEEDFB; --ink-2: #C3C1DC; --muted: #8B8AA6;
    --none: #3A3B52;
    --mint-bg: rgba(191, 230, 209, .14); --mint-fg: #BFE6D1;
    --lav-bg: rgba(216, 208, 251, .14);  --lav-fg: #D8D0FB;
    --butter-bg: rgba(250, 219, 142, .16); --butter-fg: #FADB8E;
    --danger: #F29385; --danger-bg: rgba(242, 147, 133, .14);
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 14px 34px -16px rgba(0,0,0,.7);
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3), 0 4px 12px -6px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111220; --card: #1B1C2C; --soft: #242538; --line: #2E2F45;
  --ink: #EEEDFB; --ink-2: #C3C1DC; --muted: #8B8AA6;
  --none: #3A3B52;
  --mint-bg: rgba(191, 230, 209, .14); --mint-fg: #BFE6D1;
  --lav-bg: rgba(216, 208, 251, .14);  --lav-fg: #D8D0FB;
  --butter-bg: rgba(250, 219, 142, .16); --butter-fg: #FADB8E;
  --danger: #F29385; --danger-bg: rgba(242, 147, 133, .14);
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 14px 34px -16px rgba(0,0,0,.7);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3), 0 4px 12px -6px rgba(0,0,0,.6);
  color-scheme: dark;
}

/* shape → color (same meaning everywhere: tiles, pins, pills) */
.m-blockage { --m: var(--butter); }
.m-inflammation { --m: var(--pink); }
.m-infection { --m: var(--mint); }
.m-congenital { --m: var(--lav); }
.m-functional { --m: var(--sky); }
.m-none { --m: var(--none); }

/* ============ Base ============ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
a { color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; font-weight: 600; }
p { margin: 0 0 .6em; }
mark { background: var(--butter-bg); color: inherit; padding: 0 .22em; border-radius: 5px; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
button { font: inherit; color: inherit; }
svg { flex-shrink: 0; }
:focus-visible { outline: 2.5px solid var(--lav-fg); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pad { padding: 8px 10px; margin: 0; }

.mech-icon { width: 1em; height: 1em; flex-shrink: 0; color: var(--ink); }

/* pastel tile holding a shape */
.tile {
  display: grid; place-items: center; flex-shrink: 0;
  width: 76px; height: 76px; border-radius: 18px;
  background: radial-gradient(circle at 28% 22%, rgba(255,255,255,.6), transparent 62%), var(--m, var(--none));
}
.tile .mech-icon { width: 36%; height: 36%; color: var(--navy); }
.tile.xs { width: 22px; height: 22px; border-radius: 7px; }
.tile.xs .mech-icon { width: 58%; height: 58%; }
.tile.sm { width: 38px; height: 38px; border-radius: 11px; }
.tile.lg { width: 56px; height: 56px; border-radius: 16px; }
.tile.xl { width: 112px; height: 112px; border-radius: 28px; }
.urgent-swatch { background: var(--ink); }

/* ============ Shell: sidebar + main ============ */
.shell { display: grid; grid-template-columns: 264px minmax(0, 1fr); gap: 24px; max-width: 1380px; margin: 0 auto; padding: 20px; }
.main { min-width: 0; }
.main main { padding-bottom: 60px; }

.sidebar {
  position: sticky; top: 20px; height: calc(100vh - 40px); overflow-y: auto;
  background: var(--card); border-radius: 26px; padding: 18px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 10px;
}
.block-pick {
  display: flex; align-items: center; gap: 12px; text-decoration: none;
  border: 1.5px solid var(--line); border-radius: 16px; padding: 10px 12px; margin-bottom: 14px;
}
.block-pick > svg { width: 18px; height: 18px; margin-left: auto; color: var(--muted); }
.avatar { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--butter); color: var(--navy); font-size: 12px; font-weight: 700; flex-shrink: 0; }
.block-name { display: flex; flex-direction: column; line-height: 1.15; }
.block-name small { font-size: 11.5px; color: var(--muted); }
.block-name b { font-weight: 600; font-size: 16px; }

.search-box { position: relative; display: flex; align-items: center; gap: 10px; background: var(--soft); border-radius: 14px; padding: 0 14px; }
.search-box > svg { width: 19px; height: 19px; color: var(--ink-2); }
.search-box input { border: 0; background: transparent; padding: 12px 0; margin: 0; font-size: 15px; box-shadow: none !important; }
.search-box input:focus { outline: none; }
.search-box.big { padding: 2px 16px; }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 30;
  background: var(--card); border-radius: 16px; box-shadow: var(--shadow); padding: 6px; max-height: 340px; overflow-y: auto;
  border: 1px solid var(--line);
}
.search-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; text-decoration: none; font-size: 14px; }
.search-row:hover { background: var(--soft); }
.search-list { margin-top: 12px; display: grid; gap: 2px; }

.side-btn {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 11px 14px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--card);
  font-size: 15px; font-weight: 500; text-decoration: none; cursor: pointer;
}
.side-btn svg { width: 20px; height: 20px; }
.side-btn small { margin-left: auto; font-size: 12px; color: var(--muted); }
.side-btn:hover { border-color: var(--muted); }
.side-btn.on { background: var(--soft); border-color: var(--ink); }
.side-btn.soft { background: var(--soft); border-color: transparent; }
.side-nav { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.side-foot { margin-top: auto; padding-top: 14px; display: grid; gap: 10px; }
.theme-seg { display: flex; background: var(--soft); border-radius: 14px; padding: 4px; gap: 4px; }
.theme-seg button { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; border: 0; background: none; padding: 8px 6px; border-radius: 10px; cursor: pointer; font-size: 13.5px; font-weight: 500; color: var(--muted); }
.theme-seg button svg { width: 16px; height: 16px; }
.theme-seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow-sm); }
.sync-line { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); margin: 0; }
.sync-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; flex-shrink: 0; }
.sync-dot.ok { background: #4FA776; } .sync-dot.busy { background: #E8B53F; } .sync-dot.error { background: var(--danger); }

.mobile-top, .bottom-nav { display: none; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%;
  border: 0; background: var(--card); cursor: pointer; text-decoration: none; box-shadow: var(--shadow-sm);
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn.small { width: 32px; height: 32px; font-size: 18px; line-height: 1; box-shadow: none; background: var(--soft); }

@media (max-width: 900px) {
  .shell { display: block; padding: 0; }
  .sidebar { display: none; }
  .main main { padding: 0 16px 110px; }
  .mobile-top {
    display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 20;
    padding: 12px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  }
  .mobile-top .block-pick { border: 0; padding: 0; margin: 0; }
  .top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
  .bottom-nav {
    display: flex; position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 25;
    background: var(--card); border-radius: 22px; box-shadow: var(--shadow); padding: 6px;
  }
  .bottom-nav a, .bottom-nav button {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 2px; border-radius: 16px;
    text-decoration: none; border: 0; background: none; font-size: 11px; font-weight: 500; color: var(--muted); cursor: pointer;
  }
  .bottom-nav svg { width: 22px; height: 22px; }
  .bottom-nav .on { background: var(--soft); color: var(--ink); }
}

/* ============ Page head ============ */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 10px 0 18px; }
.page-head .muted { font-size: 14px; margin-bottom: 4px; }
.page-head h1 { font-size: 32px; letter-spacing: -.02em; }
.h-sub { font-weight: 400; color: var(--muted); font-size: 20px; margin-left: 4px; }
.head-stats { display: flex; gap: 8px; flex-wrap: wrap; }
.stat { display: inline-flex; align-items: center; gap: 5px; background: var(--card); border-radius: 999px; padding: 6px 13px; font-size: 13.5px; font-weight: 500; box-shadow: var(--shadow-sm); }
.stat svg { width: 14px; height: 14px; }
.stat.lav { background: var(--lav-bg); color: var(--lav-fg); box-shadow: none; }
.stat.mint { background: var(--mint-bg); color: var(--mint-fg); box-shadow: none; }

/* ============ Chips ============ */
.chips-wrap { margin: 0 0 20px; }
.chips-label { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
  border: 0; background: var(--card); border-radius: 999px; box-shadow: var(--shadow-sm);
  padding: 8px 14px; font-weight: 500; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.chip small { font-size: 12px; color: var(--muted); }
.chip:hover { background: var(--soft); }
.chip.on { background: var(--ink); color: var(--card); }
.chip.on small { color: var(--card); opacity: .7; }
@media (max-width: 900px) {
  .chips { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 2px 16px 8px; scrollbar-width: none; }
  .chips::-webkit-scrollbar { display: none; }
}

/* ============ Cards ============ */
.card { background: var(--card); border-radius: 24px; padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h2 { display: flex; align-items: center; gap: 9px; font-size: 18px; }
.card-head h2 svg { width: 21px; height: 21px; color: var(--ink-2); }
.card-sub { color: var(--muted); font-size: 14px; margin: -4px 0 10px; }
.link-btn { background: none; border: 0; cursor: pointer; font-size: 13px; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.list-count { font-size: 15px; font-weight: 500; margin: -2px 0 12px; }

/* a topic as a note */
.note {
  display: flex; align-items: center; gap: 16px; text-decoration: none;
  padding: 14px 14px 14px 18px; border-radius: 20px; background: var(--soft);
  transition: background .15s, box-shadow .15s, transform .15s;
}
.note:hover { background: var(--card); box-shadow: var(--shadow); transform: translateY(-1px); }
.note-body { flex: 1; min-width: 0; }
.note h3 { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.note-line { font-size: 13.5px; color: var(--ink-2); margin: 0 0 10px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.note-line.empty { color: var(--muted); }
.note-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.meta-pill { display: inline-flex; align-items: center; background: var(--card); border-radius: 999px; padding: 2px 10px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.meta-pill.urgent { background: var(--ink); color: var(--card); }
.meta-pill[class*="m-"] { background: var(--m); color: var(--navy); font-weight: 500; }
.status { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 500; }
.status svg { width: 12px; height: 12px; }
.status.done { background: var(--mint-bg); color: var(--mint-fg); }
.status.partial { background: var(--lav-bg); color: var(--lav-fg); }
.status.empty { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.note-list { display: flex; flex-direction: column; gap: 10px; }
.note-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 12px; }
@media (max-width: 480px) { .note-grid { grid-template-columns: 1fr; } .note .tile { width: 64px; height: 64px; } }

.cards-view { display: grid; gap: 18px; }
.add-topic { width: fit-content; }

.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 14px; font-size: 13px; color: var(--ink-2); }
.legend > span { display: inline-flex; align-items: center; gap: 7px; }
.inline-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; }
.inline-dot.mint { background: var(--mint); }

.mini-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.mini-chip { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; font-size: 13.5px; font-weight: 500; padding: 5px 13px 5px 5px; border-radius: 999px; background: var(--soft); }
.mini-chip:hover { background: var(--line); }

/* ============ Gut map ============ */
.map-layout { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 1100px) { .map-layout { grid-template-columns: 1fr; } }
.gutmap { display: block; width: 100%; height: auto; max-height: 72vh; margin: 0 auto; overflow: visible; }
.gutmap path, .gutmap rect { stroke-linecap: round; stroke-linejoin: round; }
.gm-out { fill: none; stroke: var(--ink); }
.gm-in { fill: none; stroke: var(--card); transition: stroke .2s; }
.gm-solid { fill: var(--card); stroke: var(--ink); stroke-width: 1.8; transition: fill .2s; }
.gm-detail { fill: none; stroke: var(--muted); stroke-width: 1.2; opacity: .7; }
.gm-duct { fill: none; stroke: var(--ink); stroke-width: 1.8; }
.gm-line { fill: none; stroke: var(--muted); stroke-width: 1.6; stroke-dasharray: 5 5; }
.gm-hit { fill: none; stroke: transparent; stroke-width: 20; }
.gutmap:not(.mini) .gm-region[role=button] { cursor: pointer; }
.gm-region:focus { outline: none; }
.gutmap:not(.mini) .gm-region:hover .gm-in { stroke: color-mix(in srgb, var(--lav) 55%, var(--card)); }
.gutmap:not(.mini) .gm-region:hover .gm-solid { fill: color-mix(in srgb, var(--lav) 55%, var(--card)); }
.gutmap:not(.mini) .gm-region:hover .gm-line { stroke: var(--ink); }
.gm-region:focus-visible .gm-in, .gm-region:focus-visible .gm-solid { stroke: var(--lav-fg); }
.gm-region.on .gm-in { stroke: var(--lav) !important; }
.gm-region.on .gm-solid { fill: var(--lav) !important; }
.gm-region.on .gm-line { stroke: var(--lav-fg); stroke-dasharray: none; stroke-width: 3; }
.gm-region.dim { opacity: .38; }
.gm-body path { fill: none; stroke: var(--ink); stroke-width: 2; opacity: .5; stroke-linecap: round; }
.gm-bead-out { fill: var(--ink); }
.gm-bead { fill: var(--card); transition: fill .2s; }
.gutmap:not(.mini) .gm-region:hover .gm-bead { fill: color-mix(in srgb, var(--lav) 55%, var(--card)); }
.gm-region.on .gm-bead { fill: var(--lav) !important; }
.gm-target { fill: none; stroke: var(--lav-fg); stroke-width: 2.5; stroke-dasharray: 5 5; }

.gm-marker { cursor: pointer; }
.gm-marker circle { fill: var(--ink); stroke: var(--card); stroke-width: 2.5; transition: r .15s; }
.gm-marker text { fill: var(--card); font: 600 11.5px var(--font); text-anchor: middle; pointer-events: none; }
.gm-marker.complete circle { fill: var(--mint); }
.gm-marker.complete text { fill: var(--navy); }
.gm-marker.on circle { stroke: var(--lav); stroke-width: 5; r: 13; }
.gm-marker:hover circle { r: 13; }

.everywhere {
  display: flex; align-items: center; gap: 10px; margin: 10px auto 0; cursor: pointer;
  border: 0; background: var(--soft); border-radius: 999px; padding: 6px 16px 6px 6px; font-weight: 500; font-size: 14px;
}
.everywhere:hover { background: var(--line); }
.everywhere.on { background: var(--lav); color: var(--navy); }
.count-dot { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--ink); color: var(--card); font-size: 12px; font-weight: 600; }
.side-empty p { color: var(--ink-2); max-width: 46ch; }
.side-empty h3 { font-size: 15px; margin-top: 18px; }

/* ============ Timelines (adapted from the ruler design) ============ */
.tl-scroll { overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; scrollbar-color: var(--line) transparent; margin: 0 -20px; padding: 0 20px; }
.tl-scroll::-webkit-scrollbar { height: 4px; }
.tl-scroll::-webkit-scrollbar-thumb { background: var(--line); border-radius: 2px; }

.tl-body { position: relative; --tt: 76px; height: 166px; }
.tl-body.course { --tt: 54px; height: 136px; }
.tl-zone { position: absolute; top: 0; bottom: 0; border-left: 1px dashed var(--line); }
.tl-zone:first-child { border-left: 0; }
.tl-zone.alt { background: color-mix(in srgb, var(--soft) 70%, transparent); border-radius: 0; }
.tl-zone span { position: absolute; top: 2px; left: 10px; right: 4px; font-size: 12px; font-weight: 500; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tl-track { position: absolute; left: 0; right: 0; top: var(--tt); height: 8px; border-radius: 4px; background: var(--soft); box-shadow: inset 0 0 0 1px var(--line); }
.tl-band { position: absolute; top: 0; height: 8px; border-radius: 4px; background: var(--lav); }
.tl-band.ink { background: var(--butter); }
.tl-cap { position: absolute; top: -4px; width: 3px; height: 16px; border-radius: 2px; background: var(--ink); transform: translateX(-1.5px); box-shadow: 0 0 0 2px var(--card); }

.tl-tick { position: absolute; top: var(--tt); height: 8px; width: 1px; background: var(--muted); opacity: .45; }
.tl-tick span { position: absolute; top: calc(166px - var(--tt) - 18px); left: 0; transform: translateX(-50%); font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.tl-body.course .tl-tick span { top: calc(136px - var(--tt) - 18px); }
.tl-tick.start span { transform: none; } .tl-tick.end span { transform: translateX(-100%); }

.tl-pin-above, .tl-pin-below { position: absolute; display: flex; flex-direction: column; align-items: center; z-index: 1; }
.tl-pin-above { top: var(--tt); transform: translate(-50%, -100%); }
.tl-pin-below { top: calc(var(--tt) + 8px); transform: translateX(-50%); }
.tl-pin-above[data-topic], .tl-pin-below[data-topic] { cursor: pointer; }
.tl-pin-label {
  font-size: 11.5px; font-weight: 500; white-space: nowrap; text-align: center; color: var(--ink);
  background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 0 7px; margin-bottom: 3px;
}
.tl-pin-below .tl-pin-label { margin: 3px 0 0; }
.tl-pin-circle {
  width: 26px; height: 26px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: var(--m, var(--none)); border: 2px solid var(--card); box-shadow: var(--shadow-sm); flex-shrink: 0; transition: transform .15s;
}
.tl-pin-circle .mech-icon { width: 12px; height: 12px; color: var(--navy); }
.tl-pin-point { width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; color: var(--muted); }
/* transform-origin = the circle's centre, so a tilted pointer swings like a compass needle */
.tl-pin-above .tl-pin-point { border-top: 6px solid currentColor; margin-top: -1px; transform-origin: 50% -12px; }
.tl-pin-below .tl-pin-point { border-bottom: 6px solid currentColor; margin-bottom: -1px; order: -1; transform-origin: 50% 18px; }
.tl-pin-above.urgent .tl-pin-circle, .tl-pin-below.urgent .tl-pin-circle { background: var(--ink); }
.tl-pin-above.urgent .mech-icon, .tl-pin-below.urgent .mech-icon { color: var(--card); }
.tl-pin-above.selected .tl-pin-circle, .tl-pin-below.selected .tl-pin-circle { box-shadow: 0 0 0 4px var(--lav); }
.tl-pin-above.selected .tl-pin-label, .tl-pin-below.selected .tl-pin-label { background: var(--ink); color: var(--card); border-color: var(--ink); }
.tl-pin-above:hover .tl-pin-circle, .tl-pin-below:hover .tl-pin-circle { transform: scale(1.12); }
.tl-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--navy); }
.tl-pin-above.event .tl-pin-circle, .tl-pin-below.event .tl-pin-circle { --m: var(--butter); width: 20px; height: 20px; }

.tl-mini { position: relative; }
.tl-mini-zones { position: relative; height: 20px; }
.tl-mini-zones .tl-zone { bottom: -8px; }
.tl-mini-zones .tl-zone span { font-size: 10.5px; left: 5px; }
.tl-lane { margin: 8px 0; }
.tl-lane-label { font-size: 12px; font-weight: 500; color: var(--ink-2); margin-bottom: 4px; }
.tl-lane-track { position: relative; height: 12px; border-radius: 6px; background: var(--soft); box-shadow: inset 0 0 0 1px var(--line); }
.tl-lane-track .tl-band { top: 0; height: 12px; border-radius: 6px; }
.tl-lane-track .tl-cap { top: -4px; height: 20px; }
.tl-mini-ticks { position: relative; height: 18px; }
.tl-mini-ticks .tl-tick { top: 0; height: 4px; }
.tl-mini-ticks .tl-tick span { top: 4px; font-size: 11px; }

/* course ranges look like calendar events */
.tl-lanes { position: relative; margin-top: 8px; }
.tl-grid { position: absolute; inset: 0 0 18px; pointer-events: none; }
.tl-grid i { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--line); }
.event-lane { position: relative; height: 34px; margin: 6px 0; }
.event-lane .tl-band { top: 0; height: 34px; border-radius: 11px; display: flex; align-items: center; }
.event-lane .tl-band span { padding: 0 11px; font-size: 13px; font-weight: 500; color: var(--navy); white-space: nowrap; }
.event-lane .tl-band.out-right span, .event-lane .tl-band.out-left span { position: absolute; color: var(--ink); padding: 0; }
.event-lane .tl-band.out-right span { left: calc(100% + 8px); }
.event-lane .tl-band.out-left span { right: calc(100% + 8px); }
.tl-band.c0 { background: var(--mint); } .tl-band.c1 { background: var(--lav); } .tl-band.c2 { background: var(--butter); }
.tl-band.c3 { background: var(--pink); } .tl-band.c4 { background: var(--sky); }
.tl-empty { font-size: 13px; color: var(--muted); padding: 6px 0; }
.tl-empty.big { padding: 34px 0; text-align: center; }

.age-detail { max-width: 460px; margin: 16px 0 4px; animation: rise .3s both; }
.unplaced { margin-top: 18px; }

/* ============ Topic page ============ */
.back { display: inline-flex; align-items: center; gap: 6px; margin: 6px 0 16px; text-decoration: none; font-size: 14px; font-weight: 500; color: var(--muted); }
.back svg { width: 16px; height: 16px; }
.back:hover { color: var(--ink); }

.topic-head { display: flex; gap: 26px; align-items: flex-start; padding: 26px; margin-bottom: 18px; }
.topic-head-body { flex: 1; min-width: 0; }
.topic-head h1 { font-size: clamp(26px, 4vw, 34px); letter-spacing: -.02em; margin: 12px 0 10px; }
.one-line { font-size: 18px; line-height: 1.5; color: var(--ink-2); margin: 0; max-width: 60ch; }
.one-line.empty { color: var(--muted); font-size: 15px; }
.topic-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 20px; }
@media (max-width: 640px) {
  .topic-head { flex-direction: column; gap: 14px; padding: 20px; }
  .topic-head .tile.xl { width: 72px; height: 72px; border-radius: 20px; }
}

.secs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.sec { animation: rise .45s cubic-bezier(.2, .8, .2, 1) both; animation-delay: calc(var(--i) * 45ms); }
.sec.wide { grid-column: 1 / -1; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@media (max-width: 760px) { .secs { grid-template-columns: 1fr; } }
.sec h3 { display: flex; align-items: center; gap: 10px; font-size: 15px; margin-bottom: 14px; }
.sec-icon { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; background: var(--soft); color: var(--ink-2); }
.sec-icon svg { width: 17px; height: 17px; }
.sec ul { margin: 0; padding: 0; list-style: none; }
.sec li { position: relative; padding-left: 18px; margin: 7px 0; font-size: 15.5px; }
.sec li::before { content: ''; position: absolute; left: 3px; top: .62em; width: 6px; height: 6px; border-radius: 50%; background: var(--lav-fg); }
.sec p { font-size: 15.5px; }
.empty-hint { color: var(--muted); font-size: 14px !important; }
.empty-hint a { color: var(--ink); font-weight: 500; }

.where { display: flex; align-items: center; gap: 16px; }
.where .gutmap.mini { width: 150px; flex-shrink: 0; margin: 0; }
.where p { margin: 0; font-size: 16px; font-weight: 500; }
.age-text { font-size: 14px; font-weight: 500; color: var(--ink-2); margin: 10px 0 0; }

.vs-card { display: grid; grid-template-columns: auto 1fr auto; gap: 16px; align-items: center; text-decoration: none; padding: 14px; border-radius: 18px; background: var(--soft); }
.vs-card:hover { background: var(--line); }
.vs-badge { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; background: var(--ink); color: var(--card); font-weight: 700; font-size: 14px; letter-spacing: .02em; flex-shrink: 0; }
.vs-badge.big { width: 56px; height: 56px; font-size: 16px; }
.vs-main { min-width: 0; }
.vs-name { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 16px; }
.vs-diff { display: block; font-size: 15px; color: var(--ink-2); margin-top: 5px; }
.vs-go { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.vs-go svg { width: 15px; height: 15px; }
@media (max-width: 520px) { .vs-card { grid-template-columns: auto 1fr; } .vs-go { grid-column: 2; } }
.backlinks { margin-top: 18px; }

/* test-me covers */
.reveal { position: relative; min-height: 56px; }
.reveal-cover {
  position: absolute; inset: -4px; border: 0; border-radius: 16px; cursor: pointer; z-index: 2;
  display: grid; place-items: center;
  background-color: var(--soft);
  background-image: radial-gradient(color-mix(in srgb, var(--muted) 45%, transparent) 1.1px, transparent 1.5px);
  background-size: 14px 14px;
}
.reveal-cover span { display: inline-flex; align-items: center; gap: 7px; background: var(--card); color: var(--ink); padding: 7px 14px; border-radius: 999px; font-size: 13.5px; font-weight: 500; box-shadow: var(--shadow-sm); }
.reveal-cover span svg { width: 16px; height: 16px; }
.reveal-cover:hover span { background: var(--lav); color: var(--navy); }
.reveal.shown .reveal-cover { display: none; }
.reveal.shown .reveal-body { animation: rise .3s both; }

/* ============ Compare ============ */
.cmp-top { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.cmp-head { flex: 1; display: flex; align-items: center; gap: 14px; text-decoration: none; font-weight: 600; font-size: clamp(15px, 2.2vw, 20px); letter-spacing: -.01em; }
.cmp-head > span:last-child { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.cmp-diff { margin-bottom: 16px; box-shadow: inset 4px 0 0 var(--lav-fg), var(--shadow); }
.cmp-diff .diff { font-size: 19px; font-weight: 500; margin: 0 0 4px; }
.cmp-diff.empty p { color: var(--muted); margin: 0; }
.cmp-ages { margin-bottom: 16px; }
.cmp-row { display: grid; grid-template-columns: 140px 1fr 1fr; gap: 16px; padding: 16px 0; border-top: 1px solid var(--line); }
.cmp-row:first-child { border-top: 0; padding-top: 0; }
.cmp-row h3 { font-size: 14px; color: var(--muted); font-weight: 500; }
.cmp-cell ul { margin: 0; padding-left: 18px; }
.cmp-cell li { margin: 4px 0; }
.cmp-cell .where { flex-direction: column; align-items: flex-start; gap: 8px; }
.cmp-cell .where .gutmap.mini { width: 110px; }
@media (max-width: 640px) {
  .cmp-row { grid-template-columns: 1fr 1fr; }
  .cmp-row h3 { grid-column: 1 / -1; }
  .cmp-top { gap: 8px; }
  .cmp-head { flex-direction: column; align-items: flex-start; padding: 14px; }
  .vs-badge.big { width: 42px; height: 42px; font-size: 13px; }
}

/* ============ Buttons & forms ============ */
.btn {
  display: inline-flex; align-items: center; gap: 7px; border: 0; background: var(--soft); color: var(--ink);
  border-radius: 999px; padding: 10px 18px; font-weight: 500; font-size: 14.5px; cursor: pointer; text-decoration: none;
}
.btn svg { width: 17px; height: 17px; }
.btn:hover { background: var(--line); }
.btn.dark { background: var(--ink); color: var(--card); }
.btn.dark:hover { opacity: .88; }
.btn.primary { background: var(--butter); color: var(--navy); }
.btn.danger { background: var(--danger-bg); color: var(--danger); }
.btn.small { padding: 7px 13px; font-size: 13px; }

.edit-intro { color: var(--ink-2); max-width: 62ch; margin: -6px 0 20px; }
.edit form { display: grid; gap: 16px; max-width: 860px; }
fieldset.card { border: 0; margin: 0; }
legend { float: left; width: 100%; display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 600; padding: 0; margin-bottom: 4px; }
legend small { font-size: 12px; font-weight: 500; color: var(--muted); background: var(--soft); padding: 2px 8px; border-radius: 999px; }
legend + * { clear: both; }
.num { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--lav-bg); color: var(--lav-fg); font-size: 13px; font-weight: 600; }
.edit label, .edit .label { display: block; font-weight: 500; font-size: 14px; margin: 14px 0 0; }
.edit label small, .edit .label small { font-weight: 400; color: var(--muted); }
input, select, textarea {
  display: block; width: 100%; margin-top: 6px; font: 400 15px/1.45 var(--font); color: var(--ink);
  background: var(--soft); border: 1.5px solid transparent; border-radius: 12px; padding: 10px 12px;
}
textarea { resize: vertical; min-height: 48px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--lav-fg); background: var(--card); }
.hint { font-size: 13px; color: var(--muted); margin: 12px 0 0; }
.counter { float: right; font-size: 12px; color: var(--muted); }
.counter.over { color: var(--danger); }

.check-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.check-chip { margin: 0 !important; }
.check-chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.check-chip span { display: inline-block; padding: 6px 13px; border-radius: 999px; background: var(--soft); font-size: 13.5px; cursor: pointer; }
.check-chip input:checked + span { background: var(--ink); color: var(--card); }
.check-chip input:focus-visible + span { outline: 2.5px solid var(--lav-fg); outline-offset: 2px; }

.mech-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 14px; }
.mech-opt { margin: 0 !important; }
.mech-opt input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.mech-opt > span { display: flex; flex-direction: column; gap: 4px; padding: 12px; border-radius: 16px; background: var(--soft); border: 1.5px solid transparent; cursor: pointer; height: 100%; }
.mech-opt .tile { margin-bottom: 6px; }
.mech-opt b { font-size: 14px; font-weight: 600; } .mech-opt small { font-size: 12px; line-height: 1.35; color: var(--muted); }
.mech-opt input:checked + span { border-color: var(--ink); background: var(--card); box-shadow: var(--shadow-sm); }
.mech-opt input:focus-visible + span { outline: 2.5px solid var(--lav-fg); outline-offset: 2px; }

.toggle { display: flex !important; align-items: center; gap: 10px; cursor: pointer; margin-top: 16px !important; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle span { width: 42px; height: 25px; border-radius: 13px; background: var(--line); position: relative; transition: .2s; flex-shrink: 0; }
.toggle span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 19px; height: 19px; border-radius: 50%; background: var(--card); box-shadow: var(--shadow-sm); transition: .2s; }
.toggle input:checked + span { background: var(--ink); }
.toggle input:checked + span::after { left: 20px; }
.toggle input:focus-visible + span { outline: 2.5px solid var(--lav-fg); outline-offset: 2px; }

.age-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.age-in > div { display: flex; gap: 6px; }
.age-in input { flex: 1; min-width: 0; }
.age-in select { width: auto; flex-shrink: 0; }
@media (max-width: 600px) { .age-grid { grid-template-columns: 1fr; } }

.course-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .course-grid { grid-template-columns: 1fr 1fr; } .course-grid label:first-child { grid-column: 1 / -1; } }
#ev-rows { margin: 14px 0 10px; display: grid; gap: 8px; }
.ev-row { display: grid; grid-template-columns: minmax(0, 2fr) repeat(3, minmax(0, .8fr)) auto; gap: 6px; align-items: center; }
.ev-row input, .ev-row select { margin: 0; padding: 8px 10px; font-size: 14px; }
@media (max-width: 600px) { .ev-row { grid-template-columns: 1fr 1fr 1fr auto; } .ev-row input[name="ev_label"] { grid-column: 1 / -1; } }
#course-preview:not(:empty), #age-preview:not(:empty) { margin-top: 14px; padding: 14px 20px; background: var(--soft); border-radius: 16px; overflow: hidden; }
#course-preview .tl-scroll { margin: 0 -20px; }
.form-actions {
  display: flex; gap: 10px; flex-wrap: wrap; position: sticky; bottom: 16px; z-index: 5;
  padding: 8px; background: var(--card); box-shadow: var(--shadow); border-radius: 999px; width: fit-content;
}
@media (max-width: 900px) { .form-actions { bottom: calc(96px + env(safe-area-inset-bottom)); } }

/* ============ Settings ============ */
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
@media (max-width: 900px) { .settings-grid { grid-template-columns: 1fr; } }
.settings-grid p.muted { font-size: 14px; }
.seg { display: inline-flex; background: var(--soft); border-radius: 999px; padding: 4px; gap: 4px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 8px 16px; border-radius: 999px; cursor: pointer; font-weight: 500; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow-sm); }
.row-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row-form input { flex: 1; min-width: 200px; margin: 0; }
.settings-grid .sync-line { margin-top: 12px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ============ Category menu ============ */
.block-menu { position: relative; margin-bottom: 14px; }
.block-menu > summary { list-style: none; cursor: pointer; margin: 0; }
.block-menu > summary::-webkit-details-marker { display: none; }
.block-menu[open] > summary > svg { transform: rotate(180deg); }
.block-list {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 40; min-width: 230px;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 8px;
}
.block-group + .block-group { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 6px; }
.block-cat, .block-sub { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; border: 0; background: none; cursor: pointer; border-radius: 10px; }
.block-cat { padding: 8px 10px; font-weight: 600; font-size: 14.5px; }
.block-cat svg { width: 17px; height: 17px; color: var(--muted); }
.block-sub { padding: 7px 10px 7px 35px; font-size: 14px; }
.block-cat:hover, .block-sub:hover { background: var(--soft); }
.block-cat.on, .block-sub.on { background: var(--lav-bg); color: var(--lav-fg); }
.block-empty { font-size: 12.5px; color: var(--muted); margin: 0; padding: 2px 10px 6px 35px; }
.block-menu.compact { margin: 0; }
.block-menu.compact .block-pick { border: 0; padding: 0; margin: 0; }
.block-menu.compact .block-list { right: auto; }
.empty-cat { text-align: center; padding: 48px 24px; }
.empty-cat > svg { width: 42px; height: 42px; color: var(--muted); }
.empty-cat h2 { font-size: 20px; margin: 10px 0 6px; }
.empty-cat p { max-width: 46ch; margin: 0 auto; }

/* ============ Patient filter ============ */
.patient { margin-bottom: 20px; }
.patient-grid { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px 28px; align-items: end; margin-bottom: 16px; }
@media (max-width: 640px) { .patient-grid { grid-template-columns: 1fr; } }
.p-label { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; margin-bottom: 8px; color: var(--ink-2); }
.p-label b { color: var(--ink); font-weight: 600; font-size: 15px; }
.p-label small { color: var(--muted); font-weight: 400; font-size: 12.5px; }
.p-label .link-btn { margin-left: auto; }
.patient .chips { margin-top: 0; }
.chip.off { opacity: .45; }

.age-slider { position: relative; padding-top: 20px; }
.age-zones { position: absolute; inset: 0 0 auto 0; height: 100%; pointer-events: none; }
.age-zones span { position: absolute; top: 0; bottom: 2px; border-left: 1px dashed var(--line); padding-left: 6px; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.age-zones span:first-child { border-left: 0; padding-left: 0; }
.age-slider input[type=range] { -webkit-appearance: none; appearance: none; position: relative; width: 100%; height: 26px; margin: 0; padding: 0; background: none; border: 0; cursor: pointer; }
.age-slider input[type=range]:focus { outline: none; background: none; }
.age-slider input[type=range]::-webkit-slider-runnable-track { height: 10px; border-radius: 5px; background: var(--soft); box-shadow: inset 0 0 0 1px var(--line); }
.age-slider input[type=range]::-moz-range-track { height: 10px; border-radius: 5px; background: var(--soft); box-shadow: inset 0 0 0 1px var(--line); }
.age-slider input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 24px; height: 24px; margin-top: -7px; border-radius: 50%; background: var(--card); border: 2px solid var(--muted); box-shadow: var(--shadow-sm); }
.age-slider input[type=range]::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: var(--card); border: 2px solid var(--muted); box-shadow: var(--shadow-sm); }
.age-slider.on input[type=range]::-webkit-slider-thumb { background: var(--ink); border: 3px solid var(--card); box-shadow: 0 0 0 4px var(--lav); }
.age-slider.on input[type=range]::-moz-range-thumb { background: var(--ink); border: 3px solid var(--card); box-shadow: 0 0 0 4px var(--lav); }
.age-slider input[type=range]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--lav-fg); }

.meta-pill.warn { background: var(--butter-bg); color: var(--butter-fg); }
.tl-patient { position: absolute; top: -6px; bottom: -6px; width: 3px; border-radius: 2px; background: var(--lav-fg); transform: translateX(-1.5px); z-index: 2; }
.tl-patient::after { content: ''; position: absolute; top: -5px; left: -3.5px; width: 10px; height: 10px; border-radius: 50%; background: var(--lav-fg); }
.fit { display: inline-block; margin: 10px 0 0; font-size: 13px; font-weight: 500; padding: 3px 10px; border-radius: 999px; }
.fit.yes { background: var(--mint-bg); color: var(--mint-fg); }
.fit.no { background: var(--butter-bg); color: var(--butter-fg); }
.mini-chip.tagchip { padding: 5px 12px; }
.mini-chip.tagchip svg { width: 14px; height: 14px; color: var(--muted); }
.gutmap.mini { overflow: hidden; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .two-col { grid-template-columns: 1fr; } }
.add-tag { margin-top: 10px; }
.add-tag input { max-width: 340px; }
.sub-block + .sub-block { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.sub-block h4, .tl-title { font-size: 12.5px; font-weight: 500; color: var(--muted); margin: 0 0 8px; }
.tl-title { margin-top: 14px; }
.sym-detail { margin-top: 12px; }
.where > div { min-width: 0; }
.where ul { margin-top: 6px; }
.empty-cat > p:last-child { margin-top: 16px; }
