/* codul-morse: 1848 Brass Telegraph Desk & Bell Labs Information Theory */

@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("./fonts/fraunces-normal-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("./fonts/fraunces-normal-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Fraunces";
  font-style: italic;
  font-weight: 400 600;
  font-display: swap;
  src: url("./fonts/fraunces-italic-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Fraunces";
  font-style: italic;
  font-weight: 400 600;
  font-display: swap;
  src: url("./fonts/fraunces-italic-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Source Serif 4";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("./fonts/source-serif-4-normal-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Source Serif 4";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("./fonts/source-serif-4-normal-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Source Serif 4";
  font-style: italic;
  font-weight: 400 600;
  font-display: swap;
  src: url("./fonts/source-serif-4-italic-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Source Serif 4";
  font-style: italic;
  font-weight: 400 600;
  font-display: swap;
  src: url("./fonts/source-serif-4-italic-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("./fonts/IBMPlexSans-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("./fonts/IBMPlexSans-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("./fonts/IBMPlexMono-400-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("./fonts/IBMPlexMono-400-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("./fonts/IBMPlexMono-600-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("./fonts/IBMPlexMono-600-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --display: "Fraunces", Georgia, serif;
  --serif: "Source Serif 4", Georgia, serif;
  --ui: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --bg: #110e0b;
  --surf: #1a1511;
  --elev: #241e18;
  --tape: #16120e;
  --fg: #f4ede1;
  --mut: #c9beac;
  --line: #3a3127;
  --line-soft: #4e4234;
  --acc: #e8b24a;
  --acc-ink: #16110a;
  --warn: #e9755d;
  --warn-text: #ff9f8a;
  --ok: #68d3a3;
  --ok-text: #7de3b5;

  --to-top-bg: #1a1511;
  --to-top-fg: #f4ede1;
  --sr-line: #6d5f4e;
  --sr-ink: #f4ede1;
  --sr-acc: #e8b24a;
  --sr-ok: #68d3a3;

  --measure: 44rem;
  --wide: 68rem;
  --bar-h: 48px;
}

[data-theme="light"] {
  --bg: #f6f1e6;
  --surf: #ede5d4;
  --elev: #fffcf6;
  --tape: #fbf7ee;
  --fg: #181410;
  --mut: #463e34;
  --line: #cfc4b0;
  --line-soft: #b2a48c;
  --acc: #754400;
  --acc-ink: #fffcf6;
  --warn: #a02218;
  --warn-text: #8f1b12;
  --ok: #0c5949;
  --ok-text: #0b4f41;

  --to-top-bg: #fffcf6;
  --to-top-fg: #181410;
  --sr-line: #8c7e6a;
  --sr-ink: #181410;
  --sr-acc: #754400;
  --sr-ok: #0c5949;
}

[hidden] { display: none !important; }
svg[hidden] { display: none; }

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

html {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.62;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  overflow-x: clip;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  padding: .6rem 1rem;
  background: var(--acc);
  color: var(--acc-ink);
  font-family: var(--ui);
  font-weight: 600;
  z-index: 200;
}
.skip-link:focus { left: .75rem; top: .75rem; border-radius: .4rem; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.meta-note { margin: 0 0 .5rem; color: var(--mut); }
.no-m-bottom { margin-bottom: .5rem; }
.no-m { margin: 0; }
.mt-0 { margin-top: 0; }

/* ── Topbar ───────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 80;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding-top: var(--browser-safe-top, env(safe-area-inset-top));
  font: 500 .9rem/1 var(--ui);
}

.topbar-inner {
  max-width: var(--wide);
  margin: 0 auto;
  height: var(--bar-h);
  padding: 0 1rem;
  display: flex;
  align-items: center;
  gap: .75rem;
}

.home {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  color: var(--fg);
  text-decoration: none;
  font-family: var(--ui);
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}
.home:hover, .home:focus-visible { color: var(--acc); }
.home-motif { color: var(--acc); flex-shrink: 0; }

.topnav {
  display: flex;
  align-items: center;
  gap: .25rem;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  min-width: 0;
}
.topnav::-webkit-scrollbar { display: none; }

.topnav a {
  color: var(--mut);
  text-decoration: none;
  padding: .42rem .55rem;
  border-radius: .4rem;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color .15s, background .15s;
}
.topnav a:hover, .topnav a:focus-visible { color: var(--fg); background: var(--surf); }
.topnav a[aria-current="true"] { color: var(--acc); font-weight: 600; }

.spacer { flex: 1 1 auto; }

.chip {
  font-family: var(--ui);
  font-weight: 600;
  font-size: .82rem;
  color: var(--fg);
  background: var(--surf);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  padding: .34rem .72rem;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.chip:hover, .chip:focus-visible { border-color: var(--acc); color: var(--acc); }

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line-soft);
  background: var(--surf);
  color: var(--fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.icon-btn svg { display: block; }
.icon-btn svg[hidden] { display: none; }
.icon-btn:hover, .icon-btn:focus-visible { border-color: var(--acc); color: var(--acc); }

.progress-track {
  position: relative;
  height: 2px;
  background: transparent;
  overflow: hidden;
}
.progress-fill {
  position: absolute;
  inset: 0;
  background: var(--acc);
  transform-origin: left center;
  transform: scaleX(0);
}

/* ── Reading Rail ─────────────────────────────────────────────────────── */
.rail { display: none; }
@media (min-width: 1240px) {
  .rail {
    --col: 68rem;
    --gut: 1.1rem;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 50%;
    left: calc(50% + var(--col) / 2 + var(--gut));
    transform: translateY(-50%);
    z-index: 40;
    margin: 0;
    padding: .4rem 0;
    max-height: calc(100vh - 7rem);
  }
  .rail::before {
    content: "";
    position: absolute;
    left: calc(.875rem - .5px);
    top: 1.1rem;
    bottom: 1.1rem;
    width: 1px;
    background: var(--line);
  }
  .rail-dot {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    text-decoration: none;
    border-radius: 50%;
  }
  .rail-dot .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--mut);
    box-shadow: 0 0 0 3px var(--bg);
    transition: transform .2s, background .2s, box-shadow .2s;
    flex: none;
  }
  .rail-dot:hover .dot, .rail-dot:focus-visible .dot { background: var(--acc); transform: scale(1.25); }
  .rail-dot[aria-current="true"] .dot {
    background: var(--acc);
    transform: scale(1.45);
    box-shadow: 0 0 0 3px var(--bg), 0 0 0 4.5px color-mix(in srgb, var(--acc) 38%, transparent);
  }
  .rail-dot:focus-visible { outline: 2px solid var(--acc); outline-offset: -1px; }
  .rail-label {
    position: absolute;
    right: calc(100% + .35rem);
    top: 50%;
    transform: translate(6px, -50%);
    padding: .24rem .65rem;
    border: 1px solid var(--line);
    border-radius: .45rem;
    background: var(--elev);
    color: var(--fg);
    box-shadow: 0 6px 20px rgba(0, 0, 0, .2);
    font-family: var(--ui);
    font-size: .8rem;
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s, transform .15s;
  }
  .rail-dot:hover .rail-label, .rail-dot:focus-visible .rail-label {
    opacity: 1;
    transform: translate(0, -50%);
  }
}

/* ── Layout & Typography ──────────────────────────────────────────────── */
main { outline: none; }

section {
  scroll-margin-top: calc(var(--bar-h) + 1rem);
  padding: 2.5rem 1rem;
}

.wrap { max-width: var(--wide); margin: 0 auto; }
.prose { max-width: var(--measure); }

.kicker {
  font-family: var(--mono);
  font-size: .78rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--acc);
  margin: 0 0 .65rem;
}

h1 {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(1.75rem, 3.3vw, 2.65rem);
  line-height: 1.12;
  letter-spacing: -.015em;
  margin: 0 0 .75rem;
  max-width: 26ch;
}

.deck {
  font-size: clamp(1rem, 1.4vw, 1.14rem);
  line-height: 1.48;
  color: var(--mut);
  max-width: 60ch;
  margin: 0 0 1.1rem;
}

h2 {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(1.42rem, 2.5vw, 2rem);
  line-height: 1.22;
  margin: 0 0 .75rem;
}

h3 {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.18rem;
  line-height: 1.3;
  margin: 1.6rem 0 .5rem;
}

p { margin: 0 0 1rem; }

a { color: var(--acc); text-underline-offset: .18em; }
a:hover { opacity: .88; }

.mono { font-family: var(--mono); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.warn-t { color: var(--warn-text); font-weight: 600; }
.ok-t { color: var(--ok-text); font-weight: 600; }

/* ── Hero Telegraph Workbench ─────────────────────────────────────────── */
.hero-sec { padding-top: 1.15rem; padding-bottom: 2.25rem; }

.workbench {
  background: var(--surf);
  border: 1px solid var(--line);
  border-radius: .85rem;
  padding: 1.15rem;
  box-shadow: 0 18px 44px rgba(0, 0, 0, .18);
}
[data-theme="light"] .workbench {
  box-shadow: 0 12px 32px rgba(24, 20, 16, .08);
}

.wb-top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: .75rem;
  margin-bottom: .9rem;
}

.input-group {
  flex: 1 1 16rem;
  min-width: 0;
}

.input-label {
  display: block;
  font-family: var(--ui);
  font-size: .82rem;
  font-weight: 600;
  color: var(--mut);
  margin-bottom: .35rem;
}

.input-row {
  display: flex;
  gap: .45rem;
  align-items: center;
}

.msg-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 44px;
  padding: 0 .85rem;
  border-radius: .5rem;
  border: 1px solid var(--line-soft);
  background: var(--elev);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: .04em;
}
.msg-input:focus {
  outline: 2px solid var(--acc);
  outline-offset: 1px;
  border-color: var(--acc);
}

.btn {
  height: 44px;
  padding: 0 .95rem;
  border-radius: .5rem;
  border: 1px solid var(--line-soft);
  background: var(--elev);
  color: var(--fg);
  font-family: var(--ui);
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  white-space: nowrap;
  transition: border-color .15s, background .15s, color .15s;
}
.btn:hover, .btn:focus-visible { border-color: var(--acc); color: var(--acc); }
.btn-primary {
  background: var(--acc);
  color: var(--acc-ink);
  border-color: var(--acc);
}
.btn-primary:hover, .btn-primary:focus-visible {
  color: var(--acc-ink);
  filter: brightness(1.06);
}
.btn[data-on="true"] {
  background: var(--warn);
  color: #fff;
  border-color: var(--warn);
}
.btn-sm { height: 36px; padding: 0 .7rem; font-size: .82rem; }
@media (pointer: coarse) {
  .btn-sm { min-height: 44px; }
}

.wb-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .45rem;
}

.seg {
  display: inline-flex;
  border: 1px solid var(--line-soft);
  border-radius: .5rem;
  overflow: hidden;
  background: var(--elev);
}
.seg button {
  height: 42px;
  padding: 0 .65rem;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--mut);
  font-family: var(--ui);
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
}
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] {
  background: var(--acc);
  color: var(--acc-ink);
}

.presets {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .4rem;
  margin-bottom: .9rem;
}
.presets-lbl {
  font-family: var(--ui);
  font-size: .8rem;
  color: var(--mut);
  margin-right: .2rem;
}
.preset-chip {
  height: 32px;
  padding: 0 .65rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--elev);
  color: var(--fg);
  font-family: var(--mono);
  font-size: .78rem;
  cursor: pointer;
}
.preset-chip:hover, .preset-chip:focus-visible { border-color: var(--acc); color: var(--acc); }
.preset-chip[aria-pressed="true"] { border-color: var(--acc); background: color-mix(in srgb, var(--acc) 16%, var(--elev)); color: var(--acc); }
@media (pointer: coarse) {
  .preset-chip { min-height: 44px; }
}

/* Dual-Track Tape Stage */
.tape-wrap {
  position: relative;
  background: var(--tape);
  border: 1px solid var(--line);
  border-radius: .6rem;
  overflow: hidden;
  margin-bottom: .9rem;
}

.tape-canvas {
  display: block;
  width: 100%;
  height: 164px;
}

/* Personal Result Readout */
.result-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .75rem 1.25rem;
  padding: .85rem 1rem;
  border-radius: .6rem;
  background: var(--elev);
  border: 1px solid var(--line);
  margin-bottom: .75rem;
}

.result-text {
  flex: 1 1 20rem;
  font-size: .98rem;
  line-height: 1.48;
}
.result-text strong { color: var(--fg); }

.result-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: .9rem 1.25rem;
  align-items: center;
}

