/* ==========================================================================
   CAS · ELECTRA — Replaced Token Detection (Clark et al., ICLR 2020)
   electra-replaced-token.css : Light Textbook (default) + Dark Theme,
   sticky nav, pill buttons, Dual-Network Architecture SVG, trace & chart UI.
   ========================================================================== */

/* ------------------------------------------------ Light Textbook Theme */
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: #0d9488;
  --indigo: #4f46e5;
  --violet: #7c3aed;
  --amber: #b45309;
  --rose: #e11d48;
  --green: #047857;
  --sky: #0284c7;
  --orange: #c2410c;
}

html.light-theme body {
  background: var(--bg0);
  color: var(--text);
}

html.light-theme body::before {
  background:
    radial-gradient(1000px 620px at 8% -4%, rgba(13, 148, 136, 0.08), transparent 60%),
    radial-gradient(1100px 680px at 95% 12%, rgba(79, 70, 229, 0.07), transparent 60%),
    radial-gradient(900px 760px at 50% 112%, rgba(2, 132, 199, 0.05), transparent 65%);
}

html.light-theme body::after {
  opacity: 0.55;
  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(13, 148, 136, 0.22);
  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.94);
  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 .formula {
  background: #f1f5f9;
  color: #0f172a;
  border-color: var(--line-2);
}

html.light-theme .formula b {
  color: var(--teal);
}

html.light-theme .warn-banner {
  background: rgba(225, 29, 72, 0.07);
  border-color: rgba(225, 29, 72, 0.35);
  color: #881337;
}

html.light-theme .good-banner {
  background: rgba(4, 120, 87, 0.07);
  border-color: rgba(4, 120, 87, 0.35);
  color: #064e3b;
}

html.light-theme .note-card {
  background: rgba(180, 83, 9, 0.06);
  border-color: rgba(180, 83, 9, 0.28);
}

html.light-theme .def-banner {
  background: linear-gradient(90deg, rgba(13, 148, 136, 0.08), rgba(79, 70, 229, 0.04));
  border-color: rgba(13, 148, 136, 0.35);
}

html.light-theme .cap-tag {
  background: #ffffff;
  color: var(--text-2);
}

html.light-theme .btn {
  background: #ffffff;
  color: var(--text);
  border-color: var(--line-2);
}

html.light-theme .btn:hover {
  background: rgba(13, 148, 136, 0.08);
  border-color: var(--teal);
}

html.light-theme .tab {
  background: #ffffff;
  color: var(--text-2);
}

html.light-theme .tab[aria-selected="true"] {
  background: var(--teal);
  color: #ffffff;
  border-color: var(--teal);
}

html.light-theme .code-lab-card {
  background: #0f172a;
  border-color: var(--line-2);
}

html.light-theme .code-header {
  background: #1e293b;
  border-bottom-color: #334155;
}

html.light-theme .code-tab-btn {
  background: #0f172a;
  color: #cbd5e1;
  border-color: #475569;
}

html.light-theme .code-tab-btn.active {
  background: #0d9488;
  color: #ffffff;
  border-color: #0d9488;
}

html.light-theme .quiz-q {
  background: #f8fafc;
  border-color: var(--line);
}

html.light-theme .quiz-opt {
  background: #ffffff;
  color: var(--text-2);
  border-color: var(--line-2);
}

html.light-theme .quiz-opt:hover {
  color: var(--text);
  border-color: var(--teal);
}

html.light-theme .quiz-opt.correct {
  background: rgba(4, 120, 87, 0.10);
  border-color: #047857;
  color: #064e3b;
}

html.light-theme .quiz-opt.wrong {
  background: rgba(225, 29, 72, 0.09);
  border-color: #e11d48;
  color: #881337;
}

html.light-theme .hist-item {
  background: #ffffff;
}

html.light-theme .hist-item:hover {
  background: #f8fafc;
}

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

html.light-theme .topnav {
  background: rgba(255, 255, 255, 0.92);
}

.topnav-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0.56rem 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.56rem;
    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(--teal);
}

.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.12rem;
  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.63rem;
  letter-spacing: 0.02em;
  color: var(--text-2);
  padding: 0.28rem 0.38rem;
  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(94, 234, 212, 0.14);
  color: var(--teal);
  font-weight: 700;
}

html.light-theme .topnav-links a.active {
  background: rgba(13, 148, 136, 0.12);
}

.topnav-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: none;
}

.theme-btn {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  padding: 0.4rem 0.72rem;
  border-radius: 8px;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--text);
  white-space: nowrap;
  flex: none;
  transition: border-color 0.15s, background 0.15s;
}

.theme-btn:hover {
  border-color: var(--teal);
}

.btn-teal {
  border-color: rgba(13, 148, 136, 0.55);
  background: rgba(13, 148, 136, 0.12);
  color: var(--teal);
  font-weight: 600;
}

