/* ============================================================================
   The Math Study Map — styles
   Colour: the seven strand hues are the dataviz reference categorical palette,
   slots 1-7, validated for CVD separation against the lane stacking order used
   here (see README). Reordering the lanes invalidates the validation run.
   ========================================================================== */

:root {
  color-scheme: light;

  --plane:        #f9f9f7;
  --surface:      #fcfcfb;
  --surface-2:    #f2f1ec;
  --ink:          #0b0b0b;
  --ink-2:        #52514e;
  --ink-3:        #898781;
  --hairline:     #e1e0d9;
  --rule:         #c3c2b7;
  --ring:         rgba(11, 11, 11, .10);
  --shadow:       0 1px 2px rgba(11,11,11,.06), 0 8px 24px -12px rgba(11,11,11,.18);
  --shadow-lift:  0 2px 6px rgba(11,11,11,.10), 0 18px 40px -16px rgba(11,11,11,.28);
  --accent:       #2a78d6;
  --accent-ink:   #fcfcfb;
  --good:         #0ca30c;

  --s-number:   #2a78d6;
  --s-algebra:  #eb6834;
  --s-geometry: #1baf7a;
  --s-analysis: #eda100;
  --s-probstat: #e87ba4;
  --s-discrete: #008300;
  --s-applied:  #4a3aa7;

  --edge:        #c2c1b7;
  --edge-hi:     #0b0b0b;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane:       #0d0d0d;
    --surface:     #1a1a19;
    --surface-2:   #232321;
    --ink:         #ffffff;
    --ink-2:       #c3c2b7;
    --ink-3:       #898781;
    --hairline:    #2c2c2a;
    --rule:        #383835;
    --ring:        rgba(255,255,255,.10);
    --shadow:      0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.7);
    --shadow-lift: 0 2px 6px rgba(0,0,0,.5), 0 18px 40px -16px rgba(0,0,0,.8);
    --accent:      #3987e5;
    --accent-ink:  #0d0d0d;

    --s-number:   #3987e5;
    --s-algebra:  #d95926;
    --s-geometry: #199e70;
    --s-analysis: #c98500;
    --s-probstat: #d55181;
    --s-discrete: #008300;
    --s-applied:  #9085e9;

    --edge:       #464641;
    --edge-hi:    #ffffff;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:       #0d0d0d;
  --surface:     #1a1a19;
  --surface-2:   #232321;
  --ink:         #ffffff;
  --ink-2:       #c3c2b7;
  --ink-3:       #898781;
  --hairline:    #2c2c2a;
  --rule:        #383835;
  --ring:        rgba(255,255,255,.10);
  --shadow:      0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.7);
  --shadow-lift: 0 2px 6px rgba(0,0,0,.5), 0 18px 40px -16px rgba(0,0,0,.8);
  --accent:      #3987e5;
  --accent-ink:  #0d0d0d;

  --s-number:   #3987e5;
  --s-algebra:  #d95926;
  --s-geometry: #199e70;
  --s-analysis: #c98500;
  --s-probstat: #d55181;
  --s-discrete: #008300;
  --s-applied:  #9085e9;

  --edge:       #464641;
  --edge-hi:    #ffffff;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--plane);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button, input, select { font: inherit; color: inherit; }

.skip {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: var(--accent-ink);
  padding: 10px 16px; border-radius: 0 0 var(--radius) 0;
}
.skip:focus { left: 0; }

/* ------------------------------------------------------------------ top bar */

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
  flex: none;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand svg { flex: none; }
.brand h1 { font-size: 15px; margin: 0; letter-spacing: -.01em; white-space: nowrap; }
.brand p  { font-size: 12px; margin: 1px 0 0; color: var(--ink-3); white-space: nowrap;
            overflow: hidden; text-overflow: ellipsis; }

.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.search { position: relative; }
.search input {
  width: 224px; padding: 7px 30px 7px 32px;
  background: var(--plane); border: 1px solid var(--hairline);
  border-radius: 999px; font-size: 13px; outline: none;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.search .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
                color: var(--ink-3); pointer-events: none; display: flex; }