.stat-pill {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.stat-k {
  font-family: var(--ui);
  font-size: .74rem;
  color: var(--mut);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.stat-v {
  font-family: var(--mono);
  font-size: 1.05rem;
  font-weight: 600;
}

/* Compact Share Row */
.share-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem;
  padding-top: .25rem;
}
.share-lbl {
  font-family: var(--ui);
  font-size: .82rem;
  color: var(--mut);
  margin-right: .25rem;
}
.sr-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--sr-line);
  background: transparent;
  color: var(--sr-ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  cursor: pointer;
  transition: border-color .15s, color .15s, transform .15s;
}
.sr-btn:hover, .sr-btn:focus-visible { border-color: var(--sr-acc); color: var(--sr-acc); transform: translateY(-1px); }
@media (pointer: coarse) {
  .sr-btn { width: 44px; height: 44px; }
}
.sr-status {
  font-family: var(--ui);
  font-size: .82rem;
  color: var(--sr-ok);
  margin-left: .25rem;
}

/* Interactive Brass Telegraph Key Deck */
.key-deck {
  margin-top: .9rem;
  padding-top: .9rem;
  border-top: 1px dashed var(--line);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .9rem 1.25rem;
  align-items: center;
}
@media (max-width: 680px) {
  .key-deck { grid-template-columns: 1fr; }
}

