/* ==========================================================================
   CAS · From Tokens to Vectors — textrep.css
   Lecture-04-specific visuals layered on top of the shared series styles.
   Same standard as the LSTM lecture: sticky top nav, pill badge hero,
   stat cards, comparison table, callouts.
   ========================================================================== */

/* ------------------------------------------------- sticky top nav */
.topnav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 130;
  display: flex; align-items: center; gap: 1.4rem;
  padding: 0.55rem clamp(1rem, 3vw, 2rem);
  background: rgba(5, 8, 14, 0.82); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.topnav-brand { display: flex; align-items: center; gap: 0.6rem; text-decoration: none; color: var(--text); flex: none; }
.topnav-brand:hover { text-decoration: none; }
.topnav-brand img { width: 2.1rem; height: 2.1rem; 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.85rem; letter-spacing: 0.05em; }
.topnav-brand .tb-txt small { font-family: var(--font-mono); font-size: 0.56rem; letter-spacing: 0.14em; color: var(--text-3); text-transform: uppercase; }
.topnav-links { display: flex; gap: 0.2rem; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.topnav-links::-webkit-scrollbar { display: none; }
.topnav-links a {
  font-size: 0.82rem; font-weight: 500; color: var(--text-2); text-decoration: none;
  padding: 0.35rem 0.65rem; border-radius: 7px; 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); }
.topnav-back {
  flex: none; font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase;
  border: 1px solid var(--line-2); border-radius: 8px; padding: 0.4rem 0.8rem; color: var(--text);
  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: 900px) { .topnav-links { display: none; } }

/* push content below fixed nav; progress bar sits under nav */
main { padding-top: 3.2rem; }
.scroll-progress { top: 3.2rem; }
.rail-toggle { top: 4.4rem; }
.rail { padding-top: 4.6rem; }

/* ------------------------------------------------- hero (series standard) */
.sec-hero { text-align: center; padding-top: clamp(3rem, 8vh, 5.5rem); }
.hero-badge {
  display: inline-flex; align-items: center; gap: 0.5rem;
  font-family: var(--font-mono); font-size: 0.78rem; letter-spacing: 0.06em; color: var(--teal);
  border: 1px solid rgba(94, 234, 212, 0.35); border-radius: 999px; padding: 0.42rem 1.1rem;
  background: rgba(94, 234, 212, 0.06); margin-bottom: 1.6rem;
}
.sec-hero .hero-title { margin-inline: auto; }
.sec-hero .hero-sub { margin-inline: auto; text-align: center; }

.hero-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); gap: 1rem; max-width: 980px; margin: 0 auto 2.6rem; }
.hstat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.15rem 1rem 0.95rem; text-align: center; transition: border-color 0.25s, transform 0.25s;
}
.hstat:hover { border-color: rgba(94, 234, 212, 0.45); transform: translateY(-3px); }
.hstat b { display: block; font-family: var(--font-display); font-size: 2rem; font-weight: 700; color: var(--teal); letter-spacing: -0.02em; }
.hstat span { display: block; font-family: var(--font-mono); font-size: 0.64rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-2); margin-top: 0.3rem; }
.hstat small { display: block; font-family: var(--font-mono); font-size: 0.6rem; letter-spacing: 0.08em; color: var(--text-3); margin-top: 0.15rem; }

.sec-hero .def-banner { text-align: left; margin-inline: auto; }
.sec-hero .hero-stage-grid { margin-inline: auto; text-align: left; }

/* ------------------------------------------------- hero ladder (8 rungs) */
.ladder {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.7rem;
  max-width: 1080px; margin: 2rem auto 2.4rem;
}
@media (max-width: 980px) { .ladder { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .ladder { grid-template-columns: 1fr; } }
.rung {
  position: relative; display: flex; flex-direction: column; gap: 0.15rem; text-align: left;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-s);
  padding: 0.85rem 0.95rem 0.8rem; text-decoration: none; color: var(--text);
  transition: border-color 0.2s, transform 0.2s;
}
.rung:hover { border-color: rgba(94, 234, 212, 0.55); transform: translateY(-3px); text-decoration: none; }
.rung b {
  position: absolute; top: 0.6rem; right: 0.75rem;
  font-family: var(--font-mono); font-size: 0.62rem; color: var(--teal);
  border: 1px solid rgba(94, 234, 212, 0.4); border-radius: 999px; padding: 0.1rem 0.45rem;
}
.rung span { font-family: var(--font-display); font-weight: 600; font-size: 0.95rem; letter-spacing: -0.01em; }
.rung small { font-size: 0.74rem; color: var(--text-2); line-height: 1.35; }
.rung em { font-family: var(--font-mono); font-style: normal; font-size: 0.62rem; letter-spacing: 0.06em; color: var(--rose); margin-top: 0.35rem; }

