/* ==========================================================================
   CAS · Lecture 32 — GPT-3 (Light Textbook Default + Dark Toggle)
   ========================================================================== */

:root {
  --gpt-emerald: #34d399;
  --gpt-cyan: #22d3ee;
  --gpt-amber: #fbbf24;
  --gpt-indigo: #818cf8;
  --gpt-rose: #fb7185;
  --gpt-surface: var(--panel-solid);
  --gpt-border: var(--line-2);
  --gpt-muted-bg: var(--panel-2);
}

html.light-theme {
  --bg0: #f6f8fc;
  --bg1: #ffffff;
  --panel: rgba(255, 255, 255, 0.96);
  --panel-2: #edf2f8;
  --panel-solid: #ffffff;
  --line: #d4deec;
  --line-2: #b5c4d9;

  --text: #0f172a;
  --text-2: #334155;
  --text-3: #64748b;

  --teal: #047857;
  --indigo: #4338ca;
  --violet: #6d28d9;
  --amber: #b45309;
  --rose: #be123c;
  --green: #047857;
  --sky: #0e7490;

  --gpt-emerald: #047857;
  --gpt-cyan: #0e7490;
  --gpt-amber: #b45309;
  --gpt-indigo: #4338ca;
  --gpt-rose: #be123c;
  --gpt-surface: #ffffff;
  --gpt-border: rgba(4, 120, 87, 0.24);
  --gpt-muted-bg: #f1f5f9;
}

html {
  scroll-padding-top: 68px;
}

.section {
  padding-block: clamp(2.8rem, 5vh, 4.2rem);
  scroll-margin-top: 64px;
}

