/* Hub pages (index.html and other-topics/index.html). Shared styles: after any change, give
   every ?v= tag in both pages a new value. */

/* ---------- Tokens ---------- */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #6f6d68;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: var(--text-muted);      /* boundaries that identify a control (3:1) */
  --accent: #2670cc;                       /* white text 4.9:1 */
  --accent-ink: #ffffff;

  --series-a: #149a6a;                     /* 3.5:1 on surface */
  --series-b: #eb6834;                     /* 3.1:1 */
  --series-c: #2a78d6;                     /* 4.3:1 */
  --series-d: #4a3aa7;                     /* 8.3:1 */

  --status-good: #0ca30c;
  --status-warning: #fab219;               /* graphics only, never text */
  --status-critical: #d03b3b;
  --success-text: #006300;
  --critical-text: #d03b3b;

  --chart-font-small: 11px;                /* drawn text and line sizes */
  --chart-font: 12px;
  --chart-line: 2px;
  --chart-line-total: 2.5px;
  --chart-marker: 5px;
  --chart-halo: 4px;

  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;

  /* Card-graphic keyboard (decorative, aria-hidden) */
  --key-white: #ffffff;
  --key-black: #2b2a28;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #9a988f;
    --grid: #2c2c2a;
    --axis: #45443f;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-ink: #0b0b0b;                 /* dark ink on the brighter accent: 5.4:1 */
    --series-a: #199e70;
    --series-b: #d95926;
    --series-c: #3987e5;
    --series-d: #9085e9;
    --success-text: #0ca30c;
    --critical-text: #ef6a63;
    --key-white: #4a4944;
    --key-black: #0d0d0d;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #9a988f;
  --grid: #2c2c2a;
  --axis: #45443f;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-ink: #0b0b0b;
  --series-a: #199e70;
  --series-b: #d95926;
  --series-c: #3987e5;
  --series-d: #9085e9;
  --success-text: #0ca30c;
  --critical-text: #ef6a63;
  --key-white: #4a4944;
  --key-black: #0d0d0d;
}

/* ---------- Series keys ---------- */

.key { display: block; width: 28px; height: 4px; border-radius: 2px; background: var(--key); }

/* ---------- Base ---------- */

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

html { -webkit-text-size-adjust: 100%; }
/* Large screens: the root steps up so text keeps pace with the wider card grid. Both need a minimum
   height, so a wide but short window keeps the normal size. */
@media (min-width: 1600px) and (min-height: 900px) { html { font-size: 112.5%; } }
@media (min-width: 2200px) and (min-height: 1200px) { html { font-size: 125%; } }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.9375rem;
  line-height: 1.5;
}

h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 2.6rem; font-weight: 750; letter-spacing: -0.02em; line-height: 1.1; }
h2 { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.005em; }
h3 { font-size: 1.2rem; font-weight: 650; }

:is(a, button, input, select, summary, [tabindex]):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 16px; top: -100px; padding: 8px 12px;
  background: var(--accent); color: var(--accent-ink); border-radius: 8px; font-weight: 600;
}
.skip-link:focus { top: 16px; z-index: 10; outline: 2px solid var(--text-primary); outline-offset: 2px; }

.btn {
  display: inline-block;
  padding: 7px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text-primary);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { filter: brightness(0.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; font-weight: 500; font-size: 0.85rem; color: var(--text-secondary); white-space: nowrap; }

/* ---------- Header ---------- */

/* The page fills the window; only the lede keeps a reading measure. */
.site-header, main, .site-footer {
  width: 100%;
  margin: 0 auto;
  padding-left: 24px;
  padding-right: 24px;
}

.site-header { padding-top: 28px; padding-bottom: 28px; }

.title-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}
/* The 320px basis lets the buttons drop below the title on a phone instead of squeezing it. */
.title-row > div:first-child { flex: 1 1 320px; min-width: 0; }
.header-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.title-rule { display: flex; gap: 4px; width: 260px; max-width: 100%; margin-top: 12px; }
.title-rule span { flex: 1; height: 5px; border-radius: 1px; background: var(--series-a); }
.title-rule span:nth-child(2) { background: var(--series-b); }
.title-rule span:nth-child(3) { background: var(--series-c); }

