/* ==========================================================================
   CAS · KV Cache in Transformer Architecture — Lecture 21 Visual Styles
   Pure KV Cache Edition · Light Textbook Default + Dark Mode Toggle
   ========================================================================== */

html { scroll-padding-top: 68px; }
main { padding-top: 3.4rem; }
.section { scroll-margin-top: 64px; }
.scroll-progress { top: 3.2rem; }
.rail-toggle { top: 4.4rem; }
.rail { padding-top: 4.6rem; }
.skip-link:not(:focus) { top: -200px; opacity: 0; pointer-events: none; }
[data-reveal] { opacity: 1 !important; transform: none !important; }

/* ------------------------------------------------- Top Navbar */
.topnav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 130;
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.52rem clamp(0.85rem, 2vw, 1.5rem);
  background: rgba(5, 8, 14, 0.88); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.topnav-brand { display: flex; align-items: center; gap: 0.55rem; text-decoration: none; color: var(--text); flex: none; }
.topnav-brand:hover { text-decoration: none; }
.topnav-brand img { width: 2.05rem; height: 2.05rem; border-radius: 7px; }
.topnav-brand .tb-txt { display: flex; flex-direction: column; line-height: 1.1; }
.topnav-brand .tb-txt strong { font-family: var(--font-display); font-size: 0.84rem; letter-spacing: 0.05em; }
.topnav-brand .tb-txt small { font-family: var(--font-mono); font-size: 0.54rem; letter-spacing: 0.14em; color: var(--text-3); text-transform: uppercase; }