/* ------------------------------------------------- hero mini ladder card */
.hero-ladder-mini { display: flex; flex-direction: column; gap: 0.55rem; margin-top: 0.9rem; }
.hlm-row {
  display: flex; gap: 0.8rem; align-items: flex-start;
  border: 1px solid var(--line); border-radius: var(--radius-s);
  background: rgba(8, 13, 24, 0.45); padding: 0.7rem 0.9rem;
}
.hlm-row p { margin: 0; font-size: 0.84rem; line-height: 1.5; color: var(--text-2); }
.hlm-row p b { color: var(--text); }
.hlm-tag {
  flex: none; font-family: var(--font-mono); font-size: 0.66rem; letter-spacing: 0.08em; color: var(--teal);
  border: 1px solid rgba(94, 234, 212, 0.4); border-radius: 6px; padding: 0.2rem 0.5rem; margin-top: 0.1rem;
}

/* ------------------------------------------------- tab bar (TF-IDF, code) */
.tab-bar { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-bottom: 1.2rem; }
.tab {
  font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 0.55rem 0.95rem; border: 1px solid var(--line); border-radius: 999px; color: var(--text-2);
  background: rgba(8, 13, 24, 0.45); transition: all 0.18s; cursor: pointer;
}
.tab:hover { border-color: var(--line-2); color: var(--text); }
.tab[aria-selected="true"] { border-color: var(--teal); background: var(--teal); color: #05231f; font-weight: 700; }

/* ------------------------------------------------- shared demo primitives */
.tok-card, .id-card, .oh-card, .bow-card, .ng-card, .tfidf-card,
.emb-card, .sg-card, .an-card, .ft-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.4rem 1.5rem;
}
.sg-card, .an-card { margin-top: 1.2rem; }

.tok-input {
  width: 100%; box-sizing: border-box;
  background: #09101d; color: var(--text); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 0.6rem 0.8rem; font-family: var(--font-mono); font-size: 0.88rem;
  transition: border-color 0.2s;
}
.tok-input:focus { outline: none; border-color: var(--teal); }
select.tok-input { width: auto; max-width: 100%; }

.tok-controls { margin-bottom: 1.1rem; }
.tok-controls .mini { display: block; margin-bottom: 0.4rem; }
.tok-punct-lab {
  display: inline-flex; align-items: center; gap: 0.5rem; margin-top: 0.6rem;
  font-family: var(--font-mono); font-size: 0.74rem; color: var(--text-2); cursor: pointer;
}
.tok-punct-lab input { accent-color: var(--teal); }

.tok-stage { border: 1px solid var(--line); border-radius: var(--radius-s); background: rgba(5, 8, 14, 0.5); padding: 1rem 1.1rem; }
.tok-chips { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.tok-chip {
  position: relative; font-family: var(--font-mono); font-size: 0.85rem; color: var(--text);
  background: rgba(94, 234, 212, 0.08); border: 1px solid rgba(94, 234, 212, 0.35);
  border-radius: 8px; padding: 0.42rem 0.6rem 0.3rem; animation: tokPop 0.25s ease;
}
.tok-chip.punct { background: rgba(251, 191, 36, 0.08); border-color: rgba(251, 191, 36, 0.4); color: var(--amber); }
.tok-idx {
  position: absolute; top: -0.55rem; left: 0.35rem; font-style: normal;
  font-size: 0.55rem; color: var(--text-3); background: var(--bg0, #05070d);
  border: 1px solid var(--line); border-radius: 4px; padding: 0 0.25rem;
}
@keyframes tokPop { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.tok-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr)); gap: 0.8rem; margin-top: 1.1rem; }

