/* =============================================================================
   Theme tokens: Nord "Frost" palette. Light by default, dark via system
   preference or the Theme button. Worksheet pages are always black on white.
   ========================================================================== */

:root {
  --bg: #d8dee9;
  --bg-top: #e5e9f0;
  --panel: #eceff4;
  --tile: #ffffff;
  --tile-hover: #f3f6fa;
  --ink: #2e3440;
  --muted: #4c566a;
  --line: #c3cad6;
  --input-bg: #ffffff;
  --frame-a: #8fbcbb;
  --frame-b: #88c0d0;
  --head-ink: #242933;
  --accent: #5e81ac;
  --accent-ink: #ffffff;
  --primary: #5e81ac;
  --primary-ink: #ffffff;
  --error: #a3303a;
  --error-bg: #f7e1e3;
  --warn: #7d5700;
  --warn-bg: #fbf0d4;
  --tip-bg: #2e3440;
  --tip-ink: #eceff4;
  --shadow: 0 2px 6px rgba(46, 52, 64, .15), 0 8px 24px rgba(46, 52, 64, .08);
  --paper-shadow: 0 2px 4px rgba(46, 52, 64, .15), 0 10px 28px rgba(46, 52, 64, .12);
  --paper-answer: #000;
  --mono: "Cascadia Mono", "Cascadia Code", Consolas, "SF Mono", Menlo, "DejaVu Sans Mono", monospace;
  --sans: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #2e3440;
    --bg-top: #272c36;
    --panel: #3b4252;
    --tile: #434c5e;
    --tile-hover: #4c566a;
    --ink: #eceff4;
    --muted: #b4bccb;
    --line: #56607a;
    --input-bg: #2e3440;
    --accent: #88c0d0;
    --accent-ink: #242933;
    --primary: #88c0d0;
    --primary-ink: #242933;
    --error: #f0a3aa;
    --error-bg: rgba(191, 97, 106, .22);
    --warn: #ebcb8b;
    --warn-bg: rgba(235, 203, 139, .16);
    --tip-bg: #eceff4;
    --tip-ink: #2e3440;
    --shadow: 0 2px 6px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .2);
    --paper-shadow: 0 2px 6px rgba(0, 0, 0, .35), 0 12px 32px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #2e3440;
  --bg-top: #272c36;
  --panel: #3b4252;
  --tile: #434c5e;
  --tile-hover: #4c566a;
  --ink: #eceff4;
  --muted: #b4bccb;
  --line: #56607a;
  --input-bg: #2e3440;
  --accent: #88c0d0;
  --accent-ink: #242933;
  --primary: #88c0d0;
  --primary-ink: #242933;
  --error: #f0a3aa;
  --error-bg: rgba(191, 97, 106, .22);
  --warn: #ebcb8b;
  --warn-bg: rgba(235, 203, 139, .16);
  --tip-bg: #eceff4;
  --tip-ink: #2e3440;
  --shadow: 0 2px 6px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .2);
  --paper-shadow: 0 2px 6px rgba(0, 0, 0, .35), 0 12px 32px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

/* =============================================================================
   Base
   ========================================================================== */

* { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  font: 14px/1.45 var(--sans);
  color: var(--ink);
  background: var(--bg);
}

[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }

input[type="number"], input[type="text"], select {
  font: inherit;
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--ink);
}
input[type="number"] { width: 84px; }

a { color: var(--accent); }
label { cursor: pointer; }

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

/* =============================================================================
   Top bar
   ========================================================================== */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  padding: 14px 24px;
  background: var(--bg-top);
  border-bottom: 1px solid var(--line);
}
.brand h1 {
  margin: 0;
  font: 600 26px/1.15 var(--mono);
  letter-spacing: -.01em;
}
.brand p { margin: 2px 0 0; font-style: italic; color: var(--muted); }
.top-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* =============================================================================
   Buttons
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--tile);
  color: var(--ink);
  font: 600 14px/1.2 var(--sans);
  text-decoration: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .12);
  cursor: pointer;
  transition: background-color .15s, transform .15s, box-shadow .15s;
}
.btn:hover:not(:disabled) { background: var(--tile-hover); transform: translateY(-1px); box-shadow: 0 3px 8px rgba(0, 0, 0, .18); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover:not(:disabled) { background: var(--primary); filter: brightness(1.08); }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.btn.small { padding: 6px 12px; font-size: 13px; }

/* =============================================================================
   Windows (rounded panels with a Frost title bar)
   ========================================================================== */

.window {
  margin: 0 0 18px;
  padding: 0 4px 4px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--frame-a), var(--frame-b));
  box-shadow: var(--shadow);
}