.topnav-links { display: flex; gap: 0.08rem; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.topnav-links::-webkit-scrollbar { display: none; }
.topnav-links a {
  font-size: 0.72rem; font-weight: 500; color: var(--text-2); text-decoration: none;
  padding: 0.32rem 0.42rem; border-radius: 6px; white-space: nowrap; transition: color 0.15s, background 0.15s;
}
.topnav-links a:hover { color: var(--text); background: var(--panel-2); text-decoration: none; }
.topnav-links a.active { color: var(--teal); font-weight: 700; }

.topnav-back {
  flex: none; font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase;
  border: 1px solid var(--line-2); border-radius: 8px; padding: 0.38rem 0.72rem; color: var(--text);
  background: transparent; text-decoration: none; transition: border-color 0.2s, color 0.2s;
}
.topnav-back:hover { border-color: var(--teal); color: var(--teal); text-decoration: none; }
@media (max-width: 1020px) { .topnav-links { display: none; } }

/* ------------------------------------------------- Base Dark & Light Themes */
body {
  background-color: #070d19;
  background-image:
    radial-gradient(900px 500px at 15% 4%, rgba(45, 212, 191, 0.12), transparent 65%),
    radial-gradient(950px 550px at 88% 10%, rgba(56, 189, 248, 0.12), transparent 65%);
}

html.light-theme {
  --bg0: #f8fafc;
  --bg1: #f1f5f9;
  --panel: #ffffff;
  --panel-2: #f1f5f9;
  --panel-solid: #ffffff;
  --line: rgba(15, 23, 42, 0.12);
  --line-2: rgba(15, 23, 42, 0.22);
  --text: #0f172a;
  --text-2: #334155;
  --text-3: #64748b;
  --teal: #0d9488;
  --sky: #0284c7;
  --indigo: #4f46e5;
  --violet: #7c3aed;
  --amber: #d97706;
  --rose: #e11d48;
  --green: #059669;
}
html.light-theme body {
  background-color: #f8fafc;
  background-image:
    radial-gradient(900px 500px at 15% 4%, rgba(13, 148, 136, 0.07), transparent 65%),
    radial-gradient(950px 550px at 88% 10%, rgba(2, 132, 199, 0.07), transparent 65%);
}
html.light-theme .topnav { background: rgba(255, 255, 255, 0.94); border-bottom-color: rgba(15, 23, 42, 0.12); }
html.light-theme .rail { background: rgba(255, 255, 255, 0.97); border-right-color: rgba(15, 23, 42, 0.12); }
html.light-theme .rail-toggle { background: #ffffff; border-color: rgba(15, 23, 42, 0.18); color: #0f172a; box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08); }

/* ------------------------------------------------- Hero & Paper Citations */
.sec-hero { text-align: center; padding-top: clamp(2.8rem, 7vh, 4.8rem); }
.hero-badge {
  display: inline-flex; align-items: center; gap: 0.45rem; flex-wrap: wrap; justify-content: center;
  font-family: var(--font-mono); font-size: 0.74rem; letter-spacing: 0.05em; color: var(--teal);
  border: 1px solid rgba(13, 148, 136, 0.38); border-radius: 999px; padding: 0.4rem 1rem;
  background: rgba(13, 148, 136, 0.08); margin-bottom: 1.4rem;
}
.sec-hero .hero-title { margin-inline: auto; max-width: 24ch; }
.sec-hero .hero-sub { margin-inline: auto; text-align: center; max-width: 72ch; }

.hero-actions {
  display: flex; flex-wrap: wrap; gap: 0.65rem; justify-content: center; margin: 1.4rem auto 1.85rem; max-width: 1020px;
}
.hero-actions .btn { padding: 0.55rem 0.95rem; font-size: 0.78rem; }

.paper-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem;
  max-width: 1020px; margin: 0 auto 2.1rem; text-align: left;
}
@media (max-width: 820px) { .paper-grid { grid-template-columns: 1fr; } }

.paper-card {
  display: flex; flex-direction: column; gap: 0.45rem; padding: 1.15rem 1.25rem;
  border-radius: 14px; border: 1px solid var(--line-2); background: var(--panel);
  text-decoration: none; color: var(--text); transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.paper-card:hover {
  transform: translateY(-3px); border-color: var(--teal); text-decoration: none;
  box-shadow: 0 14px 30px rgba(13, 148, 136, 0.12);
}
.paper-top { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.paper-badge { font-family: var(--font-mono); font-size: 0.62rem; font-weight: 700; letter-spacing: 0.1em; color: var(--sky); }
.paper-arxiv {
  font-family: var(--font-mono); font-size: 0.68rem; font-weight: 700; color: var(--teal);
  background: rgba(13, 148, 136, 0.1); border: 1px solid rgba(13, 148, 136, 0.35); border-radius: 999px; padding: 0.15rem 0.55rem;
}
.paper-title { margin: 0.1rem 0 0; font-family: var(--font-display); font-size: 1.04rem; font-weight: 700; color: var(--text); }
.paper-authors { margin: 0; font-size: 0.78rem; color: var(--text-3); line-height: 1.45; }
.paper-contrib { margin: 0.15rem 0 0; font-size: 0.84rem; color: var(--text-2); line-height: 1.5; }
.paper-url-line {
  display: inline-block; margin-top: 0.25rem; padding: 0.28rem 0.55rem; border-radius: 6px;
  font-family: var(--font-mono); font-size: 0.72rem; word-break: break-all;
  color: var(--sky); background: var(--panel-2); border: 1px solid var(--line);
}
.paper-cta { font-family: var(--font-mono); font-size: 0.72rem; font-weight: 700; color: var(--teal); margin-top: auto; padding-top: 0.35rem; }

.paper-url-pill {
  display: inline-flex; flex-wrap: wrap; align-items: center; gap: 0.55rem;
  margin-top: 0.85rem; padding: 0.48rem 0.85rem; border-radius: 9px;
  background: var(--panel-2); border: 1px solid var(--line-2);
  font-family: var(--font-mono); font-size: 0.76rem; color: var(--text-2);
}
.paper-url-pill a { color: var(--sky); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }

.hero-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(175px, 100%), 1fr)); gap: 0.85rem; max-width: 1020px; margin: 0 auto 2.2rem; }
.hstat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 0.9rem; text-align: center; transition: border-color 0.2s, transform 0.2s;
}
.hstat:hover { border-color: var(--teal); transform: translateY(-2px); }
.hstat b { display: block; font-family: var(--font-display); font-size: clamp(1.15rem, 1.55vw, 1.42rem); font-weight: 700; color: var(--teal); line-height: 1.2; }
.hstat span { display: block; font-family: var(--font-mono); font-size: 0.62rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-2); margin-top: 0.28rem; }
.hstat small { display: block; font-family: var(--font-mono); font-size: 0.58rem; color: var(--text-3); margin-top: 0.15rem; }

/* ------------------------------------------------- Highlights Grid */
.hl-showcase {
  text-align: left; margin: 0 auto 1.2rem; padding: 1.45rem 1.55rem;
  border-radius: 16px; border: 1px solid var(--line-2); background: var(--panel);
}
.hl-head { margin-bottom: 1.15rem; }
.hl-title { margin: 0.25rem 0 0; font-family: var(--font-display); font-size: clamp(1.3rem, 2.2vw, 1.7rem); color: var(--text); }
.hl-title em { font-style: normal; color: var(--teal); }
.hl-bento-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.9rem; }
@media (max-width: 960px) { .hl-bento-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .hl-bento-grid { grid-template-columns: 1fr; } }

