/* ============================================================
   INFODLE — design system
   Dark-first, one accent, hand-drawn borders via SVG displacement
   applied ONLY to border pseudo-elements (text is never distorted).
   Mobile-first: base styles are for phones; wider screens add.
   ============================================================ */

:root {
  color-scheme: dark;
  --bg: #0b0f0d;
  --bg-2: #101613;
  --surface: #141b17;
  --surface-2: #1a2320;
  --ink: #e8efe9;
  --ink-2: #aab8ae;
  --ink-3: #7f8f84;
  --line: #2a3630;
  --accent: #3ddc97;
  --accent-ink: #04140c;
  --accent-soft: rgba(61, 220, 151, .12);
  --warn: #ffb84d;
  --danger: #ff6b6b;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);

  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-hand: "Caveat", "Segoe Print", "Bradley Hand", cursive;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --gutter: 16px;
  --maxw: 1080px;
  --header-h: 56px;
  --tabbar-h: 60px;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f4ee;
  --bg-2: #efece3;
  --surface: #ffffff;
  --surface-2: #f1eee5;
  --ink: #17201b;
  --ink-2: #44514a;
  --ink-3: #5d6b63;
  --line: #cfcabb;
  --accent: #087a4e;
  --accent-ink: #ffffff;
  --accent-soft: rgba(8, 122, 78, .1);
  --warn: #8a5a00;
  --danger: #b42318;
  --shadow: 0 10px 30px rgba(40, 35, 20, .12);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 12px); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } *, *::before, *::after { animation: none !important; transition: none !important; } }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.6;
  overflow-x: hidden;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b));
  background-image: radial-gradient(var(--line) 1px, transparent 1px);
  background-size: 26px 26px;
  background-position: -13px -13px;
}
body::before { /* fade the dot-grid out so content stays calm */
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background: radial-gradient(ellipse at 50% 0%, transparent 0, var(--bg) 85%);
}
#app, .site-header, .site-footer { position: relative; z-index: 1; }

img, svg { max-width: 100%; }
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: clamp(2rem, 7.5vw, 3.6rem); font-weight: 800; }
h2 { font-size: clamp(1.5rem, 5vw, 2.1rem); font-weight: 750; }
h3 { font-size: 1.15rem; font-weight: 700; }
p { margin: 0 0 1em; }
code, kbd { font-family: var(--font-mono); font-size: .9em; }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; padding: 1px 6px; background: var(--surface); }
::selection { background: var(--accent); color: var(--accent-ink); }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--accent); color: var(--accent-ink); padding: 8px 14px; border-radius: 8px; z-index: 100; font-weight: 700; }
.skip:focus { left: 8px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.wrap { width: 100%; max-width: var(--maxw); margin-inline: auto; padding-inline: var(--gutter); }
.hand { font-family: var(--font-hand); font-weight: 600; letter-spacing: .01em; }
.muted { color: var(--ink-2); }
.eyebrow { font-family: var(--font-mono); font-size: .78rem; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }

/* ---------- hand-drawn border system ----------
   .sk draws a wobbly outline on ::before only. The element's own
   text/children are untouched, so nothing blurs or shifts. */
.sk { position: relative; isolation: isolate; border-radius: 18px 14px 20px 12px / 14px 20px 12px 18px; }
.sk::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  border: 2px solid var(--sk-line, var(--line));
  border-radius: inherit;
  filter: url(#wobble);
  transition: border-color .2s;
}
.sk.fill { background: var(--surface); }
.sk-accent { --sk-line: var(--accent); }
a.sk:hover, button.sk:hover, .sk.hoverable:hover { --sk-line: var(--accent); }

/* squiggle underline (SVG data-URI, uses currentColor via mask) */
.squig { position: relative; white-space: nowrap; }
.squig::after {
  content: ""; position: absolute; left: -2%; right: -2%; bottom: -.12em; height: .3em;
  background: var(--accent);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 12' preserveAspectRatio='none'%3E%3Cpath d='M1 7 Q 9 1 17 7 T 33 7 T 49 7 T 65 7 T 81 7 T 99 7' fill='none' stroke='black' stroke-width='3' stroke-linecap='round'/%3E%3C/svg%3E") center/100% 100% no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 12' preserveAspectRatio='none'%3E%3Cpath d='M1 7 Q 9 1 17 7 T 33 7 T 49 7 T 65 7 T 81 7 T 99 7' fill='none' stroke='black' stroke-width='3' stroke-linecap='round'/%3E%3C/svg%3E") center/100% 100% no-repeat;
}

/* ---------- buttons ---------- */
.btn {
  --sk-line: var(--accent);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 10px 20px; border: 0; cursor: pointer;
  font: 700 1rem/1 var(--font-ui); color: var(--accent-ink); background: var(--accent);
  border-radius: 16px 12px 18px 12px / 12px 18px 12px 16px; text-decoration: none;
  transition: transform .12s ease, filter .12s;
}
.btn:hover { filter: brightness(1.08); transform: translateY(-1px) rotate(-.4deg); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--ink); --sk-line: var(--line); }
.btn.ghost:hover { --sk-line: var(--accent); color: var(--accent); }
.btn.small { min-height: 38px; padding: 6px 14px; font-size: .9rem; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; }