.search kbd {
  position: absolute; right: 9px; top: 50%; transform: translateY(-50%);
  font: 600 10px/1 var(--font); color: var(--ink-3);
  border: 1px solid var(--hairline); border-radius: 4px; padding: 3px 5px;
  background: var(--surface); pointer-events: none;
}
.search input:not(:placeholder-shown) ~ kbd { display: none; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; min-width: 34px; padding: 0 9px;
  background: var(--surface); color: var(--ink-2);
  border: 1px solid var(--hairline); border-radius: 9px;
  cursor: pointer; transition: background .12s, color .12s, border-color .12s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-btn .lbl { font-size: 12.5px; }

/* ------------------------------------------------------------------ toolbar */

.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
  flex: none;
}

.chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px 5px 8px;
  font-size: 12px; line-height: 1;
  background: var(--surface); color: var(--ink-2);
  border: 1px solid var(--hairline); border-radius: 999px;
  cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s, opacity .12s;
}
.chip .swatch { width: 9px; height: 9px; border-radius: 3px; background: var(--c); flex: none; }
.chip[aria-pressed="true"] { color: var(--ink); border-color: var(--rule); background: var(--surface-2); }
.chip[aria-pressed="false"] { opacity: .45; }
.chip[aria-pressed="false"] .swatch { background: var(--ink-3); }
.chip:hover { border-color: var(--rule); }
.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.toolbar-sep { width: 1px; height: 22px; background: var(--hairline); }

.toolbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.progress { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-2); }
.progress .bar { width: 96px; height: 6px; border-radius: 3px; background: var(--surface-2);
                 border: 1px solid var(--hairline); overflow: hidden; }
.progress .bar > i { display: block; height: 100%; background: var(--good); width: 0%;
                     transition: width .25s ease; }
.progress b { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; }

.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--hairline);
             border-radius: 9px; padding: 2px; }
.segmented button {
  border: 0; background: transparent; color: var(--ink-3); cursor: pointer;
  font-size: 12.5px; padding: 5px 11px; border-radius: 7px;
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.segmented button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* --------------------------------------------------------------------- main */

main { flex: 1; min-height: 0; position: relative; display: flex; }

.stage-area { position: relative; flex: 1; min-width: 0; overflow: hidden; background: var(--plane); }

#viewport {
  position: absolute; inset: 0;
  cursor: grab; touch-action: none; overflow: hidden;
}
#viewport.dragging { cursor: grabbing; }

#world { position: absolute; top: 0; left: 0; transform-origin: 0 0; will-change: transform; }

#edges { position: absolute; top: 0; left: 0; overflow: visible; pointer-events: none; }
#edges path { fill: none; stroke: var(--edge); stroke-width: 1.35px; }
#edges .e-dim { stroke-opacity: .2; }
#edges .e-hide { stroke-opacity: .05; }
#edges #edges-hi path { stroke: var(--edge-hi); stroke-width: 2px; stroke-opacity: .85; }
#edges #edges-hi path.e-down { stroke: var(--accent); stroke-dasharray: 5 4; }

/* lane bands sit behind everything in the world */
.band { position: absolute; left: 0; border-radius: 14px; background: var(--c);
        opacity: .045; pointer-events: none; }
:root[data-theme="dark"] .band { opacity: .09; }
@media (prefers-color-scheme: dark) { :root:where(:not([data-theme="light"])) .band { opacity: .09; } }

.band-rule { position: absolute; left: 0; height: 1px; background: var(--hairline); pointer-events: none; }
.col-rule  { position: absolute; top: 0; width: 1px; background: var(--hairline); pointer-events: none; opacity: .8; }

/* --------------------------------------------------------------------- node */

