/* ================================================================
   Market Microstructure Simulator
   Commercial-grade Apple Design Aesthetics
   Dark mode · i18n · Responsive
   ================================================================ */

/* ---- Design tokens ---- */
:root {
  --bg-0: #fafbfc; --bg-1: #ffffff; --bg-2: #f4f5f7; --bg-3: #e8eaed;
  --fg-0: #1a1d23; --fg-1: #3d4250; --fg-2: #6b7080; --fg-3: #9aa0ad;
  --border: #dfe1e6;
  --accent: #2563eb; --accent-light: #dbeafe; --accent-dark: #1d4ed8;
  --red: #dc2626; --red-bg: #fef2f2;
  --green: #16a34a; --green-bg: #f0fdf4;
  --amber: #d97706; --amber-bg: #fffbeb;
  --blue: #2563eb; --blue-bg: #eff6ff;
  --purple: #7c3aed; --purple-bg: #f5f3ff;
  --teal: #0d9488; --teal-bg: #f0fdfa;
  --radius-xs: 4px; --radius-sm: 8px; --radius-md: 12px; --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,.07);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.09);
  --ease: cubic-bezier(.4,0,.2,1);
  --font-sans: -apple-system, 'SF Pro Text', 'Inter', system-ui, sans-serif;
  --font-mono: 'SF Mono', 'JetBrains Mono', 'Menlo', monospace;
}

/* ---- Dark mode ---- */
[data-theme="dark"] {
  --bg-0: #0d1117; --bg-1: #161b22; --bg-2: #1c2129; --bg-3: #272d38;
  --fg-0: #e6edf3; --fg-1: #c9d1d9; --fg-2: #8b949e; --fg-3: #6e7681;
  --border: #30363d;
  --accent-light: #1e3a5f;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
  --shadow-md: 0 4px 14px rgba(0,0,0,.35);
  --shadow-lg: 0 8px 28px rgba(0,0,0,.4);
  --red-bg: #2d1b1b; --green-bg: #1a2e1a; --amber-bg: #2d2614;
  --blue-bg: #1a2540; --purple-bg: #231a35; --teal-bg: #142925;
}
@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --bg-0: #0d1117; --bg-1: #161b22; --bg-2: #1c2129; --bg-3: #272d38;
    --fg-0: #e6edf3; --fg-1: #c9d1d9; --fg-2: #8b949e; --fg-3: #6e7681;
    --border: #30363d; --accent-light: #1e3a5f;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.3); --shadow-md: 0 4px 14px rgba(0,0,0,.35);
    --shadow-lg: 0 8px 28px rgba(0,0,0,.4);
    --red-bg: #2d1b1b; --green-bg: #1a2e1a; --amber-bg: #2d2614;
    --blue-bg: #1a2540; --purple-bg: #231a35; --teal-bg: #142925;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: var(--font-sans); background: var(--bg-0); color: var(--fg-0);
  line-height: 1.5; -webkit-font-smoothing: antialiased;
}

/* ================================================================
   Navbar — matching lying project
   ================================================================ */
.navbar {
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px; height: 52px;
  background: var(--bg-1); border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm); position: sticky; top: 0; z-index: 100;
}
.nav-brand {
  font-size: 1rem; font-weight: 700; letter-spacing: -.02em;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  white-space: nowrap; margin-right: 8px;
}
.nav-tabs { display: flex; gap: 2px; flex: 1; }
.nav-tab {
  padding: 14px 16px; border: none; background: transparent;
  color: var(--fg-2); font-family: var(--font-sans); font-size: .8rem; font-weight: 500;
  cursor: pointer; transition: color .15s var(--ease); position: relative;
}
.nav-tab:hover { color: var(--fg-0); }
.nav-tab.active { color: var(--accent); font-weight: 600; }
.nav-tab.active::after {
  content: ''; position: absolute; bottom: 0; left: 8px; right: 8px;
  height: 2px; background: var(--accent); border-radius: 1px;
}

.nav-menu { display: flex; align-items: center; gap: 16px; margin-left: auto; }
.nav-tools { display: flex; align-items: center; gap: 10px; }
.paradigm-label { white-space: nowrap; }

.nav-tools select {
  font-family: var(--font-sans); font-size: .78rem; font-weight: 500;
  background: var(--bg-2); color: var(--fg-0); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0 22px 0 8px; height: 30px;
  outline: none; cursor: pointer; width: auto;
  -webkit-appearance: none; appearance: none;
  transition: border-color .15s var(--ease);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='none' stroke='%239aa0ad' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' d='M1 1l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 6px center;
}
.nav-tools select:hover { border-color: var(--accent); }