.brass-key-btn {
  width: 136px;
  height: 82px;
  border-radius: .65rem;
  border: 1px solid var(--line-soft);
  background: var(--elev);
  color: var(--fg);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .25rem;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: transform .06s, border-color .15s, background .15s;
}
.brass-key-btn:hover, .brass-key-btn:focus-visible { border-color: var(--acc); }
.brass-key-btn.is-down {
  transform: translateY(3px);
  border-color: var(--acc);
  background: color-mix(in srgb, var(--acc) 18%, var(--elev));
}
.brass-knob {
  width: 44px;
  height: 16px;
  border-radius: 999px;
  background: linear-gradient(180deg, #f3c96b, #b77e1e);
  border: 1px solid #754e0b;
  box-shadow: 0 3px 0 #5b3b06;
}
.brass-key-btn.is-down .brass-knob {
  box-shadow: 0 1px 0 #5b3b06;
}
.brass-key-lbl {
  font-family: var(--ui);
  font-size: .76rem;
  font-weight: 600;
  color: var(--mut);
}

.decoder-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .6rem 1rem;
  background: var(--tape);
  border: 1px solid var(--line);
  border-radius: .55rem;
  padding: .65rem .85rem;
  min-height: 66px;
}
.decoder-out {
  font-family: var(--mono);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: .06em;
  word-break: break-word;
}
.decoder-pending { color: var(--acc); }
.decoder-meta {
  font-family: var(--ui);
  font-size: .78rem;
  color: var(--mut);
  display: flex;
  align-items: center;
  gap: .6rem;
}

