/* ══════════════════════════════════════════════════════
   Study Site Design System
   Extracted from gate-reversibility-v2.html
   IBM Plex + warm palette
   ══════════════════════════════════════════════════════ */

/* ── CSS VARIABLES ── */
:root {
  --bg: #faf8f5;
  --text: #2d2a26;
  --good: #1a6b5a;
  --urgent: #c4621a;
  --info: #4a5f7a;
  --neutral: #9a9590;
  --bg-subtle: #f0ece7;
  --bg-card: #ffffff;
  --border: #e0dbd5;
  --good-light: #e8f5f0;
  --urgent-light: #fdf0e6;
  --info-light: #edf1f5;
  --neutral-light: #f5f3f1;
  --warn: #a07828;
  --warn-light: #faf5eb;
  --automata: #b5453a;
  --automata-light: #faf0ef;
  --quantum: #3a6fb5;
  --quantum-light: #edf3fa;
}

/* ── RESET + BODY ── */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'IBM Plex Sans', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  padding: 2.5rem 1.5rem;
}

/* ── CONTAINER ── */
.container {
  max-width: 920px;
  margin: 0 auto;
}

/* ── HEADER ── */
.header {
  text-align: center;
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.header-title {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 0.2rem;
}
.header-subtitle {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.82rem;
  color: var(--neutral);
  font-weight: 400;
  letter-spacing: 0.04em;
}

/* ── SECTION TITLES ── */
.section {
  margin-bottom: 2.2rem;
}
.section-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--neutral);
  margin-top: 2.5rem;
  margin-bottom: 0.8rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
}

/* ── PROSE ── */
p {
  font-size: 0.92rem;
  margin-bottom: 0.9rem;
}
p strong { font-weight: 600; }

a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }

h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-top: 1.4rem;
  margin-bottom: 0.6rem;
}

ul, ol { margin-bottom: 0.9rem; padding-left: 1.4rem; font-size: 0.92rem; }
li { margin-bottom: 0.3rem; }

code {
  background: var(--bg-subtle);
  padding: 2px 6px;
  border-radius: 3px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.85em;
}

pre {
  background: var(--bg-subtle);
  padding: 1rem;
  border-radius: 6px;
  overflow-x: auto;
  margin: 1rem 0;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.82rem;
  line-height: 1.6;
}

/* ── INSIGHT BOXES ── */
.box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.1rem 1.3rem;
  margin: 1rem 0;
}
.box.good {
  background: var(--good-light);
  border-color: var(--good);
  border-left: 3px solid var(--good);
}
.box.urgent {
  background: var(--urgent-light);
  border-color: var(--urgent);
  border-left: 3px solid var(--urgent);
}
.box.info {
  background: var(--info-light);
  border-color: var(--info);
  border-left: 3px solid var(--info);
}
.box.warn {
  background: var(--warn-light);
  border-color: var(--warn);
  border-left: 3px solid var(--warn);
}
.box-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.5rem;
}
.box.good .box-title { color: var(--good); }
.box.urgent .box-title { color: var(--urgent); }
.box.info .box-title { color: var(--info); }
.box.warn .box-title { color: var(--warn); }
.box ol, .box ul { margin: 0.4rem 0 0 1.2rem; font-size: 0.88rem; }
.box li { margin-bottom: 0.3rem; }
.box p { font-size: 0.88rem; margin-bottom: 0.5rem; }
.box p:last-child { margin-bottom: 0; }

/* ── MATH DISPLAY ── */
.math-block {
  background: var(--bg-subtle);
  border-radius: 6px;
  padding: 1rem 1.3rem;
  margin: 1rem 0;
  overflow-x: auto;
}
.math-block p { margin-bottom: 0.5rem; font-size: 0.88rem; }
.math-block p:last-child { margin-bottom: 0; }

.dim {
  color: var(--neutral);
  font-size: 0.82rem;
}

/* ── TABLES ── */
.table-wrap {
  margin: 1rem 0;
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 550px;
}
th {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--neutral);
  text-align: center;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 0.55rem 0.6rem;
  font-size: 0.82rem;
  border-bottom: 1px solid var(--bg-subtle);
  text-align: center;
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
td.bad { color: var(--urgent); font-weight: 600; }
td.good { color: var(--good); font-weight: 600; }
td.warn { color: var(--warn); font-weight: 600; }