.node {
  position: absolute;
  width: 190px; height: 56px;
  display: flex; align-items: stretch; gap: 0;
  padding: 0; margin: 0;
  background: var(--surface);
  border: 1px solid var(--ring);
  border-left: 3px solid var(--c);
  border-radius: 8px;
  box-shadow: var(--shadow);
  cursor: pointer; text-align: left;
  transition: box-shadow .12s, transform .12s, opacity .15s, border-color .12s;
  overflow: hidden;
}
.node:hover { box-shadow: var(--shadow-lift); transform: translateY(-1px); }
.node:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.node .body { flex: 1; min-width: 0; padding: 7px 8px 7px 9px; display: flex; flex-direction: column; }
.node .t {
  font-size: 12px; line-height: 1.22; font-weight: 500; color: var(--ink);
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3;
  overflow: hidden; word-break: break-word;
}
.node .marks { position: absolute; right: 5px; bottom: 4px; display: flex; gap: 3px; align-items: center; }
.node .mark { display: none; width: 14px; height: 14px; }
.node.is-star .mark-star { display: block; color: var(--ink-3); }
.node.is-learned .mark-done { display: block; color: var(--good); }

.node.is-learned { border-color: color-mix(in srgb, var(--good) 45%, var(--ring)); }
.node.is-learned .t { color: var(--ink-2); }
.node.is-ready { border-color: color-mix(in srgb, var(--accent) 55%, var(--ring));
                 box-shadow: var(--shadow), 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent); }

.node.n-dim  { opacity: .28; }
.node.n-hide { opacity: .1; pointer-events: none; }
.node.is-sel { border-color: var(--ink); box-shadow: var(--shadow-lift), 0 0 0 3px color-mix(in srgb, var(--ink) 16%, transparent); }
.node.is-sel .t { font-weight: 650; }

/* Zoomed far out the titles cannot be read, so the nodes become strand-tinted
   blocks: the map's shape is the information at that scale, not its labels. */
.zoom-far .node { background: color-mix(in srgb, var(--c) 26%, var(--surface));
                  border-color: color-mix(in srgb, var(--c) 40%, var(--ring)); }
.zoom-far .node .t { opacity: 0; }
.zoom-far .node .marks { opacity: .85; }
.zoom-far .node:hover { background: color-mix(in srgb, var(--c) 45%, var(--surface)); }

/* --------------------------------------------------- column & lane chrome */

#colheads {
  position: absolute; top: 0; left: 0; right: 0; height: 46px;
  overflow: hidden; pointer-events: none; z-index: 4;
  background: linear-gradient(to bottom, var(--plane) 62%, transparent);
  border-bottom: 1px solid transparent;
}
.colhead {
  position: absolute; top: 7px;
  display: flex; align-items: baseline; gap: 7px;
  padding: 4px 11px;
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: 999px; box-shadow: var(--shadow); white-space: nowrap;
}
.colhead .n { font-size: 12.5px; font-weight: 600; }
.colhead .short { font-size: 12.5px; font-weight: 600; display: none; }
.colhead .s { font-size: 11px; color: var(--ink-3); }
#colheads.tight .colhead .s { display: none; }
#colheads.tiny .colhead .n { display: none; }
#colheads.tiny .colhead .short { display: block; }

#lanerail {
  position: absolute; top: 46px; bottom: 0; left: 0; width: 132px;
  overflow: hidden; pointer-events: none; z-index: 3;
}
.lanelabel .short { display: none; }

.lanelabel {
  position: absolute; left: 10px;
  display: flex; align-items: center; gap: 7px;
  padding: 4px 9px 4px 7px;
  /* the rail floats over the map, so the labels are translucent: they name the
     lane without hiding the topic that happens to be under them */
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px);
  border: 1px solid var(--hairline);
  border-left: 3px solid var(--c);
  border-radius: 8px; box-shadow: var(--shadow);
  font-size: 10.5px; font-weight: 600; color: var(--ink-2);
  max-width: 116px; line-height: 1.2;
}

.map-controls {
  position: absolute; right: 14px; bottom: 14px; z-index: 5;
  display: flex; flex-direction: column; gap: 6px;
}
.map-controls .icon-btn { box-shadow: var(--shadow); }

