/* ---------- Design tokens ---------- */
:root {
  --bg: #faf9f6;
  --bg-elevated: #ffffff;
  --text: #232323;
  --text-muted: #5b5b5b;
  --border: #e2ddd3;
  --accent: #b5482a;       /* warm terracotta - primary accent */
  --accent-soft: #f3e3db;

  --arnold: #d9752b;       /* "coming from" side */
  --arnold-soft: #fbe9d9;
  --pxr: #2c6b8f;          /* "going to" side */
  --pxr-soft: #dcebf2;

  --callout-bg: #fff6e8;
  --callout-border: #e0a94c;

  --code-bg: #efece5;

  /* Visualisation series - NOT renderer-aligned, unlike --arnold/--pxr */
  --viz-a: #7d4a9e;        /* model A - Beckmann */
  --viz-a-soft: #ece0f4;
  --viz-b: #2f8f6b;        /* model B - GGX */
  --viz-b-soft: #d9f0e6;
  --viz-grid: #ddd8ce;
  --viz-bg: #f4f2ec;

  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 6px 20px rgba(0,0,0,0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a17;
    --bg-elevated: #242320;
    --text: #ece8e0;
    --text-muted: #b3ac9e;
    --border: #3a3833;
    --accent: #e08a63;
    --accent-soft: #3a2a22;

    --arnold: #e6944e;
    --arnold-soft: #3a2c1c;
    --pxr: #6fb3d8;
    --pxr-soft: #1f3440;

    --callout-bg: #332b18;
    --callout-border: #a97f34;

    --code-bg: #2c2a25;
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 6px 20px rgba(0,0,0,0.25);

    --viz-a: #c39ade;
    --viz-a-soft: #2f2338;
    --viz-b: #6fd4aa;
    --viz-b-soft: #1c3830;
    --viz-grid: #403d36;
    --viz-bg: #201f1c;
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.65;
  font-size: 17px;
}

img { max-width: 100%; }

a { color: var(--accent); }

/* ---------- Top nav ---------- */
.topnav {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  padding: 0.9rem 1.5rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.topnav__brand {
  font-weight: 700;
  text-decoration: none;
  color: var(--text);
  font-size: 1.05rem;
}

.topnav__brand span { color: var(--accent); }

.topnav__links {
  display: flex;
  gap: 1.25rem;
  font-size: 0.95rem;
  flex-wrap: wrap;
}

.topnav__links a {
  color: var(--text-muted);
  text-decoration: none;
}

.topnav__links a:hover,
.topnav__links a.active { color: var(--text); }

.topnav__links a.disabled {
  color: var(--text-muted);
  opacity: 0.55;
  pointer-events: none;
}

/* ---------- Layout shells ---------- */
.page {
  max-width: 880px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 5rem;
}

.hero {
  max-width: 880px;
  margin: 0 auto;
  padding: 3.5rem 1.5rem 1.5rem;
}

.hero h1 {
  font-size: 2.1rem;
  margin-bottom: 0.6rem;
}

.hero p.lead {
  font-size: 1.15rem;
  color: var(--text-muted);
  max-width: 60ch;
}

.guide-layout {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem 5rem;
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  gap: 2.5rem;
  align-items: start;
}

.toc {
  position: sticky;
  top: 4.5rem;
  font-size: 0.92rem;
}

.toc h2 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0 0 0.75rem;
}

.toc ol {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.toc a {
  text-decoration: none;
  color: var(--text-muted);
}

.toc a:hover { color: var(--accent); }

.guide-content { min-width: 0; }

@media (max-width: 800px) {
  .guide-layout { grid-template-columns: 1fr; }
  .toc { position: static; border-bottom: 1px solid var(--border); padding-bottom: 1.25rem; margin-bottom: 0.5rem; }
  .toc ol { flex-direction: row; flex-wrap: wrap; gap: 0.5rem 1rem; }
}

/* ---------- Typography helpers ---------- */
h1, h2, h3 { line-height: 1.25; }
h2 { font-size: 1.55rem; margin-top: 3rem; }
h3 { font-size: 1.15rem; margin-top: 2rem; color: var(--text); }

.section-kicker {
  display: inline-block;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.muted { color: var(--text-muted); }

code {
  background: var(--code-bg);
  border-radius: 4px;
  padding: 0.1em 0.4em;
  font-family: "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.86em;
  word-break: break-word;
}

td code, th code { font-size: 0.82em; }

/* ---------- Cards / grid ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin: 1.75rem 0;
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.card h3 { margin-top: 0; font-size: 1.05rem; }

.card.card--soon {
  opacity: 0.75;
  border-style: dashed;
}

.card--trailing { margin-top: 3rem; }

.badge {
  display: inline-block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

/* ---------- Tables ---------- */
.table-scroll {
  overflow-x: auto;
  margin: 1.5rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 640px;
  font-size: 0.95rem;
  background: var(--bg-elevated);
}

th, td {
  text-align: left;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

thead th {
  background: var(--bg);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  position: sticky;
  top: 0;
}

tbody tr:last-child td { border-bottom: none; }

td.col-arnold { color: var(--arnold); font-weight: 600; }
td.col-pxr { color: var(--pxr); font-weight: 600; }

/* ---------- Callouts ---------- */
.callout {
  background: var(--callout-bg);
  border-left: 4px solid var(--callout-border);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
}

.callout__title {
  font-weight: 700;
  font-size: 0.92rem;
  margin-bottom: 0.35rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.callout p:last-child { margin-bottom: 0; }

.callout--pitfall { border-left-color: var(--arnold); }
.callout--pitfall .callout__title { color: var(--arnold); }

/* ---------- Analogy box ---------- */
.analogy {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin: 1.25rem 0;
  font-size: 0.98rem;
}

.analogy .section-kicker { color: var(--text-muted); }

/* ---------- Numbered conversion checklist ---------- */
.steps {
  counter-reset: step;
  list-style: none;
  padding: 0;
  margin: 1.5rem 0;
}

.steps li {
  counter-increment: step;
  position: relative;
  padding: 0 0 0 2.75rem;
  margin-bottom: 1.1rem;
}

.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0.1rem;
  width: 1.85rem;
  height: 1.85rem;
  border-radius: 999px;
  background: var(--pxr-soft);
  color: var(--pxr);
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Roughness gradient bar ---------- */
.slider-viz { margin: 1.25rem 0 1.75rem; }

.slider-viz__bar {
  height: 34px;
  border-radius: 999px;
  background: linear-gradient(90deg, #e9e6df 0%, #cfcabf 35%, #a49c8c 65%, #7a7264 100%);
  border: 1px solid var(--border);
  position: relative;
}

@media (prefers-color-scheme: dark) {
  .slider-viz__bar {
    background: linear-gradient(90deg, #4a473f 0%, #625d51 35%, #857c69 65%, #b0a68d 100%);
  }
}

.slider-viz__labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

/* ---------- Layer stack diagram ---------- */
.stack-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin: 1.75rem 0;
}

@media (max-width: 620px) {
  .stack-compare { grid-template-columns: 1fr; }
}

.stack {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  background: var(--bg-elevated);
}

.stack__title {
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
  text-align: center;
}

.stack__title--arnold { color: var(--arnold); }
.stack__title--pxr { color: var(--pxr); }

.stack__layers {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.stack__layer {
  border-radius: 6px;
  padding: 0.5rem 0.7rem;
  font-size: 0.85rem;
  text-align: center;
  border: 1px solid transparent;
}

.stack--arnold .stack__layer { background: var(--arnold-soft); color: var(--text); }
.stack--pxr .stack__layer { background: var(--pxr-soft); color: var(--text); }

/* ---------- Footer ---------- */
footer {
  max-width: 880px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  border-top: 1px solid var(--border);
}

/* ---------- Language switch (EN / PL) ---------- */
/* Both languages ship in the HTML; these two rules hide the inactive one, so
   the right language renders before any JS runs and with JS disabled. */
:root[data-lang="en"] [lang="pl"] { display: none; }
:root[data-lang="pl"] [lang="en"] { display: none; }

/* Only offer the switch once i18n.js has confirmed it can do something. */
.lang-switch { display: none; }

/* On bilingual pages the brand and the switch hold the top row, and the
   (longer) link list gets a row of its own underneath. Without this the
   switch wraps below the links and ends up bottom-left. */
.topnav--i18n .lang-switch { order: 2; margin-left: auto; }
.topnav--i18n .topnav__links { order: 3; flex-basis: 100%; }

:root.js .lang-switch {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg);
}

.lang-switch button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  line-height: 1.4;
}

.lang-switch button:hover { color: var(--text); }

.lang-switch button.is-active {
  background: var(--accent);
  color: #fff;
}

.lang-switch button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* ---------- Interactive visualisation blocks ---------- */
.viz {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 1.75rem 0;
  overflow: hidden;
}

.viz__head {
  padding: 0.85rem 1.15rem;
  border-bottom: 1px solid var(--border);
}

.viz__title {
  font-weight: 700;
  font-size: 0.92rem;
  margin: 0;
}

.viz__sub {
  margin: 0.2rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.viz__stage {
  position: relative;
  background: var(--viz-bg);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0.75rem;
}

.viz__stage--split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

/* Two stacked stage rows in the same card (e.g. a schematic above a
   curve+render split) get a visible seam between them. */
.viz__stage + .viz__stage {
  border-top: 1px solid var(--border);
}

@media (max-width: 620px) {
  .viz__stage--split { grid-template-columns: 1fr; }
}

.viz canvas {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
  border-radius: 6px;
  touch-action: none;
}

.viz__controls {
  padding: 0.9rem 1.15rem 1.1rem;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 0.85rem 1.5rem;
}

.viz__legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.1rem;
  padding: 0.6rem 1.15rem;
  font-size: 0.83rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

.viz__legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.viz__legend i {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 3px;
  display: inline-block;
  flex: none;
}

.legend-a { background: var(--viz-a); }
.legend-b { background: var(--viz-b); }
.legend-arnold { background: var(--arnold); }
.legend-pxr { background: var(--pxr); }

.viz__note {
  padding: 0.7rem 1.15rem 0.9rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

.viz__note p { margin: 0; }

.viz__fallback {
  padding: 1.25rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  text-align: center;
}

/* ---------- Controls ---------- */
.ctl { font-size: 0.85rem; }

.ctl__label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.3rem;
  color: var(--text-muted);
}

.ctl__value {
  font-family: "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.82rem;
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.ctl input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
  margin: 0;
  display: block;
}

.ctl input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: var(--border);
}

.ctl input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: var(--border);
}

.ctl input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  margin-top: -5.5px;
  border-radius: 999px;
  background: var(--accent);
  border: 2px solid var(--bg-elevated);
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}

.ctl input[type="range"]::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border-radius: 999px;
  background: var(--accent);
  border: 2px solid var(--bg-elevated);
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}

.ctl input[type="range"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
  border-radius: 999px;
}

/* Segmented toggle */
.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  flex-wrap: wrap;
}

.seg button {
  appearance: none;
  border: 0;
  border-right: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.8rem;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  line-height: 1.5;
}

.seg button:last-child { border-right: 0; }
.seg button:hover { color: var(--text); }

.seg button.is-active {
  background: var(--accent);
  color: #fff;
}

.seg button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.ctl--seg .ctl__label { margin-bottom: 0.4rem; }

/* Readout strip under a widget */
.readout {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 1.5rem;
  padding: 0.6rem 1.15rem;
  border-top: 1px solid var(--border);
  font-size: 0.83rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.readout b {
  color: var(--text);
  font-family: "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.82rem;
}

/* ---------- Optional maths ---------- */
details.math {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  padding: 0.6rem 1rem;
  margin: 1.25rem 0;
  font-size: 0.93rem;
}

details.math > summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-muted);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

details.math > summary::-webkit-details-marker { display: none; }

details.math > summary::before {
  content: "▸";
  font-size: 0.75rem;
  transition: transform 0.15s ease;
}

details.math[open] > summary::before { transform: rotate(90deg); }
details.math[open] > summary { margin-bottom: 0.5rem; }
details.math > summary:hover { color: var(--accent); }

.formula {
  background: var(--code-bg);
  border-radius: 6px;
  padding: 0.7rem 0.9rem;
  margin: 0.75rem 0;
  overflow-x: auto;
  font-family: "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.84rem;
  line-height: 1.7;
  white-space: pre;
}

.formula-where {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0.4rem 0 0;
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  details.math > summary::before { transition: none; }
}