/* Simple table variant (for content pages with standard tables) */
table.simple {
  min-width: auto;
  border-collapse: collapse;
}
table.simple th,
table.simple td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  font-size: 0.88rem;
  text-align: center;
}
table.simple th {
  background: var(--bg-subtle);
  font-size: 0.72rem;
}

/* ── INTERACTIVE SECTION ── */
.interactive {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  margin: 1rem 0;
}
.interactive h3 {
  color: var(--info);
  margin-top: 0;
}

/* ── BUTTONS ── */
.btn {
  padding: 0.4rem 1rem;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 0.88rem;
  font-weight: 500;
  transition: all 0.15s;
}
.btn:hover {
  background: var(--bg-subtle);
  border-color: var(--neutral);
}
.btn.primary {
  background: var(--info);
  color: white;
  border-color: var(--info);
}
.btn.primary:hover {
  background: var(--text);
  border-color: var(--text);
}

.btn-row {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.2rem;
}

.gate-btn {
  padding: 0.35rem 0.9rem;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.78rem;
  font-weight: 500;
  transition: all 0.15s;
}
.gate-btn:hover {
  background: var(--bg-subtle);
  border-color: var(--neutral);
}
.gate-btn.active-bad {
  background: var(--urgent);
  color: white;
  border-color: var(--urgent);
}
.gate-btn.active-warn {
  background: var(--warn);
  color: white;
  border-color: var(--warn);
}
.gate-btn.active-good {
  background: var(--good);
  color: white;
  border-color: var(--good);
}

/* ── RESULT BOX ── */
.result-box {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  padding: 0.8rem 1rem;
  margin-top: 0.8rem;
  border-radius: 6px;
  min-height: 40px;
  font-size: 0.88rem;
  white-space: pre-line;
  font-family: 'IBM Plex Mono', monospace;
}

/* ── NAV (prev/next footer) ── */
.nav {
  margin-top: 2.5rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  font-size: 0.88rem;
}
.nav a {
  color: var(--info);
  text-decoration: none;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.82rem;
  font-weight: 500;
}
.nav a:hover {
  text-decoration: underline;
}

/* ── TOPIC CARDS (for index pages) ── */
.topic-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.1rem 1.3rem;
  margin: 0.8rem 0;
  transition: box-shadow 0.2s, border-color 0.2s;
}
.topic-card:hover {
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  border-color: var(--neutral);
}
.topic-card h3 {
  margin-top: 0;
  margin-bottom: 0.4rem;
}
a.topic-card {
  display: block;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}
a.topic-card:hover {
  text-decoration: none;
}
.topic-card h3 a {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}
.topic-card h3 a:hover {
  color: var(--info);
  text-decoration: none;
}
.topic-card .week {
  display: inline-block;
  background: var(--info-light);
  color: var(--info);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  margin-right: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
/* Course-scoped card colors */
.course-automata .topic-card {
  border-left: 3px solid var(--automata);
}
.course-automata .topic-card:hover {
  border-color: var(--automata);
  box-shadow: 0 2px 12px rgba(181, 69, 58, 0.08);
}
.course-automata .topic-card .week {
  background: var(--automata-light);
  color: var(--automata);
}
.course-quantum .topic-card {
  border-left: 3px solid var(--quantum);
}
.course-quantum .topic-card:hover {
  border-color: var(--quantum);
  box-shadow: 0 2px 12px rgba(58, 111, 181, 0.08);
}
.course-quantum .topic-card .week {
  background: var(--quantum-light);
  color: var(--quantum);
}

.topic-card .desc {
  color: var(--neutral);
  font-size: 0.82rem;
  margin-top: 0.3rem;
}

/* ── ROADMAP (for course overview) ── */
.roadmap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.3rem 1.5rem;
  margin: 1rem 0;
}
.roadmap h3 {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--neutral);
  margin-top: 0;
  margin-bottom: 0.6rem;
}