.lede { margin: 12px 0 0; color: var(--text-secondary); max-width: 62ch; }

/* Instrumental Teaching logo (brand kit: main logo, 4.02 : 1, at least 160 px wide), 360 px wide
   (240 px on phones). The bottom margin keeps the brand's clear space, the height of the play
   triangle: 0.32 × the logo's height, 29 px at 90 px tall. */
.brand { margin: 0 0 1.875rem; }
.brand img { display: block; width: 22.5rem; max-width: 100%; height: auto; }
.brand .brand-dark { display: none; }
:root[data-theme="dark"] .brand .brand-light { display: none; }
:root[data-theme="dark"] .brand .brand-dark { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand .brand-light { display: none; }
  :root:not([data-theme="light"]) .brand .brand-dark { display: block; }
}

.back-link { margin: 0 0 1.875rem; font-size: 0.85rem; }   /* the logo's clear space above it too */
.back-link a { color: var(--text-secondary); }

/* ---------- Cards ---------- */

main { display: grid; gap: 32px; }

.group h2 { margin-bottom: 14px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 18px 20px;
  background: var(--surface);
  border: 2px solid var(--text-muted);
  border-radius: var(--radius);
  transition: border-color 0.15s, transform 0.15s;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }

.card .key { margin-bottom: 12px; }
.card .eyebrow { margin-bottom: 4px; }

.card h3 a { color: inherit; text-decoration: none; }
/* Stretch the title link over the whole card, so any click opens the project. */
.card h3 a::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }

.card .desc { flex: 1; margin: 8px 0 18px; color: var(--text-secondary); font-size: 0.92rem; }

.card-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-top: 14px;
  border-top: 1px solid var(--grid);
}

/* ---------- Visuals (card graphics, decorative) ---------- */

.art {
  margin-bottom: 16px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--grid);
  border-radius: 8px;
}
/* overflow: visible keeps descenders on bottom-edge labels from being clipped. */
.art svg { display: block; width: 100%; height: auto; overflow: visible; }

.art .axis { fill: none; stroke: var(--axis); stroke-width: calc(var(--chart-line) * 0.75); }
.art .neutral { stroke: var(--grid); stroke-width: calc(var(--chart-line) * 0.6); stroke-dasharray: 3 3; }
.art .guide { stroke: var(--text-muted); stroke-width: calc(var(--chart-line) * 0.6); stroke-dasharray: 4 3; }
/* Halo; the paint-order attribute that puts it behind the letters is set in script. */
.art .label, .art .formula { stroke: var(--surface); stroke-width: var(--chart-halo); stroke-linejoin: round; }
.art .label { fill: var(--text-muted); font: 600 var(--chart-font-small) var(--font); }
.art .formula { fill: var(--text-primary); font: 700 var(--chart-font) var(--font); }
.art .curve { fill: none; stroke-width: var(--chart-line-total); stroke-linecap: round; stroke-linejoin: round; }
.art .curve.thin { stroke-width: var(--chart-line); }
.art .a { stroke: var(--series-a); }
.art .b { stroke: var(--series-b); }
.art .c { stroke: var(--series-c); }
.art .ta { fill: var(--series-a); }
.art .tb { fill: var(--series-b); }
.art .tc { fill: var(--series-c); }
.art .total { stroke: var(--text-primary); }
.art .buffer { fill: var(--series-a); opacity: 0.1; }
/* Marker radius comes from --chart-marker, applied in script (refreshArt). */
.art .dot { fill: var(--text-primary); stroke: var(--surface); stroke-width: 2; }
.art .ring { fill: var(--surface); stroke: var(--text-primary); stroke-width: 2; }
/* Atoms in the unit-cell graphic: fill from .ta/.tc, a surface ring separates overlaps. */
.art .atom { stroke: var(--surface); stroke-width: 2; }