/* Theme toggle button */
.theme-btn {
  width: 30px; height: 30px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-2); color: var(--fg-1);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all .2s var(--ease); padding: 0;
}
.theme-btn:hover { background: var(--bg-3); border-color: var(--accent); }
.theme-btn svg { width: 16px; height: 16px; transition: transform .3s var(--ease); }
.theme-btn:hover svg { transform: rotate(20deg); }
.theme-btn .sun { display: none; }
.theme-btn .moon { display: block; }
[data-theme="dark"] .theme-btn .sun { display: block; }
[data-theme="dark"] .theme-btn .moon { display: none; }
@media (prefers-color-scheme: dark) {
  [data-theme="auto"] .theme-btn .sun { display: block; }
  [data-theme="auto"] .theme-btn .moon { display: none; }
}

/* Sidebar toggle (mobile) */
.mobile-toggle {
  display: none; width: 30px; height: 30px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-2); color: var(--fg-1);
  cursor: pointer; align-items: center; justify-content: center; padding: 0;
}
.mobile-toggle svg { width: 16px; height: 16px; }
.mobile-toggle:hover { background: var(--bg-3); border-color: var(--accent); }

/* Hamburger (mobile) */
.nav-hamburger {
  display: none; width: 30px; height: 30px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-2); color: var(--fg-1);
  cursor: pointer; align-items: center; justify-content: center; padding: 0; margin-left: auto;
}
.nav-hamburger svg { width: 16px; height: 16px; }
.nav-hamburger:hover { background: var(--bg-3); border-color: var(--accent); }

/* ================================================================
   App layout — sidebar + main
   ================================================================ */
.app-layout {
  display: grid; grid-template-columns: 310px 1fr;
  max-width: 1520px; margin: 0 auto;
  min-height: calc(100vh - 52px);
}
.sidebar-backdrop {
  display: none; position: fixed; inset: 0; top: 52px;
  background: rgba(0,0,0,.35); z-index: 89; cursor: pointer;
}
.sidebar-backdrop.visible { display: block; }

/* ---- Sidebar ---- */
.sidebar {
  background: var(--bg-1); border-right: 1px solid var(--border);
  padding: 20px 18px 30px; overflow-y: auto; -webkit-overflow-scrolling: touch;
  max-height: calc(100vh - 52px); max-height: calc(100dvh - 52px);
  position: sticky; top: 52px;
}
.sidebar > * + * { margin-top: 6px; }

/* Mode tabs (sim/exp) */
.mode-tabs {
  display: flex; gap: 2px; background: var(--bg-2); border-radius: var(--radius-sm);
  padding: 2px; margin-bottom: 10px;
}
.mode-tab {
  flex: 1; padding: 6px 8px; border: none; border-radius: 6px;
  background: transparent; color: var(--fg-2); font-family: var(--font-sans);
  font-size: .68rem; font-weight: 600; cursor: pointer; transition: all .15s var(--ease);
}
.mode-tab.active { background: var(--accent); color: #fff; }

/* Panels */
.panel { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.panel-header {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px;
  background: var(--bg-2); cursor: pointer; user-select: none;
  transition: background .15s var(--ease);
}
.panel-header:hover { background: var(--bg-3); }
.panel-header .icon { font-size: 1rem; width: 20px; text-align: center; }
.panel-header h3 {
  font-size: .78rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--fg-1); flex: 1; margin: 0;
}
.panel-header .chevron {
  color: var(--fg-3); font-size: .7rem; transition: transform .2s var(--ease);
}
.panel-body {
  padding: 12px 14px 16px;
  max-height: 2000px;
  opacity: 1;
  overflow: hidden;
  transition: max-height .35s var(--ease), padding .3s var(--ease), opacity .2s var(--ease);
}
.panel.collapsed .panel-body {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
}
.panel.collapsed .chevron { transform: rotate(-90deg); }
.panel-body label {
  display: flex; align-items: center; justify-content: space-between;
  font-size: .76rem; color: var(--fg-1); margin-bottom: 6px; gap: 6px;
}
.panel-body label > span:first-child { flex-shrink: 0; min-width: 65px; font-weight: 500; }
.panel-body .text-input {
  width: 100%; padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg-2); color: var(--fg-0); font-family: var(--font-mono);
  font-size: .7rem; text-align: left;
}
.range-wrap {
  display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0;
}
.range-wrap input[type="range"] { flex: 1; min-width: 0; }
.range-val {
  font-family: var(--font-mono); font-size: .66rem; font-weight: 600;
  color: var(--accent); min-width: 2.5em; text-align: right;
}
.range-val.computed { color: var(--fg-2); font-style: italic; }