/* ── GATE CARDS ── */
.gate-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: center;
  margin: 1rem 0;
}
.gate-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.1rem 1.2rem;
  width: 280px;
  flex-shrink: 0;
}
.gate-card.broken { border-left: 3px solid var(--urgent); }
.gate-card.working { border-left: 3px solid var(--good); }
.gate-card.partial { border-left: 3px solid var(--warn); }

.gate-name {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
}
.gate-card.broken .gate-name { color: var(--urgent); }
.gate-card.working .gate-name { color: var(--good); }
.gate-card.partial .gate-name { color: var(--warn); }

.mapping {
  font-family: 'IBM Plex Mono', monospace;
  background: var(--bg-subtle);
  padding: 0.5rem 0.8rem;
  border-radius: 4px;
  margin: 0.4rem 0 0.7rem;
  font-size: 0.78rem;
  color: var(--text);
  line-height: 1.7;
}

.calc-section { margin: 0.6rem 0 0.3rem; }
.calc-heading {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  margin-bottom: 0.25rem;
}
.calc-heading.cause { color: var(--info); }
.calc-heading.effect { color: var(--neutral); }

.calc {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.75rem;
  color: var(--neutral);
  line-height: 1.7;
  margin: 0.2rem 0;
}
.calc-result {
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  font-size: 0.82rem;
}
.calc-result.bad { color: var(--urgent); }
.calc-result.good { color: var(--good); }

/* ── NORM PILLS ── */
.norm-pill {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  font-size: 0.72rem;
  margin-top: 0.5rem;
}
.norm-pill.bad {
  background: var(--urgent-light);
  color: var(--urgent);
  border: 1px solid var(--urgent);
}
.norm-pill.good {
  background: var(--good-light);
  color: var(--good);
  border: 1px solid var(--good);
}

/* ── VISUALIZATION LAYOUT ── */
.viz-row {
  display: flex;
  justify-content: center;
  gap: 2.5rem;
  flex-wrap: wrap;
  align-items: center;
}
.viz-col { text-align: center; }
.viz-col canvas {
  border-radius: 6px;
  background: var(--bg);
}
.viz-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  color: var(--neutral);
  margin-bottom: 0.4rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.viz-arrow {
  font-size: 1.4rem;
  color: var(--border);
}

/* ── STATE DIAGRAM (automata) ── */
.state-diagram {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.82rem;
  line-height: 1.5;
  background: var(--bg-subtle);
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow-x: auto;
  margin: 1rem 0;
}

/* ── STEP HIGHLIGHTING (automata traces) ── */
.step { padding: 4px 8px; margin: 2px 0; border-radius: 4px; }
.step-active { background: var(--info-light); }
.step-accept { background: var(--good-light); }
.step-reject { background: var(--urgent-light); }

/* ── NEXT LINK ── */
.next-link {
  display: inline-block;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--info);
  text-decoration: none;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--info);
  border-radius: 6px;
  transition: all 0.15s;
}
.next-link:hover {
  background: var(--info-light);
}

/* ── FOOTER ── */
.footer {
  text-align: center;
  padding: 1.5rem 2rem;
  border-top: 1px solid var(--border);
  margin-top: 2rem;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  color: var(--neutral);
}

/* ── GRAPHVIZ DIAGRAMS ── */
.graphviz {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.5rem;
  margin: 1rem 0;
  text-align: center;
  overflow-x: auto;
}
.graphviz svg {
  max-width: 100%;
  height: auto;
}
/* Override Graphviz inline styles to match site design */
.graphviz .node ellipse,
.graphviz .node polygon,
.graphviz .node circle {
  stroke: var(--text) !important;
  stroke-width: 1.2px !important;
}
.graphviz .edge path {
  stroke: var(--neutral) !important;
  stroke-width: 1.2px !important;
}
.graphviz .edge polygon {
  stroke: var(--neutral) !important;
  fill: var(--neutral) !important;
}
.graphviz text {
  font-family: 'IBM Plex Mono', monospace !important;
  fill: var(--text) !important;
  font-size: 11px !important;
}

