:root {
  color-scheme: light dark;
  --bg: #fbfbfa;
  --panel: #ffffff;
  --border: #eceef1;
  --grid: #f1f2f5;
  --text: #191c22;
  --muted: #697180;
  --accent: #f05138; /* Swift orange */
  --mono: "Martian Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  /* Spacing scale (4px base) — the ONLY source of every margin / padding / gap.
     Inner = padding within a component; outer = margin/gap between components.
     The chart plots mirror these steps via layout.padding in app.js. */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;
  --sp-8: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1d24;
    --panel: #23252e;
    --border: #33363f;
    --grid: #2a2d35;
    --text: #e9ebf1;
    --muted: #8b92a1;
    --accent: #ff6a4d;
  }
}

* { box-sizing: border-box; }
/* iOS-style continuous corners where supported; falls back to normal rounding. */
:where(*) { corner-shape: superellipse(1.8); }

#controls {
  position: fixed;
  top: var(--sp-2);
  right: var(--sp-3);
  z-index: 10;
  display: flex;
  gap: var(--sp-2);
  align-items: center;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  background: color-mix(in srgb, var(--panel) 82%, transparent);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: var(--sp-1) var(--sp-2);
}
#controls select {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: var(--sp-1) var(--sp-2);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--mono);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  text-wrap: pretty; /* inherited: no orphans/rivers anywhere */
  hanging-punctuation: first;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, kbd, samp, pre { font-family: inherit; }

.wrap {
  max-width: 1040px;
  margin: 0 auto;
  padding-left: clamp(var(--sp-4), 5vw, var(--sp-7));
  padding-right: clamp(var(--sp-4), 5vw, var(--sp-7));
}

/* One vertical rhythm for the whole page: top-level blocks are separated by a
   single gap, never per-block padding. Multi-section blocks get their own gap. */
main.flow { display: flex; flex-direction: column; gap: var(--sp-7); padding-top: var(--sp-7); padding-bottom: var(--sp-8); }
#app, #more { display: flex; flex-direction: column; gap: var(--sp-6); }

header { border-bottom: 1px solid var(--border); padding: var(--sp-6) 0 var(--sp-5); }
.eyebrow {
  margin: 0 0 var(--sp-3);
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--accent);
}
h1 {
  margin: 0;
  font-family: var(--mono);
  font-size: clamp(24px, 3.6vw, 34px);
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1.12;
  text-wrap: balance;
}
.meta {
  margin: var(--sp-4) 0 0;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--muted);
}
.meta b { color: var(--text); font-weight: 600; }
.updated { margin-top: var(--sp-2); }

/* Hero: the thesis — the codebase's headline modernization fact. */
.hero-stat {
  display: block;
  margin: 0;
  font-family: var(--mono);
  font-size: clamp(30px, 6vw, 56px);
  font-weight: 800;
  letter-spacing: -.03em;
  line-height: 1;
}
.hero-stat b { color: var(--accent); }
/* The second figure of a two-share headline takes the board's In Progress blue. */
.hero-stat b.mixed { color: #3b87e5; }

.section-head { margin: 0 0 var(--sp-3); display: flex; align-items: baseline; gap: var(--sp-3); }
.section-head h2 {
  margin: 0;
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--text);
}
.section-head h2::before { content: "▚ "; color: var(--accent); }

.card {
  margin: 0 0 var(--sp-4);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: var(--sp-4);
}
.card h3 { margin: 0; font-family: var(--mono); font-size: 14px; font-weight: 640; letter-spacing: -.01em; }
.card figcaption p { margin: var(--sp-1) 0 0; font-size: 12.5px; color: var(--muted); }
.card figcaption { margin-bottom: var(--sp-4); }
.card:last-child { margin-bottom: 0; }
.canvas-wrap { position: relative; height: 320px; }

