/* Rafael Romão's Coding Labs: one stylesheet for the index, lab pages and source viewer.
   Colours are tokens; dark values apply from the OS setting or the header toggle. */

:root {
  color-scheme: light;
  --paper: oklch(98.5% .006 85);
  --surface: oklch(100% .002 85);
  --panel: oklch(96% .01 85);
  --ink: oklch(25% .018 260);
  --muted: oklch(47% .015 260);
  --rule: oklch(87% .01 80);
  --accent: oklch(49% .105 195);
  --accent-soft: oklch(94% .035 195);
  --link: oklch(42% .1 215);
  --success: oklch(51% .11 145);
  --danger: oklch(53% .15 25);
  --focus: oklch(58% .13 250);
  --shadow: 0 1px 2px oklch(25% .02 260 / .06), 0 4px 16px oklch(25% .02 260 / .05);
  --code-border: oklch(35% .02 260);

  --fig-box: oklch(100% .003 85);
  --fig-acc: oklch(94% .035 195);
  --fig-ok: oklch(94% .04 145);
  --fig-ok-text: oklch(40% .12 145);
  --fig-bad: oklch(95% .035 25);
  --fig-band: oklch(94% .035 195 / .55);
  --fig-strip: oklch(92% .008 85);
  --fig-bar: oklch(88% .02 260);
  --fig-bar-acc: oklch(86% .06 195);
  --fig-dim: oklch(70% .015 260);
  --fig-dot-dim: oklch(75% .012 260);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: oklch(18% .012 260);
    --surface: oklch(22% .014 260);
    --panel: oklch(24% .014 260);
    --ink: oklch(93% .01 85);
    --muted: oklch(73% .015 260);
    --rule: oklch(33% .015 260);
    --accent: oklch(76% .11 195);
    --accent-soft: oklch(32% .05 195);
    --link: oklch(80% .09 215);
    --success: oklch(75% .13 145);
    --danger: oklch(72% .15 25);
    --focus: oklch(75% .13 250);
    --shadow: none;
    --code-border: oklch(36% .02 260);

    --fig-box: oklch(26% .014 260);
    --fig-acc: oklch(34% .06 195);
    --fig-ok: oklch(33% .06 145);
    --fig-ok-text: oklch(80% .13 145);
    --fig-bad: oklch(33% .07 25);
    --fig-band: oklch(40% .06 195 / .45);
    --fig-strip: oklch(27% .012 260);
    --fig-bar: oklch(36% .02 260);
    --fig-bar-acc: oklch(42% .08 195);
    --fig-dim: oklch(56% .015 260);
    --fig-dot-dim: oklch(56% .012 260);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: oklch(18% .012 260);
  --surface: oklch(22% .014 260);
  --panel: oklch(24% .014 260);
  --ink: oklch(93% .01 85);
  --muted: oklch(73% .015 260);
  --rule: oklch(33% .015 260);
  --accent: oklch(76% .11 195);
  --accent-soft: oklch(32% .05 195);
  --link: oklch(80% .09 215);
  --success: oklch(75% .13 145);
  --danger: oklch(72% .15 25);
  --focus: oklch(75% .13 250);
  --shadow: none;
  --code-border: oklch(36% .02 260);

  --fig-box: oklch(26% .014 260);
  --fig-acc: oklch(34% .06 195);
  --fig-ok: oklch(33% .06 145);
  --fig-ok-text: oklch(80% .13 145);
  --fig-bad: oklch(33% .07 25);
  --fig-band: oklch(40% .06 195 / .45);
  --fig-strip: oklch(27% .012 260);
  --fig-bar: oklch(36% .02 260);
  --fig-bar-acc: oklch(42% .08 195);
  --fig-dim: oklch(56% .015 260);
  --fig-dot-dim: oklch(56% .012 260);
}