.map-hint {
  position: absolute; left: 14px; bottom: 14px; z-index: 5;
  font-size: 11.5px; color: var(--ink-3);
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  border: 1px solid var(--hairline); border-radius: 8px;
  padding: 5px 10px; pointer-events: none; backdrop-filter: blur(4px);
}
.map-hint b { color: var(--ink-2); font-weight: 600; }

.filter-note {
  position: absolute; left: 50%; transform: translateX(-50%); top: 54px; z-index: 6;
  display: none; align-items: center; gap: 10px;
  background: var(--ink); color: var(--plane);
  border-radius: 999px; padding: 6px 8px 6px 14px; font-size: 12.5px;
  box-shadow: var(--shadow-lift);
}
.filter-note.on { display: flex; }
.filter-note button {
  border: 0; background: color-mix(in srgb, var(--plane) 22%, transparent);
  color: inherit; border-radius: 999px; padding: 4px 10px; cursor: pointer; font-size: 12px;
}
.filter-note button:hover { background: color-mix(in srgb, var(--plane) 34%, transparent); }

/* -------------------------------------------------------------- detail panel */

.panel {
  flex: none; width: 372px;
  background: var(--surface);
  border-left: 1px solid var(--hairline);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.panel.closed { display: none; }

.panel-head { padding: 16px 16px 12px; border-bottom: 1px solid var(--hairline); position: relative; }
.panel-head .close { position: absolute; right: 10px; top: 12px; }
.panel-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 9px; }
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; line-height: 1; padding: 4px 8px;
  border: 1px solid var(--hairline); border-radius: 999px; color: var(--ink-2);
  background: var(--plane);
}
.badge .swatch { width: 8px; height: 8px; border-radius: 2px; background: var(--c); }
.badge.key { border-color: color-mix(in srgb, var(--ink) 25%, transparent); color: var(--ink); }
.panel h2 { margin: 0; font-size: 19px; line-height: 1.22; letter-spacing: -.015em; padding-right: 30px; }

.panel-body { overflow-y: auto; padding: 14px 16px 24px; flex: 1; }
.panel-body p.lede { margin: 0 0 16px; font-size: 13.5px; line-height: 1.55; color: var(--ink-2); }

.sect { margin: 0 0 18px; }
.sect > h3 {
  margin: 0 0 8px; font-size: 10.5px; letter-spacing: .09em; text-transform: uppercase;
  color: var(--ink-3); font-weight: 700;
}
.sect ul.ideas { margin: 0; padding: 0; list-style: none; }
.sect ul.ideas li {
  position: relative; padding-left: 16px; margin-bottom: 7px;
  font-size: 13px; line-height: 1.5; color: var(--ink);
}
.sect ul.ideas li::before {
  content: ""; position: absolute; left: 2px; top: 8px;
  width: 5px; height: 5px; border-radius: 2px; background: var(--c);
}

.linkchips { display: flex; flex-wrap: wrap; gap: 6px; }
.linkchip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; padding: 5px 10px 5px 8px;
  background: var(--plane); border: 1px solid var(--hairline);
  border-radius: 7px; cursor: pointer; color: var(--ink); text-align: left;
}
.linkchip:hover { border-color: var(--rule); background: var(--surface-2); }
.linkchip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.linkchip .swatch { width: 8px; height: 8px; border-radius: 2px; background: var(--c); flex: none; }
.linkchip .tick { color: var(--good); display: none; }
.linkchip.done .tick { display: inline-flex; }
.empty-note { font-size: 12.5px; color: var(--ink-3); margin: 0; }

.path-list { margin: 0; padding: 0; list-style: none; counter-reset: step; }
.path-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 6px; border-radius: 6px; font-size: 12.5px; cursor: pointer;
}
.path-list li:hover { background: var(--surface-2); }
.path-list li .num {
  flex: none; width: 20px; height: 20px; border-radius: 6px;
  display: grid; place-items: center;
  background: var(--plane); border: 1px solid var(--hairline);
  font-size: 10.5px; color: var(--ink-3); font-variant-numeric: tabular-nums;
}
.path-list li.done .num { background: var(--good); border-color: var(--good); color: #fff; }
.path-list li .nm { flex: 1; min-width: 0; }
.path-list li .sg { font-size: 10.5px; color: var(--ink-3); white-space: nowrap; }

.panel-foot {
  flex: none; padding: 12px 16px; border-top: 1px solid var(--hairline);
  display: flex; gap: 8px; background: var(--surface);
}
.btn {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 12px; font-size: 13px; font-weight: 500;
  border-radius: 9px; border: 1px solid var(--hairline);
  background: var(--surface); color: var(--ink); cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--ink); color: var(--plane); border-color: var(--ink); }