.hl-card {
  display: flex; flex-direction: column; gap: 0.55rem; padding: 1.05rem 1.1rem; text-align: left;
  border-radius: 12px; border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text);
  cursor: pointer; transition: transform 0.2s, border-color 0.2s; position: relative; overflow: hidden;
}
.hl-card::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--teal); }
.hl-card.acc-rose::before { background: var(--rose); }
.hl-card.acc-sky::before { background: var(--sky); }
.hl-card.acc-amber::before { background: var(--amber); }
.hl-card.acc-violet::before { background: var(--violet); }
.hl-card.acc-green::before { background: var(--green); }
.hl-card:hover { transform: translateY(-3px); border-color: var(--teal); }
.hl-card h3 { margin: 0; font-family: var(--font-display); font-size: 1rem; color: var(--text); line-height: 1.3; }
.hl-card p { margin: 0; font-size: 0.83rem; color: var(--text-2); line-height: 1.5; }
.hl-theme { font-family: var(--font-mono); font-size: 0.62rem; font-weight: 700; letter-spacing: 0.1em; color: var(--teal); }
.hl-go { font-family: var(--font-mono); font-size: 0.68rem; font-weight: 700; color: var(--teal); margin-top: auto; }

/* ------------------------------------------------- Shared Card & Color Utilities */
.tok-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.35rem 1.45rem; }
.rose-txt, .fact b.rose-txt { color: var(--rose); }
.teal-txt, .fact b.teal-txt { color: var(--teal); }
.sky-txt, .fact b.sky-txt { color: var(--sky); }
.amber-txt, .fact b.amber-txt { color: var(--amber); }
.violet-txt, .fact b.violet-txt { color: var(--violet); }
.green-txt, .fact b.green-txt { color: var(--green); }
.stat-big { font-family: var(--font-display); font-size: 1.4rem; display: block; margin: 0.2rem 0; }
.range-header { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-2); margin-bottom: 0.25rem; }
.range-val { color: var(--teal); font-weight: 700; }

.pn-presets { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.pn-preset {
  font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-2);
  border: 1px solid var(--line-2); border-radius: 999px; padding: 0.36rem 0.82rem;
  background: var(--panel-2); cursor: pointer; transition: all 0.15s;
}
.pn-preset:hover { color: var(--teal); border-color: var(--teal); }
.pn-preset.on { color: #ffffff; background: var(--teal); border-color: var(--teal); font-weight: 700; }

.nt-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.15rem; }
@media (max-width: 860px) { .nt-grid { grid-template-columns: 1fr; } }
.tok-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr)); gap: 0.8rem; margin-top: 1rem; }

/* ------------------------------------------------- §02 Redundancy Meters */
.step-ledger { display: flex; flex-direction: column; gap: 0.35rem; margin-top: 0.85rem; }
.step-row { display: flex; align-items: center; gap: 0.55rem; font-family: var(--font-mono); font-size: 0.72rem; flex-wrap: wrap; }
.step-lbl { min-width: 3rem; color: var(--text-3); font-weight: 700; }
.step-cells { display: flex; flex-wrap: wrap; gap: 0.28rem; flex: 1; }
.scell { padding: 0.16rem 0.45rem; border-radius: 5px; font-size: 0.68rem; border: 1px solid transparent; }
.scell-waste { background: rgba(225, 29, 72, 0.14); border-color: rgba(225, 29, 72, 0.42); color: var(--rose); }
.scell-new { background: rgba(217, 119, 6, 0.16); border-color: rgba(217, 119, 6, 0.5); color: var(--amber); font-weight: 700; }
.step-cost { min-width: 5.5rem; text-align: right; font-weight: 700; }