/* Custom range slider */
input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 5px; border-radius: 3px;
  background: var(--bg-3); outline: none; margin: 6px 0 2px;
  transition: background .15s;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg-1);
  box-shadow: var(--shadow-sm); cursor: pointer;
  transition: transform .12s var(--ease);
}
input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.2); }
input[type=range]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg-1);
  box-shadow: var(--shadow-sm); cursor: pointer;
}
input[type=range]:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.checkbox-label { cursor: pointer; }
.checkbox-label input[type="checkbox"] { accent-color: var(--accent); margin-right: 4px; }

/* Composition bar */
.comp-bar {
  display: flex; height: 18px; border-radius: 9px; overflow: hidden;
  margin-bottom: 8px; border: 1px solid var(--border);
}
.comp-bar .seg {
  display: flex; align-items: center; justify-content: center;
  transition: flex .2s var(--ease); min-width: 0;
}
.comp-bar .seg span {
  font-size: .52rem; font-weight: 700; color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.3); white-space: nowrap;
}

/* Form hints */
.form-hint {
  font-size: .64rem; line-height: 1.5; color: var(--fg-3);
  margin: 2px 0 8px; padding: 0;
}

/* Panel divider */
.panel-divider {
  height: 1px; background: var(--border); margin: 10px 0;
}

/* Primary button — sticky at bottom of sidebar scroll */
.btn-primary {
  display: block; width: 100%; padding: 12px; margin-top: 10px;
  border: none; border-radius: var(--radius-md);
  background: var(--accent); color: #fff; font-family: var(--font-sans);
  font-size: .82rem; font-weight: 700; cursor: pointer;
  transition: all .2s var(--ease); letter-spacing: .02em;
  position: sticky; bottom: 0; z-index: 2;
  box-shadow: 0 -4px 12px rgba(0,0,0,.15), var(--shadow-sm);
}
.btn-primary:hover { background: var(--accent-dark); transform: translateY(-1px); }
.btn-primary:disabled { opacity: .5; cursor: default; transform: none; }

