/* ============================================================
   Mines Financial — Memphis / Y2K theme
   Fonts: Fredoka One (display) + Space Mono (body/code)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Fredoka+One&family=Space+Mono:ital,wght@0,400;0,700;1,400&display=swap');

/* ── Keyframes ──────────────────────────────────────────────── */
@keyframes mf-bob {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-8px); }
}
@keyframes mf-ticker {
  from { transform: translateX(0); }
  to   { transform: translateX(-50%); }
}
@keyframes mf-pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.06); }
  100% { transform: scale(1); }
}

/* ── Palette ────────────────────────────────────────────────── */
:root {
  --coral:  #FF6B6B;
  --teal:   #4ECDC4;
  --yellow: #FFDD00;
  --lav:    #A29BFE;
  --green:  #2ECC71;
  --pink:   #FF8B94;
  --font-display: 'Fredoka One', cursive;
  --font-mono:    'Space Mono', 'Cascadia Code', monospace;
}

/* ══════════════════════════════════════════════════════════════
   DARK MEMPHIS  (default)
   ══════════════════════════════════════════════════════════════ */
html, html[data-theme="dark"] {
  /* content */
  --bg:           #111111;
  --dot:          rgba(255,255,255,0.05);
  --text:         #f0f0f0;
  --text-muted:   #cccccc;
  --text-dim:     #888888;
  --border:       var(--yellow);
  --border-mild:  rgba(255,255,255,0.12);
  --shadow:       4px 4px 0 var(--yellow);
  --shadow-sm:    3px 3px 0 var(--yellow);
  --tag-bg:       rgba(78,205,196,0.16);
  --tag-fg:       var(--teal);
  --tag-bdr:      var(--teal);
  --flow-bg:      #000000;
  --flow-bdr:     var(--yellow);
  --flow-fg:      var(--teal);
  --hdr-bg:       #000000;
  --hdr-bdr:      var(--yellow);
  --code-bg:      #0d0d0d;
  --sub-bg:       rgba(78,205,196,0.07);
  --strong-col:   var(--teal);
  --em-col:       var(--lav);

  /* sidebar */
  --sb-bg:        #000000;
  --sb-dot:       transparent;           /* no polka on dark sidebar */
  --sb-hdr-bg:    #000000;
  --sb-hdr-bdr:   var(--yellow);
  --sb-sep:       rgba(255,255,255,0.10);
  --sb-logo:      var(--yellow);
  --sb-folder:    var(--yellow);
  --sb-file:      #bbbbbb;
  --sb-hover-bg:  rgba(255,221,0,0.10);
  --sb-hover-fg:  var(--yellow);
  --sb-toggle-bdr: rgba(255,255,255,0.35);
  --sb-toggle-sh:  rgba(255,255,255,0.20);
}

/* ══════════════════════════════════════════════════════════════
   LIGHT MEMPHIS
   ══════════════════════════════════════════════════════════════ */
html[data-theme="light"] {
  /* content */
  --bg:           #FAFAFA;
  --dot:          rgba(0,0,0,0.08);
  --text:         #111111;
  --text-muted:   #333333;
  --text-dim:     #666666;
  --border:       #000000;
  --border-mild:  rgba(0,0,0,0.14);
  --shadow:       4px 4px 0 #000000;
  --shadow-sm:    3px 3px 0 #000000;
  --tag-bg:       var(--teal);
  --tag-fg:       #000000;
  --tag-bdr:      #000000;
  --flow-bg:      #ffffff;
  --flow-bdr:     #000000;
  --flow-fg:      #000000;
  --hdr-bg:       #ffffff;
  --hdr-bdr:      #000000;
  --code-bg:      #e4e8ee;
  --sub-bg:       rgba(78,205,196,0.12);
  --strong-col:   #000000;
  --em-col:       #444444;

  /* sidebar — matches content exactly */
  --sb-bg:        #FAFAFA;
  --sb-dot:       rgba(0,0,0,0.08);     /* same polka dot as content */
  --sb-hdr-bg:    #F0F0F0;              /* slightly darker header so logo area reads */
  --sb-hdr-bdr:   #000000;
  --sb-sep:       rgba(0,0,0,0.13);
  --sb-logo:      #111111;
  --sb-folder:    #111111;
  --sb-file:      #555555;
  --sb-hover-bg:  rgba(255,221,0,0.22);
  --sb-hover-fg:  #000000;
  --sb-toggle-bdr: rgba(0,0,0,0.30);
  --sb-toggle-sh:  rgba(0,0,0,0.18);
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  font-family: var(--font-mono);
  background: var(--bg);
  color: var(--text);
}
body { overflow: hidden; }

