/* ============ Tokens ============ */
/* Palette follows the trippy.ch design language: violet night, teal, pink and violet glows.
   Dark ("night") is the default; light ("dawn") only when chosen via the theme toggle. */
:root {
  --bg: #1a0a2e; --surface: #241338; --surface-2: #2d1b4e; --text: #e8e0f5; --muted: #a89ec7;
  --border: #3b2a5c; --accent: #c084fc; --accent-ink: #1a0a2e; --accent-soft: #2f1d55;
  --lime: #2dd4bf;           /* highlight role: trippy teal */
  --coral: #ec4899;          /* warm role: trippy pink */
  --ok: #2dd4bf; --bad: #fb7185;
  --ink: #12071f;            /* always-dark surfaces (hero, demo) */
  --ink-2: #22133a;
  --ink-text: #ede6fb;
  --ink-muted: #a89ec7;
  --radius: 18px;
  --shadow: 0 0 0 1px rgba(168, 85, 247, .08), 0 18px 40px -24px rgba(124, 58, 237, .45);
  --font-display: "Bricolage Grotesque", "Inter", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f6f2fc; --surface: #ffffff; --surface-2: #ece4f8; --text: #1d1030; --muted: #5b4f78;
  --border: #e1d6f2; --accent: #7c3aed; --accent-ink: #ffffff; --accent-soft: #efe6ff;
  --lime: #2dd4bf; --coral: #db2777; --ok: #0f9b8e; --bad: #e11d48;
  --ink: #1a0a2e; --ink-2: #241338;
  --shadow: 0 1px 0 rgba(29, 16, 48, .04), 0 10px 30px -12px rgba(124, 58, 237, .22);
  color-scheme: light;
}
body { background-image: radial-gradient(ellipse 80% 50% at 85% 0%, rgba(124, 58, 237, .12), transparent 60%), radial-gradient(ellipse 60% 40% at 0% 100%, rgba(236, 72, 153, .07), transparent 60%); background-attachment: fixed; }
:root[data-theme="light"] body { background-image: none; }

/* ============ Base ============ */
* { box-sizing: border-box; }
/* No blue/grey tap flash on phones (inherited, so this covers every link and button) */
html, body { -webkit-tap-highlight-color: transparent; }
:where(a, button, [role="button"], input, select, textarea, label, summary) { -webkit-tap-highlight-color: transparent; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.6 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.1; letter-spacing: -.02em; }
h2 { font-size: clamp(1.8rem, 4vw, 2.6rem); margin: 0 0 18px; }
h3 { font-size: 1.15rem; margin: 0 0 8px; }
code { font-family: var(--font-mono); background: var(--accent-soft); padding: .1em .4em; border-radius: 6px; font-size: .85em; }
::selection { background: var(--lime); color: #111; }

.wrap { max-width: 1160px; margin: 0 auto; padding: 0 16px; }
section.block { padding: 88px 0 0; }
.kicker {
  display: inline-block; font-family: var(--font-mono); font-size: .78rem; font-weight: 600;
  letter-spacing: .16em; text-transform: uppercase; color: var(--lime); margin-bottom: 10px;
}
:root[data-theme="light"] .kicker { color: var(--accent); }
.empty { color: var(--muted); }
.section-lead { color: var(--muted); font-size: 1.1rem; max-width: 60ch; margin: -6px 0 24px; }

/* ============ Header ============ */
.site-header {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 800; font-size: 1.05rem; text-decoration: none; color: var(--text); white-space: nowrap; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: var(--ink); color: var(--lime); font-family: var(--font-mono); font-size: .8rem; font-weight: 700;
}
nav { display: flex; align-items: center; gap: 18px; }
nav a { color: var(--muted); text-decoration: none; font-size: .95rem; font-weight: 500; }
nav a:hover, nav a[aria-current="page"] { color: var(--text); }
/* "Start" button back to the malacarne.com start page */
nav a.nav-start {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--lime) 55%, transparent); color: var(--text);
  font-size: .88rem; font-weight: 600; white-space: nowrap;
  transition: border-color .2s, background-color .2s, color .2s, box-shadow .2s;
}
nav a.nav-start:hover { background: color-mix(in srgb, var(--lime) 14%, transparent); border-color: var(--lime); box-shadow: 0 0 16px -4px var(--lime); color: var(--text); }
nav a.nav-start span[aria-hidden] { color: var(--lime); display: inline-block; transition: transform .25s; }
nav a.nav-start:hover span[aria-hidden] { transform: translateX(-3px); }
:root[data-theme="light"] nav a.nav-start span[aria-hidden] { color: var(--accent); }
.icon-btn { background: none; border: 1px solid var(--border); border-radius: 10px; padding: 5px 9px; cursor: pointer; color: var(--text); font-size: .95rem; }
.lang-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.lang-switch button { font: 600 .78rem var(--font-mono); background: none; border: 0; padding: 6px 10px; cursor: pointer; color: var(--muted); }
.lang-switch button[aria-pressed="true"] { background: var(--text); color: var(--bg); }
.lang-switch a { font: 600 .78rem var(--font-mono); padding: 6px 10px; color: var(--muted); text-decoration: none; }
.lang-switch a[aria-current="true"] { background: var(--text); color: var(--bg); }