.art .wkey { fill: var(--key-white); stroke: var(--axis); stroke-width: calc(var(--chart-line) * 0.6); }
.art .wkey.on { fill: color-mix(in srgb, var(--series-c) 30%, var(--key-white)); }
.art .bkey { fill: var(--key-black); }
.art .pill { fill: var(--surface); stroke: var(--axis); stroke-width: calc(var(--chart-line) * 0.6); }
.art .pill.on { fill: var(--accent); stroke: none; }
.art .pill-text { fill: var(--text-secondary); font: 700 var(--chart-font-small) var(--font); text-anchor: middle; dominant-baseline: central; }
.art .pill-text.on { fill: var(--accent-ink); }
.art .arrow { fill: none; stroke: var(--text-muted); stroke-width: calc(var(--chart-line) * 0.75); stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Notes and footer ---------- */

.site-footer { padding-top: 36px; padding-bottom: 32px; font-size: 0.8rem; color: var(--text-muted); }
.site-footer a { color: var(--text-secondary); }

/* ---------- Responsive ---------- */

@media (max-width: 560px) {
  .site-header, main, .site-footer { padding-left: 16px; padding-right: 16px; }
  h1 { font-size: 2rem; }
  .title-rule { width: 200px; }
  .brand img { width: 15rem; }
  .card { padding: 14px; }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
  .card:hover { transform: none; }
}

/* ---------- Presentation mode ---------- */

html[data-present] .eyebrow, html[data-present] .lede, html[data-present] .hint,
html[data-present] .notes, html[data-present] .site-footer { display: none; }
.present-hint { display: none; }
html[data-present] .present-hint { display: block; margin: 12px 0 0; color: var(--text-secondary); }

@media (min-width: 900px) {
  html[data-present] { font-size: 125%; }
  html[data-present] body { font-size: 1rem; }
  html[data-present] .site-header, html[data-present] main { padding-left: 32px; padding-right: 32px; }
  html[data-present] main { gap: 20px; }
  html[data-present] h1 { font-size: 2.8rem; }
  html[data-present] h2, html[data-present] .notes summary { font-size: 1.5rem; }
  html[data-present] .pill-sym { font-size: 1.5rem; }
  html[data-present] .legend, html[data-present] .live, html[data-present] .control-sub,
  html[data-present] .tile-sub, html[data-present] .card-sub { font-size: 1.05rem; }
  html[data-present] .chip { padding: 6px 16px; font-size: 1rem; }
  html[data-present] input[type="range"] { height: 36px; }
  html[data-present] .check input, html[data-present] .control .toggle input { width: 24px; height: 24px; }
  html[data-present] .btn { padding: 12px 24px; }
  html[data-present] .visual { height: min(calc(var(--h) * 1.5), 80vh); }
  html[data-present] .tooltip { font-size: 1rem; min-width: 220px; }
  html[data-present] :is(a, button, input, select, summary, [tabindex]):focus-visible { outline-width: 3px; outline-offset: 3px; }

  html[data-present] {
    --chart-font-small: 15px; --chart-font: 16px; --chart-line: 3px; --chart-line-total: 3.5px;
    --chart-marker: 7px; --chart-halo: 5px;
    --text-secondary: #3a3936; --text-muted: #55534f; --axis: #7f7d76; --grid: #cfcdc4;
    --series-a: #0c8259; --series-b: #bf4a1d; --series-c: #1f66c4;
    --critical-text: #a52a2a;
  }
}

@media (min-width: 900px) and (prefers-color-scheme: dark) {
  html[data-present]:not([data-theme="light"]) {
    --text-secondary: #d6d5cb; --text-muted: #b3b1a7; --axis: #8a8880; --grid: #3a3a37;
    --series-a: #22b07f; --series-b: #e8672f; --series-c: #4a93ec; --series-d: #a89ff0;
    --critical-text: #f28b85; --success-text: #40bf40;
  }
}
@media (min-width: 900px) {
  html[data-present][data-theme="dark"] {
    --text-secondary: #d6d5cb; --text-muted: #b3b1a7; --axis: #8a8880; --grid: #3a3a37;
    --series-a: #22b07f; --series-b: #e8672f; --series-c: #4a93ec; --series-d: #a89ff0;
    --critical-text: #f28b85; --success-text: #40bf40;
  }
}