.window-head {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 40px;
  padding: 7px 8px 7px 10px;
  color: var(--head-ink);
}
.window-head h2 {
  margin: 0;
  font: 600 15px/1.2 var(--mono);
}
.wicon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.wicon circle { fill: currentColor; stroke: none; }
.wicon circle[r="4.5"] { fill: none; stroke: currentColor; }
.window-head .help { margin-left: auto; }

.window-body {
  padding: 14px;
  border-radius: 7px;
  background: var(--panel);
}

.head-note {
  margin-left: auto;
  font-size: 13px;
  font-weight: 600;
}
.head-note.stale {
  padding: 2px 10px;
  border-radius: 999px;
  background: #ebcb8b;
  color: #3b3000;
}
.pill:empty { display: none; }
.pill {
  margin-left: 6px;
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(36, 41, 51, .18);
}

/* =============================================================================
   App layout
   ========================================================================== */

.app {
  display: grid;
  grid-template-columns: minmax(340px, 400px) minmax(0, 1fr);
  align-items: start;
  gap: 24px;
  padding: 22px 24px;
}

.settings {
  position: sticky;
  top: 0;
  max-height: 100vh;
  overflow-y: auto;
  margin: -22px 0;
  padding: 22px 6px 0 2px;
}

.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin-bottom: 10px; }
.row:last-child { margin-bottom: 0; }
.row-label { margin-top: 10px; }
.row-label input[type="text"] { flex: 1; min-width: 0; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.field-label { margin-bottom: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }

.print-options { display: grid; gap: 8px; }

/* Worksheet code */
.code-current {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 2px 10px;
  margin-bottom: 12px;
}
.code-current .field-label { grid-column: 1 / -1; margin-bottom: 0; }
.code-text {
  font: 600 15px/1.3 var(--mono);
  letter-spacing: .03em;
  overflow-wrap: anywhere;
}
.code-load { margin-bottom: 0; }
.code-load label { width: 100%; font-size: 12px; font-weight: 600; color: var(--muted); }
.code-load input { flex: 1; min-width: 0; font-family: var(--mono); text-transform: uppercase; }
.code-load input::placeholder { text-transform: none; }
#err-code { margin-top: 8px; }

/* Segmented control for Format */
.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input-bg);
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: 4px 12px; border-radius: 6px; font-weight: 600; color: var(--muted); }
.segmented input:checked + span { background: var(--primary); color: var(--primary-ink); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Operation tiles */
fieldset.op {
  margin: 0 0 12px;
  padding: 0 12px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--tile);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .12);
  min-width: 0;
}
fieldset.op:last-child { margin-bottom: 0; }
fieldset.op.is-off { padding-bottom: 0; box-shadow: none; background: transparent; }
fieldset.op.has-error { border-color: var(--error); box-shadow: 0 0 0 1px var(--error); }

.op-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 0;
  float: left; /* lets the legend sit inside the tile */
  font-weight: 600;
  font-size: 15px;
}
.op-head label { flex: 1; }
.op-head + * { clear: both; }
.op-sym {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--frame-a), var(--frame-b));
  color: var(--head-ink);
  font: 700 16px/1 var(--sans);
}
.is-off .op-sym { opacity: .55; }

.op-body { display: grid; gap: 12px; }

table.digits { border-collapse: collapse; width: 100%; }
table.digits th, table.digits td { padding: 3px 6px 3px 0; text-align: left; font-weight: 400; white-space: nowrap; }
table.digits thead th { font-size: 12px; font-weight: 600; color: var(--muted); }
table.digits td:last-child { width: 30px; text-align: right; }

.add-operand {
  justify-self: start;
  padding: 6px 12px;
  border: 1px dashed var(--accent);
  border-radius: 7px;
  background: transparent;
  color: var(--accent);
  font: 600 13px/1.2 var(--sans);
  cursor: pointer;
}
.add-operand:hover:not(:disabled) { background: var(--tile-hover); }
.add-operand:disabled { border-color: var(--line); color: var(--muted); cursor: not-allowed; }