/* Secondary button */
.btn-secondary {
  display: block; width: 100%; padding: 12px; margin-top: 8px;
  border: 1px solid var(--accent); border-radius: var(--radius-md);
  background: transparent; color: var(--accent); font-family: var(--font-sans);
  font-size: .82rem; font-weight: 700; cursor: pointer;
  transition: all .2s var(--ease); letter-spacing: .02em;
}
.btn-secondary:hover { background: var(--accent); color: #fff; transform: translateY(-1px); }
.btn-secondary:disabled { opacity: .5; cursor: default; transform: none; }

/* Progress bar */
.progress-bar {
  margin-top: 8px; height: 20px; background: var(--bg-2);
  border-radius: 10px; overflow: hidden; position: relative;
  border: 1px solid var(--border); display: flex; align-items: center;
}
.progress-fill {
  height: 100%; background: linear-gradient(90deg, var(--accent), var(--teal));
  border-radius: 10px; transition: width .2s ease; width: 0%;
}
.progress-text {
  position: absolute; width: 100%; text-align: center;
  font-size: .6rem; font-weight: 700; color: var(--fg-0);
}

/* ---- Main content ---- */
.main-area {
  padding: 22px 26px 40px; overflow-y: auto; min-width: 0;
}

/* View toggle */
.view-toggle {
  display: flex; gap: 2px; background: var(--bg-2); border-radius: var(--radius-sm);
  padding: 2px; margin-bottom: 14px; width: fit-content;
}
.view-btn {
  padding: 6px 16px; border: none; border-radius: 6px; background: transparent;
  color: var(--fg-2); font-family: var(--font-sans); font-size: .72rem; font-weight: 600;
  cursor: pointer; transition: all .15s var(--ease);
}
.view-btn.active { background: var(--accent); color: #fff; }

/* Export row */
.export-row { display: flex; gap: 8px; margin-bottom: 14px; }
.btn-export {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; background: var(--bg-2); color: var(--fg-1);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-family: var(--font-sans); font-size: .72rem; font-weight: 500;
  cursor: pointer; transition: all .15s var(--ease);
}
.btn-export:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-export svg { width: 14px; height: 14px; }

/* Summary cards */
.summary-row { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.summary-card {
  flex: 1; min-width: 100px; background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 14px 16px; box-shadow: var(--shadow-sm);
  transition: box-shadow .15s var(--ease), transform .15s var(--ease);
}
.summary-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.sc-label {
  font-size: .6rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--fg-2); margin-bottom: 4px;
}
.sc-value {
  font-family: var(--font-mono); font-size: 1.4rem; font-weight: 700; color: var(--fg-0);
}

/* Charts */
.chart-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; margin-bottom: 16px; }
.chart-card {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px; min-height: 280px;
  box-shadow: var(--shadow-sm); overflow: hidden; min-width: 0;
}
.chart-title {
  font-size: .82rem; font-weight: 600; color: var(--fg-1);
  padding: 0 2px; margin: 0 0 10px;
  display: flex; align-items: center; gap: 6px;
}
.chart-title .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.chart-card .js-plotly-plot, .chart-card .plot-container { width: 100% !important; border-radius: var(--radius-sm); }
.chart-note {
  font-size: .66rem; line-height: 1.65; color: var(--fg-3);
  margin: 0; padding: 10px 4px 0; border-top: 1px solid var(--border); margin-top: 10px;
}
.chart-note strong { color: var(--fg-2); }
.chart-wide { grid-column: 1 / -1; }

/* Game */
.game-container {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-md);
  margin-bottom: 16px;
}
.game-controls {
  display: flex; align-items: center; gap: 8px; padding: 8px 14px;
  background: var(--bg-2); border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.g-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 12px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg-1); color: var(--fg-1); font-family: var(--font-sans);
  font-size: .68rem; font-weight: 600; cursor: pointer; transition: all .15s var(--ease);
}
.g-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.g-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.g-btn-sm { padding: 3px 7px; font-size: .66rem; min-width: 22px; justify-content: center; }
.g-zoom-wrap, .g-speed-wrap {
  display: flex; align-items: center; gap: 5px; font-size: .66rem; color: var(--fg-2);
}
.g-speed-wrap { margin-left: auto; }
.g-speed-wrap label { font-weight: 600; }
.g-speed-wrap input[type="range"] { width: 60px; accent-color: var(--accent); }
.g-zoom-val, .g-speed-val {
  font-family: var(--font-mono); font-weight: 600; font-size: .62rem;
  color: var(--accent); min-width: 2.8em; text-align: center;
}
.game-canvas-wrap canvas {
  display: block; width: 100%; min-height: 480px; touch-action: none;
}

/* Log */
.log-card {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 14px 16px;
  margin-bottom: 16px;
}
.log-card > summary {
  display: flex; align-items: center; cursor: pointer;
  list-style: none; user-select: none;
}
.log-card > summary::-webkit-details-marker { display: none; }
.log-card > summary::before {
  content: '\25B6'; font-size: .6rem; color: var(--fg-3);
  margin-right: 8px; transition: transform .2s;
}
.log-card[open] > summary::before { transform: rotate(90deg); }
.log-card > summary h4 {
  font-size: .78rem; font-weight: 700; color: var(--fg-0); margin: 0;
}
.log-toggle-hint {
  font-size: .65rem; color: var(--fg-3); margin-left: auto; font-weight: 400;
}
.log-card[open] .log-toggle-hint { display: none; }
.log-body {
  max-height: 600px; overflow-y: auto; padding-top: 10px;
  border-top: 1px solid var(--border); margin-top: 10px;
  font-size: .72rem; font-family: var(--font-mono); line-height: 1.7; color: var(--fg-2);
}
.log-round {
  border: 1px solid var(--border); border-radius: 6px; margin-bottom: 4px; overflow: hidden;
}
.log-round > summary {
  cursor: pointer; padding: 5px 8px; font-weight: 600; font-size: .66rem;
  list-style: none; background: var(--bg-2); color: var(--fg-0);
}
.log-round > summary::-webkit-details-marker { display: none; }
.log-round > summary::before {
  content: '\25B6'; font-size: .5rem; color: var(--fg-3); margin-right: 6px;
  display: inline-block; transition: transform .12s var(--ease);
}
.log-round[open] > summary::before { transform: rotate(90deg); }
.log-round[open] > summary { border-bottom: 1px solid var(--border); }
.log-entry {
  padding: 3px 8px; border-bottom: 1px solid var(--border);
  font-size: .6rem; color: var(--fg-2);
}
.log-entry:last-child { border-bottom: none; }
.log-tag {
  display: inline-block; padding: 1px 4px; border-radius: 3px;
  font-size: .5rem; font-weight: 700; text-transform: uppercase;
  vertical-align: middle; margin-left: 3px;
}
.log-tag-buy { background: var(--green-bg); color: var(--green); }
.log-tag-sell { background: var(--red-bg); color: var(--red); }
.log-tag-lie { background: var(--red-bg); color: var(--red); }
.log-tag-truth { background: var(--green-bg); color: var(--green); }