/* ============ Buttons ============ */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  font: 600 .95rem var(--font-body); cursor: pointer; text-decoration: none; white-space: nowrap;
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 12px; padding: 11px 18px;
  transition: transform .15s, box-shadow .15s;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 8px 20px -8px var(--accent); }
.btn.lime { background: var(--lime); color: #111; }
.btn.lime:hover { box-shadow: 0 8px 24px -8px var(--lime); }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { box-shadow: none; border-color: var(--text); }
.btn.on-ink { background: transparent; color: var(--ink-text); border: 1px solid #44306b; }
.btn.on-ink:hover { border-color: var(--ink-text); box-shadow: none; }
.btn.small { padding: 7px 12px; font-size: .85rem; border-radius: 10px; }

/* ============ Hero ============ */
.hero {
  position: relative; overflow: hidden; background: var(--ink); color: var(--ink-text);
  padding: 72px 0 64px; isolation: isolate;
}
.hero::before, .hero::after {
  content: ""; position: absolute; z-index: -1; border-radius: 50%; filter: blur(80px); opacity: .55;
}
.hero::before { width: 520px; height: 520px; background: #7c3aed; top: -180px; right: -120px; }
.hero::after { width: 380px; height: 380px; background: #ec4899; bottom: -220px; left: -100px; opacity: .35; }
.hero-grid { display: grid; grid-template-columns: 1.1fr .9fr; gap: 48px; align-items: center; }
.hero .kicker { color: var(--lime); }
.hero h1 { font-size: clamp(2.8rem, 7.5vw, 5.6rem); margin: 0 0 22px; letter-spacing: -.035em; line-height: .98; text-shadow: 0 0 40px rgba(168, 85, 247, .45); }
.hero h1 .hl {
  background: linear-gradient(transparent 74%, #2dd4bf 74%, #2dd4bf 90%, transparent 90%);
  padding: 0 .04em; color: #fff;
}
.hero h1 .soft { display: block; color: var(--ink-muted); font-size: .62em; margin-top: .25em; letter-spacing: -.02em; }
.hero .lead { font-size: 1.15rem; color: #c9bde3; max-width: 560px; margin: 0 0 28px; }
.cta-row { display: flex; flex-wrap: wrap; gap: 12px; }

/* Next-token demo */
.demo {
  background: color-mix(in srgb, var(--ink-2) 88%, transparent); border: 1px solid #3a2660;
  border-radius: 22px; padding: 22px; box-shadow: 0 30px 60px -30px rgba(0, 0, 0, .7);
  font-family: var(--font-mono);
}
.demo-label { display: flex; align-items: center; gap: 8px; font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-muted); }
.demo-label .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 12px var(--lime); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.demo-text { font-size: 1.15rem; line-height: 1.5; color: #fff; min-height: 3.5em; margin: 14px 0 18px; font-family: var(--font-body); font-weight: 500; }
.demo-text .picked { background: #2dd4bf; color: #111; border-radius: 6px; padding: 0 6px; animation: pop .35s ease-out; }
.demo-text .caret { display: inline-block; width: 2px; height: 1.1em; background: var(--lime); vertical-align: -0.15em; margin-left: 3px; animation: pulse 1s infinite; }
@keyframes pop { from { transform: scale(.7); opacity: 0; } }
.cands { display: grid; gap: 7px; }
.cand { display: grid; grid-template-columns: 110px 1fr 44px; gap: 10px; align-items: center; font-size: .82rem; color: #d9cdef; }
.cand .bar { height: 10px; border-radius: 99px; background: #2e1d4a; overflow: hidden; }
.cand .bar > i { display: block; height: 100%; width: 0; border-radius: 99px; background: linear-gradient(90deg, #8b5cf6, #c084fc); transition: width .6s cubic-bezier(.2, .8, .2, 1); }
.cand.win { color: #fff; }
.cand.win .bar > i { background: linear-gradient(90deg, #14b8a6, #5eead4); }
.cand .p { text-align: right; color: var(--ink-muted); }
.demo-caption { margin: 16px 0 0; font-size: .78rem; color: var(--ink-muted); font-family: var(--font-body); }

/* Ticker */
.ticker { background: var(--lime); color: #111; overflow: hidden; border-block: 1px solid #111; }
.ticker-track { display: flex; gap: 0; width: max-content; animation: ticker 60s linear infinite; }
.ticker:hover .ticker-track { animation-play-state: paused; }
.ticker a { display: inline-flex; align-items: center; gap: 14px; padding: 12px 0 12px 14px; color: #111; text-decoration: none; font: 700 1rem var(--font-display); white-space: nowrap; }
.ticker a::after { content: "✦"; font-size: .8rem; }
.ticker a:hover { text-decoration: underline; }
@keyframes ticker { to { transform: translateX(-50%); } }

/* Facts */
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.fact { padding: 22px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); }
.fact b { display: block; font: 800 2.6rem/1 var(--font-display); letter-spacing: -.03em; margin-bottom: 8px; }
.fact:nth-child(1) b { color: var(--coral); }
.fact:nth-child(2) b { color: var(--accent); }
.fact:nth-child(3) b { color: var(--ok); }
.fact p { margin: 0; color: var(--muted); }

/* ============ Cards & grids ============ */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; margin: 14px 0 6px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--coral)); border-radius: 99px; transition: width .5s; }
.progress-label { font-size: .82rem; color: var(--muted); }
.meta { font-size: .85rem; color: var(--muted); margin: 4px 0 0; }
.tag { display: inline-block; font: 600 .72rem var(--font-mono); padding: 3px 9px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }

.topic-grid { grid-template-columns: 2fr 1fr; }
.topic { display: flex; flex-direction: column; gap: 8px; position: relative; overflow: hidden; }
.topic.featured { background: linear-gradient(135deg, #2b1650 0%, var(--ink) 60%); color: var(--ink-text); border-color: #3a2660; padding: 30px; }
.topic.featured p { color: #c9bde3; }
.topic.featured .progress { background: #2e1d4a; }
.topic.featured .progress-label, .topic.featured .meta { color: var(--ink-muted); }
.topic-emoji { font-size: 2.6rem; line-height: 1; }
.topic h3 { font-size: 1.8rem; margin-top: 6px; }
.topic p { margin: 0; color: var(--muted); }
.topic .cta-row { margin-top: 14px; }
.topic.planned { border-style: dashed; box-shadow: none; background: transparent; justify-content: center; }

/* Sessions */
.sessions { display: grid; gap: 12px; }
.session { display: grid; grid-template-columns: 76px 1fr auto; gap: 18px; align-items: center; }
.date-badge { text-align: center; background: var(--ink); color: var(--lime); border-radius: 14px; padding: 10px 0; font-family: var(--font-mono); }
.date-badge b { display: block; font: 800 1.7rem/1 var(--font-display); color: #fff; }
.date-badge span { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; }
.session h4 { margin: 0 0 4px; font-size: 1.1rem; }
.session p { margin: 0; color: var(--muted); font-size: .92rem; }
details { margin-top: 20px; }
summary { cursor: pointer; color: var(--muted); }
details .sessions { margin-top: 12px; opacity: .7; }
h3.sub { font: 600 .8rem var(--font-mono); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 12px; }

.contribute .card p { color: var(--muted); }
.contribute .card h3 { display: flex; gap: 10px; align-items: center; }

.footer { padding: 72px 16px 48px; color: var(--muted); font-size: .88rem; }
.footer p { margin: 0 0 6px; }
.footer-links a { color: var(--muted); text-decoration: none; font-weight: 600; }
.footer-links a:hover { color: var(--text); }
.brand-text small { font: 600 .72rem var(--font-mono); color: var(--muted); margin-left: 6px; letter-spacing: .02em; }

/* ============ Course ============ */
.course { display: grid; grid-template-columns: 290px 1fr; gap: 40px; padding-top: 32px; align-items: start; }
.course-nav { position: sticky; top: 80px; }
.course-title { font: 800 1.2rem var(--font-display); color: var(--text); text-decoration: none; }
#module-list { list-style: none; padding: 0; margin: 14px 0 0; counter-reset: m; }
#module-list a { display: flex; gap: 10px; align-items: center; padding: 9px 10px; border-radius: 12px; color: var(--text); text-decoration: none; font-size: .92rem; }
#module-list a:hover { background: var(--surface-2); }
#module-list li.active a { background: var(--ink); color: #fff; font-weight: 600; }
#module-list .check { width: 24px; text-align: center; flex: none; }
#module-list li.done .check { color: var(--ok); font-weight: 800; }
#module-list li.active.done .check { color: var(--lime); }
.nav-lexicon { display: block; margin-top: 14px; padding: 12px 14px; border-radius: 12px; background: var(--lime); color: #111; text-decoration: none; font-weight: 700; font-size: .9rem; }
.course-main { min-width: 0; outline: none; padding-bottom: 20px; }
.course-main h1 { font-size: clamp(2.1rem, 5vw, 3.4rem); margin: 6px 0 12px; letter-spacing: -.03em; }
.course-main h2 { font-size: clamp(1.4rem, 3vw, 1.75rem); margin-top: 40px; }
.course-main .lead { font-size: 1.15rem; color: var(--muted); margin: 0 0 24px; max-width: 62ch; }
.module-hero { display: flex; gap: 18px; align-items: center; }
.module-emoji { width: 72px; height: 72px; flex: none; border-radius: 20px; background: var(--ink); display: grid; place-items: center; font-size: 2.2rem; }
.lesson { max-width: 68ch; font-size: 1.04rem; }
.lesson ul { padding-left: 0; list-style: none; }
.lesson li { position: relative; padding-left: 26px; margin: 10px 0; }
.lesson li::before { content: "→"; position: absolute; left: 0; color: var(--accent); font-weight: 700; }
.aha {
  max-width: 68ch; margin: 36px 0 0; padding: 20px 22px; border-radius: var(--radius);
  background: var(--ink); color: var(--ink-text); position: relative; border: 1px solid #3a2660;
}
.aha b { display: inline-block; font: 700 .75rem var(--font-mono); text-transform: uppercase; letter-spacing: .08em; color: #111; background: var(--lime); padding: 3px 9px; border-radius: 99px; margin-bottom: 8px; }
.aha p { margin: 0; color: #e4dbf5; }
.module-grid { grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }
.module-card { display: flex; gap: 14px; text-decoration: none; color: var(--text); transition: transform .15s, border-color .15s; }
.module-card:hover { transform: translateY(-3px); border-color: var(--text); }
.module-card .track-icon { font-size: 1.8rem; }
.module-card h3 { margin: 4px 0 6px; }
.module-card p { margin: 0; color: var(--muted); font-size: .92rem; }
.module-card.done { border-color: var(--ok); }
.callout { display: flex; flex-wrap: wrap; gap: 18px; align-items: center; justify-content: space-between; margin-top: 40px; background: var(--lime); color: #111; border: 0; }
.callout h3 { font-size: 1.4rem; }
.callout p { margin: 0; max-width: 56ch; }
.callout .btn { background: #111; color: var(--lime); }

.quiz { margin-top: 44px; max-width: 68ch; }
.quiz h2 { margin-top: 0; }
.quiz fieldset { border: 1px solid var(--border); border-radius: 14px; padding: 14px 18px; margin: 0 0 14px; transition: border-color .2s, background .2s; }
.quiz fieldset.ok { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 7%, transparent); }
.quiz fieldset.bad { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 7%, transparent); }
.quiz legend { font-weight: 700; padding: 0 6px; }
.quiz label { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; cursor: pointer; }
.quiz input { margin-top: 5px; accent-color: var(--accent); }
.feedback { margin: 8px 0 0; font-size: .92rem; color: var(--muted); }
.quiz-actions { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; }
#quiz-result { font-weight: 700; }
.pager { display: flex; justify-content: space-between; gap: 12px; margin: 32px 0 0; max-width: 68ch; }
.banner { padding: 14px 18px; border-radius: 14px; background: var(--accent-soft); font-weight: 600; }
.banner.ok { color: var(--ok); }

/* Clickable terms inside course text */
.term {
  font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: help;
  text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: 2px;
  text-underline-offset: 3px; text-decoration-style: dotted;
}
.term:hover, .term[aria-expanded="true"] { background: var(--accent-soft); border-radius: 4px; text-decoration-style: solid; }
.popover {
  position: absolute; z-index: 50; width: min(340px, calc(100vw - 32px));
  background: var(--ink); color: var(--ink-text); border-radius: 16px; padding: 16px 18px;
  box-shadow: 0 20px 50px -20px rgba(0, 0, 0, .6); font-size: .93rem; line-height: 1.5;
  animation: pop .18s ease-out;
}
.popover strong { display: block; font: 800 1.05rem var(--font-display); margin-bottom: 4px; color: #fff; }
.popover p { margin: 0 0 10px; color: #ddd3f0; }
.popover a { color: var(--lime); font-weight: 600; text-decoration: none; }

/* ============ Lexicon ============ */
.lex-hero { background: var(--ink); color: var(--ink-text); padding: 56px 0 40px; position: relative; overflow: hidden; isolation: isolate; }
.lex-hero::before { content: ""; position: absolute; z-index: -1; width: 460px; height: 460px; border-radius: 50%; background: #7c3aed; filter: blur(90px); opacity: .25; right: -120px; top: -200px; }
.lex-hero h1 { font-size: clamp(2.6rem, 7vw, 4.6rem); margin: 0 0 12px; letter-spacing: -.035em; }
.lex-hero .lead { color: #c9bde3; max-width: 620px; font-size: 1.12rem; margin: 0 0 26px; }
.lex-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.lex-tools input {
  flex: 1 1 260px; max-width: 420px; font: inherit; padding: 12px 16px; border-radius: 14px;
  border: 1px solid #44306b; background: #211238; color: #fff;
}
.lex-tools input::placeholder { color: #9488b5; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { font: 600 .85rem var(--font-body); padding: 8px 14px; border-radius: 99px; border: 1px solid #44306b; background: transparent; color: #ddd3f0; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--lime); color: #111; border-color: var(--lime); }
.lex-count { font: 600 .8rem var(--font-mono); color: var(--muted); margin: 28px 0 14px; }
.lex-grid { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.term-card {
  text-align: left; font: inherit; color: var(--text); cursor: pointer; display: flex; flex-direction: column; gap: 8px;
  transition: transform .15s, border-color .15s;
}
.term-card:hover { transform: translateY(-3px); border-color: var(--text); }
a.term-card { text-decoration: none; }

/* ---- Share ---- */
.share-wrap { position: relative; display: inline-flex; }
.share-btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 99px; cursor: pointer;
  font: 600 .85rem var(--font-body); color: var(--ink-text); background: #2e1d4a; border: 1px solid #54407c;
  transition: border-color .2s, background-color .2s, box-shadow .2s;
}
.share-btn:hover, .share-btn[aria-expanded="true"] { border-color: var(--lime); background: #36225a; box-shadow: 0 0 16px -6px var(--lime); }
.share-btn svg { color: var(--lime); }
.share-menu {
  position: absolute; z-index: 60; top: calc(100% + 8px); left: 0; min-width: 210px; padding: 6px;
  display: grid; gap: 2px; border-radius: 14px; background: #1c0f30; border: 1px solid #44306b;
  box-shadow: 0 18px 40px -16px rgba(0, 0, 0, .7); animation: share-in .16s ease;
}
.share-menu a, .share-menu button {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px; border: 0; background: none; cursor: pointer;
  font: 500 .88rem var(--font-body); color: #ede6fb; text-decoration: none; text-align: left;
}
.share-menu a:hover, .share-menu button:hover, .share-menu :focus-visible { background: #2e1d4a; outline: none; }
.share-menu svg { flex: none; color: var(--lime); }
@keyframes share-in { from { opacity: 0; transform: translateY(-4px); } }

/* share icon on every term card (sits beside the card link, top right) */
.term-item { position: relative; display: grid; }
.term-item > .term-card { height: 100%; }
.term-card > .tag { align-self: flex-start; margin-right: 44px; }
.card-share { position: absolute; top: 14px; right: 14px; }
.card-share .share-menu { left: auto; right: 0; }
.share-btn.icon-only { width: 36px; height: 36px; padding: 0; justify-content: center; }

/* the open term as a sheet you can flick down (touch) */
.dlg-grab { display: none; width: 42px; height: 5px; margin: -12px auto 14px; border-radius: 99px; background: rgba(237, 230, 251, .35); }
dialog.term-dialog.dragging { transition: none !important; }
dialog.term-dialog.flicking { transition: transform .23s cubic-bezier(.4, 0, 1, 1), opacity .23s ease !important; opacity: .6; }
dialog.term-dialog.dragging::backdrop { opacity: calc(1 - var(--drag, 0)); }
@media (pointer: coarse) { .dlg-grab { display: block; } }

/* ---- Term pages (/ailiteracy/<lang>/<id>/, generated) ---- */
.term-hero {
  position: relative; z-index: 2; padding: 30px 0 34px; color: var(--ink-text);
  background: radial-gradient(520px 380px at calc(100% - 60px) 0, rgba(124, 58, 237, .32), transparent 70%), var(--ink);
}
.crumbs { font: 500 .8rem var(--font-mono); color: var(--ink-muted); margin: 0 0 22px; display: flex; flex-wrap: wrap; gap: 6px; }
.crumbs a { color: var(--ink-muted); text-decoration: none; }
.crumbs a:hover { color: var(--ink-text); }
.crumbs [aria-current] { color: var(--ink-text); }
.term-hero .kicker { color: var(--lime); }
.term-hero h1 { font-size: clamp(2.3rem, 6.4vw, 4rem); margin: 4px 0 10px; letter-spacing: -.03em; }
.term-aliases { margin: -2px 0 12px; font: 500 .85rem var(--font-mono); color: var(--ink-muted); }
.term-hero .lead { margin: 0 0 22px; max-width: 64ch; font-size: 1.15rem; line-height: 1.6; color: #d6cbec; }
.term-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.term-meta .row { display: flex; gap: 6px; }
.byline { font-size: .82rem; color: var(--ink-muted); }
.byline a { color: var(--ink-text); }
.term-body { display: grid; gap: 14px; padding-top: 28px; padding-bottom: 8px; }
.box-h { margin: 0 0 6px; font: 700 .75rem var(--font-mono); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.term-media { margin: 0; }
.term-related .related { margin-top: 4px; }
.related a { font: 600 .85rem var(--font-body); padding: 7px 12px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none; }
.related a:hover { border-color: var(--text); }
.term-pager { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); }
.term-pager a { text-decoration: none; color: var(--text); font-weight: 600; }
.term-pager a small { display: block; font: 600 .7rem var(--font-mono); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 2px; }
.term-pager .pg-next { text-align: right; }
.term-pager .pg-all { font: 600 .82rem var(--font-mono); padding: 8px 14px; border: 1px solid var(--border); border-radius: 99px; }
.term-pager a:hover { color: var(--lime); }
.term-body .callout { margin-top: 26px; }
.course-outline h1 { font-size: clamp(2rem, 5vw, 3rem); margin: 0 0 10px; }
.course-outline ol { padding-left: 1.2em; display: grid; gap: 10px; }
.course-outline h2 { font-size: 1.15rem; margin: 0 0 2px; }
.course-outline p { margin: 0; color: var(--muted); }
@media (max-width: 640px) {
  .term-pager { grid-template-columns: 1fr 1fr; }
  .term-pager .pg-all { grid-column: 1 / -1; grid-row: 2; justify-self: center; }
}

.term-card h3 { font-size: 1.3rem; margin: 0; }
.term-card p { margin: 0; color: var(--muted); font-size: .92rem; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.term-card .row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; padding-top: 6px; }
.tag.demo-tag { background: var(--lime); color: #111; }

dialog.term-dialog {
  width: min(760px, calc(100vw - 24px)); max-height: calc(100vh - 40px); padding: 0; border: 0;
  border-radius: 24px; background: var(--bg); color: var(--text); box-shadow: 0 40px 80px -30px rgba(0, 0, 0, .6);
}
dialog.term-dialog::backdrop { background: rgba(15, 6, 28, .6); backdrop-filter: blur(4px); }
.dlg-head { background: var(--ink); color: var(--ink-text); padding: 26px 28px 22px; position: relative; }
.dlg-head h2 { margin: 6px 0 8px; font-size: clamp(1.8rem, 5vw, 2.6rem); padding-right: 84px; }
.dlg-head p { margin: 0; color: #d6cbec; font-size: 1.05rem; }
.dlg-close { position: absolute; top: 18px; right: 18px; background: #2e1d4a; color: #fff; border: 0; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; font-size: 1.1rem; }
/* share sits beside the close button and looks like it */
.dlg-share { position: absolute; top: 18px; right: 62px; }
.dlg-share .share-btn { background: #2e1d4a; border-color: transparent; color: #fff; }
.dlg-share .share-btn svg { color: inherit; }
.dlg-share .share-btn:hover, .dlg-share .share-btn[aria-expanded="true"] { color: var(--lime); border-color: var(--lime); }
.dlg-share .share-menu { left: auto; right: -44px; }
.dlg-close:hover { box-shadow: 0 0 0 1px var(--lime); }
.dlg-body { padding: 24px 28px 28px; display: grid; gap: 14px; }
.dlg-box { border-radius: 16px; padding: 16px 18px; background: var(--surface); border: 1px solid var(--border); }
.dlg-box h4 { margin: 0 0 6px; font: 700 .75rem var(--font-mono); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.dlg-box p { margin: 0; }
.dlg-box.analogy { background: var(--accent-soft); border-color: transparent; }
.dlg-box.analogy p { font-size: 1.08rem; }
.dlg-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.related { display: flex; flex-wrap: wrap; gap: 8px; }
.related button { font: 600 .85rem var(--font-body); padding: 7px 12px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.related button:hover { border-color: var(--text); }

/* Widgets */
.widget { border-radius: 16px; padding: 18px; background: var(--ink); color: var(--ink-text); border: 1px solid #3a2660; }
.widget h4 { margin: 0 0 12px; font: 700 .75rem var(--font-mono); text-transform: uppercase; letter-spacing: .08em; color: var(--lime); }
.widget p.note { font-size: .8rem; color: var(--ink-muted); margin: 10px 0 0; }
.widget textarea, .widget input[type="text"] {
  width: 100%; font: 1rem var(--font-body); padding: 10px 12px; border-radius: 12px; border: 1px solid #44306b;
  background: #211238; color: #fff; resize: vertical;
}
.widget input[type="range"] { width: 100%; accent-color: var(--lime); }
.widget .btn { margin-top: 10px; }
.tok-out { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 12px; font: .95rem var(--font-mono); }
.tok-out span { padding: 2px 4px; border-radius: 5px; white-space: pre; color: #111; }
.tok-stats { display: flex; gap: 18px; margin-top: 12px; font: .85rem var(--font-mono); color: var(--ink-muted); }
.tok-stats b { color: #fff; }
.temp-prompt { font-size: 1.05rem; margin-bottom: 10px; }
.temp-prompt b { background: var(--lime); color: #111; border-radius: 6px; padding: 0 6px; }
.temp-row { display: flex; justify-content: space-between; font: .8rem var(--font-mono); color: var(--ink-muted); margin-top: 4px; }
.history { font: .85rem var(--font-mono); color: var(--ink-muted); margin-top: 8px; min-height: 1.3em; }
.ctx-bar { display: flex; gap: 3px; height: 46px; margin: 12px 0 6px; padding: 4px; border-radius: 12px; border: 2px dashed #44306b; }
.ctx-bar span { border-radius: 7px; display: grid; place-items: center; font: 600 .7rem var(--font-mono); color: #111; overflow: hidden; }
.ctx-sys { background: #c084fc; }
.ctx-msg { background: var(--lime); }
.ctx-q { background: var(--coral); }
.ctx-dropped { display: flex; gap: 4px; flex-wrap: wrap; min-height: 22px; font: .75rem var(--font-mono); color: var(--ink-muted); }
.ctx-dropped span { text-decoration: line-through; opacity: .6; }
.cnn-wrap { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.px-grid { display: grid; gap: 2px; }
.px-grid div { width: 22px; height: 22px; border-radius: 3px; background: #2e1d4a; }
.px-grid div.on { background: #ede6fb; }
.px-grid div.win { outline: 2px solid var(--lime); outline-offset: -1px; }
.px-grid.out div { background: #2e1d4a; }
.cnn-kernel { font: .78rem var(--font-mono); color: var(--ink-muted); text-align: center; }
.cnn-kernel table { border-collapse: collapse; margin: 4px auto; }
.cnn-kernel td { width: 24px; height: 22px; text-align: center; color: #fff; border: 1px solid #44306b; }
.flow { display: grid; gap: 8px; counter-reset: s; }
.flow div { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 12px; background: #211238; border: 1px solid #3a2660; opacity: .45; transition: all .3s; }
.flow div.on { opacity: 1; border-color: var(--lime); }
.flow div b { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: #2e1d4a; color: var(--lime); font: 700 .85rem var(--font-mono); }
.flow div.on b { background: var(--lime); color: #111; }
.emb svg { width: 100%; height: auto; display: block; }
.mcp-diagram { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center; }
.mcp-node { padding: 12px; border-radius: 12px; background: #211238; border: 1px solid #3a2660; text-align: center; font-size: .9rem; }
.mcp-node.app { border-color: #c084fc; }
.mcp-plug { font: 700 .8rem var(--font-mono); background: var(--lime); color: #111; padding: 6px 10px; border-radius: 99px; }
.mcp-tools { display: grid; gap: 8px; }
.halu p.q { margin: 0 0 10px; color: var(--ink-muted); font-size: .9rem; }
.halu .answer { display: grid; gap: 8px; }
.halu button { text-align: left; font: inherit; padding: 10px 12px; border-radius: 12px; background: #211238; border: 1px solid #3a2660; color: #fff; cursor: pointer; }
.halu button:hover { border-color: #fff; }
.halu button.right { border-color: var(--lime); background: #10302f; }
.halu button.wrong { border-color: var(--coral); opacity: .7; }
.halu .result { margin-top: 10px; font-size: .92rem; min-height: 1.4em; }

/* Burst */
.burst { position: fixed; z-index: 100; pointer-events: none; font-size: 1.6rem; animation: burst 1.1s cubic-bezier(.2, .7, .3, 1) forwards; }
@keyframes burst { to { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); opacity: 0; } }

/* ============ Responsive ============ */
@media (max-width: 960px) {
  .hero-grid { grid-template-columns: 1fr; gap: 36px; }
  .topic-grid { grid-template-columns: 1fr; }
  .course { grid-template-columns: 1fr; gap: 20px; }
  .course-nav { position: static; }
}
@media (max-width: 700px) {
  nav a.hide-sm { display: none; }
  .facts { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr; }
  .session { grid-template-columns: 60px 1fr; }
  .session .btn { grid-column: 2; justify-self: start; }
  .dlg-cols { grid-template-columns: 1fr; }
  /* phones: the open term is a bottom sheet */
  dialog.term-dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; max-height: calc(100dvh - 18px); border-radius: 22px 22px 0 0; overscroll-behavior: contain; }
  .dlg-head { padding: 22px 20px 20px; }
  .dlg-body { padding: 20px 16px 28px; }
  .mcp-diagram { grid-template-columns: 1fr; }
  .cand { grid-template-columns: 92px 1fr 40px; }
  .hero { padding: 48px 0; }
  section.block { padding-top: 64px; }
  .module-emoji { width: 56px; height: 56px; font-size: 1.7rem; border-radius: 16px; }
  .brand-text { display: none; }
  /* phones: the current page's own link is redundant, keep room for "Start" */
  nav { gap: 12px; }
  nav a[aria-current="page"], nav a.nav-sub { display: none; }
  nav a.nav-start { padding: 5px 11px; font-size: .84rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  html { scroll-behavior: auto; }
}