.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border: 0; background: transparent;
  color: var(--ink-2); cursor: pointer; border-radius: 12px;
}
.icon-btn:hover { color: var(--accent); background: var(--accent-soft); }
.icon-btn svg { width: 22px; height: 22px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 4px 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
  color: var(--ink-2); font: 600 .85rem var(--font-ui); cursor: pointer; text-decoration: none;
}
.chip:hover, .chip[aria-pressed="true"], .chip.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 40; padding-top: var(--safe-t);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.site-header .wrap { height: var(--header-h); display: flex; align-items: center; gap: 8px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 800; font-size: 1.2rem; letter-spacing: -.02em; margin-right: auto; }
.brand svg { width: 30px; height: 30px; color: var(--accent); }
.brand span b { color: var(--accent); }
.nav-links { display: none; gap: 4px; }
.nav-links a { color: var(--ink-2); text-decoration: none; font-weight: 600; padding: 8px 12px; border-radius: 10px; }
.nav-links a:hover, .nav-links a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
.hdr-install { display: none; }
body.can-install .hdr-install { display: inline-flex; }

/* ---------- bottom tab bar (mobile) ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--bg-2) 94%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar a, .tabbar button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--ink-3); font: 600 .68rem/1.1 var(--font-ui); text-decoration: none; background: none; border: 0; cursor: pointer; min-width: 0;
}
.tabbar svg { width: 22px; height: 22px; }
.tabbar a[aria-current="page"], .tabbar button.on { color: var(--accent); }
.tabbar a[aria-current="page"] svg { filter: drop-shadow(0 0 6px var(--accent-soft)); }

/* ---------- hero ---------- */
.hero { padding: 36px 0 20px; }
.hero .eyebrow { margin-bottom: 14px; display: block; }
.hero h1 { margin-bottom: 14px; }
.hero .lede { font-size: 1.1rem; color: var(--ink-2); max-width: 56ch; }
.hero-cta { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 22px; }
.hero-note { font-size: 1.3rem; color: var(--accent); display: inline-block; transform: rotate(-3deg); margin-top: 16px; }
.hero-grid { display: grid; gap: 28px; }

