/* RL Zero prototype: shared tokens and base styles */

@font-face { font-family: "iA Writer Quattro"; src: url("../fonts/iAWriterQuattroS-Regular.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "iA Writer Quattro"; src: url("../fonts/iAWriterQuattroS-Italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "iA Writer Quattro"; src: url("../fonts/iAWriterQuattroS-Bold.woff2") format("woff2"); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: "iA Writer Quattro"; src: url("../fonts/iAWriterQuattroS-BoldItalic.woff2") format("woff2"); font-weight: 700; font-style: italic; font-display: swap; }

:root {
  --paper: #edf0ee;
  --paper-2: #f6f8f6;
  --grid: rgba(62, 84, 74, 0.075);
  --ink: #27312c;
  --ink-2: #56625c;
  --ink-3: #87928c;
  --line: #cfd7d2;

  /* meaning-carrying colors: reward, penalty, idea, highlight */
  --sage: #5f8c75;
  --sage-soft: #dbe7df;
  --rose: #a9726c;
  --rose-soft: #f0e1de;
  --slate: #5f6f99;
  --slate-soft: #e0e4ef;
  --ochre: #a98a4f;
  --ochre-soft: #efe6d3;

  /* key RL concepts: one colour each, in running text and in formulas */
  --k-state: #4f5f8f;
  --k-action: #8a6a2c;
  --k-reward: #3f7a5c;
  --k-policy: #9a514a;
  --k-value: #6c5694;

  --font-body: "iA Writer Quattro", "IBM Plex Sans", system-ui, sans-serif;
  --font-head: Optima, "Optima nova", Candara, "Segoe UI", "Noto Sans", sans-serif;

  --measure: 74ch;
  --radius-s: 6px;
  --radius-m: 14px;
  --shadow: 0 1px 0 rgba(39, 49, 44, 0.06), 0 8px 24px -12px rgba(39, 49, 44, 0.25);
  color-scheme: light;
}

/* ---------- palette options (light mode), chosen with ?palette=b|c|d|e; "a" is the default above ---------- */
:root[data-palette="b"] { /* Brighter: same hues, more saturation */
  --paper: #eef2ef; --paper-2: #f8faf8; --ink: #1f2a25; --line: #cad6cf;
  --sage: #2e9a68; --sage-soft: #d3eddf; --rose: #d4574b; --rose-soft: #f8dcd8;
  --slate: #3d63d1; --slate-soft: #dbe3f8; --ochre: #d8961c; --ochre-soft: #f8e8c8;
  --k-state: #3456c0; --k-action: #b5760c; --k-reward: #1f8656; --k-policy: #c2433a; --k-value: #7a4fc9;
}
:root[data-palette="c"] { /* Ink and tomato: warm paper, editorial primaries */
  --paper: #f6f1e7; --paper-2: #fcf9f3; --grid: rgba(80, 60, 30, 0.07); --ink: #1d1d1f; --ink-2: #4a4a4f; --ink-3: #85837d; --line: #ddd5c6;
  --sage: #0f9d6b; --sage-soft: #d2efe2; --rose: #e4572e; --rose-soft: #fbe0d6;
  --slate: #2b59c3; --slate-soft: #dce4f7; --ochre: #e89a00; --ochre-soft: #fcebc4;
  --k-state: #2b59c3; --k-action: #b87400; --k-reward: #0b8a5d; --k-policy: #d9481f; --k-value: #7b3fbf;
}
:root[data-palette="d"] { /* Retro game: matches the pixel dog */
  --paper: #fbf5ec; --paper-2: #fffdf8; --grid: rgba(90, 60, 120, 0.06); --ink: #2a2140; --ink-2: #574d6b; --ink-3: #8f86a0; --line: #e3d9cb;
  --sage: #17a884; --sage-soft: #d4f3ea; --rose: #f2506f; --rose-soft: #ffe0e6;
  --slate: #6c4bd8; --slate-soft: #e7e0fb; --ochre: #ec9a12; --ochre-soft: #fdebc8;
  --k-state: #6c4bd8; --k-action: #c27800; --k-reward: #12946f; --k-policy: #e03a5c; --k-value: #2f73d9;
}
:root[data-palette="e"] { /* Ocean and coral: cool paper, blue and coral */
  --paper: #eef3f8; --paper-2: #f8fbfe; --grid: rgba(30, 70, 120, 0.07); --ink: #18263a; --ink-2: #475569; --ink-3: #8392a6; --line: #cfdbe7;
  --sage: #0e9f8d; --sage-soft: #d0f0eb; --rose: #f2604f; --rose-soft: #ffe1dd;
  --slate: #2f6fe4; --slate-soft: #dbe7fc; --ochre: #f09a12; --ochre-soft: #fdecc9;
  --k-state: #2f6fe4; --k-action: #c07a08; --k-reward: #0b8a7b; --k-policy: #e04a3a; --k-value: #8a4fd6;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1c2220; --paper-2: #232a27; --grid: rgba(200, 220, 210, 0.05);
    --ink: #dde3df; --ink-2: #a7b1ab; --ink-3: #75807a; --line: #36403b;
    --sage: #8db5a0; --sage-soft: #2a3a32; --rose: #cf9d97; --rose-soft: #3d2d2b;
    --slate: #98a5cb; --slate-soft: #2b3142; --ochre: #ccb07a; --ochre-soft: #3a3426;
    --k-state: #a3b0d8; --k-action: #d6b97c; --k-reward: #8fc4a7; --k-policy: #dc9e96; --k-value: #b9a6dc;
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 10px 28px -14px rgba(0, 0, 0, 0.7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #1c2220; --paper-2: #232a27; --grid: rgba(200, 220, 210, 0.05);
  --ink: #dde3df; --ink-2: #a7b1ab; --ink-3: #75807a; --line: #36403b;
  --sage: #8db5a0; --sage-soft: #2a3a32; --rose: #cf9d97; --rose-soft: #3d2d2b;
  --slate: #98a5cb; --slate-soft: #2b3142; --ochre: #ccb07a; --ochre-soft: #3a3426;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 10px 28px -14px rgba(0, 0, 0, 0.7);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background-color: var(--paper);
  /* graph paper: the gridworld every RL agent grows up in */
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.65;
  overflow-x: hidden;
}

h1, h2, h3 {
  font-family: var(--font-head);
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: 0.005em;
  margin: 0 0 0.5em;
  text-wrap: balance;
}
h2 { font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.15rem); }
h3 { font-size: 1.3rem; }
p { margin: 0 0 1em; max-width: var(--measure); text-wrap: pretty; }
a { color: var(--slate); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
strong { font-weight: 700; }
small, .fine { font-size: 0.875rem; color: var(--ink-2); }

:focus-visible { outline: 2px solid var(--slate); outline-offset: 3px; border-radius: 3px; }

.wrap { width: min(100% - 32px, 1080px); margin-inline: auto; }
.wrap-text { width: min(100% - 32px, 720px); margin-inline: auto; }

/* ---------- brand (home link) ---------- */
.brand { display: inline-flex; align-items: center; gap: 8px; font-family: var(--font-head); font-size: 1.08rem; color: var(--ink); text-decoration: none; white-space: nowrap; }
.brand .zero { width: 30px; height: 30px; }

/* ---------- home: section rail ---------- */
.rail {
  position: fixed; z-index: 30; right: 22px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
}
.rail a { display: flex; align-items: center; gap: 10px; padding: 5px 0; text-decoration: none; color: var(--ink-2); font-size: 0.85rem; }
.rail i { width: 7px; height: 7px; border-radius: 99px; background: var(--ink-3); opacity: 0.55; transition: height 0.2s, background 0.2s, opacity 0.2s; }
.rail span { opacity: 0; transform: translateX(6px); transition: opacity 0.15s, transform 0.15s; pointer-events: none;
  background: color-mix(in srgb, var(--paper-2) 85%, transparent); padding: 2px 8px; border-radius: 99px; }
.rail:hover span, .rail a:focus-visible span { opacity: 1; transform: none; }
.rail a:hover i { opacity: 1; background: var(--ink-2); }
.rail a[aria-current] i { height: 20px; background: var(--sage); opacity: 1; }
.rail a[aria-current] span { color: var(--ink); }
@media (max-width: 900px) { .rail { display: none; } }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-size: 0.95rem;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--paper-2); color: var(--ink);
  cursor: pointer; text-decoration: none;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:hover { border-color: var(--ink-3); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn.primary:hover { background: color-mix(in srgb, var(--ink) 85%, var(--sage)); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 3px; background: var(--paper-2); }
.seg button { font: inherit; font-size: 0.9rem; border: 0; background: none; color: var(--ink-2); padding: 6px 14px; border-radius: 999px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

/* ---------- formula symbols ---------- */
.katex [data-sym] {
  cursor: help;
  border-radius: 3px;
  transition: background 0.15s, box-shadow 0.15s;
  box-shadow: inset 0 -1.5px 0 color-mix(in srgb, var(--slate) 55%, transparent);
}
.katex [data-sym]:hover, .katex [data-sym]:focus-visible, .katex [data-sym].is-on {
  background: var(--slate-soft);
  box-shadow: none;
  outline: none;
}
.sym-tip {
  position: fixed; z-index: 50; max-width: 280px;
  background: var(--ink); color: var(--paper);
  font-size: 0.875rem; line-height: 1.45;
  padding: 10px 12px; border-radius: var(--radius-s);
  pointer-events: none; opacity: 0; transform: translateY(4px);
  transition: opacity 0.12s, transform 0.12s;
}
.sym-tip.show { opacity: 1; transform: none; }
.sym-tip b { font-family: var(--font-head); font-weight: 600; display: block; margin-bottom: 2px; }

/* ---------- Zero, the mascot (a line-drawn dog) ---------- */
.zero { overflow: visible; color: var(--ink); }
.zero path, .zero circle, .zero ellipse { fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; }
.zero .zero-head { stroke-width: 5; }
.zero .zero-face { fill: #f7ecd9; stroke: none; }
.zero .zero-knot { fill: #ecd1a6; stroke: none; }
.zero .zero-tuft { fill: #ecd1a6; stroke-width: 3.6; }
.zero .zero-ear { fill: #dca46a; stroke-width: 4; transform-box: fill-box; transition: transform 0.25s; }
.zero .zero-curl { stroke: #b07c4a; stroke-width: 2.4; }
.zero .zero-muzzle { fill: #fffaf1; stroke: none; }
.zero .zero-pupil circle, .zero .zero-nose { fill: currentColor; stroke: none; }
.zero .zero-pupil .zero-shine { fill: #fff; }
.zero .zero-pupil { transition: transform 0.06s linear; }
.zero .zero-mouth { stroke-width: 3; }
.zero .zero-eyes-happy { stroke-width: 3.6; }
.zero .zero-ear-l { transform-origin: 100% 0; }
.zero .zero-ear-r { transform-origin: 0 0; }
.zero .zero-eyes-happy, .zero .zero-tongue { opacity: 0; }
.zero .zero-tongue { fill: var(--rose); stroke-width: 2.6; }
.zero.happy .zero-eyes-open { opacity: 0; }
.zero.happy .zero-eyes-happy, .zero.happy .zero-tongue { opacity: 1; }
.zero.happy .zero-ear-l { transform: rotate(10deg); }
.zero.happy .zero-ear-r { transform: rotate(-10deg); }
.zero.scared .zero-ear-l { transform: rotate(-6deg) translateY(3px); }
.zero.scared .zero-ear-r { transform: rotate(6deg) translateY(3px); }
.zero.scared { animation: shake 0.35s; }
@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

footer.site {
  margin-top: 96px; padding: 28px 0 40px; border-top: 1px solid var(--line);
  color: var(--ink-3); font-size: 0.875rem;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* key concepts: coloured word, followed by its symbol */
.kw { font-weight: 700; color: var(--kc, var(--ink)); white-space: nowrap; }
.kw .ksym { font-weight: 400; }
[data-k="state"] { --kc: var(--k-state); }
[data-k="action"] { --kc: var(--k-action); }
[data-k="reward"] { --kc: var(--k-reward); }
[data-k="policy"] { --kc: var(--k-policy); }
[data-k="value"] { --kc: var(--k-value); }
.katex [data-k] { color: var(--kc); }

/* words in running text that explain themselves on hover/tap */
.word-sym[data-sym] {
  cursor: help; border-radius: 3px; text-decoration: underline dotted color-mix(in srgb, var(--slate) 70%, transparent);
  text-underline-offset: 0.2em; transition: background 0.15s;
}
.word-sym[data-sym]:hover, .word-sym[data-sym]:focus-visible, .word-sym[data-sym].is-on { background: var(--slate-soft); outline: none; }