/* Base */
* { box-sizing: border-box; }
html {
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}
body { margin: 0; background: var(--paper); line-height: 1.6; }
a { color: var(--link); text-underline-offset: .16em; }
a:hover { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
img, svg { max-width: 100%; }
code, pre { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
:not(pre) > code { padding: .05em .3em; font-size: .88em; background: var(--panel); border: 1px solid var(--rule); border-radius: .25rem; }
h1, h2, h3, h4 { line-height: 1.15; letter-spacing: -.02em; }
h1 { max-width: 20ch; margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(2.2rem, 5.5vw, 4.2rem); font-weight: 500; }
h2 { margin: 3rem 0 .85rem; font-size: 1.4rem; }
h3 { margin: 1.6rem 0 .4rem; font-size: 1.05rem; }
details { margin-top: 1rem; }
summary { cursor: pointer; font-weight: 700; }

/* Layout */
.page { width: min(100% - 2.5rem, 76rem); margin: 0 auto; padding: 2.5rem 0 5rem; }
.page article > section, .page article > p, .page article > figure { max-width: 72ch; }
.eyebrow { margin: 0 0 .6rem; color: var(--accent); font-size: .76rem; font-weight: 750; letter-spacing: .12em; text-transform: uppercase; }
.lede { max-width: 66ch; margin: 1.3rem 0 0; color: var(--muted); font-size: 1.12rem; }

/* Site header and footer sit outside the article, so reader views leave them out. */
.site-bar { border-bottom: 1px solid var(--rule); background: var(--paper); }
.site-bar-inner { display: flex; align-items: center; justify-content: space-between; gap: .75rem 1.5rem; width: min(100% - 2.5rem, 76rem); margin: 0 auto; padding: .9rem 0; }
.brand { display: inline-flex; align-items: center; gap: .55rem; color: var(--ink); font-weight: 750; letter-spacing: -.01em; text-decoration: none; }
.brand:hover { color: var(--ink); }
.brand-mark { display: grid; place-items: center; flex: 0 0 auto; width: 1.75rem; height: 1.75rem; color: var(--paper); background: var(--ink); border-radius: .35rem; font: 800 .7rem/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.site-nav { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem 1.1rem; font-size: .9rem; }
.site-nav a { color: var(--muted); text-decoration: none; }
.site-nav a:hover { color: var(--ink); }
.theme-toggle { display: inline-grid; place-items: center; width: 2.25rem; height: 2.25rem; padding: 0; color: var(--ink); background: transparent; border: 1px solid var(--rule); border-radius: 50%; cursor: pointer; }
.theme-toggle:hover { background: var(--panel); }
.theme-toggle svg { width: 1.05rem; height: 1.05rem; }
.theme-toggle .moon { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .moon { display: block; }
}
.site-footer { width: min(100% - 2.5rem, 76rem); margin: 0 auto; padding: 1.5rem 0 3rem; border-top: 1px solid var(--rule); color: var(--muted); font-size: .86rem; }

/* Index page */
.hero { padding: 2rem 0 .5rem; }
.hero h1 { max-width: none; text-wrap: balance; }
.keep { white-space: nowrap; }
.tagline { max-width: 34ch; text-wrap: balance; margin: .9rem 0 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.25rem, 2.6vw, 1.7rem); line-height: 1.3; }
.actions { display: flex; flex-wrap: wrap; gap: .75rem; margin: 2rem 0 0; }
.button { display: inline-flex; align-items: center; gap: .5rem; padding: .7rem 1.05rem; color: var(--paper); background: var(--ink); border: 1px solid var(--ink); border-radius: .45rem; font-weight: 700; text-decoration: none; }
.button:hover { color: var(--paper); opacity: .88; }
.button.secondary { color: var(--ink); background: transparent; border-color: var(--rule); }
.button.secondary:hover { color: var(--ink); background: var(--panel); opacity: 1; }
.facts { display: flex; flex-wrap: wrap; gap: .4rem 1.1rem; margin: 1.6rem 0 0; padding: 0; color: var(--muted); font-size: .9rem; list-style: none; }
.facts li + li::before { content: "·"; margin-right: 1.1rem; color: var(--accent); font-weight: 800; }

.home article > section { max-width: none; }
.section-intro { max-width: 68ch; color: var(--muted); }
.projects { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.project { display: flex; flex-direction: column; min-width: 0; padding: 1.25rem 1.3rem; background: var(--surface); border: 1px solid var(--rule); border-radius: .6rem; box-shadow: var(--shadow); }
.project h3 { margin: 0 0 .35rem; font-size: 1.15rem; }
.project p { margin: .35rem 0; color: var(--muted); }
.project .project-link { margin-top: auto; padding-top: 1rem; font-weight: 700; }

.steps { counter-reset: step; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin: 1rem 0 0; padding: 0; list-style: none; }
.steps li { padding: 1rem 1.05rem; background: var(--surface); border: 1px solid var(--rule); border-radius: .6rem; }
.steps li::before { counter-increment: step; content: counter(step, decimal-leading-zero); display: block; margin-bottom: .4rem; color: var(--accent); font-size: .74rem; font-weight: 800; letter-spacing: .08em; }
.steps strong { display: block; margin-bottom: .25rem; }
.steps span { color: var(--muted); font-size: .94rem; }

.group { margin-top: 2.2rem; }
.group h3 { margin: 0 0 .9rem; font-size: 1.05rem; }
.lab-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 19rem), 1fr)); gap: .9rem; margin: 0; padding: 0; list-style: none; }
.lab-card { position: relative; display: flex; flex-direction: column; gap: .35rem; padding: 1rem 1.1rem 1.1rem; background: var(--surface); border: 1px solid var(--rule); border-radius: .6rem; box-shadow: var(--shadow); transition: border-color .15s, transform .15s; }
.lab-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.lab-card:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.lab-card h4 { margin: 0; font-size: 1.02rem; }
.lab-card h4 a { color: var(--ink); text-decoration: none; }
.lab-card h4 a::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.lab-card h4 a:focus-visible { outline: none; }
.lab-id { display: inline-block; margin-right: .5rem; padding: .05rem .4rem; color: var(--accent); background: var(--accent-soft); border-radius: .3rem; font-size: .72rem; font-weight: 800; letter-spacing: .06em; vertical-align: .12em; }
.lab-card p { margin: 0; color: var(--muted); font-size: .92rem; line-height: 1.5; }