.term-preview { background: #070a08; color: #d6e8dc; padding: 16px; font: 500 .82rem/1.65 var(--font-mono); overflow: hidden; --sk-line: var(--accent); min-height: 210px; }
:root[data-theme="light"] .term-preview { background: #121a15; }
.term-preview .dots { display: flex; gap: 6px; margin-bottom: 10px; }
.term-preview .dots i { width: 10px; height: 10px; border-radius: 50%; background: #3a4a41; }
.term-preview .p { color: var(--accent); }
.term-preview .c { color: #8aa194; }
.term-preview .cur { display: inline-block; width: 8px; height: 1em; background: var(--accent); vertical-align: -2px; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.term-preview .out { white-space: pre-wrap; word-break: break-word; }

/* ---------- sections ---------- */
.section { padding-block: 34px; }
.section-head { margin-bottom: 20px; }
.section-head p { color: var(--ink-2); max-width: 60ch; margin: 0; }
.rule { border: 0; height: 12px; margin: 8px 0; background: var(--line); -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 12' preserveAspectRatio='none'%3E%3Cpath d='M0 6 Q 10 0 20 6 T 40 6 T 60 6 T 80 6 T 100 6 T 120 6 T 140 6 T 160 6 T 180 6 T 200 6' fill='none' stroke='black' stroke-width='2'/%3E%3C/svg%3E") center/100% 100% no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 12' preserveAspectRatio='none'%3E%3Cpath d='M0 6 Q 10 0 20 6 T 40 6 T 60 6 T 80 6 T 100 6 T 120 6 T 140 6 T 160 6 T 180 6 T 200 6' fill='none' stroke='black' stroke-width='2'/%3E%3C/svg%3E") center/100% 100% no-repeat; }

/* continue card */
.continue { display: flex; align-items: center; gap: 14px; padding: 14px 18px; text-decoration: none; color: var(--ink); --sk-line: var(--accent); margin-bottom: 8px; }
.continue .hand { color: var(--accent); font-size: 1.2rem; line-height: 1; }
.continue strong { display: block; }
.continue svg { margin-left: auto; width: 20px; height: 20px; color: var(--accent); flex: none; }

/* ---------- domain cards ---------- */
.cards { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.card { display: flex; flex-direction: column; gap: 8px; padding: 20px; text-decoration: none; color: var(--ink); min-width: 0; }
.card:hover { text-decoration: none; transform: translateY(-2px) rotate(-.3deg); }
.card { transition: transform .15s; }
.card .num { font: 600 .8rem var(--font-mono); color: var(--accent); }
.card .ico { width: 44px; height: 44px; color: var(--accent); }
.card h3 { margin: 0; font-size: 1.2rem; }
.card .q { font-size: 1.25rem; color: var(--accent); line-height: 1.1; }
.card p { color: var(--ink-2); margin: 0; font-size: .95rem; }
.progress { display: flex; align-items: center; gap: 10px; margin-top: auto; padding-top: 8px; font: 600 .78rem var(--font-mono); color: var(--ink-3); }
.progress .bar { flex: 1; height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; }
.progress .bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .5s; }
.progress.done { color: var(--accent); }

/* ---------- knowledge map (desktop) / journey (mobile) ---------- */
.journey { list-style: none; margin: 0; padding: 0 0 0 22px; border-left: 2px dashed var(--line); display: grid; gap: 14px; }
.journey li { position: relative; }
.journey li::before { content: ""; position: absolute; left: -31px; top: 18px; width: 14px; height: 14px; border-radius: 50%; background: var(--bg); border: 2px solid var(--accent); }
.journey a { display: block; padding: 14px 16px; text-decoration: none; color: var(--ink); }
.journey .hand { color: var(--accent); font-size: 1.15rem; display: block; line-height: 1.1; }
.journey small { color: var(--ink-3); }
.mapwrap { display: none; }

.i { width: 1.25em; height: 1.25em; flex: none; vertical-align: -.2em; }
h3 .i { color: var(--accent); }
h3 { display: flex; align-items: center; gap: 8px; }

/* ---------- toolbar / search ---------- */
.toolbar { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; margin-bottom: 18px; }
.search { display: flex; min-width: 0; align-items: center; gap: 10px; padding: 0 14px; min-height: 48px; background: var(--surface); --sk-line: var(--line); }
.search:focus-within { --sk-line: var(--accent); }
.search svg { width: 20px; height: 20px; color: var(--ink-3); flex: none; }
.search input { flex: 1; min-width: 0; height: 46px; background: none; border: 0; color: var(--ink); font: 500 1rem var(--font-ui); outline: none; }
.search input::placeholder { color: var(--ink-3); }
.search kbd { display: none; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chips .chip { flex: none; }
.count { font: 600 .82rem var(--font-mono); color: var(--ink-3); }

/* ---------- topic list ---------- */
.topic-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; list-style: none; margin: 0; padding: 0; }
.topic-row { display: block; padding: 16px 18px; text-decoration: none; color: var(--ink); }
.topic-row h3 { margin: 0 0 4px; font-size: 1.1rem; }
.topic-row p { margin: 0 0 8px; color: var(--ink-2); font-size: .95rem; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font: 500 .78rem var(--font-mono); color: var(--ink-3); }
.meta .read-badge { color: var(--accent); }
.stub-badge { color: var(--warn); }

/* ---------- reader ---------- */
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; font-size: .85rem; color: var(--ink-3); padding: 18px 0 6px; }
.crumbs a { color: var(--ink-2); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }
.reader { display: grid; gap: 22px; padding-bottom: 20px; }
.reader header h1 { font-size: clamp(1.8rem, 6.5vw, 2.8rem); margin-bottom: 8px; }
.reader .sub { font-size: 1.25rem; color: var(--accent); line-height: 1.2; margin-bottom: 10px; }
.prose { max-width: 68ch; font-size: 1.05rem; line-height: 1.75; overflow-wrap: anywhere; }
.prose h4 { font-size: 1.2rem; margin: 1.6em 0 .4em; padding-left: 12px; border-left: 3px solid var(--accent); }
.prose sup a { text-decoration: none; font-weight: 700; padding: 0 2px; }
.stub-note { padding: 14px 16px; background: var(--accent-soft); color: var(--ink); --sk-line: var(--warn); font-size: .95rem; margin-bottom: 18px; }
.sources, .related { padding: 18px; margin-top: 8px; }
.sources ol { margin: 0; padding-left: 1.2em; }
.sources li { margin: 6px 0; overflow-wrap: anywhere; }
.related ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.related a { display: flex; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: 10px; text-decoration: none; color: var(--ink); background: var(--surface-2); }
.related a:hover { color: var(--accent); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.pager { display: grid; gap: 12px; margin-top: 18px; }
.pager a { padding: 14px 16px; text-decoration: none; color: var(--ink); display: block; }
.pager small { color: var(--ink-3); display: block; }
.pager .next { text-align: right; }

/* notes (private, on-device) */
.notes { padding: 18px; margin-top: 8px; }
.notes h3 { display: flex; align-items: center; gap: 8px; }
.notes .hint { color: var(--ink-3); font-size: .85rem; margin-bottom: 12px; }
.notes textarea, .field textarea, .field input, .field select {
  width: 100%; background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; font: 500 1rem var(--font-ui);
}
.notes textarea:focus, .field textarea:focus, .field input:focus, .field select:focus { outline: 3px solid var(--accent-soft); border-color: var(--accent); }
.note-item { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-top: 1px dashed var(--line); }
.note-item p { margin: 0; flex: 1; white-space: pre-wrap; overflow-wrap: anywhere; }
.note-item time { font: 500 .72rem var(--font-mono); color: var(--ink-3); display: block; }


/* ---------- article content (Markdown output) ---------- */
.prose h2, .prose h3, .prose h4 { margin: 1.6em 0 .4em; padding-left: 12px; border-left: 3px solid var(--accent); line-height: 1.25; }
.prose h2 { font-size: 1.35rem; } .prose h3 { font-size: 1.15rem; } .prose h4 { font-size: 1.05rem; }
.prose ul, .prose ol { padding-left: 1.3em; margin: 0 0 1em; } .prose li { margin: .25em 0; }
.prose blockquote { margin: 1.2em 0; padding: .6em 1em; border-left: 3px solid var(--line); color: var(--ink-2); background: var(--surface); border-radius: 0 10px 10px 0; }
.prose blockquote p:last-child { margin: 0; }
.prose code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; }
.prose pre { background: #070a08; color: #d6e8dc; padding: 14px 16px; border-radius: 12px; overflow-x: auto; font-size: .88rem; line-height: 1.6; margin: 1.2em 0; border: 1px solid var(--line); }
.prose pre code { background: none; padding: 0; color: inherit; }
.prose img { max-width: 100%; height: auto; border-radius: 12px; display: block; margin: 1.2em 0; border: 1px solid var(--line); }
.prose hr { border: 0; height: 1px; background: var(--line); margin: 2em 0; }
.table-wrap { overflow-x: auto; margin: 1.2em 0; -webkit-overflow-scrolling: touch; }
.prose table { border-collapse: collapse; min-width: 100%; font-size: .95rem; }
.prose th, .prose td { border: 1px solid var(--line); padding: 8px 12px; text-align: left; vertical-align: top; }
.prose th { background: var(--surface-2); }
.reader .cover { width: 100%; height: auto; max-height: 360px; object-fit: cover; border-radius: 14px; border: 1px solid var(--line); }

/* ---------- glossary ---------- */
.gloss { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; list-style: none; margin: 0; padding: 0; }
.gloss li { padding: 14px 16px; }
.gloss dt, .gloss .term { font-weight: 800; font-size: 1.05rem; }
.gloss p { margin: 4px 0 6px; color: var(--ink-2); }
.az { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.az a { min-width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px; border: 1px solid var(--line); text-decoration: none; color: var(--ink-2); font: 700 .85rem var(--font-mono); }
.az a:hover { border-color: var(--accent); color: var(--accent); }
.az span { min-width: 34px; height: 34px; display: grid; place-items: center; color: var(--line); font: 700 .85rem var(--font-mono); }

/* ---------- about / me ---------- */
.profile { display: grid; gap: 20px; }
.avatar { width: 96px; height: 96px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font: 800 2rem var(--font-ui); --sk-line: var(--accent); }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.stat { padding: 16px; }
.stat b { font-size: 1.8rem; display: block; line-height: 1.1; color: var(--accent); }
.stat span { color: var(--ink-2); font-size: .88rem; }
.list-plain { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.settings-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 16px; flex-wrap: wrap; }

/* ---------- modal & toast ---------- */
.overlay { position: fixed; inset: 0; z-index: 80; background: rgba(0, 0, 0, .6); display: none; align-items: flex-end; justify-content: center; padding: 0; }
.overlay.open { display: flex; }
.modal {
  width: 100%; max-width: 520px; max-height: 92dvh; overflow: auto; background: var(--surface);
  padding: 22px var(--gutter) calc(22px + var(--safe-b)); border-radius: 22px 22px 0 0; border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.modal h2 { font-size: 1.5rem; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 700; font-size: .9rem; }
.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px); transform: translate(-50%, 20px);
  z-index: 90; max-width: min(92vw, 420px); padding: 12px 18px; background: var(--ink); color: var(--bg);
  border-radius: 14px; font-weight: 600; font-size: .92rem; opacity: 0; pointer-events: none; transition: .25s;
  box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- terminal overlay ---------- */
.terminal {
  position: fixed; inset: 0; z-index: 95; display: none; flex-direction: column;
  background: #060908; color: #d6e8dc; font: 500 14px/1.6 var(--font-mono);
  padding-top: var(--safe-t);
}
.terminal.open { display: flex; }
.t-bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid #1d2a23; color: #7f9487; font-size: 12px; }
.t-bar b { color: var(--accent); }
.t-bar button { margin-left: auto; background: none; border: 1px solid #2a3a31; color: #aac0b2; border-radius: 8px; padding: 6px 12px; font: 600 12px var(--font-mono); cursor: pointer; min-height: 36px; }
.t-bar button:hover { border-color: var(--accent); color: var(--accent); }
.t-out { flex: 1; overflow: auto; padding: 14px 14px 6px; white-space: pre-wrap; word-break: break-word; -webkit-overflow-scrolling: touch; }
.t-out .cmd { color: #fff; }
.t-out .ok { color: var(--accent); }
.t-out .err { color: var(--danger); }
.t-out .dim { color: #7f9487; }
.t-out a, .t-out .lnk { color: var(--accent); cursor: pointer; text-decoration: underline; }
.t-in { display: flex; align-items: center; gap: 8px; padding: 10px 14px calc(10px + var(--safe-b)); border-top: 1px solid #1d2a23; background: #060908; }
.t-in .p { color: var(--accent); flex: none; }
.t-in input { flex: 1; min-width: 0; background: none; border: 0; outline: none; color: #fff; font: inherit; font-size: 16px; /* 16px stops iOS zoom */ caret-color: var(--accent); }
.t-quick { display: flex; gap: 8px; overflow-x: auto; padding: 8px 14px 0; scrollbar-width: none; }
.t-quick::-webkit-scrollbar { display: none; }
.t-quick button { flex: none; background: #0f1713; color: #aac0b2; border: 1px solid #22322a; border-radius: 999px; padding: 6px 12px; font: 600 12px var(--font-mono); cursor: pointer; min-height: 34px; }
.t-quick button:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- sketch overlay ---------- */
.sketch-canvas { position: absolute; left: 0; top: 0; z-index: 70; display: none; pointer-events: none; touch-action: none; }
.sketch-canvas.has { display: block; }
body.sketching .sketch-canvas { display: block; pointer-events: auto; cursor: crosshair; }
body.sketching.sk-scroll .sketch-canvas { pointer-events: none; cursor: auto; }
.sketch-layer { position: absolute; left: 0; top: 0; z-index: 60; pointer-events: none; }
.sketch-bar {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 72; display: none; gap: 6px; align-items: center;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 10px); max-width: calc(100vw - 2 * var(--gutter));
  padding: 8px; background: var(--surface); border: 1px solid var(--accent); border-radius: 16px; box-shadow: var(--shadow);
  flex-wrap: wrap; justify-content: center; width: max-content;
}
body.sketching .sketch-bar { display: flex; }
body.sketching .toast { bottom: auto; top: calc(var(--header-h) + var(--safe-t) + 12px); }
.sketch-bar button { flex: none; min-width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); cursor: pointer; font: 700 .8rem var(--font-ui); }
.sketch-bar button.on { border-color: var(--accent); color: var(--accent); }
.sketch-bar .sw { width: 36px; height: 36px; min-width: 36px; border-radius: 50%; padding: 0; }
.sketch-bar .sw.on { outline: 3px solid var(--ink); outline-offset: 2px; }

/* ---------- footer ---------- */
.site-footer { margin-top: 40px; padding: 30px 0 24px; border-top: 1px solid var(--line); color: var(--ink-2); font-size: .9rem; }
.footer-grid { display: grid; gap: 22px; }
.site-footer h4 { font: 700 .78rem var(--font-mono); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 10px; }
.site-footer ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.site-footer a { color: var(--ink-2); text-decoration: none; }
.site-footer a:hover { color: var(--accent); }
.fine { margin-top: 22px; font-size: .8rem; color: var(--ink-3); }

/* ---------- install banner (iOS hint etc.) ---------- */
.install-hint { padding: 16px; margin-top: 14px; font-size: .92rem; }

/* ---------- print ---------- */
@media print {
  body { background: #fff; color: #000; padding: 0; }
  body::before, .site-header, .tabbar, .site-footer, .actions, .notes, .toast, .pager, .sketch-bar, .sketch-canvas { display: none !important; }
  .sk::before { display: none; }
  a { color: #000; }
}

/* ============================================================
   TABLET+ (>= 700px)
   ============================================================ */
@media (min-width: 700px) {
  :root { --gutter: 28px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .gloss { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pager { grid-template-columns: 1fr 1fr; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .footer-grid { grid-template-columns: 2fr 1fr 1fr; }
  .overlay { align-items: center; padding: 20px; }
  .modal { border-radius: 22px; padding-bottom: 22px; }
  .search kbd { display: inline-block; }
  .profile { grid-template-columns: auto 1fr; align-items: center; }
}


/* ============================================================
   LEARNING PATHS, QUIZ, FLASHCARDS
   ============================================================ */
.card .tags { display: flex; flex-wrap: wrap; gap: 6px; }
.card .tags span { font: 600 .72rem var(--font-mono); color: var(--ink-3); border: 1px solid var(--line); border-radius: 99px; padding: 2px 10px; }
.read-badge { color: var(--accent); font-weight: 700; }
.path-progress { margin: 6px 0 24px; }
.stages { list-style: none; margin: 0; padding: 0; display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); counter-reset: none; }
.stage { padding: 18px 16px; min-width: 0; --sk-line: var(--line); }
.stage-head { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 8px; }
.stage-head h2 { margin: 0; font-size: 1.25rem; line-height: 1.2; }
.stage-head p { margin: 4px 0 0; color: var(--ink-2); font-size: .95rem; }
.stage-num { flex: none; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; border: 2px solid var(--accent); color: var(--accent); font: 700 1.05rem var(--font-hand), var(--font-ui); }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.step { display: flex; gap: 12px; align-items: flex-start; padding: 10px 2px; border-top: 1px dashed var(--line); min-width: 0; }
.step:first-child { border-top: 0; }
.step-body { min-width: 0; display: flex; flex-direction: column; gap: 2px; overflow-wrap: anywhere; }
.step-body > a { font-weight: 650; }
.step-body small { color: var(--ink-3); font-size: .82rem; line-height: 1.4; }
.step.done .step-body > a { color: var(--ink-2); text-decoration: line-through; text-decoration-color: var(--line); }
.soon-t { font-weight: 600; color: var(--ink-3); }
.step.soon { opacity: .85; }
.ext { color: var(--ink-3); }
.check { flex: none; width: 26px; height: 26px; margin-top: 1px; border-radius: 8px; border: 2px solid var(--line); background: transparent; color: transparent; display: grid; place-items: center; padding: 0; }
.check svg { width: 16px; height: 16px; }
button.check { cursor: pointer; position: relative; }
button.check::after { content: ""; position: absolute; inset: -9px; }       /* 44px touch target */
button.check:hover { border-color: var(--accent); }
.check.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.check.soon { border-style: dotted; }
.study-box { padding: 16px 18px; margin: 26px 0; --sk-line: var(--accent); }
.study-box h3 { margin: 0; }

.quiz { padding: 18px 16px; max-width: 720px; min-width: 0; --sk-line: var(--accent); }
.qtext { margin: 14px 0 14px; font-size: 1.2rem; line-height: 1.35; }
.opts { display: grid; gap: 10px; }
.opt { display: flex; gap: 12px; align-items: flex-start; text-align: left; width: 100%; padding: 12px 14px; min-height: 48px; border: 2px solid var(--line); border-radius: 12px; background: var(--surface-2); color: var(--ink); font: 500 1rem/1.4 var(--font-ui); cursor: pointer; }
.opt:hover:not([disabled]) { border-color: var(--accent); }
.opt[disabled] { cursor: default; }
.opt .k { flex: none; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 6px; border: 1px solid var(--line); font: 600 .8rem var(--font-mono); color: var(--ink-3); }
.opt .ot { min-width: 0; overflow-wrap: anywhere; display: flex; flex-direction: column; gap: 4px; }
.opt .tag { font: 700 .78rem var(--font-ui); }
.opt.right { border-color: var(--accent); background: var(--accent-soft); }
.opt.right .tag { color: var(--accent); }
.opt.wrong { border-color: var(--danger); }
.opt.wrong .tag { color: var(--danger); }
.fb { margin-top: 14px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); font-size: .95rem; line-height: 1.5; }
.fb.good strong { color: var(--accent); }
.fb.bad strong { color: var(--danger); }
.score { font: 700 1.4rem var(--font-ui); margin: 6px 0; }
.score b { font: 700 3rem/1 var(--font-hand), var(--font-ui); color: var(--accent); }
.review { margin: 0; padding-left: 18px; display: grid; gap: 12px; font-size: .95rem; }
.flashcard { margin-top: 16px; padding: 22px 18px; min-height: 180px; border: 2px dashed var(--line); border-radius: 16px; background: var(--surface-2); }
.flashcard hr { border: 0; border-top: 1px dashed var(--line); margin: 16px 0; }
.fc-side { font: 700 .72rem var(--font-mono); letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.fc-text { margin: 6px 0 0; font-size: 1.15rem; line-height: 1.5; overflow-wrap: anywhere; }
.quiz .btn kbd { margin-left: 6px; font-size: .7rem; padding: 0 5px; opacity: .8; }
@media (min-width: 700px) {
  .quiz { padding: 24px; }
  .stage { padding: 22px 24px; }
}

/* ============================================================
   DESKTOP (>= 980px): top nav replaces tab bar, map replaces journey
   ============================================================ */
@media (min-width: 980px) {
  body { padding-bottom: 0; }
  .tabbar { display: none; }
  .nav-links { display: flex; }
  .hero { padding: 64px 0 30px; }
  .hero-grid { grid-template-columns: 1.1fr .9fr; align-items: center; gap: 48px; }
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .toast { bottom: 24px; }
  .sketch-bar { bottom: 24px; }
  .journey-wrap { display: none; }
  .mapwrap { display: block; }
}

/* map drawing */
.mapwrap svg { width: 100%; height: auto; display: block; overflow: visible; }
.mapwrap .node rect { fill: var(--surface); stroke: var(--line); stroke-width: 2; transition: stroke .2s; }
.mapwrap a:hover .node rect, .mapwrap a:focus-visible .node rect { stroke: var(--accent); }
.mapwrap text { fill: var(--ink); font-family: var(--font-ui); }
.mapwrap .hand-t { font-family: var(--font-hand); fill: var(--accent); font-size: 22px; }
.mapwrap .path { fill: none; stroke: var(--ink-3); stroke-width: 2; stroke-dasharray: 6 7; stroke-linecap: round; }
.mapwrap .num-t { font-family: var(--font-mono); fill: var(--accent); font-size: 13px; font-weight: 600; }

/* very small phones */
@media (max-width: 359px) {
  :root { --gutter: 12px; }
  .tabbar a span, .tabbar button span { font-size: .6rem; }
  h1 { font-size: 1.8rem; }
}

/* polish: path header meta, keyboard hints on buttons */
.section-head .meta { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 14px; }
.quiz .btn kbd { background: transparent; border-color: currentColor; color: inherit; }

/* ============================================================
   WIDE SCREENS: a wider page and denser grids, so large monitors are used well.
   Reading text stays at a comfortable line length; the sides carry navigation and aids.
   ============================================================ */
@media (min-width: 1400px) {
  :root { --maxw: 1240px; --gutter: 36px; }
  .gloss { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .hero { padding-top: 76px; }
}
@media (min-width: 1800px) {
  :root { --maxw: 1480px; --gutter: 44px; }
  .cards { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .gloss { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .hero-grid { gap: 72px; }
}

/* ============================================================
   ARTICLE + BLOG PAGE: reading column with side rails
   ============================================================ */
.art { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; align-items: start; padding-bottom: 20px; }
.art-head { display: grid; gap: 22px; margin-bottom: 22px; min-width: 0; }
.art-body { display: grid; gap: 22px; min-width: 0; }
.rails { display: block; min-width: 0; }
.rail-l { display: none; }
.rail-r { display: grid; gap: 14px; margin-bottom: 22px; }
.rail-r:empty { display: none; }
.rail-card { padding: 14px 16px; }
.rail-h { margin: 0 0 10px; font: 600 .72rem var(--font-mono); letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.rail-link { font-size: .88rem; color: var(--ink-2); text-decoration: none; padding: 0 4px; }
.rail-link:hover { color: var(--accent); }
.desk { display: none; }
.kt { list-style: none; margin: 0; padding: 0; display: grid; gap: 9px; }
.kt li { position: relative; padding-left: 22px; font-size: .95rem; line-height: 1.45; color: var(--ink); }
.kt li::before { content: "\2713"; position: absolute; left: 0; top: 0; color: var(--accent); font-weight: 700; }
.toc { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.toc a { display: block; padding: 5px 10px; border-left: 2px solid var(--line); color: var(--ink-2); text-decoration: none; font-size: .9rem; line-height: 1.35; overflow-wrap: anywhere; }
.toc .l3 a { padding-left: 22px; font-size: .85rem; }
.toc a:hover { color: var(--ink); border-left-color: var(--ink-3); }
.toc a.on { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }
.rp { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.rp b { font-size: 1.7rem; line-height: 1; }
.rail-card .bar { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; }
.rail-card .bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .15s linear; }
.gl-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.gl-chip { display: inline-block; padding: 3px 10px; border: 1px dashed var(--accent); border-radius: 99px; font-size: .82rem; color: var(--ink); text-decoration: none; }
.gl-chip:hover, .gl-chip:focus-visible { background: var(--surface-2); color: var(--accent); }
.prose h2, .prose h3, .prose h4 { scroll-margin-top: 8px; }   /* html already has scroll-padding-top for the sticky header */

/* top reading bar (all sizes) */
.read-bar { position: fixed; left: 0; right: 0; top: var(--header-h); height: 3px; z-index: 30; background: transparent; pointer-events: none; }
.read-bar i { display: block; height: 100%; width: 0; background: var(--accent); }

/* the dotted words that have a hover definition */
.gl { border-bottom: 1.5px dotted var(--accent); cursor: help; border-radius: 2px; }
.gl:hover, .gl:focus-visible, .gl.open { background: color-mix(in srgb, var(--accent) 16%, transparent); outline: none; }
.gl:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.gl-tip { position: fixed; z-index: 95; width: min(340px, calc(100vw - 16px)); padding: 12px 14px; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 34px rgba(0, 0, 0, .38); font-size: .92rem; line-height: 1.5; }
.gl-tip[hidden] { display: none; }
.gl-tip strong { color: var(--accent); }
.gl-tip .tag { margin-left: 6px; font: 600 .68rem var(--font-mono); color: var(--ink-3); border: 1px solid var(--line); border-radius: 99px; padding: 1px 8px; }
.gl-tip p { margin: 6px 0 8px; color: var(--ink-2); }
.gl-tip a { font-size: .85rem; font-weight: 600; }

/* two columns: article + one stacked rail */
@media (min-width: 1100px) {
  .desk { display: block; }
  .art { grid-template-columns: minmax(0, 740px) 300px; gap: 0 44px; justify-content: center; }
  .art.solo { grid-template-columns: minmax(0, 760px); }
  .art-head, .art-body { grid-column: 1; }
  .rails { grid-column: 2; grid-row: 1 / span 2; position: sticky; top: calc(var(--header-h) + 18px); align-self: start; display: grid; gap: 14px; max-height: calc(100vh - var(--header-h) - 36px); overflow: auto; padding: 2px; }
  .rail-l { display: grid; gap: 14px; }
  .rail-r { margin-bottom: 0; }
  .rail-r .gl-list, .rail-l .toc { max-height: 42vh; overflow: auto; }
}
/* three columns: contents on the left, takeaways on the right */
@media (min-width: 1500px) {
  .art { grid-template-columns: 250px minmax(0, 720px) 300px; gap: 0 40px; }
  .art.solo { grid-template-columns: minmax(0, 760px); }
  .rails { display: contents; }
  .rail-l, .rail-r { position: sticky; top: calc(var(--header-h) + 18px); align-self: start; max-height: calc(100vh - var(--header-h) - 36px); overflow: auto; padding: 2px; }
  .rail-l { grid-column: 1; grid-row: 1 / span 2; }
  .rail-r { grid-column: 3; grid-row: 1 / span 2; }
  .art-head, .art-body { grid-column: 2; }
}
@media print { .rails, .read-bar, .gl-tip { display: none !important; } .gl { border: 0; } }

/* ---------- story status (blog) ---------- */
.story { margin: 0 0 18px; padding: 14px 16px; border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 10px; background: var(--surface); font-size: .95rem; }
.story-developing { border-left-color: var(--warn); }
.story-updated { border-left-color: #6ea8ff; }
.story-resolved { border-left-color: var(--accent); }
.story-top { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; margin-bottom: 6px; }
.story-badge { font-weight: 800; font-size: .78rem; letter-spacing: .06em; text-transform: uppercase; color: var(--ink); }
.story-developing .story-badge { color: var(--warn); }
.story-updated .story-badge { color: #6ea8ff; }
.story-resolved .story-badge { color: var(--accent); }
.story-date { color: var(--ink-3); font-size: .85rem; }
.story p { margin: 4px 0 0; color: var(--ink); }
.story .story-stale { color: var(--warn); font-size: .9rem; }
.story.stale { background: color-mix(in srgb, var(--warn) 8%, var(--surface)); }
.story-chip { font-weight: 700; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; }
.story-chip.story-developing { color: var(--warn); }
.story-chip.story-updated { color: #6ea8ff; }
.story-chip.story-resolved { color: var(--accent); }

/* ---------- global search ---------- */
.srch-ov { align-items: flex-start; padding-top: 8vh; }
.modal.srch { width: min(640px, 100%); max-height: 80vh; display: flex; flex-direction: column; gap: 10px; border-radius: 18px; padding: 14px; }
.srch-out { overflow: auto; min-height: 60px; padding: 0 2px; }
.srch-h { font: 700 .72rem var(--font-ui); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); margin: 12px 4px 4px; }
.srch-list { list-style: none; margin: 0; padding: 0; }
.srch-list a { display: flex; flex-direction: column; gap: 1px; padding: 9px 12px; border-radius: 10px; text-decoration: none; color: var(--ink); }
.srch-list a small { color: var(--ink-3); font-size: .82rem; }
.srch-list a:hover, .srch-list a.sel, .srch-list a:focus-visible { background: var(--accent-soft); }
.srch-empty { padding: 16px 6px; margin: 0; }
.srch-keys { margin: 0; text-align: center; }
@media (max-width: 700px) { .srch-keys { display: none; } .srch-ov { padding-top: 0; align-items: flex-end; } .modal.srch { max-height: 85vh; border-radius: 18px 18px 0 0; } }
.explore h4 { margin: 12px 0 6px; font: 700 .72rem var(--font-ui); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.explore h4:first-of-type { margin-top: 4px; }

/* ---------- grid / list switch (wide screens only) ---------- */
.vt { display: none; }
.vt .chip svg { width: 16px; height: 16px; margin-right: 6px; }
@media (min-width: 1000px) {
  .vt { display: inline-flex; gap: 6px; justify-self: end; }
  .toolbar:has(.vt) { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; }
  .topic-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  html[data-view="list"] .topic-list { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  html[data-view="list"] .topic-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "h m" "p m"; column-gap: 28px; align-items: center; }
  html[data-view="list"] .topic-row h3 { grid-area: h; }
  html[data-view="list"] .topic-row p { grid-area: p; -webkit-line-clamp: unset; display: block; max-width: 80ch; }
  html[data-view="list"] .topic-row .meta { grid-area: m; flex-direction: column; align-items: flex-end; gap: 4px; margin: 0; text-align: right; }
}
@media (min-width: 1800px) {
  html:not([data-view="list"]) .topic-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ---------- progress dashboard ---------- */
.dash-cols { display: grid; gap: 22px; margin-top: 18px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) { .dash-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.dash-cols h3 { margin: 0 0 8px; font-size: 1.05rem; }
.dom-bars, .recent { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.dom-bars a { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) auto; gap: 12px; align-items: center; text-decoration: none; color: var(--ink); padding: 8px 12px; border-radius: 10px; background: var(--surface); }
.dom-bars a:hover, .recent a:hover { color: var(--accent); }
.dom-bars .progress { display: block; } .dom-bars small { color: var(--ink-3); }
.recent a { display: flex; flex-direction: column; text-decoration: none; color: var(--ink); padding: 9px 12px; border-radius: 10px; background: var(--surface); }
.recent small { color: var(--ink-3); }