.kv-meter-row { display: grid; grid-template-columns: minmax(9rem, 15rem) 1fr minmax(9rem, auto); gap: 0.8rem; align-items: center; margin-top: 0.65rem; font-family: var(--font-mono); font-size: 0.74rem; }
@media (max-width: 720px) { .kv-meter-row { grid-template-columns: 1fr; gap: 0.25rem; } }
.kv-barwrap { height: 14px; border-radius: 7px; background: rgba(148, 163, 184, 0.2); overflow: hidden; }
.kv-barwrap i { display: block; height: 100%; border-radius: 7px; transition: width 0.25s ease; }
.kv-barwrap i.no { background: linear-gradient(90deg, #fb7185, #e11d48); }
.kv-barwrap i.yes { background: linear-gradient(90deg, #2dd4bf, #0d9488); }

.prob-visual-grid { display: grid; grid-template-columns: 1.15fr 1fr; gap: 1rem; margin-top: 1.1rem; }
@media (max-width: 920px) { .prob-visual-grid { grid-template-columns: 1fr; } }
.prob-panel {
  display: flex; flex-direction: column; gap: 0.55rem;
  padding: 0.95rem 1rem; border-radius: 13px; border: 1px solid var(--line-2); background: var(--panel-2);
}
.prob-panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.6rem; flex-wrap: wrap; }
.prob-graph-readout {
  font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-2);
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 0.48rem 0.7rem; line-height: 1.45;
}

/* ------------------------------------------------- §03 SPECIAL VISUAL LEARNING STUDIO */
.studio-shell {
  border-radius: 18px; border: 2px solid rgba(13, 148, 136, 0.42);
  background: var(--panel); padding: 1.4rem; box-shadow: 0 18px 46px rgba(15, 23, 42, 0.08);
}
.st-top-controls {
  display: flex; flex-direction: column; gap: 0.85rem;
  padding-bottom: 1rem; border-bottom: 1px solid var(--line);
}
.st-prompt-bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem;
}
.st-custom-wrap { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.st-input {
  font-family: var(--font-mono); font-size: 0.78rem; padding: 0.42rem 0.75rem;
  border-radius: 8px; border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text);
  min-width: 265px; max-width: 100%;
}
.st-transport-row {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem;
}
.st-transport-btns { display: flex; flex-wrap: wrap; gap: 0.4rem; }

.st-timeline {
  display: flex; flex-wrap: wrap; gap: 0.45rem; margin: 1rem 0;
}
.st-tok-pill {
  display: flex; flex-direction: column; align-items: flex-start; gap: 0.12rem;
  min-width: 82px; padding: 0.45rem 0.7rem; border-radius: 10px;
  border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text);
  cursor: pointer; transition: all 0.16s; font-family: var(--font-mono);
}
.st-tok-pill .st-tok-idx { font-size: 0.62rem; color: var(--text-3); }
.st-tok-pill strong { font-size: 0.88rem; }
.st-tok-pill small { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.06em; }
.st-tok-cached { border-color: rgba(13, 148, 136, 0.55); background: rgba(13, 148, 136, 0.1); }
.st-tok-cached small { color: var(--teal); font-weight: 700; }
.st-tok-active { border: 2px solid var(--amber); background: rgba(217, 119, 6, 0.14); transform: translateY(-2px); }
.st-tok-active small { color: var(--amber); font-weight: 700; }
.st-tok-future { opacity: 0.58; }

.st-battle-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem;
}
@media (max-width: 920px) { .st-battle-grid { grid-template-columns: 1fr; } }

.st-side {
  border-radius: 14px; border: 1px solid var(--line-2); padding: 1.05rem;
  background: var(--panel-2); display: flex; flex-direction: column; gap: 0.75rem;
}
.st-naive { border-color: rgba(225, 29, 72, 0.35); }
.st-cached { border-color: rgba(13, 148, 136, 0.42); }
.st-side-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; flex-wrap: wrap; }
.st-side-head h4 { margin: 0.25rem 0 0; font-size: 0.96rem; color: var(--text); }
.st-side-sub { margin: 0; font-size: 0.8rem; color: var(--text-2); line-height: 1.48; }

.st-pill {
  display: inline-block; font-family: var(--font-mono); font-size: 0.62rem; font-weight: 700;
  letter-spacing: 0.08em; padding: 0.2rem 0.58rem; border-radius: 999px;
  border: 1px solid var(--line-2); background: var(--panel); color: var(--text);
}
.st-pill-rose { color: var(--rose); border-color: rgba(225, 29, 72, 0.45); background: rgba(225, 29, 72, 0.09); }
.st-pill-teal { color: var(--teal); border-color: rgba(13, 148, 136, 0.45); background: rgba(13, 148, 136, 0.1); }
.st-stat-badge { font-family: var(--font-mono); font-size: 0.72rem; font-weight: 700; }