/* ── Section 2: Fibonacci Codebook ────────────────────────────────────── */
.stage-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .75rem 1rem;
  margin-bottom: 1rem;
}

.fib-layout {
  display: grid;
  grid-template-columns: 1fr 20rem;
  gap: 1.25rem;
  align-items: start;
}
@media (max-width: 960px) {
  .fib-layout { grid-template-columns: 1fr; }
}

.fib-matrix {
  background: var(--surf);
  border: 1px solid var(--line);
  border-radius: .75rem;
  padding: 1rem;
  position: relative;
}

.fib-row {
  display: grid;
  grid-template-columns: 5.5rem 1fr;
  gap: .65rem;
  align-items: center;
  padding: .5rem 0;
  border-bottom: 1px solid var(--line);
}
.fib-row:last-child { border-bottom: 0; }

.fib-dur {
  font-family: var(--mono);
  font-size: .82rem;
  line-height: 1.25;
}
.fib-dur strong { display: block; color: var(--acc); font-size: .95rem; }
.fib-dur span { color: var(--mut); font-size: .74rem; }

.fib-slots {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
}

.slot-btn {
  min-width: 3.3rem;
  padding: .35rem .5rem;
  border-radius: .45rem;
  border: 1px solid var(--line-soft);
  background: var(--elev);
  color: var(--fg);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .1rem;
  transition: border-color .15s, transform .1s, background .15s;
}
.slot-btn:hover, .slot-btn:focus-visible { border-color: var(--acc); transform: translateY(-1px); }
.slot-btn[aria-pressed="true"] {
  border-color: var(--acc);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--acc) 35%, transparent);
}
.slot-btn.is-warn { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 16%, var(--elev)); }
.slot-btn.is-ok { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, var(--elev)); }
.slot-btn.is-empty { opacity: .52; border-style: dashed; }