.btn-teal:hover {
  background: rgba(13, 148, 136, 0.22);
}

/* ------------------------------------------------ Hero & Overview */
.sec-hero-elc {
  padding-top: clamp(2.8rem, 6vh, 4.4rem);
  padding-bottom: clamp(2.5rem, 5vh, 4rem);
}

.hero-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.36rem 0.85rem;
  border-radius: 999px;
  border: 1px solid rgba(13, 148, 136, 0.45);
  background: rgba(13, 148, 136, 0.08);
  color: var(--teal);
  margin-bottom: 1.1rem;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin: 1.35rem 0 1.6rem;
}

.stats-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 0.75rem;
  margin: 1.5rem 0;
}

.stat-chip {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem 1rem;
}

.stat-val {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--teal);
  line-height: 1.15;
}

.stat-lbl {
  font-size: 0.78rem;
  color: var(--text-2);
  margin-top: 0.25rem;
}

.hero-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(275px, 100%), 1fr));
  gap: 0.9rem;
  margin-top: 1.2rem;
}

.elc-finding-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.05rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.fc-tag {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--indigo);
}

.fc-metric {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
}

.fc-desc {
  font-size: 0.88rem;
  color: var(--text-2);
  margin: 0;
  line-height: 1.55;
}

.elc-card-box {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem 1.15rem;
}

.callout-box {
  border-left: 3px solid var(--teal);
  background: rgba(13, 148, 136, 0.06);
  border-radius: 0 10px 10px 0;
  padding: 0.85rem 1.05rem;
  font-size: 0.92rem;
  color: var(--text-2);
  margin-top: 0.9rem;
}

.callout-box strong {
  color: var(--text);
}

/* ------------------------------------------------ Pill Presets & Steppers */
.pn-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}

.pn-preset {
  font-family: var(--font-mono);
  font-size: 0.73rem;
  letter-spacing: 0.06em;
  padding: 0.44rem 0.82rem;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.15s ease;
}

.pn-preset:hover {
  border-color: var(--teal);
  color: var(--text);
}

.pn-preset.on {
  background: var(--teal);
  border-color: var(--teal);
  color: #042220;
  font-weight: 700;
}

html.light-theme .pn-preset {
  background: #ffffff;
}

html.light-theme .pn-preset.on {
  background: #0d9488;
  border-color: #0d9488;
  color: #ffffff;
}

.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.74rem;
  letter-spacing: 0.08em;
  padding: 0.34rem 0.75rem;
  border-radius: 8px;
  background: rgba(13, 148, 136, 0.12);
  color: var(--teal);
  font-weight: 700;
}

/* ------------------------------------------------ Evolution Strip */
.evo-track {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 0.7rem;
  margin-top: 1rem;
}

.evo-node {
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem 0.95rem;
  background: var(--panel-2);
  transition: border-color 0.15s, background 0.15s;
}

.evo-node:hover {
  border-color: var(--teal);
}

.evo-node.active {
  border-color: var(--teal);
  background: rgba(13, 148, 136, 0.1);
}

.evo-yr {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-3);
}

.evo-node.active .evo-yr {
  color: var(--teal);
  font-weight: 700;
}

.evo-name {
  font-weight: 700;
  font-size: 0.94rem;
  color: var(--text);
  margin: 0.15rem 0;
}

.evo-obj {
  font-size: 0.78rem;
  color: var(--text-2);
}

/* ------------------------------------------------ Token Chips & RTD Cells */
.tok-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.tok-card {
  border: 1px solid var(--line-2);
  border-radius: 10px;
  padding: 0.5rem 0.7rem;
  min-width: 78px;
  background: var(--panel-solid);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.tok-card.is-mask {
  border-color: var(--amber);
  background: rgba(180, 83, 9, 0.10);
}

.tok-card.is-replaced {
  border-color: var(--rose);
  background: rgba(225, 29, 72, 0.10);
}

.tok-card.is-orig {
  border-color: var(--green);
  background: rgba(4, 120, 87, 0.08);
}

.tok-card.is-lucky {
  border-color: var(--indigo);
  background: rgba(79, 70, 229, 0.10);
}

.tok-word {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text);
}

.tok-badge {
  font-family: var(--font-mono);
  font-size: 0.63rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.12rem 0.35rem;
  border-radius: 5px;
}

.tok-tag-orig {
  background: rgba(4, 120, 87, 0.15);
  color: var(--green);
}

.tok-tag-repl {
  background: rgba(225, 29, 72, 0.16);
  color: var(--rose);
}

.tok-tag-mask {
  background: rgba(180, 83, 9, 0.16);
  color: var(--amber);
}

.tok-tag-lucky {
  background: rgba(79, 70, 229, 0.16);
  color: var(--indigo);
}