/* ------------------------------------------------- §03 token IDs */
.id-grid { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(300px, 1fr); gap: 1.4rem; }
@media (max-width: 860px) { .id-grid { grid-template-columns: 1fr; } }
.id-table-head { display: flex; justify-content: space-between; align-items: center; gap: 0.8rem; margin-bottom: 0.6rem; flex-wrap: wrap; }
.id-table { display: flex; flex-direction: column; gap: 0.35rem; }
.id-row {
  display: grid; grid-template-columns: 1fr auto auto; gap: 0.8rem; align-items: center;
  border: 1px solid var(--line); border-radius: 8px; background: rgba(8, 13, 24, 0.45);
  padding: 0.45rem 0.8rem;
}
.id-word { font-family: var(--font-mono); font-size: 0.88rem; color: var(--text); }
.id-arrow { color: var(--text-3); font-family: var(--font-mono); font-size: 0.8rem; }
.id-val {
  font-family: var(--font-mono); font-size: 0.82rem; font-weight: 700; color: var(--teal);
  border: 1px solid rgba(94, 234, 212, 0.4); border-radius: 6px; padding: 0.12rem 0.5rem;
  background: rgba(94, 234, 212, 0.07); display: inline-block;
}
.id-encoded { font-size: 1rem; line-height: 2.2; margin: 0; }
.id-lookup { margin-top: 1.2rem; }
.id-lookup .mini { display: block; margin-bottom: 0.4rem; }
.id-lookup-out { font-family: var(--font-mono); font-size: 0.8rem; color: var(--text-3); margin: 0.55rem 0 0; }
.id-lookup-out.ok { color: var(--teal); }
.id-lookup-out.bad { color: var(--rose); }
.flash { animation: idFlash 0.6s ease; }
@keyframes idFlash { 0% { opacity: 0.2; transform: translateY(3px); } 100% { opacity: 1; transform: none; } }

/* ------------------------------------------------- §04 one-hot */
.oh-top { display: grid; grid-template-columns: minmax(180px, 0.6fr) minmax(320px, 1.4fr); gap: 1.2rem; align-items: start; }
@media (max-width: 860px) { .oh-top { grid-template-columns: 1fr; } }
.oh-top .mini { display: block; margin-bottom: 0.4rem; }
.oh-grid { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.oh-col {
  display: flex; flex-direction: column; align-items: center; gap: 0.3rem;
  border: 1px solid var(--line); border-radius: 8px; background: rgba(8, 13, 24, 0.45);
  padding: 0.55rem 0.6rem; min-width: 4.2rem; transition: border-color 0.25s, background 0.25s;
}
.oh-col.on { border-color: var(--teal); background: rgba(94, 234, 212, 0.1); box-shadow: 0 0 14px rgba(94, 234, 212, 0.15); }
.oh-bit { font-family: var(--font-mono); font-size: 1.15rem; font-weight: 700; color: var(--text-3); }
.oh-col.on .oh-bit { color: var(--teal); }
.oh-word { font-family: var(--font-mono); font-size: 0.62rem; letter-spacing: 0.04em; color: var(--text-2); }
.oh-scale { margin-top: 1.3rem; border-top: 1px dashed var(--line); padding-top: 1.1rem; }
.oh-dist { margin-top: 1.3rem; border-top: 1px dashed var(--line); padding-top: 1.1rem; }
.oh-dist-row { display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap; }

/* ------------------------------------------------- §05 bag of words */
.bow-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.1rem; }
@media (max-width: 700px) { .bow-inputs { grid-template-columns: 1fr; } }
.bow-inputs .mini { display: block; margin-bottom: 0.4rem; }
.bow-stage-wrap { border: 1px solid var(--line); border-radius: var(--radius-s); background: rgba(5, 8, 14, 0.5); padding: 1rem 1.1rem; overflow-x: auto; }
.bow-stage { display: flex; flex-direction: column; gap: 0.4rem; min-width: fit-content; }
.bow-row { display: flex; gap: 0.4rem; align-items: center; }
.bow-lab { flex: none; width: 4.6rem; font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.08em; color: var(--text-3); text-transform: uppercase; }
.bow-word {
  flex: none; min-width: 3.6rem; text-align: center;
  font-family: var(--font-mono); font-size: 0.68rem; color: var(--text-2);
  border-bottom: 1px dashed var(--line-2); padding-bottom: 0.25rem;
}
.bow-cell {
  flex: none; min-width: 3.6rem; text-align: center;
  font-family: var(--font-mono); font-size: 0.95rem; font-weight: 700; color: var(--text-3);
  border: 1px solid var(--line); border-radius: 7px; background: rgba(8, 13, 24, 0.45); padding: 0.4rem 0;
  transition: all 0.2s;
}
.bow-cell.on { color: var(--teal); border-color: rgba(94, 234, 212, 0.45); background: rgba(94, 234, 212, 0.09); }
#bowVerdict { margin-top: 1.1rem; }