html.light-theme body { background: var(--bg0); color: var(--text); }
html.light-theme body::before {
  background:
    radial-gradient(1000px 620px at 8% -4%, rgba(4, 120, 87, 0.08), transparent 60%),
    radial-gradient(1100px 680px at 95% 12%, rgba(14, 116, 144, 0.07), transparent 60%),
    radial-gradient(900px 760px at 50% 112%, rgba(67, 56, 202, 0.05), transparent 65%);
}
html.light-theme body::after {
  opacity: 0.52;
  background-image:
    linear-gradient(rgba(15, 23, 42, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 23, 42, 0.04) 1px, transparent 1px);
}
html.light-theme ::selection { background: rgba(4, 120, 87, 0.2); color: #0f172a; }
html.light-theme .panel { background: var(--panel); box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05), 0 8px 24px rgba(15, 23, 42, 0.03); }
html.light-theme .rail { background: rgba(255, 255, 255, 0.95); border-right-color: var(--line); }
html.light-theme .rail-toggle { background: rgba(255, 255, 255, 0.96); color: var(--text); border-color: var(--line-2); box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08); }
html.light-theme .brand-logo { background: #ffffff; border: 1px solid var(--line); }
html.light-theme .toc-panel { background: #ffffff; }
html.light-theme .btn { background: #ffffff; color: var(--text); border-color: var(--line-2); }
html.light-theme .btn:hover { background: rgba(4, 120, 87, 0.08); border-color: var(--gpt-emerald); }
html.light-theme .quiz-q { background: #f8fafc; border-color: var(--line); }

/* ------------------------------------------------ Sticky Top Navigation */
.topnav {
  position: sticky; top: 0; z-index: 90; backdrop-filter: blur(14px);
  background: rgba(5, 8, 15, 0.88); border-bottom: 1px solid var(--line);
}
html.light-theme .topnav { background: rgba(255, 255, 255, 0.94); }

.topnav-inner {
  max-width: 1440px; margin: 0 auto;
  padding: 0.54rem clamp(0.75rem, 2vw, 1.25rem);
  display: flex; align-items: center; gap: 0.65rem;
}
@media (min-width: 1100px) {
  .topnav-inner { padding-right: 6.8rem; }
  .rail-toggle { top: 0.54rem; right: 0.75rem; }
}

.topnav-brand {
  display: inline-flex; align-items: center; gap: 0.45rem;
  font-family: var(--font-display); font-weight: 700; font-size: 0.82rem;
  color: var(--text); white-space: nowrap; flex: none;
}
.topnav-brand:hover { text-decoration: none; color: var(--gpt-emerald); }
.topnav-logo { width: 26px; height: 26px; border-radius: 7px; object-fit: cover; border: 1px solid var(--line-2); }

.topnav-links {
  display: flex; align-items: center; gap: 0.14rem; flex: 1; min-width: 0;
  overflow-x: auto; scrollbar-width: none;
}
.topnav-links::-webkit-scrollbar { display: none; }
.topnav-links a {
  font-family: var(--font-mono); font-size: 0.62rem; letter-spacing: 0.02em;
  color: var(--text-2); padding: 0.28rem 0.4rem; border-radius: 6px;
  white-space: nowrap; flex: none; transition: background 0.15s, color 0.15s;
}
.topnav-links a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.topnav-links a.active { background: rgba(52, 211, 153, 0.16); color: var(--gpt-emerald); font-weight: 700; }
html.light-theme .topnav-links a.active { background: rgba(4, 120, 87, 0.11); }

.topnav-actions { display: flex; align-items: center; gap: 0.45rem; flex: none; }
.theme-btn {
  font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.05em;
  padding: 0.36rem 0.64rem; border-radius: 8px; border: 1px solid var(--line-2);
  background: var(--panel-2); color: var(--text); white-space: nowrap; flex: none;
}
.theme-btn:hover { border-color: var(--gpt-emerald); }
.btn-teal { border-color: rgba(4, 120, 87, 0.45); background: rgba(4, 120, 87, 0.11); color: var(--gpt-emerald); font-weight: 600; }
.btn-teal:hover { background: rgba(4, 120, 87, 0.2); }

/* ------------------------------------------------ Hero & Section Headers */
.hero-pill {
  display: inline-flex; align-items: center; gap: 0.55rem; font-family: var(--font-mono);
  font-size: 0.74rem; letter-spacing: 0.1em; text-transform: uppercase; padding: 0.36rem 0.85rem;
  border-radius: 999px; border: 1px solid var(--gpt-border);
  background: rgba(4, 120, 87, 0.08); color: var(--gpt-emerald); margin-bottom: 1.05rem;
}
.hero-title { font-size: clamp(2.1rem, 4.4vw, 3.35rem); line-height: 1.12; margin-bottom: 0.9rem; }
.hero-sub { font-size: clamp(1rem, 1.5vw, 1.15rem); max-width: 72ch; color: var(--text-2); }

.stats-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.75rem; margin: 1.35rem 0; }
.stat-chip { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 0.82rem 0.95rem; }
.stat-val { font-family: var(--font-mono); font-size: 1.18rem; font-weight: 700; color: var(--gpt-emerald); line-height: 1.15; }
.stat-lbl { font-size: 0.78rem; color: var(--text-2); margin-top: 0.25rem; }

.sec-head { display: flex; flex-direction: column; align-items: flex-start; gap: 0.45rem; margin-bottom: 1rem; max-width: 900px; }
.sec-num {
  display: inline-grid; place-items: center; min-width: 2.3rem; height: 1.75rem; padding-inline: 0.5rem;
  font-family: var(--font-mono); font-size: 0.76rem; font-weight: 700;
  border: 1px solid var(--gpt-border); border-radius: 7px; color: var(--gpt-emerald); background: var(--panel-2);
}
.sec-head h2 { font-size: clamp(1.6rem, 3vw, 2.3rem); font-weight: 700; margin: 0; color: var(--text); }
.sec-lead { color: var(--text-2); font-size: 1rem; max-width: 74ch; margin: 0 0 1.15rem; line-height: 1.62; }

.step-controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.8rem; margin-bottom: 1rem; }
.step-bar { display: flex; flex-wrap: wrap; gap: 0.45rem; align-items: center; }
.step-badge {
  font-family: var(--font-mono); font-size: 0.73rem; letter-spacing: 0.07em;
  padding: 0.34rem 0.72rem; border-radius: 8px; background: rgba(4, 120, 87, 0.12);
  color: var(--gpt-emerald); font-weight: 700;
}
.rail-list a .rail-num { font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-3); min-width: 1.8rem; }

/* ------------------------------------------------ Cards, Buttons & Controls */
.gpt-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.gpt-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.9rem; }