.slot-ch {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.05rem;
  line-height: 1.1;
}
.slot-code {
  font-family: var(--mono);
  font-size: .72rem;
  color: var(--mut);
}

.detail-card {
  background: var(--surf);
  border: 1px solid var(--line-soft);
  border-radius: .75rem;
  padding: 1.05rem 1.15rem;
}
.detail-card h3 { margin-top: 0; margin-bottom: .35rem; }
.detail-kv {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .35rem .75rem;
  margin: .75rem 0;
  font-size: .9rem;
}
.detail-kv dt { color: var(--mut); font-family: var(--ui); }
.detail-kv dd { margin: 0; font-family: var(--mono); font-weight: 600; text-align: right; }

/* ── Section 3: 14 Languages Stage ────────────────────────────────────── */
.lang-stage {
  display: grid;
  grid-template-columns: 1fr 20rem;
  gap: 1.25rem;
  align-items: start;
  margin-bottom: 1.5rem;
}
@media (max-width: 960px) {
  .lang-stage { grid-template-columns: 1fr; }
}

.lang-chart-box {
  background: var(--surf);
  border: 1px solid var(--line);
  border-radius: .75rem;
  padding: 1rem;
}

.bar-row {
  display: grid;
  grid-template-columns: 7.5rem 1fr 4.4rem;
  gap: .6rem;
  align-items: center;
  width: 100%;
  padding: .36rem .45rem;
  border: 0;
  border-radius: .4rem;
  background: transparent;
  color: var(--fg);
  text-align: left;
  cursor: pointer;
  font-family: var(--ui);
  font-size: .88rem;
}
.bar-row:hover, .bar-row:focus-visible { background: var(--elev); }
.bar-row[aria-pressed="true"] { background: var(--elev); outline: 1px solid var(--acc); }