.remove-operand {
  width: 26px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: 600 16px/1 var(--sans);
  cursor: pointer;
}
.remove-operand:hover { border-color: var(--error); color: var(--error); }

/* Sticky action bar */
.actions {
  position: sticky;
  bottom: 0;
  margin: 0 -6px 0 -2px;
  padding: 14px 6px 22px 2px;
  background: linear-gradient(to bottom, transparent, var(--bg) 18px);
}
#messages { max-height: 40vh; overflow-y: auto; }
.buttons { display: flex; gap: 10px; }
.buttons .btn { flex: 1; padding-block: 11px; font-size: 15px; }

/* Preview */
.preview { min-width: 0; }
.paper-well {
  padding: 24px;
  overflow-x: auto;
  background: var(--bg);
}

/* =============================================================================
   Help icons and tooltip
   ========================================================================== */

.help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex: none;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  color: var(--muted);
  font: 700 11px/1 var(--sans);
  text-decoration: none;
  vertical-align: 1px;
  cursor: help;
  opacity: .8;
}
.help:hover, .help:focus-visible { opacity: 1; background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.window-head .help { color: var(--head-ink); }
.window-head .help:hover, .window-head .help:focus-visible { background: var(--head-ink); border-color: var(--head-ink); color: var(--frame-b); }

.tooltip {
  position: fixed;
  z-index: 10;
  max-width: 290px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--tip-bg);
  color: var(--tip-ink);
  font-size: 13px;
  line-height: 1.45;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .28);
  pointer-events: none;
}
.tooltip-more { display: block; margin-top: 6px; font-size: 12px; opacity: .7; }

/* =============================================================================
   Validation and messages
   ========================================================================== */

.field-error { margin: 0; color: var(--error); font-size: 13px; }
.field-error:empty { display: none; }
.field-error span { display: block; }
.field-error span + span { margin-top: 4px; }
#err-count, #err-ops { margin: -4px 0 10px; }
#err-ops { margin: 10px 0 0; }

[aria-invalid="true"] { border-color: var(--error) !important; background: var(--error-bg); }
input[type="checkbox"][aria-invalid="true"] { outline: 2px solid var(--error); outline-offset: 1px; }

.msg { margin: 0 0 10px; padding: 9px 12px; border-radius: 8px; font-size: 13px; box-shadow: var(--shadow); }
.msg.error { background: var(--error-bg); color: var(--error); border: 1px solid var(--error); }
.msg.warning { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn); }
.msg ul { margin: 4px 0 0; padding-left: 18px; }
.msg li + li { margin-top: 3px; }
/* Keep the bullet beside the first line when a message link wraps. */
.msg li .link { vertical-align: top; text-align: left; }

button.link {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  text-decoration: underline;
  cursor: pointer;
}

.noscript {
  margin: 0;
  padding: 16px 20px;
  background: var(--error-bg);
  color: var(--error);
  font-weight: 600;
  text-align: center;
}

/* =============================================================================
   Worksheet pages (always paper colours)
   ========================================================================== */

.sheet {
  width: 8.5in;
  height: 11in;
  padding: 0.5in;
  margin: 0 auto 24px;
  background: #fff;
  color: #000;
  border-radius: 3px;
  box-shadow: var(--paper-shadow);
  /* Set by app.js so whole pages fit narrow screens. Preview only: print resets it. */
  zoom: var(--sheet-scale, 1);
}
.sheet:last-child { margin-bottom: 0; }

.page-inner {
  position: relative;
  width: 7.5in;
  overflow: hidden;
}

.sheet-head { padding-bottom: 0.3in; box-sizing: border-box; }
.fields.is-ghost { visibility: hidden; }
.sheet-title { margin: 0 0 0.15in; font: 700 18pt/1.2 "Segoe UI", Arial, Helvetica, sans-serif; }