.gpt-card {
  background: var(--gpt-surface);
  color: var(--text);
  border: 1px solid var(--gpt-border);
  border-radius: 12px;
  padding: 1rem 1.1rem;
}

.gpt-badge-row { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-bottom: 0.75rem; }
.gpt-pill {
  display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.24rem 0.62rem;
  border-radius: 999px; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.03em;
  border: 1px solid var(--gpt-border); background: var(--gpt-muted-bg); color: var(--gpt-emerald);
}
.gpt-pill.cyan { color: var(--gpt-cyan); border-color: rgba(14, 116, 144, 0.35); }
.gpt-pill.amber { color: var(--gpt-amber); border-color: rgba(180, 83, 9, 0.35); }

.ctrl-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-bottom: 0.9rem; }
.ctrl-btn {
  padding: 0.44rem 0.85rem; border-radius: 8px; border: 1px solid var(--gpt-border);
  background: var(--gpt-muted-bg); color: var(--text); font-family: inherit;
  font-size: 0.82rem; font-weight: 600; cursor: pointer;
  transition: transform 0.14s ease, border-color 0.14s ease, background 0.14s ease;
}
.ctrl-btn:hover { transform: translateY(-1px); border-color: var(--gpt-emerald); }
.ctrl-btn.active { background: var(--gpt-emerald); color: #ffffff; border-color: var(--gpt-emerald); }
.ctrl-btn.cyan.active { background: var(--gpt-cyan); border-color: var(--gpt-cyan); color: #ffffff; }

/* ------------------------------------------------ Architecture Diagram */
.arch-wrap { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
.arch-svg-box { background: var(--gpt-surface); border: 1px solid var(--gpt-border); border-radius: 12px; padding: 0.75rem; overflow-x: auto; }
.arch-svg { width: 100%; min-width: 540px; height: auto; display: block; }
.arch-node { cursor: pointer; }
.arch-node:hover rect, .arch-node.active rect { stroke-width: 2.6px; filter: drop-shadow(0 3px 8px rgba(4, 120, 87, 0.25)); }

.arch-inspector {
  background: var(--gpt-surface); color: var(--text);
  border: 1px solid var(--gpt-border); border-radius: 12px; padding: 1rem 1.1rem;
}

/* ------------------------------------------------ Attention Matrix, Vectors & Tables */
.attn-matrix { display: grid; grid-template-columns: 82px repeat(4, minmax(0, 1fr)); gap: 0.35rem; margin: 0.65rem 0; align-items: center; }
.attn-cell {
  padding: 0.42rem 0.35rem; border-radius: 7px; text-align: center;
  font-family: var(--font-mono); font-size: 0.75rem;
  border: 1px solid rgba(148, 163, 184, 0.28); color: var(--text);
}
.attn-cell.active-tok { background: rgba(4, 120, 87, 0.15); color: var(--gpt-emerald); font-weight: 700; }
.attn-cell.masked-tok { background: rgba(148, 163, 184, 0.16); color: var(--text-3); opacity: 0.65; }

.vec-row {
  display: grid; grid-template-columns: 90px minmax(0, 1fr); gap: 0.55rem; align-items: center;
  padding: 0.36rem 0; border-bottom: 1px dashed rgba(148, 163, 184, 0.3);
}
.vec-row:last-child { border-bottom: none; }
.vec-lbl { font-family: var(--font-mono); font-size: 0.76rem; font-weight: 700; color: var(--gpt-emerald); white-space: nowrap; }
.vec-cells { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.vec-cell {
  font-family: var(--font-mono); font-size: 0.76rem; padding: 0.18rem 0.48rem;
  border-radius: 6px; background: var(--gpt-muted-bg); color: var(--text);
  border: 1px solid rgba(148, 163, 184, 0.32);
}

.gpt-table-wrap { overflow-x: auto; border-radius: 10px; border: 1px solid var(--gpt-border); }
.gpt-table { width: 100%; border-collapse: collapse; font-size: 0.84rem; color: var(--text); }
.gpt-table th, .gpt-table td { padding: 0.55rem 0.72rem; text-align: left; border-bottom: 1px solid rgba(148, 163, 184, 0.22); }
.gpt-table th { font-weight: 700; background: var(--gpt-muted-bg); color: var(--gpt-emerald); }
.gpt-table tr.highlight-row td { background: rgba(4, 120, 87, 0.09); font-weight: 600; }

.bar-track { width: 100%; height: 9px; border-radius: 999px; background: rgba(148, 163, 184, 0.22); overflow: hidden; margin-top: 0.25rem; }
.bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--gpt-emerald), var(--gpt-cyan)); transition: width 0.25s ease; }
.bar-fill.amber { background: linear-gradient(90deg, var(--gpt-amber), var(--gpt-indigo)); }

.trace-step-bar { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0.4rem; margin-bottom: 0.9rem; width: 100%; }
.trace-step-btn {
  padding: 0.48rem 0.4rem; border-radius: 8px; border: 1px solid var(--gpt-border);
  background: var(--gpt-muted-bg); color: var(--text); font-size: 0.75rem; font-weight: 700;
  text-align: center; cursor: pointer;
}
.trace-step-btn.active { background: var(--gpt-emerald); color: #ffffff; border-color: var(--gpt-emerald); }

/* ------------------------------------------------ Quiz 2x2 Desktop Layout & Footer */
.quiz-q { background: var(--gpt-surface); color: var(--text); border: 1px solid var(--gpt-border); border-radius: 12px; padding: 0.95rem 1.05rem; }
.quiz-q-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.45rem; }
.q-num { font-family: var(--font-mono); font-size: 0.74rem; color: var(--text-3); font-weight: 700; }
.quiz-opts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.55rem; margin-top: 0.65rem; }
.quiz-opt {
  display: flex; align-items: flex-start; gap: 0.45rem; width: 100%; text-align: left;
  padding: 0.62rem 0.78rem; border-radius: 9px; border: 1px solid var(--gpt-border);
  background: var(--gpt-muted-bg); color: var(--text); font-family: inherit; font-size: 0.85rem;
  cursor: pointer; transition: border-color 0.14s ease, transform 0.12s ease;
}
.quiz-opt:hover:not(:disabled) { border-color: var(--gpt-emerald); transform: translateY(-1px); }
.quiz-opt.correct { border-color: var(--gpt-emerald); background: rgba(4, 120, 87, 0.14); color: var(--text); font-weight: 600; }
.quiz-opt.wrong { border-color: var(--gpt-rose); background: rgba(190, 18, 60, 0.12); color: var(--text); }
.q-letter {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 1.45rem; height: 1.45rem; border-radius: 6px;
  background: rgba(4, 120, 87, 0.15); color: var(--gpt-emerald); font-weight: 800; font-size: 0.76rem;
}
.quiz-expl {
  margin: 0.65rem 0 0; padding: 0.6rem 0.8rem; border-radius: 8px;
  border-left: 3px solid var(--gpt-emerald); background: var(--gpt-muted-bg);
  color: var(--text-2); font-size: 0.83rem; line-height: 1.48;
}

.site-footer { border-top: 1px solid var(--line); background: var(--panel); padding: 2rem 0; margin-top: 2.5rem; }
.footer-inner { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 1.1rem; }
.footer-left { display: flex; align-items: center; gap: 0.85rem; }
.footer-left img { width: 42px; height: 42px; border-radius: 10px; object-fit: cover; border: 1px solid var(--line-2); }

@media (max-width: 960px) {
  .arch-wrap, .gpt-grid-3 { grid-template-columns: 1fr; }
  .trace-step-bar { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .gpt-grid-2, .quiz-opts, .trace-step-bar { grid-template-columns: 1fr; }
}