.btn.primary:hover { opacity: .88; background: var(--ink); }
.btn.done { background: color-mix(in srgb, var(--good) 14%, var(--surface));
            border-color: color-mix(in srgb, var(--good) 45%, var(--hairline)); color: var(--ink); }

/* ---------------------------------------------------------------- list view */

#listview { position: absolute; inset: 0; overflow-y: auto; background: var(--plane); padding: 24px 16px 64px; }
#listview.closed { display: none; }
.list-inner { max-width: 940px; margin: 0 auto; }
.list-intro { font-size: 13.5px; line-height: 1.6; color: var(--ink-2); margin: 0 0 24px; max-width: 60ch; }
.list-stage { margin-bottom: 30px; }
.list-stage > header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px;
                       padding-bottom: 8px; border-bottom: 1px solid var(--hairline); }
.list-stage h2 { margin: 0; font-size: 17px; letter-spacing: -.01em; }
.list-stage .sub { font-size: 12px; color: var(--ink-3); }
.list-stage .count { margin-left: auto; font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.list-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(258px, 1fr)); gap: 10px; }
.list-card {
  display: block; width: 100%; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--ring);
  border-left: 3px solid var(--c); border-radius: 9px;
  padding: 10px 12px; box-shadow: var(--shadow);
}
.list-card:hover { box-shadow: var(--shadow-lift); }
.list-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.list-card h3 { margin: 0 0 4px; font-size: 13px; font-weight: 600; line-height: 1.3;
                display: flex; align-items: flex-start; gap: 6px; }
.list-card h3 .mark { flex: none; margin-top: 1px; }
.list-card p { margin: 0; font-size: 12px; line-height: 1.45; color: var(--ink-3);
               display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
.list-card.is-learned { border-color: color-mix(in srgb, var(--good) 45%, var(--ring)); }
.list-card.n-hide { display: none; }

/* -------------------------------------------------------------------- misc */

.no-results { display: none; text-align: center; color: var(--ink-3); font-size: 13px; padding: 40px 0; }
.no-results.on { display: block; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* --------------------------------------------------------------- responsive */

@media (max-width: 900px) {
  .brand p { display: none; }
  .search input { width: 150px; }
  .search kbd { display: none; }
  .panel {
    position: absolute; inset: auto 0 0 0; width: auto; height: 74%;
    border-left: 0; border-top: 1px solid var(--hairline);
    border-radius: 16px 16px 0 0; box-shadow: var(--shadow-lift); z-index: 20;
  }
  #lanerail { width: 84px; }
  .lanelabel { max-width: 74px; font-size: 10px; padding: 4px 7px 4px 6px; }
  .lanelabel .full { display: none; }
  .lanelabel .short { display: block; }
  .map-hint { display: none; }
}

@media (max-width: 620px) {
  .topbar { flex-wrap: wrap; gap: 8px 12px; }
  .top-actions { width: 100%; margin-left: 0; }
  .search { flex: 1; }
  .search input { width: 100%; }
  .toolbar { gap: 8px; }
  .toolbar-right { width: 100%; margin-left: 0; justify-content: space-between; }
  .chips { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 2px; -webkit-overflow-scrolling: touch; }
  .toolbar-sep { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

@media print {
  .topbar, .toolbar, .map-controls, .map-hint, .panel, #colheads, #lanerail, .stage-area { display: none !important; }
  #listview { position: static; display: block !important; overflow: visible; }
  body { overflow: visible; display: block; }
  .list-card { break-inside: avoid; box-shadow: none; }
}