/* Results table */
.table-title { font-size: .76rem; font-weight: 700; margin: 0 0 8px; color: var(--fg-0); }
.results-table {
  width: 100%; border-collapse: collapse; font-size: .66rem; font-family: var(--font-sans);
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius-sm); overflow: hidden; box-shadow: var(--shadow-sm);
}
.results-table th {
  background: var(--bg-2); padding: 6px 10px; text-align: left; font-weight: 700;
  font-size: .6rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--fg-2); border-bottom: 1px solid var(--border);
}
.results-table td {
  padding: 5px 10px; border-bottom: 1px solid var(--border);
  font-family: var(--font-mono); font-size: .62rem; color: var(--fg-1);
}
.results-table tr:last-child td { border-bottom: none; }
.results-table tr:hover { background: var(--bg-2); }

/* ================================================================
   Responsive
   ================================================================ */
@media (max-width: 1100px) {
  .chart-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .nav-brand { display: none; }
  .mobile-toggle { display: flex; }
  .nav-hamburger {
    display: flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: var(--bg-2); color: var(--fg-1);
    cursor: pointer; padding: 0; margin-left: auto;
  }
  .nav-hamburger:hover { background: var(--bg-3); border-color: var(--accent); }
  .nav-hamburger svg { width: 16px; height: 16px; }
  .nav-menu.open ~ .nav-hamburger { background: var(--bg-3); border-color: var(--accent); }
  .nav-menu {
    display: none; position: absolute; top: 52px; right: 0;
    flex-direction: column; gap: 12px;
    background: var(--bg-1); border: 1px solid var(--border); border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    box-shadow: var(--shadow-md); padding: 14px 16px; min-width: 180px; z-index: 99;
  }
  .nav-menu.open { display: flex; }
  .app-layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 52px; left: 0; bottom: 0; width: 310px; z-index: 90;
    max-height: calc(100vh - 52px); max-height: calc(100dvh - 52px);
    overflow-y: auto; -webkit-overflow-scrolling: touch;
    border-right: 1px solid var(--border);
    transform: translateX(-100%); transition: transform .3s var(--ease);
    box-shadow: none; padding-bottom: 60px;
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar .panel-body { padding: 10px 12px 14px; }
  .sidebar .panel-body label { font-size: .74rem; }
  .sidebar .form-hint { font-size: .64rem; }
  .summary-row { display: grid; grid-template-columns: repeat(3, 1fr); }
  .sc-value { font-size: 1.15rem; }
  .main-area { padding: 18px 16px 30px; }
  .arch-defs { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
  .arch-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .arch-svg-container { padding: 12px; }
  .gloss-table th, .gloss-table td { padding: 6px 8px; font-size: .76rem; }
}
@media (max-width: 550px) {
  .navbar { padding: 0 10px; gap: 8px; }
  .nav-tab { padding: 14px 8px; font-size: .72rem; }
  .sidebar {
    width: 100%; border-right: none;
  }
  .main-area { padding: 12px 10px 24px; }
  .summary-row { grid-template-columns: repeat(2, 1fr); }
  .summary-card { padding: 8px 10px; }
  .sc-value { font-size: .9rem; }
  .chart-card { padding: 6px; min-height: 240px; }
  .chart-title { font-size: .7rem; }
  .chart-note { font-size: .6rem; padding: 6px 6px 0; }
  .view-btn { padding: 5px 10px; font-size: .68rem; }
  .game-canvas-wrap canvas { min-height: 420px; }
  .game-controls { gap: 4px; padding: 6px 8px; }
  .g-btn { padding: 4px 8px; font-size: .62rem; }
  .log-body { max-height: 200px; font-size: .6rem; }
  .arch-defs { grid-template-columns: 1fr; }
  .arch-header h2 { font-size: 1.1rem; }
  .arch-header p { font-size: .75rem; }
  .arch-svg-container { padding: 8px; }
  .arch-def-card { padding: 12px 14px; }
  .arch-def-card h4 { font-size: .76rem; }
  .paradigm-switch { gap: 1px; }
  .paradigm-btn { padding: 5px 10px; font-size: .7rem; }
  .paradigm-icon { font-size: .72rem; }
}

/* ================================================================
   Tab content
   ================================================================ */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ================================================================
   Architecture
   ================================================================ */
.arch-wrap { max-width: 1000px; margin: 0 auto; padding: 8px 0 30px; }
.arch-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 14px; margin-bottom: 24px; flex-wrap: wrap;
}
.arch-header h2 { font-size: 1.3rem; font-weight: 700; color: var(--fg-0); margin-bottom: 4px; }
.arch-header p { font-size: .78rem; color: var(--fg-2); line-height: 1.5; }
.btn-drawio {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; background: var(--bg-2); color: var(--fg-1);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-family: var(--font-sans); font-size: .72rem; font-weight: 500;
  cursor: pointer; transition: all .15s var(--ease);
  text-decoration: none; white-space: nowrap; flex-shrink: 0;
}
.btn-drawio:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-drawio svg { width: 14px; height: 14px; }
.arch-svg-container {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 20px;
  box-shadow: var(--shadow-sm); margin-bottom: 24px; overflow-x: auto;
}
.arch-svg-container svg { width: 100%; height: auto; min-width: 600px; }
.arch-svg-container .box-title {
  font-family: -apple-system, 'SF Pro Text', sans-serif;
  font-size: 13px; font-weight: 700; fill: var(--fg-0);
}
.arch-svg-container .box-sub {
  font-family: var(--font-mono); font-size: 10px; fill: var(--fg-2);
}
.arch-svg-container .box-detail {
  font-family: -apple-system, 'SF Pro Text', sans-serif;
  font-size: 9px; fill: var(--fg-3);
}
.arch-svg-container .section-label {
  font-family: -apple-system, 'SF Pro Text', sans-serif;
  font-size: 11px; font-weight: 600; fill: var(--accent);
  text-transform: uppercase; letter-spacing: 0.05em;
}