.fields {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15in 0.35in;
  font: 12pt/1.3 "Segoe UI", Arial, Helvetica, sans-serif;
}
.field { display: inline-flex; align-items: flex-end; gap: 0.08in; }
.field .line { display: inline-block; width: 1.2in; height: 1.1em; border-bottom: 1px solid #000; }
.field--name .line { width: 2.6in; }
.field--score .line { width: 0.7in; }

.grid { display: grid; align-items: start; }

.prob {
  display: flex;
  align-items: baseline;
  gap: 0.1in;
  width: max-content;
  white-space: nowrap;
  font-family: "Segoe UI", Arial, Helvetica, sans-serif;
  font-size: 16pt;
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
  color: #000;
}
.prob.stacked { align-items: flex-start; }

.num-label { min-width: 2.4em; font-size: 11pt; color: #444; }
.prob.stacked .num-label { padding-top: 0.3em; }

.expr { display: inline-flex; align-items: baseline; gap: 0.35em; }

.blank {
  display: inline-block;
  height: 1.2em;
  border-bottom: 1.5px solid #000;
  text-align: center;
}

.stack {
  display: inline-grid;
  grid-template-columns: auto auto;
  column-gap: 0.3em;
  row-gap: 0.12em;
}
.stack .val, .stack .blank { justify-self: end; text-align: right; }
.stack .rule { grid-column: 1 / -1; border-top: 2px solid #000; margin: 0.05em 0 0.1em; }
.prob.stacked .blank {
  height: 1.3em;
  padding: 0 0.15em;
  border: 1.5px solid #000;
  border-radius: 3px;
}

.answer {
  color: var(--paper-answer);
  font-weight: 700;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.page-foot {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  font: 9pt/1 "Segoe UI", Arial, Helvetica, sans-serif;
  color: #666;
}

/* Off-screen area used to measure problem sizes before paginating. */
#measure {
  position: absolute;
  top: 0;
  left: -10000px;
  visibility: hidden;
}

/* =============================================================================
   Instructions page
   ========================================================================== */

.doc-wrap {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 24px 48px;
}
.doc-intro { margin: 0 0 20px; font-size: 16px; }
.doc-intro .doc-note { display: block; margin-top: 4px; font-size: 13px; color: var(--muted); }

.toc-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.toc-tiles a {
  display: block;
  height: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--tile);
  color: var(--ink);
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .12);
  transition: background-color .15s, transform .15s;
}
.toc-tiles a:hover { background: var(--tile-hover); transform: translateY(-1px); }

.doc-section { scroll-margin-top: 16px; transition: box-shadow .2s; }
.doc-section:target { box-shadow: 0 0 0 3px var(--accent), var(--shadow); }
.doc-section .window-body { font-size: 15px; line-height: 1.6; }
.doc-section .window-body > :first-child { margin-top: 0; }
.doc-section .window-body > :last-child { margin-bottom: 0; }
.doc-section ul, .doc-section ol { padding-left: 22px; }
.doc-section li + li { margin-top: 4px; }

.doc-table { border-collapse: collapse; margin: 8px 0 12px; }
.doc-table th, .doc-table td { padding: 6px 16px 6px 0; border-bottom: 1px solid var(--line); text-align: left; }
.doc-table th { font-size: 13px; font-weight: 600; color: var(--muted); }

.doc-dl dt { margin-top: 14px; font-weight: 600; color: var(--error); }
.doc-dl dt:first-child { margin-top: 0; }
.doc-dl dd { margin: 2px 0 0; }

.example {
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--tile);
  font-family: var(--mono);
  font-size: 14px;
  /* Long example links (worksheet URLs) wrap instead of widening the page on phones. */
  overflow-wrap: anywhere;
}

/* =============================================================================
   Landing page
   ========================================================================== */

.landing {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px 16px;
}
.landing-window { width: 100%; max-width: 560px; margin: 0; }
.landing-body { padding: 36px 32px 28px; text-align: center; }
.landing-body h1 {
  margin: 0 0 10px;
  font: 600 28px/1.2 var(--mono);
  letter-spacing: -.01em;
}
.landing-lede { margin: 0 auto 28px; max-width: 42ch; font-size: 16px; color: var(--muted); }
.landing-cta {
  padding: 14px 30px;
  border-radius: 999px;
  font-size: 17px;
}
.landing-contact {
  margin: 30px 0 0;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 14px;
  color: var(--muted);
}
.landing-contact a { font-weight: 600; overflow-wrap: anywhere; }