/* ── Two-column layout ──────────────────────────────────────── */
.layout { display: flex; height: 100vh; }

/* ══════════════════════════════════════════════════════════════
   SIDEBAR
   ══════════════════════════════════════════════════════════════ */
.sidebar {
  width: 262px;
  min-width: 262px;
  background-color: var(--sb-bg);
  background-image: radial-gradient(circle, var(--sb-dot) 1.5px, transparent 1.5px);
  background-size: 28px 28px;
  border-right: 4px solid var(--yellow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

/* ── Sidebar header ─────────────────────────────────────────── */
.sidebar-header {
  padding: 12px 14px;
  border-bottom: 3px solid var(--sb-hdr-bdr);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--sb-hdr-bg);
  flex-shrink: 0;
}

.sidebar-header a {
  text-decoration: none;
  flex: 1;
  min-width: 0;
}

.logo {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--sb-logo);
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Theme toggle — injected by nav.js ──────────────────────── */
.theme-toggle {
  background: var(--yellow);
  color: #000;
  border: 2px solid var(--sb-toggle-bdr);
  width: 26px;
  height: 26px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 2px 2px 0 var(--sb-toggle-sh);
  transition: transform 0.1s, box-shadow 0.1s;
  line-height: 1;
  font-family: inherit;
  border-radius: 0;
}
.theme-toggle:hover  { transform: translate(-1px,-1px); box-shadow: 3px 3px 0 var(--sb-toggle-sh); }
.theme-toggle:active { transform: translate(1px,1px); box-shadow: none; }

/* ── Nav tree (scrolls; ticker stays pinned) ────────────────── */
.nav-tree { padding: 6px 0; flex: 1; overflow-y: auto; min-height: 0; }

/* ── Divider — styled via CSS class (set in nav.js) ─────────── */
.nav-divider {
  height: 2px;
  background: var(--sb-sep);
  margin: 8px 12px;
  position: relative;
}
/* Memphis star accent on the divider */
.nav-divider::after {
  content: '★';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 10px;
  color: var(--coral);
  background: var(--sb-hdr-bg);
  padding: 0 4px;
  line-height: 1;
}

/* ── Folders ────────────────────────────────────────────────── */
.nav-folder-header {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px 5px 10px;
  font-size: 13px;
  color: var(--sb-folder);
  cursor: pointer;
  user-select: none;
  transition: background 0.12s;
  border-left: 3px solid transparent;  /* placeholder — overridden per color */
}
.nav-folder-header:hover { background: var(--sb-hover-bg); }
.nav-folder.open > .nav-folder-header { opacity: 1; }

.nav-folder-toggle {
  display: inline-block;
  width: 12px;
  font-size: 10px;
  color: var(--sb-folder);      /* overridden per folder color below */
  transition: transform 0.15s;
  flex-shrink: 0;
}
.nav-folder.open .nav-folder-toggle { transform: rotate(90deg); }

.nav-folder-icon { font-size: 13px; }

/* Chapter number badge — displayed instead of folder emoji */
.nav-section-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 15px;
  font-size: 9px;
  font-family: var(--font-mono);
  font-weight: 700;
  letter-spacing: 0.05em;
  border: 1.5px solid currentColor;
  border-radius: 2px;
  flex-shrink: 0;
  padding: 0 2px;
  opacity: 0.85;
}

.nav-folder-name {
  font-family: var(--font-display);   /* Fredoka One — playful & bold */
  font-size: 13px;
  letter-spacing: 0.02em;
}

.nav-children { display: none; }
.nav-folder.open > .nav-children { display: block; }