.bar-track {
  height: 16px;
  border-radius: 999px;
  background: var(--tape);
  border: 1px solid var(--line);
  overflow: hidden;
  position: relative;
}
.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--acc);
  transition: width .25s ease;
}
.bar-row.is-best .bar-fill { background: var(--ok); }
.bar-row.is-high .bar-fill { background: var(--warn); }

.bar-val {
  font-family: var(--mono);
  font-size: .82rem;
  font-weight: 600;
  text-align: right;
}

.scatter-wrap {
  margin-top: 1rem;
  padding-top: .9rem;
  border-top: 1px solid var(--line);
}
.scatter-canvas {
  display: block;
  width: 100%;
  height: 220px;
}

/* Data Table */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: .65rem;
  background: var(--surf);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--ui);
  font-size: .86rem;
}
th, td {
  padding: .55rem .7rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}
th {
  font-weight: 600;
  color: var(--mut);
  background: var(--elev);
  font-size: .8rem;
}
td.num, th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
tr.row-hidden { display: none; }

.table-more {
  margin-top: .75rem;
}

/* ── Section 4: History Figures & 1844 Diff ───────────────────────────── */
.fig-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.4rem;
  margin: 1.5rem 0;
}

figure {
  margin: 0;
  background: var(--surf);
  border: 1px solid var(--line);
  border-radius: .75rem;
  overflow: hidden;
}
figure img {
  display: block;
  width: 100%;
  height: auto;
}
figcaption {
  padding: .8rem 1rem;
  font-size: .88rem;
  line-height: 1.45;
  color: var(--mut);
  border-top: 1px solid var(--line);
}
figcaption strong { color: var(--fg); }

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 800px) {
  .two-col { grid-template-columns: 1fr; }
}

.diff-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: .55rem;
  margin: 1.25rem 0;
}
.diff-cell {
  background: var(--surf);
  border: 1px solid var(--line);
  border-radius: .55rem;
  padding: .6rem .75rem;
}
.diff-cell.is-o { border-color: var(--warn); }
.diff-ch { font-family: var(--display); font-weight: 700; font-size: 1.15rem; }
.diff-line { font-family: var(--mono); font-size: .8rem; color: var(--mut); }

.shannon-gauge {
  background: var(--surf);
  border: 1px solid var(--line);
  border-radius: .75rem;
  padding: 1rem 1.15rem;
  margin: 1.25rem 0;
}
.gauge-bar {
  height: 18px;
  border-radius: 999px;
  background: var(--tape);
  border: 1px solid var(--line);
  position: relative;
  overflow: hidden;
  margin: .6rem 0;
}
.gauge-mark {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 999px;
}

/* ── Sources & Footer ─────────────────────────────────────────────────── */
.sources-list {
  padding-left: 1.2rem;
  margin: .75rem 0 0;
}
.sources-list li { margin-bottom: .5rem; font-size: .94rem; }

footer {
  max-width: var(--wide);
  margin: 1rem auto 0;
  padding: 1.5rem 1rem 3rem;
  border-top: 1px solid var(--line);
  font-family: var(--ui);
  font-size: .86rem;
  color: var(--mut);
  display: flex;
  flex-wrap: wrap;
  gap: .6rem 1.4rem;
  align-items: center;
}
footer a { color: var(--fg); font-weight: 600; text-decoration: none; border-bottom: 1px solid var(--line-soft); }
footer a:hover, footer a:focus-visible { color: var(--acc); border-color: var(--acc); }

@media (max-width: 560px) {
  .topnav { display: none; }
  section { padding: 1.5rem .85rem; }
  .hero-sec { padding-top: 1rem; padding-bottom: 2rem; }
  h1 { font-size: clamp(1.5rem, 6.2vw, 2.05rem); margin-bottom: .75rem; }
  .deck { font-size: .95rem; margin-bottom: 1rem; }
  .workbench { padding: .85rem; }
  .bar-row { grid-template-columns: 6rem 1fr 3.9rem; font-size: .82rem; }
}