.release-notes {
  margin: 26px auto 0;
  max-width: 44ch;
  font-size: 14px;
  text-align: left;
  color: var(--muted);
}
.release-notes summary {
  cursor: pointer;
  text-align: center;
  font-weight: 600;
}
.release-notes .version { font-family: var(--mono); color: var(--ink); }
.release-notes dl { margin: 12px 0 0; }
.release-notes dt { margin-top: 10px; font-weight: 600; color: var(--ink); }
.release-notes dt:first-child { margin-top: 0; }
.release-notes time { margin-left: 6px; font-weight: 400; color: var(--muted); }
.release-notes dd { margin: 2px 0 0; }
.release-notes ul { margin: 0; padding-left: 20px; }
.release-notes li + li { margin-top: 2px; }

/* =============================================================================
   Narrow screens
   ========================================================================== */

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); padding: 16px; }
  .settings { position: static; max-height: none; overflow: visible; margin: 0; padding: 0; }
  .actions { margin: 0; padding: 12px 0 16px; }
  .topbar { padding: 12px 16px; }
  .doc-wrap { padding: 16px 16px 40px; }
  .paper-well { padding: 12px; }
  .brand h1 { font-size: 22px; }
}

/* =============================================================================
   Touch screens: bigger tap targets, and 16px text in fields so iPhones and
   iPads don't zoom in when a field is tapped
   ========================================================================== */

@media (pointer: coarse) {
  input[type="number"], input[type="text"], select { font-size: 16px; min-height: 40px; }
  input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; vertical-align: -4px; }
  .checks { gap: 10px 18px; }
  .checks label, .print-options label, .op-head label { padding-block: 4px; }
  .help { position: relative; }
  .help::after { content: ""; position: absolute; inset: -13px; }
  .remove-operand { width: 40px; height: 40px; }
  table.digits td:last-child { width: 44px; }
  .btn.small, .add-operand { padding: 10px 14px; }
  .segmented span { padding: 8px 14px; }
  /* Collapsible sections on the landing page: a finger-sized tap area. */
  .release-notes summary { padding-block: 12px; }
}

/* No hover lift that sticks after a tap. */
@media (hover: none) {
  .btn:hover:not(:disabled), .toc-tiles a:hover { transform: none; }
}

/* =============================================================================
   Print: only the paper pages
   ========================================================================== */

@page {
  size: letter;
  margin: 0.5in;
}

@media print {
  html, body { background: #fff !important; color: #000; }
  .topbar, .settings, .window-head, .no-print, .print-exclude, .tooltip, .noscript { display: none !important; }
  .app { display: block; padding: 0; }
  .window, .window-body, .paper-well {
    margin: 0;
    padding: 0;
    border-radius: 0;
    background: none;
    box-shadow: none;
    overflow: visible;
  }

  .sheet {
    width: auto;
    height: auto;
    margin: 0;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    zoom: 1;
    page-break-after: always;
    break-after: page;
  }
  .sheet.is-last { page-break-after: auto; break-after: auto; }
  .sheet.first-answer { page-break-before: always; break-before: page; }
}


/* =============================================================================
   Version links (every page)
   ========================================================================== */

.landing-version { margin: 22px 0 0; font-size: 14px; }
.landing-version a { font-weight: 600; }
.version-link { font-style: normal; white-space: nowrap; }
@media (pointer: coarse) {
  .version-link, .landing-version a { display: inline-block; padding-block: 8px; }
}

/* =============================================================================
   Release notes page: stage colours (one per step a feature moves through)
   ========================================================================== */

:root {
  --st-idea: #6b7385;
  --st-reviewed: #5e81ac;
  --st-building: #9a6700;
  --st-beta: #8a5a8f;
  --st-released: #4f7f3a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --st-idea: #9aa3b5;
    --st-reviewed: #88c0d0;
    --st-building: #ebcb8b;
    --st-beta: #c9a0c4;
    --st-released: #a3be8c;
  }
}
:root[data-theme="dark"] {
  --st-idea: #9aa3b5;
  --st-reviewed: #88c0d0;
  --st-building: #ebcb8b;
  --st-beta: #c9a0c4;
  --st-released: #a3be8c;
}
.stage-idea { --st: var(--st-idea); }
.stage-reviewed { --st: var(--st-reviewed); }
.stage-building { --st: var(--st-building); }
.stage-beta { --st: var(--st-beta); }
.stage-released { --st: var(--st-released); }

/* ---- Page layout ---------------------------------------------------------- */

.rn-page { max-width: 880px; }
.rn-jump { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 18px; }
.rn-jump .btn { gap: 8px; }
.rn-jump .jump-val {
  font-family: var(--mono);
  font-size: 12px;
  padding: 1px 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}