/* Segmented toggle above a chart (e.g. deprecations by symbol / by module). */
.chart-toggle { display: inline-flex; gap: 2px; margin-top: var(--sp-2); padding: 2px; background: color-mix(in srgb, var(--muted) 12%, transparent); border-radius: 8px; }
.chart-toggle-btn {
  appearance: none; border: 0; cursor: pointer;
  font-family: var(--mono); font-size: 11px; letter-spacing: .03em;
  padding: var(--sp-1) var(--sp-3); border-radius: 6px;
  background: transparent; color: var(--muted);
  transition: background .15s, color .15s;
}
.chart-toggle-btn:hover { color: var(--text); }
.chart-toggle-btn[aria-pressed="true"] { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }

.board { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-3); }
.col {
  background: color-mix(in srgb, var(--muted) 8%, var(--panel));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: var(--sp-3);
}
.col-head { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.col-head .tag {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .03em;
  padding: var(--sp-1) var(--sp-2);
  border-radius: 6px;
}
.col-head .count { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.tag.backlog { background: color-mix(in srgb, var(--muted) 18%, transparent); color: var(--muted); }
.tag.progress { background: color-mix(in srgb, #3b87e5 20%, transparent); color: #3b87e5; }
.tag.done { background: color-mix(in srgb, #199e70 20%, transparent); color: #199e70; }
.col ul { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: var(--sp-2); }
.card-item {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: var(--sp-2) var(--sp-3);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.35;
  color: var(--text);
  appearance: none;
  -webkit-tap-highlight-color: transparent;
}
button.card-item { cursor: pointer; transition: border-color .12s; }
button.card-item:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); }
@media (max-width: 720px) { .board { grid-template-columns: 1fr; } }

dialog.detail {
  max-width: 560px;
  width: calc(100% - 2 * var(--sp-4));
  padding: var(--sp-5);
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
}
dialog.detail::backdrop { background: rgba(0, 0, 0, .45); backdrop-filter: blur(2px); }
.dlg-x { float: right; margin: calc(-1 * var(--sp-2)) calc(-1 * var(--sp-2)) 0 0; }
.dlg-x button { padding: var(--sp-1); background: none; border: 0; color: var(--muted); font-size: 16px; cursor: pointer; }
dialog.detail h3 { margin: 0 0 var(--sp-3); font-family: var(--mono); font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.dlg-body { font-family: var(--mono); font-size: 14px; line-height: 1.55; }
.dlg-body p { margin: 0 0 var(--sp-3); }
.dlg-body ul, .dlg-body ol { margin: 0 0 var(--sp-3); padding-left: var(--sp-5); }
.dlg-body li { margin: 0 0 var(--sp-1); }
.dlg-body a { color: var(--accent); }

.section-note {
  margin: 0 0 var(--sp-4);
  max-width: 60ch;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--muted);
}
.links { margin: 0 0 var(--sp-2); padding: 0; list-style: none; }
.links li { margin: 0 0 var(--sp-2); font-family: var(--mono); font-size: 13px; }
.links a { font-weight: 600; }
.links a.btn {
  display: inline-block;
  padding: var(--sp-2) var(--sp-4);
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  font-weight: 700;
}
.links a.btn:hover { text-decoration: none; opacity: .92; }
.links span { color: var(--muted); }
.links span::before { content: " — "; color: var(--muted); }
.links ul { margin: var(--sp-2) 0 0; padding-left: var(--sp-4); list-style: none; border-left: 1px solid var(--border); }

@media (prefers-reduced-motion: no-preference) {
  .card, #hero { animation: rise .5s cubic-bezier(.2, .7, .3, 1) both; }
  @keyframes rise { from { opacity: 0; transform: translateY(var(--sp-2)); } }
}
@media (max-width: 560px) { .canvas-wrap { height: 240px; } }

/* Footer easter egg: a lone mascot — each app brings its own — dim until noticed;
   tap it for a speech bubble. The bubble is absolutely positioned above the mascot,
   so showing it never shifts the page — the mascot stays put. */
.egg { display: flex; justify-content: center; padding: var(--sp-6) 0 var(--sp-8); }
.egg-mascot-wrap { position: relative; display: inline-flex; }
.egg-mascot {
  background: none; border: 0; padding: var(--sp-2);
  font-size: 22px; line-height: 1; cursor: pointer; color: var(--text);
  opacity: .3; filter: grayscale(1);
  transition: opacity .2s, transform .1s, filter .2s;
  -webkit-tap-highlight-color: transparent;
}
.egg-mascot:hover { opacity: 1; filter: grayscale(0); }
.egg-mascot:active { transform: scale(.85); }
/* A drawn mascot inks itself from the button's colour, so it follows the theme. */
.egg-mascot svg { display: block; width: 24px; height: 24px; }
.egg-bubble {
  position: absolute;
  bottom: calc(100% + var(--sp-2));
  left: 50%;
  width: max-content; max-width: 32ch;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: var(--sp-2) var(--sp-3);
  font-family: var(--mono); font-size: 12.5px; line-height: 1.4; color: var(--text);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .1);
  /* resting state — hidden; .show pops it in, dropping .show fades it out */
  opacity: 0; visibility: hidden;
  transform: translateX(-50%) translateY(6px) scale(.96);
  transition: opacity .2s ease, transform .25s cubic-bezier(.2, .7, .3, 1), visibility 0s linear .2s;
}
.egg-bubble.show {
  opacity: 1; visibility: visible;
  transform: translateX(-50%) translateY(0) scale(1);
  transition: opacity .2s ease, transform .25s cubic-bezier(.2, .7, .3, 1);
}
/* little tail pointing down at the mascot */
.egg-bubble::after {
  content: ""; position: absolute; left: 50%; bottom: -5px; width: 9px; height: 9px;
  background: var(--panel); border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  transform: translateX(-50%) rotate(45deg);
}
@media (prefers-reduced-motion: reduce) {
  .egg-bubble, .egg-bubble.show { transition: opacity .2s ease, visibility 0s; transform: translateX(-50%); }
}

/* Sparkline grid: one cell per module. The cells size themselves, so a repository
   with twice the modules fills the same card instead of doubling its height. */
.canvas-wrap.sparks {
  height: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
}
/* Fill rather than a border: forty-two outlines fight the sparklines inside them,
   a tint just groups the cell. */
.spark {
  margin: 0;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--muted) 8%, transparent);
}
.spark figcaption {
  margin-bottom: 4px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.spark figcaption b { color: var(--ink); font-weight: 500; }
/* Chart.js sizes the canvas to its container, so the height lives here. */
.spark-canvas { position: relative; height: 36px; }
/* Line and number share a row, so the value reads as the end of the curve.
   minmax(0, 1fr), not 1fr: the canvas carries its own pixel width, and a column
   whose min-width resolves to auto lets it push the number out of the cell. */
.spark-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: var(--sp-2); }
.spark-row b { font: 500 12px var(--mono); }
/* A module with no views of the shown kind keeps its cell: switching pools must
   not reflow the grid under the reader's cursor. */
.spark.bare { opacity: 0.55; }
.spark .none {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
  display: flex;
  align-items: center;
  height: 100%;
}

details.modules { margin-top: 14px; }
details.modules > summary {
  cursor: pointer;
  padding: 6px 0;
  font-size: 13px;
  color: var(--muted);
  user-select: none;
}
details.modules > summary:hover { color: var(--fg); }
details.modules[open] > summary { margin-bottom: 6px; }

/* App switcher in the controls bar: links, so a page can be shared and opened in a new tab. */
#controls .apps {
  display: flex;
  gap: var(--sp-2);
}

#controls .apps a {
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

#controls .apps a[aria-current="page"] {
  color: var(--text);
  border-bottom-color: currentColor;
}