/* Definition cards */
.arch-defs {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px; margin-top: 24px;
}
.arch-def-card {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 16px 18px;
  box-shadow: var(--shadow-sm); transition: box-shadow .15s var(--ease), transform .15s var(--ease);
}
.arch-def-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.arch-def-card h4 { font-size: .82rem; font-weight: 700; color: var(--accent); margin-bottom: 6px; }
.arch-def-card p { font-size: .72rem; color: var(--fg-1); line-height: 1.5; }
.formula {
  font-family: var(--font-mono); font-size: .72rem; color: var(--purple);
  background: var(--bg-2); padding: 6px 10px; border-radius: var(--radius-xs);
  margin-top: 8px; display: inline-block;
}
.formula-ref {
  display: block; font-size: .58rem; color: var(--fg-3);
  margin-top: 4px; font-style: italic;
}

/* ================================================================
   Glossary
   ================================================================ */
.glossary-wrap { max-width: 1000px; margin: 0 auto; padding: 8px 0 30px; }
.glossary-wrap > h2 { font-size: 1.3rem; font-weight: 700; color: var(--fg-0); margin-bottom: 20px; }
.gloss-section { margin-bottom: 28px; }
.gloss-section h3 {
  font-size: .9rem; font-weight: 600; color: var(--fg-0); margin-bottom: 10px;
  padding-bottom: 8px; border-bottom: 2px solid var(--accent-light);
}
.gloss-table {
  width: 100%; border-collapse: collapse; font-size: .7rem;
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius-sm); overflow: hidden; box-shadow: var(--shadow-sm);
}
.gloss-table th {
  background: var(--bg-2); padding: 8px 12px; text-align: left;
  font-size: .62rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--fg-2); border-bottom: 1px solid var(--border);
}
.gloss-table td {
  padding: 6px 12px; border-bottom: 1px solid var(--border);
  color: var(--fg-1); vertical-align: top; line-height: 1.5;
}
.gloss-table tr:last-child td { border-bottom: none; }
.gloss-table tr:hover { background: var(--bg-2); }
.gloss-table .term {
  font-family: var(--font-mono); font-weight: 700; color: var(--fg-0);
  white-space: nowrap;
}
.gloss-table .math {
  font-family: var(--font-mono); color: var(--purple); white-space: nowrap;
}