/* ---- Version badges and the "hero" row of each section ------------------- */

.rn-hero { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin-bottom: 14px; }
.rn-badge {
  display: inline-block;
  padding: 6px 16px;
  border-radius: 12px;
  font: 700 28px/1.1 var(--mono);
  color: var(--ink);
  background: color-mix(in srgb, var(--accent) 20%, var(--tile));
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
}
.rn-badge.beta {
  font-size: 20px;
  background: color-mix(in srgb, var(--st-beta) 20%, var(--tile));
  border-color: color-mix(in srgb, var(--st-beta) 50%, transparent);
}
.rn-hero-meta { display: flex; flex-direction: column; gap: 4px; }
.rn-hero-meta time { color: var(--muted); font-size: 14px; }
.rn-pill {
  align-self: flex-start;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
  color: var(--st-released);
  background: color-mix(in srgb, var(--st-released) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--st-released) 45%, transparent);
}
.rn-pill.beta {
  color: var(--st-beta);
  background: color-mix(in srgb, var(--st-beta) 16%, transparent);
  border-color: color-mix(in srgb, var(--st-beta) 45%, transparent);
}
.rn-hero .btn { margin-left: auto; }

.rn-notes { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.rn-notes li {
  position: relative;
  padding: 10px 12px 10px 38px;
  border-radius: 10px;
  background: var(--tile);
  border: 1px solid var(--line);
}
.rn-notes li::before {
  content: "";
  position: absolute;
  left: 13px;
  top: 14px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--st-released);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 0a8 8 0 1 0 0 16A8 8 0 0 0 8 0zm3.6 5.6-4.3 4.8a.8.8 0 0 1-1.1.1L4.4 8.9a.8.8 0 1 1 1-1.2l1.2 1 3.8-4.2a.8.8 0 1 1 1.2 1.1z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 0a8 8 0 1 0 0 16A8 8 0 0 0 8 0zm3.6 5.6-4.3 4.8a.8.8 0 0 1-1.1.1L4.4 8.9a.8.8 0 1 1 1-1.2l1.2 1 3.8-4.2a.8.8 0 1 1 1.2 1.1z'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* ---- Collapsible blocks ---------------------------------------------------- */

.rn-more { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 6px; }
.rn-more > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 600;
  padding-block: 8px;
  list-style: none;
}
.rn-more > summary::-webkit-details-marker { display: none; }
.rn-more > summary::before {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform .2s;
  margin-right: 4px;
}
.rn-more[open] > summary::before { transform: rotate(45deg); }
.rn-more > summary .count {
  font: 600 12px/1 var(--mono);
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--tile);
  border: 1px solid var(--line);
  color: var(--muted);
}

/* ---- Release history timeline --------------------------------------------- */

.rn-timeline { position: relative; margin: 10px 0 0; padding: 0 0 0 26px; list-style: none; }
.rn-timeline::before {
  content: "";
  position: absolute;
  left: 7px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  border-radius: 2px;
  background: var(--line);
}
.rn-timeline > li { position: relative; padding-bottom: 18px; }
.rn-timeline > li:last-child { padding-bottom: 0; }
.rn-timeline > li::before {
  content: "";
  position: absolute;
  left: -25px;
  top: 5px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--panel);
}
.rn-timeline.beta > li::before { background: var(--st-beta); }
.tl-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin-bottom: 4px; }
.tl-ver {
  font: 700 14px/1.2 var(--mono);
  padding: 2px 9px;
  border-radius: 7px;
  background: var(--tile);
  border: 1px solid var(--line);
}
.tl-head time { color: var(--muted); font-size: 13px; }
.rn-timeline ul { margin: 0; padding-left: 20px; }
.rn-timeline li li + li { margin-top: 2px; }

/* ---- Version 3 dashboard: ring + stage counts ------------------------------ */

.rm-dash { display: grid; grid-template-columns: auto 1fr; gap: 20px 28px; align-items: center; }
.rm-ring { position: relative; width: 148px; height: 148px; }
.rm-ring svg { width: 100%; height: 100%; display: block; }
.ring-track, .ring-fill { fill: none; stroke-width: 12; }
.ring-track { stroke: var(--line); }
.ring-fill {
  stroke: var(--accent);
  stroke-linecap: round;
  transition: stroke-dashoffset 1.2s cubic-bezier(.2, .8, .2, 1);
}
.ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.1;
}
.ring-label strong { font: 700 32px/1 var(--mono); }
.ring-label span { font-size: 12px; color: var(--muted); margin-top: 4px; }

