/* dark is the root default — layout applies data-theme from localStorage on load */
:root {
  --bg:          #1a1512;
  --paper:       #211c17;
  --surface:     #221c18;
  --surface-2:   #2b2420;
  --ink:         #f0e8dc;
  --text:        #f0e8dc;
  --muted:       #9e8f82;
  --text-muted:  #a89c8a;
  --line:        #3d3028;
  --border:      rgba(240, 232, 220, 0.12);
  --accent:      #d4734a;
  --accent-soft: #3d1e10;
  --green:       #5ab08b;
  --green-soft:  #0f2e22;
  --blue:        #6ba8cc;
  --blue-soft:   #0d2330;
  --gold:        #e0ab3a;
  --shadow:      0 24px 70px rgba(0, 0, 0, 0.4);
  --code-bg:       rgba(255, 255, 255, 0.07);
  --diagram-bg:    #1f1916;
}

[data-theme="light"] {
  --bg:          #f6f1e6;
  --paper:       #fffaf2;
  --surface:     rgba(255, 255, 255, 0.62);
  --surface-2:   rgba(255, 255, 255, 0.55);
  --ink:         #201a15;
  --text:        #201a15;
  --muted:       #6d655d;
  --text-muted:  #6b5e4f;
  --line:        #dbcfbe;
  --border:      rgba(26, 21, 18, 0.12);
  --accent:      #8e3f1d;
  --accent-soft: #f4d3c3;
  --green:       #2f6b53;
  --green-soft:  #d9efe4;
  --blue:        #285a7a;
  --blue-soft:   #dbe9f3;
  --gold:        #c88a1d;
  --shadow:      0 24px 70px rgba(64, 49, 31, 0.08);
  --code-bg:       rgba(0, 0, 0, 0.06);
  --diagram-bg:    #fffaf2;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  font-family: "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  background: var(--bg);
}
[data-theme="light"] body {
  background:
    radial-gradient(circle at top left, #fffdf8 0, rgba(255, 253, 248, 0.2) 35%, transparent 60%),
    linear-gradient(180deg, #fbf6ee 0%, var(--bg) 35%, #efe5d4 100%);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px 80px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 22px;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.topbar-links {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.hero,
.card,
.theorem-box,
.visual-box,
.note-box {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hero {
  padding: 30px;
}

.eyebrow {
  display: inline-block;
  margin-bottom: 14px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 0.74rem;
  color: var(--text-muted);
}

h1 {
  margin: 0 0 12px;
  font-size: clamp(2.3rem, 6vw, 4.6rem);
  line-height: 0.94;
  letter-spacing: -0.05em;
}

h2 {
  margin: 0 0 10px;
  font-size: clamp(1.6rem, 4vw, 2.6rem);
  line-height: 0.98;
  letter-spacing: -0.03em;
}

h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}

p {
  margin: 0 0 14px;
  font-size: 1.05rem;
  line-height: 1.65;
}

.muted,
.small {
  color: var(--muted);
}

.small {
  font-size: 0.96rem;
}

.lead {
  font-size: 1.18rem;
}

.grid {
  display: grid;
  gap: 22px;
  margin-top: 24px;
}

.two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.three {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.card,
.theorem-box,
.visual-box,
.note-box {
  padding: 22px;
}

.theorem-box {
  background: linear-gradient(90deg, var(--blue-soft), var(--surface));
}

.use-box {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 0.84rem;
  border: 1px solid var(--line);
  background: var(--code-bg);
  margin: 0 8px 8px 0;
}

.formula {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 0.95rem;
  line-height: 1.1;
  vertical-align: middle;
}

.formula mjx-container {
  margin: 0 !important;
  font-size: 0.92em !important;
  line-height: 1 !important;
  vertical-align: middle !important;
}

mjx-container[jax="SVG"][display="false"] {
  display: inline-block !important;
  font-size: 0.98em !important;
  line-height: 1 !important;
  vertical-align: -0.08em !important;
}

code {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--code-bg);
  color: var(--text);
  font-family: "Courier New", monospace;
  font-size: 0.9rem;
}

.math-block {
  margin: 14px 0 16px;
  padding: 14px 18px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  overflow-x: auto;
}

.math-block mjx-container {
  margin: 0 !important;
  font-size: 1em !important;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 14px;
  font-size: 0.95rem;
}

th,
td {
  padding: 10px 12px;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--text);
  background: var(--surface-2);
  font-weight: 600;
}

.visual-box {
  background: var(--surface);
}

.note-box {
  background: var(--surface-2);
}

.mini-card {
  border-radius: 18px;
  padding: 16px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}

.mini-card p {
  margin: 0;
  font-size: 0.97rem;
}

.steps {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
}

.steps li {
  margin: 8px 0;
  line-height: 1.6;
}

.flow-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.flow {
  border-radius: 18px;
  padding: 18px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}

.flow h3 {
  margin: 0 0 12px;
  font-size: 1rem;
}

.widget-grid {
  display: grid;
  grid-template-columns: minmax(240px, 0.9fr) minmax(0, 1.1fr);
  gap: 18px;
  margin-top: 18px;
  align-items: start;
}

.control-panel,
.status-panel {
  border-radius: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.control-stack {
  display: grid;
  gap: 12px;
}

.control-row {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr) 54px;
  gap: 12px;
  align-items: center;
}

.control-row span:first-child {
  font-size: 0.94rem;
}

.control-row input[type="range"],
.control-row select {
  width: 100%;
  accent-color: var(--accent);
}

.control-value {
  color: var(--muted);
  font-size: 0.92rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.toggle-list {
  display: grid;
  gap: 10px;
}

.toggle-row {
  display: flex;
  gap: 10px;
  align-items: center;
  color: var(--ink);
  font-size: 0.95rem;
}

.toggle-row input[type="checkbox"] {
  accent-color: var(--accent);
}

.widget-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.86rem;
  border: 1px solid var(--line);
  background: var(--surface);
  margin-bottom: 12px;
}

.widget-badge.good {
  color: var(--green);
  background: var(--green-soft);
  border-color: rgba(47, 107, 83, 0.25);
}

.widget-badge.warn {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: rgba(142, 63, 29, 0.25);
}

.widget-badge.info {
  color: var(--blue);
  background: var(--blue-soft);
  border-color: rgba(40, 90, 122, 0.25);
}

.widget-copy {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.98rem;
}

.matrix-board {
  display: grid;
  gap: 8px;
}

.matrix-row {
  display: grid;
  grid-template-columns: 42px repeat(4, minmax(0, 1fr));
  gap: 8px;
  align-items: center;
}

.matrix-label {
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
}

.matrix-cell {
  border-radius: 12px;
  padding: 10px 6px;
  border: 1px solid var(--line);
  background: var(--surface);
  text-align: center;
  font-size: 0.84rem;
  line-height: 1.2;
}

.matrix-cell.allowed {
  color: var(--green);
  background: var(--green-soft);
  border-color: rgba(47, 107, 83, 0.25);
}

.matrix-cell.blocked {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: rgba(142, 63, 29, 0.25);
}

.meter-stack {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.meter-row {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr) 46px;
  gap: 10px;
  align-items: center;
}

.meter-label,
.meter-value {
  color: var(--muted);
  font-size: 0.88rem;
}

.meter-value {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.meter-track {
  height: 10px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--gold));
}

.flow-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.box {
  border-radius: 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: var(--paper);
  font-size: 0.93rem;
  min-width: 72px;
  text-align: center;
}

.box mjx-container[jax="SVG"][display="false"] {
  font-size: 0.95em !important;
}

.arrow {
  color: var(--muted);
  font-size: 1.15rem;
}

.visual-box svg {
  width: 100%;
  height: auto;
  display: block;
}

.footer-nav {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 26px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  color: var(--muted);
}

@media (max-width: 920px) {
  .two,
  .three,
  .flow-grid,
  .widget-grid {
    grid-template-columns: 1fr;
  }

  .control-row,
  .meter-row {
    grid-template-columns: 1fr;
  }

  .control-value,
  .meter-value {
    text-align: left;
  }
}

/* overflow fix for long Lean identifiers */
.page code { overflow-wrap: anywhere; }
.page code, .page pre, .page svg { max-width: 100%; }
.page svg { height: auto; }

/* back-banner */
.survey-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1.5rem;
  height: 44px;
  background: var(--paper);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.back-link {
  color: var(--ink);
  text-decoration: none;
  font-family: inherit;
  font-size: 0.9rem;
}
.back-link:hover { text-decoration: underline; }
.theme-toggle-mini {
  background: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 3px 8px;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.8rem;
}
.theme-toggle-mini:hover { background: var(--code-bg); }
.theme-toggle-mini.flashed { opacity: 0.5; }

/* footer */
.survey-footer {
  font-size: 0.85rem;
  color: var(--muted);
  padding: 1.5rem 2rem;
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}
.survey-footer a { color: var(--ink); }

/* SVG diagram dark-mode overrides — CSS beats SVG presentation attributes by specificity */
[data-theme="dark"] [fill="#fffaf2"] { fill: var(--diagram-bg) !important; }
[data-theme="dark"] [fill="#6d655d"] { fill: var(--text-muted) !important; }
[data-theme="dark"] [fill="#8e3f1d"] { fill: var(--accent) !important; }
[data-theme="dark"] [fill="#2f6b53"] { fill: var(--green) !important; }
[data-theme="dark"] [fill="#f4d3c3"] { fill: var(--accent-soft) !important; }
[data-theme="dark"] [fill="#d9efe4"] { fill: var(--green-soft) !important; }
[data-theme="dark"] [fill="#dbe9f3"] { fill: var(--blue-soft) !important; }
[data-theme="dark"] [fill="#285a7a"] { fill: var(--blue) !important; }
[data-theme="dark"] [fill="#c88a1d"] { fill: var(--gold) !important; }
[data-theme="dark"] [fill="#201a15"] { fill: var(--ink) !important; }
[data-theme="dark"] [stroke="#dbcfbe"] { stroke: var(--line) !important; }
[data-theme="dark"] [stroke="#cdbfae"] { stroke: var(--line) !important; }
[data-theme="dark"] [stroke="#6d655d"] { stroke: var(--text-muted) !important; }
[data-theme="dark"] [stroke="#2f6b53"] { stroke: var(--green) !important; }
[data-theme="dark"] [stroke="#8e3f1d"] { stroke: var(--accent) !important; }
[data-theme="dark"] [stroke="#285a7a"] { stroke: var(--blue) !important; }