.st-mat-section { overflow-x: auto; }
.st-qkv-rows { display: flex; flex-direction: column; gap: 0.28rem; min-width: 390px; }
.st-row-header, .st-m-row {
  display: grid; grid-template-columns: 4.2rem 2.7rem 2.7rem 2.7rem 1fr; gap: 0.3rem; align-items: center;
  font-family: var(--font-mono); font-size: 0.68rem;
}
.st-row-header { color: var(--text-3); font-weight: 700; padding-bottom: 0.2rem; border-bottom: 1px solid var(--line); }
.st-m-row { padding: 0.26rem 0.35rem; border-radius: 7px; border: 1px solid transparent; }
.st-row-waste { background: rgba(225, 29, 72, 0.08); border-color: rgba(225, 29, 72, 0.25); }
.st-row-new { background: rgba(217, 119, 6, 0.13); border-color: rgba(217, 119, 6, 0.45); }
.st-tok-tag { font-weight: 700; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.st-vec {
  display: inline-block; padding: 0.14rem 0.32rem; border-radius: 5px; text-align: center;
  font-family: var(--font-mono); font-size: 0.66rem; font-weight: 700; border: 1px solid var(--line);
}
.v-waste { background: rgba(225, 29, 72, 0.14); color: var(--rose); border-color: rgba(225, 29, 72, 0.35); }
.v-new { background: rgba(217, 119, 6, 0.16); color: var(--amber); border-color: rgba(217, 119, 6, 0.48); }
.v-sky { background: rgba(2, 132, 199, 0.14); color: var(--sky); border-color: rgba(2, 132, 199, 0.45); }
.v-teal { background: rgba(13, 148, 136, 0.14); color: var(--teal); border-color: rgba(13, 148, 136, 0.45); }

.st-arow { display: flex; flex-wrap: wrap; gap: 0.22rem; }
.st-acell {
  padding: 0.14rem 0.32rem; border-radius: 4px; font-family: var(--font-mono); font-size: 0.64rem;
  border: 1px solid var(--line);
}
.attn-waste { background: rgba(225, 29, 72, 0.13); border-color: rgba(225, 29, 72, 0.35); color: var(--rose); }
.attn-new { background: rgba(217, 119, 6, 0.18); border-color: rgba(217, 119, 6, 0.55); color: var(--amber); font-weight: 700; }
.attn-cached { background: rgba(13, 148, 136, 0.14); border-color: rgba(13, 148, 136, 0.45); color: var(--teal); }
.attn-mask { background: rgba(148, 163, 184, 0.12); color: var(--text-3); opacity: 0.65; }

.st-fresh-strip {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.55rem; padding: 0.6rem 0.75rem;
  border-radius: 10px; border: 1px solid rgba(217, 119, 6, 0.45); background: rgba(217, 119, 6, 0.08);
}
.st-fresh-tok { display: flex; flex-direction: column; }
.st-arrow { font-weight: 700; color: var(--text-3); }
.st-qkv-new-chips { display: flex; flex-wrap: wrap; gap: 0.32rem; }

.st-discard-q {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.45rem 0.65rem; border-radius: 8px;
  border: 1px dashed var(--line-2); background: var(--panel); font-size: 0.76rem; color: var(--text-2);
}
.st-trash-ico {
  font-family: var(--font-mono); font-size: 0.6rem; font-weight: 700; color: var(--rose);
  border: 1px solid rgba(225, 29, 72, 0.4); border-radius: 4px; padding: 0.12rem 0.32rem;
}

.st-shelves { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem; }
@media (max-width: 560px) { .st-shelves { grid-template-columns: 1fr; } }
.st-shelf {
  border-radius: 10px; border: 1px solid rgba(13, 148, 136, 0.38); background: var(--panel); padding: 0.55rem 0.65rem;
}
.st-shelf-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.4rem; font-size: 0.76rem; gap: 0.35rem; flex-wrap: wrap; }
.st-slot-list { display: flex; flex-direction: column; gap: 0.25rem; }
.st-slot {
  display: grid; grid-template-columns: 2.2rem 1fr auto; gap: 0.35rem; align-items: center;
  padding: 0.22rem 0.42rem; border-radius: 6px; font-family: var(--font-mono); font-size: 0.68rem;
  border: 1px solid transparent;
}
.slot-frozen { background: rgba(13, 148, 136, 0.1); border-color: rgba(13, 148, 136, 0.35); color: var(--teal); }
.slot-frozen small { font-size: 0.56rem; font-weight: 700; }
.slot-new { background: rgba(217, 119, 6, 0.16); border-color: rgba(217, 119, 6, 0.5); color: var(--amber); font-weight: 700; }
.slot-new small { font-size: 0.56rem; }
.slot-tok { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.st-strip-box {
  padding: 0.55rem 0.7rem; border-radius: 10px; border: 1px solid rgba(2, 132, 199, 0.38);
  background: rgba(2, 132, 199, 0.06); display: flex; flex-direction: column; gap: 0.38rem;
}
.st-strip-lbl { font-family: var(--font-mono); font-size: 0.72rem; color: var(--text); }

.st-foot-note { padding: 0.6rem 0.75rem; border-radius: 9px; font-size: 0.78rem; line-height: 1.5; margin-top: auto; }
.st-note-rose { background: rgba(225, 29, 72, 0.09); border: 1px solid rgba(225, 29, 72, 0.3); color: var(--text); }
.st-note-teal { background: rgba(13, 148, 136, 0.1); border: 1px solid rgba(13, 148, 136, 0.35); color: var(--text); }

/* Mode 2 X-Ray */
.st-xray-box { display: flex; flex-direction: column; gap: 0.9rem; }
.st-xray-top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.8rem; }
.st-xray-formula { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 10px; padding: 0.55rem 0.8rem; font-size: 0.78rem; overflow-x: auto; }
.st-xray-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); gap: 0.6rem; }
.st-xray-col {
  display: flex; flex-direction: column; align-items: flex-start; gap: 0.32rem;
  padding: 0.7rem; border-radius: 11px; border: 1px solid var(--line-2); background: var(--panel-2);
  color: var(--text); cursor: pointer; text-align: left;
}
.st-xray-col.col-sel { border: 2px solid var(--sky); background: rgba(2, 132, 199, 0.1); }
.xray-slot-tag { font-family: var(--font-mono); font-size: 0.58rem; font-weight: 700; color: var(--teal); }
.xray-kv-badges { display: flex; gap: 0.3rem; }
.xray-bar-wrap { width: 100%; height: 9px; border-radius: 5px; background: rgba(148, 163, 184, 0.25); overflow: hidden; }
.xray-bar-wrap i { display: block; height: 100%; background: var(--teal); border-radius: 5px; }
.xray-pct { font-family: var(--font-mono); font-size: 0.78rem; color: var(--teal); }