.tok-tag-skip {
  background: rgba(100, 116, 139, 0.14);
  color: var(--text-3);
}

.tok-prob {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-2);
}

/* ------------------------------------------------ Dual-Network Architecture Diagram */
.elc-arch-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(275px, 0.78fr);
  gap: 1.05rem;
  align-items: start;
}

@media (max-width: 980px) {
  .elc-arch-shell {
    grid-template-columns: 1fr;
  }
}

.elc-arch-stage {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.75rem;
  overflow: hidden;
}

.elc-arch-svg {
  width: 100%;
  min-width: 0;
  height: auto;
  display: block;
}

.elc-blk {
  cursor: pointer;
  transition: transform 0.14s ease, filter 0.14s ease;
}

.elc-blk .elc-box {
  stroke-width: 1.5;
  transition: stroke-width 0.15s, fill-opacity 0.15s, filter 0.15s;
}

.elc-blk:hover .elc-box {
  stroke-width: 2.3;
  filter: drop-shadow(0 3px 8px rgba(13, 148, 136, 0.2));
}

.elc-blk.active .elc-box {
  stroke-width: 2.8;
  filter: drop-shadow(0 4px 12px rgba(13, 148, 136, 0.34));
}

.elc-inspector {
  background: var(--panel-solid);
  border: 1px solid var(--line-2);
  border-radius: 14px;
  padding: 1.15rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.elc-insp-stage {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--teal);
}

.elc-insp-title {
  font-size: 1.2rem;
  margin: 0;
  color: var(--text);
}

.elc-insp-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

.elc-insp-chip {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0.5rem 0.65rem;
}

.elc-insp-chip .lbl {
  font-family: var(--font-mono);
  font-size: 0.63rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
}

.elc-insp-chip .val {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 0.12rem;
}

.elc-insp-eq {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0.65rem 0.8rem;
  color: var(--indigo);
  overflow-x: auto;
}

/* ------------------------------------------------ Charts & Data Tables */
.chart-box {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem 1.15rem;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(140px, 195px) 1fr 68px;
  align-items: center;
  gap: 0.7rem;
  margin: 0.45rem 0;
  font-size: 0.84rem;
}

.bar-lbl {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--text);
  font-weight: 600;
}

.bar-track {
  height: 16px;
  background: rgba(148, 163, 184, 0.18);
  border-radius: 6px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 6px;
  transition: width 0.3s ease;
}

.bar-val {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  text-align: right;
  color: var(--text);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.data-table th {
  font-family: var(--font-mono);
  font-size: 0.69rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
  text-align: left;
  padding: 0.55rem 0.6rem;
  border-bottom: 1.5px solid var(--line-2);
}

.data-table td {
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--line);
  color: var(--text-2);
}

.data-table td.num {
  font-family: var(--font-mono);
  font-size: 0.79rem;
  color: var(--text);
}

.data-table tr.row-hl {
  background: rgba(13, 148, 136, 0.09);
}

.data-table tr.row-hl td {
  color: var(--text);
  font-weight: 600;
}

/* ------------------------------------------------ 3D Trace Matrices */
.trace-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(265px, 100%), 1fr));
  gap: 0.9rem;
}

.vec-card {
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem 0.95rem;
}

.vec-card-title {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--teal);
  margin-bottom: 0.55rem;
}

.vec-row {
  display: grid;
  grid-template-columns: 36px 1fr 78px;
  align-items: center;
  gap: 0.45rem;
  margin: 0.25rem 0;
  font-family: var(--font-mono);
  font-size: 0.72rem;
}

.vec-bar-wrap {
  height: 10px;
  background: rgba(148, 163, 184, 0.18);
  border-radius: 4px;
  overflow: hidden;
}

.vec-bar {
  height: 100%;
  border-radius: 4px;
}

.vec-num {
  text-align: right;
  color: var(--text);
  font-weight: 600;
}

.loss-equation-card {
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  padding: 0.95rem 1.1rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text);
  margin-top: 0.9rem;
}

/* ------------------------------------------------ Grid Helpers & Dynasty */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(360px, 100%), 1fr));
  gap: 1.1rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));
  gap: 0.95rem;
}

.dyn-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(205px, 1fr));
  gap: 0.75rem;
}

.dyn-card {
  text-align: left;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem 0.95rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.dyn-card:hover {
  border-color: var(--teal);
}

.dyn-card.active {
  border-color: var(--teal);
  background: rgba(13, 148, 136, 0.11);
}

/* ------------------------------------------------ Footer */
.site-footer {
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 2.2rem 0;
  margin-top: 3rem;
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1.2rem;
}

.footer-left {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.footer-left img {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--line-2);
}

@media (max-width: 720px) {
  .bar-row {
    grid-template-columns: 120px 1fr 56px;
  }
  .elc-insp-grid {
    grid-template-columns: 1fr;
  }
}