/* ------------------------------------------------- §06 n-grams */
.ng-chip {
  font-family: var(--font-mono); font-size: 0.8rem; color: var(--sky);
  background: rgba(56, 189, 248, 0.08); border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 8px; padding: 0.35rem 0.6rem; animation: tokPop 0.25s ease;
}
.ng-explosion { margin-top: 1.3rem; border-top: 1px dashed var(--line); padding-top: 1.1rem; }
.ng-bars { display: flex; flex-direction: column; gap: 0.55rem; }
.ng-bar-row { display: grid; grid-template-columns: 5.4rem 1fr 3.2rem; gap: 0.8rem; align-items: center; }
.ng-bar-lab { font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.08em; color: var(--text-2); text-transform: uppercase; }
.ng-bar-track { height: 14px; border-radius: 5px; background: rgba(148, 163, 184, 0.12); overflow: hidden; }
.ng-bar-fill { display: block; height: 100%; border-radius: 5px; background: linear-gradient(90deg, rgba(56, 189, 248, 0.5), rgba(251, 113, 133, 0.75)); transition: width 0.6s cubic-bezier(0.2, 0.8, 0.2, 1); }
.ng-bar-val { font-family: var(--font-mono); font-size: 0.82rem; font-weight: 700; color: var(--text); text-align: right; }

/* ------------------------------------------------- §07 TF-IDF */
.tf-table { display: flex; flex-direction: column; gap: 0.3rem; }
.tf-row {
  display: grid; grid-template-columns: 1.2fr 0.6fr 0.9fr 0.9fr 1.6fr; gap: 0.7rem; align-items: center;
  border: 1px solid var(--line); border-radius: 8px; background: rgba(8, 13, 24, 0.45);
  padding: 0.45rem 0.8rem;
}
.tf-row.head { background: none; border-color: transparent; padding-bottom: 0.1rem; }
.tf-row.head span { font-family: var(--font-mono); font-size: 0.62rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-3); }
.tf-word { font-family: var(--font-mono); font-size: 0.88rem; color: var(--text); }
.tf-num { font-family: var(--font-mono); font-size: 0.8rem; color: var(--text-2); }
.tf-score { position: relative; display: flex; align-items: center; height: 1.5rem; border-radius: 6px; background: rgba(148, 163, 184, 0.1); overflow: hidden; }
.tf-fill { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, rgba(94, 234, 212, 0.25), rgba(94, 234, 212, 0.6)); }
.tf-score b { position: relative; padding-left: 0.55rem; font-family: var(--font-mono); font-size: 0.78rem; color: var(--text); }
@media (max-width: 640px) { .tf-row { grid-template-columns: 1fr 0.5fr 0.8fr 0.8fr 1.3fr; gap: 0.4rem; padding: 0.4rem 0.55rem; } }