.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 3rem; }
.plain-list { padding-left: 1.1rem; }
.plain-list li { margin: .5rem 0; }

/* Lab pages */
.callout { padding: 1rem 1.15rem; background: var(--panel); border: 1px solid var(--rule); border-radius: .45rem; }
.numbered { padding-left: 1.5rem; }
.numbered li { margin: .5rem 0; padding-left: .25rem; }
.lab-rules li { margin: .45rem 0; }
.checks { margin: 1rem 0 0; padding: 0; list-style: none; }
.checks li { display: flex; align-items: baseline; gap: .65rem; margin: .55rem 0; }
.checks li::before { content: "☐"; flex: 0 0 auto; color: var(--muted); }
.lab-nav { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .75rem 1.5rem; max-width: 72ch; margin-top: 2.5rem; padding-top: 1rem; border-top: 1px solid var(--rule); font-weight: 750; }

.lab-figure { margin: 1.5rem 0; padding: 1rem; overflow-x: auto; background: var(--panel); border: 1px solid var(--rule); border-radius: .45rem; }
.lab-figure svg { display: block; width: 100%; min-width: 34rem; height: auto; }
.lab-figure figcaption { margin-top: .75rem; color: var(--muted); font-size: .86rem; }
.lab-figure text { fill: var(--ink); font-size: 13px; }
.lab-figure text.m { fill: var(--muted); font-size: 11.5px; }
.lab-figure text.bt { font-size: 12px; }
.lab-figure text.bt.mono { font-size: 11.5px; }
.lab-figure text.b { font-weight: 700; }
.lab-figure text.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.lab-figure text.acc { fill: var(--accent); }
.lab-figure text.ok { fill: var(--fig-ok-text); }
.lab-figure text.bad { fill: var(--danger); }
.lab-figure .bx { fill: var(--fig-box); stroke: var(--ink); stroke-width: 1.2; }
.lab-figure .bx.acc { fill: var(--fig-acc); stroke: var(--accent); }
.lab-figure .bx.ok { fill: var(--fig-ok); stroke: var(--success); }
.lab-figure .bx.bad { fill: var(--fig-bad); stroke: var(--danger); }
.lab-figure .bx.dim { fill: var(--panel); stroke: var(--fig-dim); stroke-dasharray: 4 3; }
.lab-figure .bx.ring { fill: var(--fig-band); stroke: var(--accent); }
.lab-figure .bx.dash { stroke-dasharray: 6 4; }
.lab-figure .ln { fill: none; stroke: var(--ink); stroke-width: 1.3; }
.lab-figure .ln.acc { stroke: var(--accent); stroke-width: 2; }
.lab-figure .ln.ok { stroke: var(--success); }
.lab-figure .ln.bad { stroke: var(--danger); }
.lab-figure .ln.mut { stroke: var(--fig-dim); }
.lab-figure .ln.dash { stroke-dasharray: 5 4; }
.lab-figure .mk { fill: var(--ink); }
.lab-figure .mk.acc { fill: var(--accent); }
.lab-figure .mk.bad { fill: var(--danger); }
.lab-figure .dot { fill: var(--ink); }
.lab-figure .dot.acc { fill: var(--accent); }
.lab-figure .dot.ok { fill: var(--success); }
.lab-figure .dot.bad { fill: var(--danger); }
.lab-figure .dot.dim { fill: var(--fig-dot-dim); }
.lab-figure .band { fill: var(--fig-band); }
.lab-figure .strip { fill: var(--fig-strip); stroke: var(--paper); }
.lab-figure .frame { fill: none; stroke: var(--fig-dim); stroke-width: 1.5; stroke-dasharray: 6 4; }
.lab-figure .bar { fill: var(--fig-bar); stroke: var(--ink); stroke-width: 1; }
.lab-figure .bar.acc, .lab-figure .fill.acc { fill: var(--fig-bar-acc); stroke: var(--accent); }
.lab-figure .ghost { stroke-width: 1.5; stroke-dasharray: 6 4; }
.lab-figure .ghost.bad { fill: color-mix(in oklch, var(--fig-bad) 70%, transparent); stroke: var(--danger); }
.lab-figure .ghost.acc { fill: color-mix(in oklch, var(--fig-acc) 60%, transparent); stroke: var(--accent); }
/* Raster diagrams were drawn on white; soften them in dark mode. */
:root[data-theme="dark"] article img { background: oklch(96% .005 85); border-radius: .35rem; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) article img { background: oklch(96% .005 85); border-radius: .35rem; }
}