/* ── Per-folder color coding (data-color set in nav.js) ─────── */

/* Left border accent on folder header */
.nav-folder[data-color="coral"]  > .nav-folder-header { border-left-color: var(--coral); }
.nav-folder[data-color="teal"]   > .nav-folder-header { border-left-color: var(--teal); }
.nav-folder[data-color="lav"]    > .nav-folder-header { border-left-color: var(--lav); }
.nav-folder[data-color="green"]  > .nav-folder-header { border-left-color: var(--green); }
.nav-folder[data-color="yellow"] > .nav-folder-header { border-left-color: var(--yellow); }
.nav-folder[data-color="pink"]   > .nav-folder-header { border-left-color: var(--pink); }

/* Colored toggle arrows */
.nav-folder[data-color="coral"]  .nav-folder-toggle { color: var(--coral); }
.nav-folder[data-color="teal"]   .nav-folder-toggle { color: var(--teal); }
.nav-folder[data-color="lav"]    .nav-folder-toggle { color: var(--lav); }
.nav-folder[data-color="green"]  .nav-folder-toggle { color: var(--green); }
.nav-folder[data-color="yellow"] .nav-folder-toggle { color: var(--yellow); }
.nav-folder[data-color="pink"]   .nav-folder-toggle { color: var(--pink); }

/* Open folder: subtle colored bg tint on header */
.nav-folder[data-color="coral"].open  > .nav-folder-header { background: rgba(255,107,107,0.12); }
.nav-folder[data-color="teal"].open   > .nav-folder-header { background: rgba(78,205,196,0.12); }
.nav-folder[data-color="lav"].open    > .nav-folder-header { background: rgba(162,155,254,0.12); }
.nav-folder[data-color="green"].open  > .nav-folder-header { background: rgba(46,204,113,0.12); }
.nav-folder[data-color="yellow"].open > .nav-folder-header { background: rgba(255,221,0,0.12); }
.nav-folder[data-color="pink"].open   > .nav-folder-header { background: rgba(255,139,148,0.12); }

/* Active file link inside each folder gets that folder's color */
.nav-folder[data-color="coral"]  .nav-file-link.active { background: var(--coral); }
.nav-folder[data-color="teal"]   .nav-file-link.active { background: var(--teal); }
.nav-folder[data-color="lav"]    .nav-file-link.active { background: var(--lav); }
.nav-folder[data-color="green"]  .nav-file-link.active { background: var(--green); }
.nav-folder[data-color="yellow"] .nav-file-link.active { background: var(--yellow); }
.nav-folder[data-color="pink"]   .nav-file-link.active { background: var(--pink); }

/* Children: colored left connector line */
.nav-folder[data-color="coral"]  > .nav-children { border-left: 2px solid rgba(255,107,107,0.35); margin-left: 14px; }
.nav-folder[data-color="teal"]   > .nav-children { border-left: 2px solid rgba(78,205,196,0.35);  margin-left: 14px; }
.nav-folder[data-color="lav"]    > .nav-children { border-left: 2px solid rgba(162,155,254,0.35); margin-left: 14px; }
.nav-folder[data-color="green"]  > .nav-children { border-left: 2px solid rgba(46,204,113,0.35);  margin-left: 14px; }
.nav-folder[data-color="yellow"] > .nav-children { border-left: 2px solid rgba(255,221,0,0.35);   margin-left: 14px; }
.nav-folder[data-color="pink"]   > .nav-children { border-left: 2px solid rgba(255,139,148,0.35); margin-left: 14px; }

/* ── File links ─────────────────────────────────────────────── */
.nav-file-item { display: block; }

.nav-file-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 20px;
  font-size: 12px;
  color: var(--sb-file);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.12s, color 0.12s;
}
.nav-root-file .nav-file-link { padding-left: 12px; }