/* ------------------------------------------------- §08 embeddings */
.emb-stage { border: 1px solid var(--line); border-radius: var(--radius-s); background: rgba(5, 8, 14, 0.55); padding: 0.5rem; }
.emb-svg { width: 100%; height: auto; display: block; }
.emb-grid { stroke: rgba(148, 163, 184, 0.09); stroke-width: 1; }
.emb-word { cursor: pointer; outline: none; }
.emb-dot { transition: r 0.2s, opacity 0.2s; }
.emb-word .emb-lab { font-family: var(--font-mono); font-size: 12px; fill: var(--text-2); transition: fill 0.2s; }
.emb-word.sel .emb-dot { r: 9; stroke: #fff; stroke-width: 1.5; }
.emb-word.sel .emb-lab { fill: #fff; font-weight: 700; }
.emb-word.near .emb-dot { stroke: var(--teal); stroke-width: 2; }
.emb-word.near .emb-lab { fill: var(--teal); }
.emb-info { margin-top: 0.9rem; border: 1px solid var(--line); border-radius: var(--radius-s); background: rgba(8, 13, 24, 0.45); padding: 0.9rem 1.1rem; min-height: 3.4rem; font-size: 0.92rem; color: var(--text-2); line-height: 1.6; }

.sg-stage { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.9rem; }
.sg-word {
  font-family: var(--font-mono); font-size: 0.88rem; color: var(--text-3);
  border: 1px solid var(--line); border-radius: 8px; padding: 0.42rem 0.7rem;
  background: rgba(8, 13, 24, 0.45); transition: all 0.25s;
}
.sg-word.ctx { color: var(--sky); border-color: rgba(56, 189, 248, 0.45); background: rgba(56, 189, 248, 0.08); }
.sg-word.center { color: #05231f; font-weight: 700; background: var(--teal); border-color: var(--teal); }

.an-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.9rem; }
.an-stage { border: 1px solid var(--line); border-radius: var(--radius-s); background: rgba(5, 8, 14, 0.55); padding: 0.5rem; }
.an-arrow { stroke: var(--teal); stroke-width: 2.2; }
.an-arrow.dash { stroke-dasharray: 6 4; opacity: 0.85; }
.an-target { animation: anPulse 1.6s ease-in-out infinite; }
@keyframes anPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
#anOut { margin-top: 0.9rem; }

/* ------------------------------------------------- §09 fasttext */
.ft-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 700px) { .ft-inputs { grid-template-columns: 1fr; } }
.ft-inputs .mini { display: block; margin-bottom: 0.4rem; }
.ft-pairs { display: flex; flex-wrap: wrap; gap: 0.45rem; margin: 0.9rem 0 1.1rem; }
.ft-stage-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem; }
@media (max-width: 860px) { .ft-stage-grid { grid-template-columns: 1fr; } }
.ft-chip {
  font-family: var(--font-mono); font-size: 0.78rem; color: var(--text-2);
  background: rgba(8, 13, 24, 0.5); border: 1px solid var(--line);
  border-radius: 7px; padding: 0.32rem 0.55rem; transition: all 0.2s;
}
.ft-chip.shared {
  color: var(--green); border-color: rgba(52, 211, 153, 0.55); background: rgba(52, 211, 153, 0.1);
  box-shadow: 0 0 10px rgba(52, 211, 153, 0.12);
}

/* ------------------------------------------------- comparison table */
.cmp-wrap { margin-top: 1.2rem; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.cmp-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.cmp-table th { text-align: left; font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-3); padding: 0.85rem 1.1rem; background: rgba(148, 163, 184, 0.06); border-bottom: 1px solid var(--line-2); }
.cmp-table th.cmp-hl { color: var(--teal); }
.cmp-table td { padding: 0.75rem 1.1rem; border-bottom: 1px solid var(--line); color: var(--text-2); vertical-align: top; }
.cmp-table tr:last-child td { border-bottom: 0; }
.cmp-table td:first-child { color: var(--text-3); font-size: 0.82rem; }
.cmp-table td.cmp-hl { color: var(--text); background: rgba(94, 234, 212, 0.045); }
.cmp-table td.cmp-hl b { color: var(--teal); }
.cmp-table td .mono { font-size: 0.72rem; }
.cmp-table td.cmp-dim { color: var(--text-3); }
@media (max-width: 640px) { .cmp-table { font-size: 0.8rem; } .cmp-table th, .cmp-table td { padding: 0.6rem 0.7rem; } }

/* ------------------------------------------------- footer */
.cite-note { font-size: 0.8rem; color: var(--text-3); max-width: 70ch; line-height: 1.6; }

/* ------------------------------------ series-standard section kickers */
.sec-head .kicker { gap: 0.4rem; letter-spacing: 0.22em; }
.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: " ·"; }

/* ------------------------------------------------- static print mode */
html.static .tok-chip, html.static .ng-chip, html.static .an-target,
html.static .ng-bar-fill, html.static .emb-dot { animation: none; transition: none; }