/* Code: Catppuccin Mocha in both themes */
.source-code, .lab-code {
  --syntax-base: #1e1e2e; --syntax-text: #cdd6f4; --syntax-mauve: #cba6f7; --syntax-green: #a6e3a1;
  --syntax-peach: #fab387; --syntax-yellow: #f9e2af; --syntax-comment: #a6adc8; --syntax-blue: #89b4fa;
  overflow: auto; margin: 1rem 0 0; padding: 1rem 1.1rem;
  color: var(--syntax-text); background: var(--syntax-base); border: 1px solid var(--code-border); border-radius: .45rem;
  font: .82rem/1.55 ui-monospace, SFMono-Regular, Consolas, monospace; tab-size: 4;
}
.source-code { max-height: 75vh; margin-top: 1.5rem; font-size: .84rem; }
.source-code code, .lab-code code { white-space: pre; }
:is(.source-code, .lab-code) .hljs-keyword { color: var(--syntax-mauve); }
:is(.source-code, .lab-code) .hljs-title.function_, :is(.source-code, .lab-code) .hljs-title { color: var(--syntax-blue); }
:is(.source-code, .lab-code) .hljs-title.class_, :is(.source-code, .lab-code) .hljs-type { color: var(--syntax-yellow); }
:is(.source-code, .lab-code) .hljs-string { color: var(--syntax-green); }
:is(.source-code, .lab-code) .hljs-number, :is(.source-code, .lab-code) .hljs-literal { color: var(--syntax-peach); }
:is(.source-code, .lab-code) .hljs-comment { color: var(--syntax-comment); font-style: italic; }
:is(.source-code, .lab-code) .hljs-built_in, :is(.source-code, .lab-code) .hljs-meta { color: var(--syntax-blue); }
.source-page h1 { word-break: break-word; }

/* Responsive */
@media (max-width: 900px) {
  .steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .page, .site-bar-inner, .site-footer { width: min(100% - 2rem, 76rem); }
  .page { padding-top: 1.5rem; }
  .projects, .two-col { grid-template-columns: 1fr; }
  .hero { padding-top: 1rem; }
}
@media (max-width: 560px) {
  .site-bar-inner { flex-wrap: wrap; }
  .brand-name { font-size: .95rem; }
  .steps { grid-template-columns: 1fr; }
  .actions .button { flex: 1 1 100%; justify-content: center; }
  .lede { font-size: 1.02rem; }
}
@media (prefers-reduced-motion: reduce) {
  .lab-card { transition: none; }
  .lab-card:hover { transform: none; }
}
@media print {
  .site-bar, .site-footer, .theme-toggle { display: none; }
  .lab-card, .project, .steps li { box-shadow: none; break-inside: avoid; }
}