/* Mode 3 Prefill vs Decode & Mode 4 Multi-Layer */
.st-phases-wrap, .st-ml-wrap { display: flex; flex-direction: column; gap: 0.85rem; }
.st-phase-ctrl, .st-ml-ctrls { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; padding: 0.65rem 0.85rem; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); font-family: var(--font-mono); font-size: 0.75rem; }
.st-phase-banner { padding: 0.9rem 1.05rem; border-radius: 12px; border: 1px solid var(--line-2); }
.ph-prefill { background: rgba(2, 132, 199, 0.08); border-color: rgba(2, 132, 199, 0.45); }
.ph-decode { background: rgba(217, 119, 6, 0.08); border-color: rgba(217, 119, 6, 0.45); }
.st-phase-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(115px, 1fr)); gap: 0.5rem; }
.st-ph-tok { display: flex; flex-direction: column; gap: 0.15rem; padding: 0.55rem 0.65rem; border-radius: 9px; border: 1px solid var(--line-2); background: var(--panel-2); opacity: 0.55; }
.st-ph-tok.ph-done { opacity: 1; }
.st-ph-tok.ph-pre.ph-done { border-color: var(--sky); background: rgba(2, 132, 199, 0.1); }
.st-ph-tok.ph-dec.ph-done { border-color: var(--amber); background: rgba(217, 119, 6, 0.1); }

.st-ml-sl { display: flex; flex-direction: column; gap: 0.2rem; }
.st-ml-shape { display: flex; flex-direction: column; margin-left: auto; }
.st-layer-rack { display: flex; flex-direction: column; gap: 0.42rem; }
.st-layer-row {
  display: grid; grid-template-columns: 4.5rem repeat(2, minmax(0, 1fr)); gap: 0.5rem; align-items: center;
  padding: 0.42rem 0.6rem; border-radius: 9px; border: 1px solid var(--line); background: var(--panel-2);
}
@media (max-width: 680px) { .st-layer-row { grid-template-columns: 1fr; } }
.st-layer-id { font-family: var(--font-mono); font-size: 0.72rem; font-weight: 700; color: var(--text); }
.st-tank { display: flex; align-items: center; gap: 0.4rem; }
.st-tank-lbl { font-family: var(--font-mono); font-size: 0.66rem; font-weight: 700; color: var(--text-3); min-width: 2.3rem; }
.st-tank-slots { display: flex; gap: 0.22rem; flex: 1; }
.tk-slot {
  flex: 1; text-align: center; padding: 0.18rem 0.25rem; border-radius: 5px;
  font-family: var(--font-mono); font-size: 0.64rem; border: 1px solid transparent;
}
.tk-frozen { background: rgba(13, 148, 136, 0.14); border-color: rgba(13, 148, 136, 0.4); color: var(--teal); font-weight: 600; }
.tk-new { background: rgba(217, 119, 6, 0.18); border-color: rgba(217, 119, 6, 0.55); color: var(--amber); font-weight: 700; }
.tk-empty { border-style: dashed; border-color: var(--line-2); color: var(--text-3); }