.nav-file-link:hover  { background: var(--sb-hover-bg); color: var(--sb-hover-fg); }
.nav-file-link.active { color: #000; font-weight: 700; }

/* Root-level active link defaults to coral */
.nav-root-file .nav-file-link.active { background: var(--coral); }

.nav-file-icon { font-size: 10px; flex-shrink: 0; opacity: 0.5; }

/* Sub-section number labels (1.1, 1.2 …) inside folder sections */
.nav-file-num {
  font-size: 9px;
  font-family: var(--font-mono);
  font-weight: 700;
  flex-shrink: 0;
  min-width: 22px;
  text-align: right;
  opacity: 0.55;
  letter-spacing: 0.01em;
}

/* ── Sidebar ticker — injected by nav.js ────────────────────── */
.sidebar-ticker {
  background: var(--coral);
  border-top: 3px solid var(--yellow);
  padding: 8px 0;
  overflow: hidden;
  white-space: nowrap;
  flex-shrink: 0;
}
.sidebar-ticker-inner {
  display: inline-block;
  animation: mf-ticker 22s linear infinite;
  font-family: var(--font-display);
  font-size: 11px;
  color: #000;
  letter-spacing: 0.03em;
}

/* ══════════════════════════════════════════════════════════════
   CONTENT AREA
   ══════════════════════════════════════════════════════════════ */
.content {
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
  background-image: radial-gradient(circle, var(--dot) 1.5px, transparent 1.5px);
  background-size: 28px 28px;
  min-width: 0;
}

/* ══════════════════════════════════════════════════════════════
   OVERVIEW  (index.html)
   ══════════════════════════════════════════════════════════════ */
.overview {
  max-width: 900px;
  margin: 0 auto;
  padding: 48px 52px 88px;
}

/* H1 — big Fredoka One with offset shadow */
.overview h1 {
  font-family: var(--font-display);
  font-size: 3rem;
  color: var(--coral);
  margin-bottom: 14px;
  line-height: 1.05;
  text-shadow: 5px 5px 0 var(--yellow);
}
html[data-theme="light"] .overview h1 { text-shadow: 5px 5px 0 #000; }

/* Subtitle box */
.overview .subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 48px;
  line-height: 1.85;
  padding: 16px 20px;
  border: 3px solid var(--border);
  background: var(--sub-bg);
  box-shadow: var(--shadow);
}
html[data-theme="light"] .overview .subtitle { color: #111; }

/* Sections */
.overview section { margin-bottom: 48px; }

/* H2 — Fredoka One with ★ prefix */
.overview h2 {
  font-family: var(--font-display);
  font-size: 1.4rem;
  color: var(--yellow);
  margin-bottom: 18px;
  padding-bottom: 10px;
  border-bottom: 3px solid var(--border);
}
html[data-theme="light"] .overview h2 { color: #000; }

.overview h2::before {
  content: '★ ';
  color: var(--coral);
  font-size: 0.85em;
}

/* Body text */
.overview p {
  font-size: 13px;
  line-height: 1.9;
  color: var(--text);
  margin-bottom: 10px;
}
html[data-theme="light"] .overview p { color: #111; }

.overview strong { color: var(--strong-col); font-weight: 700; }
.overview em     { color: var(--em-col); font-style: normal; font-weight: 700; }
html[data-theme="light"] .overview em { font-style: italic; font-weight: 400; }

/* Tech stack tags */
.tag {
  display: inline-block;
  background: var(--tag-bg);
  color: var(--tag-fg);
  border: 2px solid var(--tag-bdr);
  padding: 3px 10px;
  font-size: 11px;
  font-family: var(--font-mono);
  font-weight: 700;
  margin: 3px 2px;
  box-shadow: var(--shadow-sm);
  cursor: default;
  transition: transform 0.1s, box-shadow 0.1s;
}
.tag:hover { transform: translate(-2px,-2px); box-shadow: 5px 5px 0 var(--tag-bdr); }

/* Card grid */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(204px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.card {
  border: 3px solid var(--border);
  padding: 16px 16px 18px;
  box-shadow: var(--shadow);
  transition: transform 0.12s, box-shadow 0.12s;
  cursor: default;
}
.card:nth-child(3n+1) { background: var(--coral); }
.card:nth-child(3n+2) { background: var(--teal); }
.card:nth-child(3n)   { background: var(--lav); }

.card:hover { transform: translate(-3px,-3px); box-shadow: 7px 7px 0 var(--border); }

.card-title {
  font-size: 12px;
  font-weight: 700;
  color: #000;
  font-family: var(--font-mono);
  margin-bottom: 8px;
}
.card-desc {
  font-size: 11.5px;
  color: rgba(0,0,0,0.78);
  line-height: 1.65;
}

/* Flow box */
.flow-box {
  background: var(--flow-bg);
  border: 3px solid var(--flow-bdr);
  padding: 20px 24px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--flow-fg);
  white-space: pre;
  overflow-x: auto;
  line-height: 1.85;
  box-shadow: var(--shadow);
}
.flow-box .dim { color: var(--text-dim); }
.flow-box .hi  { color: var(--coral); }

/* ══════════════════════════════════════════════════════════════
   CODE PAGE  (all sub-pages)
   ══════════════════════════════════════════════════════════════ */
.code-page {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

/* Header strip */
.code-header {
  padding: 20px 30px 18px;
  border-bottom: 4px solid var(--hdr-bdr);
  border-left: 6px solid var(--coral);
  background: var(--hdr-bg);
  flex-shrink: 0;
}

/* Breadcrumb */
.breadcrumb {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 8px;
  font-family: var(--font-mono);
}
.breadcrumb a { color: var(--teal); text-decoration: none; }
.breadcrumb a:hover { color: var(--yellow); }

/* File title */
.code-header h1 {
  font-family: var(--font-display);
  font-size: 1.75rem;
  color: #ffffff;
  margin-bottom: 2px;
  line-height: 1.1;
}
html[data-theme="light"] .code-header h1 { color: #000; }

/* Description */
.code-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 10px;
  line-height: 1.65;
  padding-left: 12px;
  border-left: 3px solid var(--teal);
}
html[data-theme="light"] .code-desc { color: #333; }

/* ── View toggle (nodes / retrieval_nodes pages) ────────────────────────────── */
.mf-view-toggle {
  position: fixed;
  top: 18px;
  right: 20px;
  z-index: 200;
  display: flex;
}
.mf-vbtn {
  padding: 7px 16px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  border: 2.5px solid #000;
  border-right: none;
  box-shadow: 3px 3px 0 #000;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  border-radius: 0;
  color: #000;
  line-height: 1;
  background: var(--hdr-bg);
}
.mf-vbtn:last-child   { border-right: 2.5px solid #000; }
.mf-vbtn-active       { background: var(--yellow); }
.mf-vbtn:not(.mf-vbtn-active):hover  { transform: translate(-1px,-1px); box-shadow: 4px 4px 0 #000; }
.mf-vbtn:not(.mf-vbtn-active):active { transform: translate(1px,1px); box-shadow: none; }

/* ── Section-map delete badge (edit mode only) ──────────────────────────────── */
.mf-del-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 18px;
  height: 18px;
  background: #111;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  border: 2px solid #fff;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  z-index: 10;
  transition: background 0.1s;
}
.mf-del-btn:hover { background: var(--coral); }

/* Code body */
.code-body { flex: 1; }
.code-body pre { margin: 0; }

.code-body pre code.hljs {
  padding: 24px 28px;
  font-size: 13px;
  font-family: var(--font-mono);
  line-height: 1.65;
  background: var(--code-bg);
  min-height: 100%;
  display: block;
}

/* Segmented code pages: sticky function nav + full-width section cards */
.code-section-map {
  --map-ink: #050505;
  --map-paper: rgba(255, 248, 220, 0.94);
  --map-panel: rgba(18, 18, 18, 0.92);
  --map-panel-light: #fffdf4;
  position: sticky;
  top: 0;
  z-index: 12;
  display: flex;
  gap: 8px;
  align-items: center;
  overflow-x: auto;
  padding: 10px 18px 12px;
  border-bottom: 4px solid var(--border);
  background:
    linear-gradient(135deg, rgba(255, 221, 0, 0.16) 25%, transparent 25%) 0 0 / 18px 18px,
    var(--hdr-bg);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.2);
}

.code-section-map a {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 7px 12px;
  border: 2.5px solid var(--map-ink);
  border-radius: 8px;
  background: var(--map-paper);
  color: var(--map-ink);
  box-shadow: 3px 3px 0 var(--map-ink);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.code-section-map a:nth-child(4n+1) { background: var(--teal); }
.code-section-map a:nth-child(4n+2) { background: var(--yellow); }
.code-section-map a:nth-child(4n+3) { background: var(--coral); }
.code-section-map a:nth-child(4n) { background: var(--lav); }

.code-section-map a:hover,
.code-section-map a:focus-visible {
  transform: translate(-2px, -2px);
  box-shadow: 5px 5px 0 var(--map-ink);
  outline: none;
}

.code-section-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  padding: 22px;
}

.code-section-card {
  scroll-margin-top: 76px;
  width: 100%;
  overflow: hidden;
  border: 3px solid var(--border);
  border-radius: 8px;
  background: var(--map-panel);
  box-shadow: var(--shadow);
}

html[data-theme="light"] .code-section-card {
  background: var(--map-panel-light);
}

.code-section-card:nth-child(4n+1) { border-left: 8px solid var(--teal); }
.code-section-card:nth-child(4n+2) { border-left: 8px solid var(--yellow); }
.code-section-card:nth-child(4n+3) { border-left: 8px solid var(--coral); }
.code-section-card:nth-child(4n) { border-left: 8px solid var(--lav); }

.code-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 3px solid var(--border);
  background: var(--hdr-bg);
}

.code-section-title h2 {
  font-family: var(--font-display);
  font-size: 1rem;
  line-height: 1.2;
  color: var(--yellow);
}

html[data-theme="light"] .code-section-title h2 {
  color: #000;
}

.code-section-title span {
  flex: 0 0 auto;
  padding: 3px 7px;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: var(--teal);
  color: #000;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

.code-section-card pre {
  overflow-x: auto;
  overflow-y: visible;
  background: var(--code-bg);
}

.code-section-card pre code.hljs {
  min-height: 0;
  padding: 18px 20px;
  font-size: 12.5px;
}

@media (max-width: 720px) {
  .code-section-map { padding: 8px 12px 10px; }
  .code-section-map a { min-height: 32px; padding: 6px 10px; font-size: 10px; }
  .code-section-grid { padding: 14px; gap: 14px; }
  .code-section-title { align-items: flex-start; flex-direction: column; gap: 7px; }
  .code-section-card { scroll-margin-top: 84px; }
  .code-section-card pre code.hljs { padding: 14px 16px; font-size: 12px; }
}

/* Light-mode hljs theme — overrides github-dark CDN stylesheet */
html[data-theme="light"] .hljs                                { background: #f6f8fa; color: #24292e; }
html[data-theme="light"] .hljs-comment,
html[data-theme="light"] .hljs-code,
html[data-theme="light"] .hljs-formula                        { color: #6a737d; font-style: italic; }
html[data-theme="light"] .hljs-keyword,
html[data-theme="light"] .hljs-template-tag,
html[data-theme="light"] .hljs-type,
html[data-theme="light"] .hljs-variable.language_             { color: #d73a49; }
html[data-theme="light"] .hljs-string,
html[data-theme="light"] .hljs-regexp,
html[data-theme="light"] .hljs-meta .hljs-string              { color: #032f62; }
html[data-theme="light"] .hljs-number,
html[data-theme="light"] .hljs-literal,
html[data-theme="light"] .hljs-attr,
html[data-theme="light"] .hljs-attribute,
html[data-theme="light"] .hljs-operator                       { color: #005cc5; }
html[data-theme="light"] .hljs-title,
html[data-theme="light"] .hljs-title.class_,
html[data-theme="light"] .hljs-title.function_,
html[data-theme="light"] .hljs-built_in,
html[data-theme="light"] .hljs-symbol                         { color: #6f42c1; }
html[data-theme="light"] .hljs-meta                           { color: #005cc5; }
html[data-theme="light"] .hljs-subst                          { color: #24292e; }
html[data-theme="light"] .hljs-doctag                         { color: #d73a49; }

/* ══════════════════════════════════════════════════════════════
   EDITOR  (File System Access API — nav.js)
   ══════════════════════════════════════════════════════════════ */

/* Floating toolbar — bottom-right of content area */
#mf-editor-toolbar {
  position: fixed;
  bottom: 28px;
  right: 28px;
  display: flex;
  gap: 8px;
  z-index: 1000;
}

/* Shared button base */
.mf-btn {
  padding: 7px 16px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  border: 2.5px solid #000;
  box-shadow: 3px 3px 0 #000;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  border-radius: 0;
  color: #000;
  line-height: 1;
}
.mf-btn:hover  { transform: translate(-2px,-2px); box-shadow: 5px 5px 0 #000; }
.mf-btn:active { transform: translate(1px,1px); box-shadow: none; }

.mf-btn-primary { background: var(--yellow); }
.mf-btn-save    { background: var(--teal); }
.mf-btn-cancel  { background: var(--coral); }

/* Editable element — dashed outline while in edit mode */
.mf-editable {
  outline: 2px dashed var(--yellow) !important;
  outline-offset: 3px;
  cursor: text;
  border-radius: 1px;
}
.mf-editable:focus {
  outline: 2px solid var(--coral) !important;
  background: rgba(255,107,107,0.06) !important;
}
html[data-theme="light"] .mf-editable         { outline-color: #555 !important; }
html[data-theme="light"] .mf-editable:focus   { outline-color: #000 !important; background: rgba(0,0,0,0.04) !important; }

/* Toast notification */
.mf-toast {
  position: fixed;
  bottom: 80px;
  right: 28px;
  background: var(--teal);
  color: #000;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  padding: 8px 18px;
  border: 2.5px solid #000;
  box-shadow: 3px 3px 0 #000;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.18s, transform 0.18s;
  pointer-events: none;
  z-index: 1001;
}
.mf-toast-show { opacity: 1; transform: translateY(0); }
.mf-toast-err  { background: var(--coral); }

/* Code editor overlay: highlighted <pre> behind + transparent <textarea> on top */

/* Wrapper sizes itself to the textarea; highlight layer fills it absolutely */
.mf-code-wrapper {
  position: relative;
  height: calc(100vh - 180px);
  background: var(--code-bg);
  outline: 2px dashed var(--yellow);
  overflow: hidden;
}
.mf-code-wrapper:focus-within { outline-color: var(--coral); }
html[data-theme="light"] .mf-code-wrapper            { outline-color: #555; }
html[data-theme="light"] .mf-code-wrapper:focus-within { outline-color: #000; }

/* Syntax-highlighted mirror — sits behind the textarea, never receives events */
.mf-code-highlight {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 24px 28px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
  white-space: pre;
  overflow: scroll;
  scrollbar-width: none;
  box-sizing: border-box;
  pointer-events: none;
  tab-size: 4;
}
.mf-code-highlight::-webkit-scrollbar { display: none; }
/* Strip hljs default padding so text aligns exactly with the textarea */
/* All alignment-critical props use !important: .code-section-card pre code.hljs (0,2,2)
   would otherwise beat this rule (0,2,1) and shift font-size to 12.5px, causing
   a cumulative ~1-line selection offset after ~25 lines */
.mf-code-highlight > code.hljs {
  padding: 0 !important;
  background: transparent;
  font-size: 13px !important;
  line-height: 1.65 !important;
  font-family: var(--font-mono) !important;
}

/* Transparent editing layer — user types here; caret visible, text invisible */
.mf-code-editor {
  position: absolute;
  inset: 0;
  padding: 24px 28px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
  background: transparent;
  color: transparent;
  caret-color: var(--yellow);
  border: none;
  outline: none;
  resize: none;
  box-sizing: border-box;
  tab-size: 4;
  white-space: pre;
  overflow-wrap: normal;
  overflow: scroll;
  z-index: 1;
}
.mf-code-editor::selection { background: rgba(255,221,0,0.28); }
html[data-theme="light"] .mf-code-editor { caret-color: #111; }
html[data-theme="light"] .mf-code-editor::selection { background: rgba(37,99,235,0.30); }