/* ── PROOF STEPS ── */
.proof-step {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--info);
  border-radius: 6px;
  padding: 0.8rem 1.1rem;
  margin: 0.6rem 0;
}
.proof-step h4 {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--info);
  margin-bottom: 0.4rem;
}
.proof-step p { font-size: 0.88rem; margin-bottom: 0.4rem; }
.proof-step p:last-child { margin-bottom: 0; }

/* ── QUANTIFIER CHAIN (pumping lemma game) ── */
.quantifier-chain {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.88rem;
  background: var(--bg-subtle);
  padding: 0.8rem 1.2rem;
  border-radius: 6px;
  margin: 1rem 0;
  text-align: center;
  line-height: 2;
}
.game-them {
  display: inline-block;
  background: var(--urgent-light);
  color: var(--urgent);
  border: 1px solid var(--urgent);
  padding: 0.15rem 0.6rem;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.82rem;
  margin: 0.15rem 0.2rem;
}
.game-you {
  display: inline-block;
  background: var(--good-light);
  color: var(--good);
  border: 1px solid var(--good);
  padding: 0.15rem 0.6rem;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.82rem;
  margin: 0.15rem 0.2rem;
}

/* ── TABS ── */
.tab-group {
  margin: 1rem 0;
}
.tab-buttons {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 0;
}
.tab-btn {
  padding: 0.5rem 1.1rem;
  background: none;
  color: var(--neutral);
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.78rem;
  font-weight: 500;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover {
  color: var(--text);
}
.tab-btn.active {
  color: var(--info);
  border-bottom-color: var(--info);
  font-weight: 600;
}
.tab-panel {
  display: none;
  padding-top: 1rem;
}
.tab-panel.active {
  display: block;
}

/* ── RESPONSIVE ── */
@media (max-width: 640px) {
  body { padding: 1.5rem 1rem; }
  .header-title { font-size: 1.6rem; }
  .gate-card { width: 100%; }
  th, td { padding: 0.35rem 0.5rem; font-size: 0.78rem; }
  .viz-row { gap: 1rem; }
  table { min-width: auto; }
  .nav { flex-direction: column; gap: 0.5rem; }
}

/* ══════════════════════════════════════════════════════
   DARK MODE
   Toggled via body.dark-mode class (set by study.js)
   ══════════════════════════════════════════════════════ */

body.dark-mode {
  --bg: #1c1a18;
  --text: #d8d4cc;
  --good: #40b888;
  --urgent: #e08a52;
  --info: #7da0c8;
  --neutral: #8e877d;
  --bg-subtle: #262320;
  --bg-card: #242120;
  --border: #3d3832;
  --good-light: #1c2c24;
  --urgent-light: #2e2318;
  --info-light: #1f2530;
  --neutral-light: #2a2824;
  --warn: #c8a04a;
  --warn-light: #2c2518;
  --automata: #d06858;
  --automata-light: #2e201c;
  --quantum: #5a9ad5;
  --quantum-light: #1e2634;
}

/* Graphviz SVG node fills in dark mode */
body.dark-mode .graphviz .node ellipse,
body.dark-mode .graphviz .node polygon,
body.dark-mode .graphviz .node circle {
  fill: var(--bg-subtle) !important;
}

/* Topic card hover shadow in dark mode */
body.dark-mode .topic-card:hover {
  box-shadow: 0 2px 12px rgba(0,0,0,0.3);
}
body.dark-mode .course-automata .topic-card:hover {
  box-shadow: 0 2px 12px rgba(208, 104, 88, 0.15);
}
body.dark-mode .course-quantum .topic-card:hover {
  box-shadow: 0 2px 12px rgba(90, 154, 213, 0.15);
}

/* Form elements */
body.dark-mode input[type="text"],
body.dark-mode input[type="number"],
body.dark-mode select,
body.dark-mode textarea {
  background: var(--bg-subtle) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}

/* MathJax color override for dark mode */
body.dark-mode mjx-container,
body.dark-mode .MathJax,
body.dark-mode .MathJax_Display {
  color: var(--text) !important;
}

/* Dark mode toggle button */
.dark-mode-toggle {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--neutral);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  line-height: 1;
  z-index: 9999;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
  padding: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.dark-mode-toggle:hover {
  border-color: var(--neutral);
  color: var(--text);
}
body.dark-mode .dark-mode-toggle {
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