.rm-dash-line { margin: 0 0 12px; font-size: 15px; }
.rm-dash-line strong { font-family: var(--mono); }
.rm-stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.rm-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 4px 8px;
  border-radius: 10px;
  background: var(--tile);
  border: 1px solid var(--line);
  border-top: 4px solid var(--st);
  text-align: center;
}
.rm-stat strong { font: 700 24px/1.1 var(--mono); color: var(--st); }
.rm-stat span { font-size: 12px; color: var(--muted); margin-top: 2px; }
.rm-stat.is-zero { opacity: .55; }

/* ---- Feature cards ---------------------------------------------------------- */

.rm-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}
.rm-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 14px 12px;
  border-radius: 12px;
  background: var(--tile);
  border: 1px solid var(--line);
  border-left: 5px solid var(--st);
}
.rm-card-head { display: flex; align-items: center; gap: 10px; }
.rm-card-head h3 { margin: 0; font-size: 16px; flex: 1; min-width: 0; }
.rm-ver {
  font: 700 13px/1 var(--mono);
  padding: 6px 8px;
  border-radius: 8px;
  color: var(--st);
  background: color-mix(in srgb, var(--st) 16%, transparent);
}
.rm-chip {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
  white-space: nowrap;
  padding: 3px 9px;
  border-radius: 999px;
  color: var(--st);
  background: color-mix(in srgb, var(--st) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--st) 50%, transparent);
}
.rm-desc { margin: 0; font-size: 14px; line-height: 1.45; color: var(--muted); }
.rm-meter { height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; }
.rm-meter span { display: block; height: 100%; min-width: 6px; border-radius: inherit; background: var(--st); }

/* Five-step tracker: Idea → Reviewed → Building → In Beta → Released */
.rm-track { display: grid; grid-template-columns: repeat(5, 1fr); margin: 0; padding: 0; list-style: none; }
.rm-track li { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.rm-track li + li::before {
  content: "";
  position: absolute;
  top: 5px;
  right: 50%;
  width: 100%;
  height: 2px;
  background: var(--line);
}
.rm-track li.done + li::before, .rm-track li.done + li.current::before { background: var(--st); }
.rm-track .dot {
  position: relative;
  z-index: 1;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--tile);
  border: 2px solid var(--line);
}
.rm-track .done .dot { background: var(--st); border-color: var(--st); }
.rm-track .current .dot {
  background: var(--st);
  border-color: var(--st);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--st) 28%, transparent);
}
.rm-track .lbl { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.rm-track .current .lbl { color: var(--st); font-weight: 700; }

.rm-sub { margin: 20px 0 10px; font-size: 15px; }
.rm-tags { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.rm-tag {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  background: var(--tile);
  border: 1px dashed var(--line);
}
.rm-legend { margin: 10px 0 0; font-size: 12px; color: var(--muted); }

@media (max-width: 600px) {
  .rm-dash { grid-template-columns: 1fr; justify-items: center; }
  .rm-dash-side { width: 100%; }
  .rm-dash-line { text-align: center; }
  .rm-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .rn-hero .btn { margin-left: 0; }
  .rn-badge { font-size: 24px; }
}
/* Release notes page: undo the doc-page list spacing for these custom lists. */
.doc-section .rn-notes, .doc-section .rm-tags, .doc-section .rm-cards, .doc-section .rm-track { padding-left: 0; }
.doc-section .rn-notes li + li, .doc-section .rm-tags li + li,
.doc-section .rm-cards li + li, .doc-section .rm-track li + li,
.doc-section .rn-timeline > li + li { margin-top: 0; }
@media (max-width: 600px) {
  /* Narrow cards: only the current stage is labelled, so labels never collide. */
  .rm-track .lbl { display: none; }
  .rm-track .current .lbl { display: block; }
}
@media (prefers-reduced-motion: reduce) {
  .ring-fill, .rn-more > summary::before { transition: none; }
}
@media (pointer: coarse) {
  .rn-more > summary { padding-block: 12px; }
}