/* ------------------------------------------------- §05 Phases Cards & §06 Walkthrough */
.ph-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin-top: 1rem; }
@media (max-width: 820px) { .ph-cards { grid-template-columns: 1fr; } }
.ph-card { border-radius: 13px; border: 1px solid var(--line-2); background: var(--panel-2); padding: 1.05rem; }
.ph-card.ph-sky { border-top: 3px solid var(--sky); }
.ph-card.ph-amber { border-top: 3px solid var(--amber); }
.ph-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.65rem; }
.ph-head h4 { margin: 0; font-size: 1rem; }
.ph-badge { font-family: var(--font-mono); font-size: 0.64rem; font-weight: 700; color: var(--text-2); border: 1px solid var(--line-2); border-radius: 6px; padding: 0.16rem 0.48rem; background: var(--panel); }

.wk-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
@media (max-width: 820px) { .wk-grid { grid-template-columns: 1fr; } }
.wk-panel { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 11px; padding: 1rem 1.1rem; }
.wk-line { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; padding: 0.3rem 0; border-bottom: 1px dashed var(--line); font-family: var(--font-mono); font-size: 0.76rem; flex-wrap: wrap; }
.wk-line:last-of-type { border-bottom: 0; }
.wk-k { font-weight: 700; color: var(--text-2); }
.vec-inline { font-family: var(--font-mono); font-size: 0.76rem; color: var(--text); background: var(--panel); padding: 0.16rem 0.48rem; border-radius: 6px; border: 1px solid var(--line); }
.vec-inline.vc-q { border-color: rgba(2, 132, 199, 0.45); color: var(--sky); }
.vec-inline.vc-k, .vec-inline.vc-v { border-color: rgba(217, 119, 6, 0.45); color: var(--amber); }
.vec-inline.vc-out { border-color: rgba(13, 148, 136, 0.45); color: var(--teal); }
.wk-cache-rows { display: flex; flex-direction: column; gap: 0.38rem; }
.wk-crow { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.4rem; padding: 0.38rem 0.6rem; border-radius: 7px; font-family: var(--font-mono); font-size: 0.72rem; border: 1px solid var(--line); }
.wk-crow.crow-cached { background: rgba(13, 148, 136, 0.1); border-color: rgba(13, 148, 136, 0.35); color: var(--teal); }
.wk-crow.crow-new { background: rgba(217, 119, 6, 0.14); border-color: rgba(217, 119, 6, 0.5); color: var(--amber); font-weight: 700; }
.crow-vec { color: var(--text); }
.wk-parity { margin-top: 0.7rem; padding: 0.6rem 0.78rem; border-radius: 8px; background: rgba(13, 148, 136, 0.09); border: 1px solid rgba(13, 148, 136, 0.38); font-size: 0.82rem; display: flex; flex-direction: column; gap: 0.25rem; }

/* ------------------------------------------------- §07 Architecture SVG & Inspector */
.svg-wrap { width: 100%; overflow-x: auto; }
.kv-svg { width: 100%; height: auto; display: block; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 12px; padding: 0.35rem; }
.svg-tick { font-family: var(--font-mono); font-size: 11px; fill: var(--text-2); }
.svg-lab { font-family: var(--font-mono); font-size: 12.5px; font-weight: 700; fill: var(--text); }
.svg-teal { fill: var(--teal) !important; }
.svg-amber { fill: var(--amber) !important; }
.svg-sky { fill: var(--sky) !important; }
.svg-rose { fill: var(--rose) !important; }
.arch-insp-top { display: flex; flex-wrap: wrap; align-items: center; gap: 0.65rem; }