/* Plot descriptions */
.plot-desc {
  display: flex; gap: 14px; padding: 10px 0;
  border-bottom: 1px solid var(--border); align-items: flex-start;
}
.plot-desc:last-child { border-bottom: none; }
.plot-icon {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: .78rem; flex-shrink: 0;
}
.plot-info h4 { font-size: .78rem; font-weight: 600; color: var(--accent); margin-bottom: 2px; }
.plot-info p { font-size: .7rem; color: var(--fg-2); line-height: 1.5; }

@media (max-width: 550px) {
  .plot-icon { width: 28px; height: 28px; font-size: .66rem; }
}

/* ================================================================
   Paradigm Switcher (Math / AI Agent)
   ================================================================ */
.paradigm-switch {
  display: flex; gap: 2px; background: var(--bg-2); border-radius: var(--radius-sm);
  padding: 2px;
}
.paradigm-btn {
  display: flex; align-items: center; gap: 4px;
  padding: 4px 10px; border: none; border-radius: 6px; background: transparent;
  color: var(--fg-3); font-family: var(--font-sans); font-size: .72rem; font-weight: 600;
  cursor: pointer; transition: all .2s var(--ease);
}
.paradigm-btn:hover { color: var(--fg-1); }
.paradigm-btn.active { background: var(--bg-1); color: var(--fg-0); box-shadow: var(--shadow-sm); }
.paradigm-btn[data-v="ai"].active { background: linear-gradient(135deg, var(--purple), var(--accent)); color: #fff; }
.paradigm-icon { font-size: .82rem; }

/* ================================================================
   AI Agent Mode
   ================================================================ */
body.mode-ai .navbar { border-bottom-color: var(--purple); }

/* Global select styling (dark mode aware) */
.sidebar select, .section-card select, .roster-row select {
  font-family: var(--font-sans); font-size: .68rem; font-weight: 500;
  background: var(--bg-2); color: var(--fg-0); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 6px; height: 26px; outline: none;
  cursor: pointer; transition: border-color .15s;
}
.sidebar select:focus, .section-card select:focus, .roster-row select:focus {
  border-color: var(--accent);
}

/* API key/endpoint inputs */
.input-text {
  font-family: var(--font-mono); font-size: .68rem;
  background: var(--bg-2); color: var(--fg-0); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 8px; width: 100%; outline: none; transition: border-color .15s;
}
.input-text:focus { border-color: var(--accent); }
.input-key { margin-top: 4px; }
.input-endpoint { margin-top: 2px; opacity: .5; transition: opacity .15s; }
.input-endpoint:focus { opacity: 1; }

/* AI run button */
.btn-ai { background: linear-gradient(135deg, var(--purple), var(--accent)); }
.btn-ai:hover { filter: brightness(1.1); }

/* AI progress */
.ai-progress {
  font-size: .66rem; color: var(--fg-3); margin-top: 4px; min-height: 1em;
  font-family: var(--font-mono);
}

/* Section card */
.section-card {
  padding: 8px; background: var(--bg-2); border-radius: 6px;
  border: 1px solid var(--border); margin-bottom: 8px;
}
.section-card select { font-size: .68rem; padding: 3px 6px; height: 26px; }

/* Agent roster */
#agent-roster { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.roster-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; align-items: center;
  padding: 8px; background: var(--bg-2); border-radius: 6px; border: 1px solid var(--border);
}
.roster-group-label {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 6px;
  font-size: .7rem; font-weight: 600; color: var(--fg-1); margin-bottom: 2px;
}
.roster-group-label .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.roster-auto-count {
  margin-left: auto; width: 40px; height: 22px; padding: 2px 4px;
  font-family: var(--font-mono); font-size: .64rem; font-weight: 500;
  color: var(--fg-2); background: var(--bg-1); border: 1px solid var(--border);
  border-radius: 4px; text-align: center; cursor: default; opacity: .75;
}
.roster-row select { font-size: .68rem; padding: 3px 5px; height: 26px; min-width: 0; }
.roster-row .input-key,
.roster-row .input-endpoint { grid-column: 1 / -1; }