/* ------------------------------------------------- §08 VRAM Calculator */
.mem-eq-box { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 10px; padding: 0.85rem 1.05rem; margin: 0.9rem 0; }
.mem-eq-line { display: flex; align-items: center; justify-content: space-between; gap: 0.7rem; flex-wrap: wrap; }
.vram-track { height: 22px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line-2); display: flex; overflow: hidden; margin-top: 0.35rem; }
.vram-seg-w { height: 100%; background: linear-gradient(90deg, #0284c7, #38bdf8); transition: width 0.25s ease; }
.vram-seg-kv { height: 100%; background: linear-gradient(90deg, #d97706, #fbbf24); transition: width 0.25s ease; }

/* ------------------------------------------------- §09 Pitfalls */
.pf-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; margin: 0.9rem 0 0.75rem; }
.pf-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
@media (max-width: 780px) { .pf-grid { grid-template-columns: 1fr; } }
.pf-fix { border-color: rgba(13, 148, 136, 0.45); background: rgba(13, 148, 136, 0.06); }

/* ------------------------------------------------- Tables, Code Tabs, Quiz 2x2 */
.tab-bar { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.tab {
  font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-2);
  background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 0.4rem 0.78rem; cursor: pointer; transition: all 0.15s;
}
.tab:hover { color: var(--teal); border-color: var(--teal); }
.tab[aria-selected="true"] { color: #ffffff; background: var(--teal); border-color: var(--teal); font-weight: 700; }

.cmp-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--panel); }
.cmp-table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
.cmp-table th, .cmp-table td { text-align: left; padding: 0.68rem 0.85rem; border-bottom: 1px solid var(--line); vertical-align: top; line-height: 1.5; }
.cmp-table th { font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3); background: var(--panel-2); }
.cmp-table td:first-child { color: var(--text); font-weight: 600; white-space: nowrap; }
.cmp-table td { color: var(--text-2); }
.cmp-hl { background: rgba(13, 148, 136, 0.06); color: var(--text) !important; font-weight: 500; }

.quiz-opts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.65rem; }
@media (max-width: 720px) { .quiz-opts { grid-template-columns: 1fr; } }
html.light-theme .quiz-card { background: #ffffff; border: 1px solid rgba(15, 23, 42, 0.14); box-shadow: 0 10px 28px rgba(15, 23, 42, 0.06); }
html.light-theme .quiz-q { background: #ffffff; border: 1px solid rgba(15, 23, 42, 0.14); box-shadow: 0 4px 12px rgba(15, 23, 42, 0.04); }
html.light-theme .quiz-q h4 { color: #0f172a; }
html.light-theme .fact { background: #f8fafc; border-color: rgba(15, 23, 42, 0.15); }
html.light-theme .quiz-opt { background: #f8fafc; border-color: rgba(15, 23, 42, 0.18); color: #0f172a; }
html.light-theme .quiz-opt.correct { background: rgba(5, 150, 105, 0.12); border-color: #059669; color: #065f46; }
html.light-theme .quiz-opt.wrong { background: rgba(225, 29, 72, 0.1); border-color: #e11d48; color: #9f1239; }
html.light-theme .code-lab-card { background: #ffffff; border: 1px solid rgba(15, 23, 42, 0.14); box-shadow: 0 10px 28px rgba(15, 23, 42, 0.05); }
html.light-theme .code-header { background: #f8fafc; border-bottom: 1px solid rgba(15, 23, 42, 0.12); }
#codeTabs .tab { font-size: 0.68rem; padding: 0.34rem 0.66rem; }
html.light-theme .code-pre { background: #f8fafc; color: #0f172a; border: 1px solid rgba(15, 23, 42, 0.12); }
html.light-theme .code-pre code { color: #0f172a; }
html.light-theme .code-terminal { background: #f0fdfa; color: #0f766e; border-top-color: rgba(13, 148, 136, 0.25); }
html.light-theme .btn { background: #ffffff; border-color: rgba(15, 23, 42, 0.22); color: #0f172a; }
html.light-theme .btn:hover { background: #f0fdfa; border-color: #0d9488; color: #0d9488; }
html.light-theme .btn.btn-teal { background: rgba(13, 148, 136, 0.12); border-color: #0d9488; color: #0f766e; }
html.light-theme .btn.btn-teal:hover { background: #0d9488; color: #ffffff; }

.cite-note { font-size: 0.8rem; color: var(--text-3); max-width: 82ch; line-height: 1.6; }
.cite-note a { color: var(--teal); text-decoration: underline; text-underline-offset: 3px; }
.sec-head .kicker { gap: 0.4rem; letter-spacing: 0.2em; }
.sec-head .kicker .knum { display: inline; border: 0; background: none; padding: 0; min-width: 0; height: auto; border-radius: 0; white-space: nowrap; }
.sec-head .kicker .knum::before { content: "— SECTION "; }
.sec-head .kicker .knum::after { content: " ·"; }
