/* styles.css — Palmleaf Observatory.
 * Tailwind covers ~80% of layout; this file holds the typography rules that
 * Tailwind cannot, the plate-transition primitives, the SVG draw animation,
 * and the night-mode inversion. */

:root {
  --vellum:   #F4ECD8;
  --vellum-2: #EBE0C2;
  --ink:      #1B1A17;
  --ink-2:    #3A3833;
  --ink-soft: #5A554B;
  --kumkum:   #8B2E1F;
  --indigo:   #3A5A6C;
  --brass:    #C8A24A;
  --rule:     rgba(27, 26, 23, 0.18);
  --rule-2:   rgba(27, 26, 23, 0.32);
  --duration: 600ms;
  --duration-slow: 1800ms;
  --duration-hero: 2400ms;
  --ease-paper: cubic-bezier(0.2, 0, 0, 1);
}

/* Night mode — the same plate after dusk. URL fragment turns it on. */
:root[data-theme="ink"] {
  --vellum:   #1B1A17;
  --vellum-2: #232220;
  --ink:      #F4ECD8;
  --ink-2:    #D7CDB1;
  --ink-soft: #9A917A;
  --rule:     rgba(244, 236, 216, 0.22);
  --rule-2:   rgba(244, 236, 216, 0.36);
}

html, body { background: var(--vellum); color: var(--ink); }
body { font-feature-settings: "onum" 1, "ss01" 1, "liga" 1; }

/* ─── Typography ──────────────────────────────────────────────────────── */

.font-display, h1, h2, h3 {
  font-family: 'Newsreader', ui-serif, Georgia, serif;
  font-feature-settings: "lnum" 1, "ss01" 1;
  letter-spacing: -0.005em;
}

.font-mono, .kt {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-weight: 350;
}
.kt { font-style: normal; padding: 0 0.1em; color: var(--ink-2); white-space: nowrap; }

.font-deva, [lang="sa"] {
  font-family: 'Tiro Devanagari Sanskrit', serif;
  font-feature-settings: "kern" 1;
}

::selection { background: rgba(139, 46, 31, 0.18); }

/* ─── Hero typing-in line ───────────────────────────────────────────── */

.typeset-line .line {
  display: inline-block;
  margin-right: 0.45em;
  opacity: 0;
}
.typeset-line.is-played .line {
  animation: typesetIn 700ms var(--ease-paper) both;
}
.typeset-line.is-played .line:nth-child(1) { animation-delay: 4500ms; }
.typeset-line.is-played .line:nth-child(2) { animation-delay: 5300ms; }
.typeset-line.is-played .line:nth-child(3) { animation-delay: 6100ms; }
.typeset-line.is-played .line:nth-child(4) { animation-delay: 6900ms; }

@keyframes typesetIn {
  from { opacity: 0; transform: translateY(0.25em); }
  to   { opacity: 1; transform: none; }
}

/* ─── Stipple-ink stroke draw — used everywhere SVG appears ───────── */

.ink-draw {
  stroke-dasharray: var(--len, 1000);
  stroke-dashoffset: var(--len, 1000);
  animation: inkDraw var(--duration-slow) var(--ease-paper) forwards;
}
.ink-draw[style*="--delay"] {
  animation-delay: var(--delay);
}
@keyframes inkDraw {
  to { stroke-dashoffset: 0; }
}

/* ─── Vermillion pulse — for Z-triangle, vivadi extremals ───────── */

.vermillion-pulse {
  animation: vermillionPulse 2.4s ease-in-out infinite;
}
@keyframes vermillionPulse {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(139, 46, 31, 0)); opacity: 0.85; }
  50%      { filter: drop-shadow(0 0 6px rgba(139, 46, 31, 0.55)); opacity: 1; }
}

/* ─── Plate transitions (FLIP-friendly) ──────────────────────────── */

.plate {
  position: relative;
  min-height: 100vh;
  width: 100%;
}
.plate.hidden { display: none; }

.plate.entering { animation: plateEnter 700ms var(--ease-paper) both; }
.plate.leaving  { animation: plateLeave 400ms var(--ease-paper) both; }
@keyframes plateEnter {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
@keyframes plateLeave {
  from { opacity: 1; }
  to   { opacity: 0; }
}

.plate-frame {
  max-width: 1280px;
  margin: 0 auto;
  padding: 8vh 7vw 12vh;
}

.plate-heading {
  border-bottom: 1px solid var(--rule);
  padding-bottom: 1.5rem;
  margin-bottom: 3rem;
  position: relative;
}

.folio {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 11px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 0.6rem;
}

.plate-body { position: relative; }

/* Plate-index dots — vertical right gutter */

.plate-link {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 10px;
  width: 26px;
  text-align: center;
  padding: 4px 0;
  color: var(--ink-soft);
  text-decoration: none;
  transition: color 200ms, transform 200ms var(--ease-paper);
}
.plate-link:hover { color: var(--kumkum); transform: translateX(-3px); }
.plate-link.active { color: var(--ink); font-weight: 500; }
.plate-link.active::before {
  content: "·";
  position: absolute;
  margin-left: -10px;
  color: var(--kumkum);
}

/* ─── Hex / nibble chips, mela tiles ────────────────────────────── */

.nibble-chip {
  display: inline-block;
  padding: 1px 6px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 10px;
  border: 1px solid var(--rule);
  border-radius: 2px;
  letter-spacing: 0.04em;
  margin-right: 2px;
}
.nibble-chip[data-region="L"] { color: var(--indigo); border-color: rgba(58, 90, 108, 0.35); }
.nibble-chip[data-region="M"] { color: var(--kumkum); border-color: rgba(139, 46, 31, 0.35); }
.nibble-chip[data-region="U"] { color: var(--brass); border-color: rgba(200, 162, 74, 0.55); }

.bit-strip {
  display: inline-flex;
  gap: 1px;
}
.bit-cell {
  width: 8px; height: 16px;
  background: var(--vellum-2);
  border: 1px solid var(--rule);
  border-radius: 1px;
}
.bit-cell.on  { background: var(--ink); border-color: var(--ink); }
.bit-cell.region-S { border-bottom: 2px solid var(--brass); }
.bit-cell.region-P { border-bottom: 2px solid var(--brass); }
.bit-cell.region-L.on { background: var(--indigo); border-color: var(--indigo); }
.bit-cell.region-U.on { background: var(--ink); border-color: var(--ink); }
.bit-cell.region-M.on { background: var(--kumkum); border-color: var(--kumkum); }

/* Harmonic-function "vocabulary" colors shared with guitar.html.
   When present, these override the region-based colors above
   (specificity matches; source order wins). */
.bit-cell.func-root.on  { background: hsl(38, 85%, 38%);  border-color: hsl(38, 85%, 38%); }
.bit-cell.func-p5.on    { background: hsl(36, 72%, 34%);  border-color: hsl(36, 72%, 34%); }
.bit-cell.func-maj3.on  { background: hsl(10, 82%, 42%);  border-color: hsl(10, 82%, 42%); }
.bit-cell.func-min3.on  { background: hsl(2,  72%, 38%);  border-color: hsl(2,  72%, 38%); }
.bit-cell.func-maj7.on  { background: hsl(350, 65%, 42%); border-color: hsl(350, 65%, 42%); }
.bit-cell.func-min7.on  { background: hsl(340, 52%, 38%); border-color: hsl(340, 52%, 38%); }
.bit-cell.func-2.on     { background: hsl(168, 60%, 38%); border-color: hsl(168, 60%, 38%); }
.bit-cell.func-6.on     { background: hsl(174, 48%, 36%); border-color: hsl(174, 48%, 36%); }
.bit-cell.func-4.on     { background: hsl(195, 30%, 36%); border-color: hsl(195, 30%, 36%); }
.bit-cell.func-b2.on    { background: hsl(268, 38%, 42%); border-color: hsl(268, 38%, 42%); }
.bit-cell.func-b6.on    { background: hsl(273, 32%, 38%); border-color: hsl(273, 32%, 38%); }
.bit-cell.func-b5.on    { background: hsl(278, 45%, 32%); border-color: hsl(278, 45%, 32%); }

.bit-cell.on.diff { background: var(--kumkum); border-color: var(--kumkum); box-shadow: inset 0 0 0 1px var(--vellum); }

/* ─── Quake-style color-legend drawer ────────────────────────────────
   A dark slide-down panel that surfaces the harmonic-function legend.
   Toggled via the "Color legend" link on Plate I or the `l` hotkey. */
.quake-drawer {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 60;
  background: rgba(15, 23, 42, 0.96);  /* slate-900 @ 96% */
  color: #e2e8f0;                       /* slate-200 */
  border-bottom: 1px solid rgba(200, 162, 74, 0.5);  /* brass thread */
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.35);
  transform: translateY(-100%);
  transition: transform 280ms cubic-bezier(0.2, 0, 0, 1);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 12px;
  max-height: 70vh;
  overflow-y: auto;
}
.quake-drawer.open { transform: translateY(0); }
.quake-drawer .qd-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 18px;
  background: rgba(200, 162, 74, 0.08);
  border-bottom: 1px solid rgba(226, 232, 240, 0.08);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #c8a24a;
}
.quake-drawer .qd-close {
  cursor: pointer;
  color: #94a3b8;
  background: none;
  border: 1px solid rgba(148, 163, 184, 0.3);
  padding: 2px 8px;
  border-radius: 3px;
  font-family: inherit; font-size: 11px;
  letter-spacing: 0.1em;
}
.quake-drawer .qd-close:hover { color: #e2e8f0; border-color: rgba(226, 232, 240, 0.6); }
.quake-drawer .qd-body { padding: 18px 22px; }
.quake-drawer .qd-prose { color: #cbd5e1; line-height: 1.65; font-family: 'Spectral', serif; font-style: italic; font-size: 13px; max-width: 70ch; }
.quake-drawer h3 { font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; margin-top: 16px; margin-bottom: 8px; color: #94a3b8; }
.quake-drawer .qd-fam {
  display: grid; grid-template-columns: 110px 1fr; gap: 8px 16px;
  align-items: baseline; margin-bottom: 4px;
}
.quake-drawer .qd-fam-name { font-weight: 700; }
.quake-drawer .qd-swatch-row {
  display: grid; grid-template-columns: repeat(12, minmax(0,1fr));
  gap: 4px; margin-top: 8px;
}
.quake-drawer .qd-swatch {
  display: flex; flex-direction: column; align-items: center;
  padding: 6px 2px;
  border-radius: 3px;
  text-align: center;
}
.quake-drawer .qd-swatch .swara { font-size: 11px; font-weight: 700; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.8); }
.quake-drawer .qd-swatch .ivl   { font-size: 9px; color: rgba(255,255,255,0.75); margin-top: 2px; }
.quake-drawer .qd-swatch .bit   { font-size: 8px; color: rgba(255,255,255,0.55); margin-top: 1px; letter-spacing: 0.08em; }

/* Color legend trigger link on Plate I (and anywhere else we add it). */
.color-legend-link {
  cursor: pointer;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
  border-bottom: 1px dotted var(--ink-soft);
  padding-bottom: 1px;
  transition: color 200ms;
}
.color-legend-link:hover { color: var(--kumkum); border-bottom-color: var(--kumkum); }

.mela-tile {
  position: relative;
  background: var(--vellum);
  border: 1px solid var(--rule);
  padding: 14px 14px 12px;
  font-family: 'Newsreader', serif;
  cursor: pointer;
  transition: transform 200ms var(--ease-paper), border-color 200ms;
  user-select: none;
}
.mela-tile:hover {
  transform: translateY(-2px);
  border-color: var(--ink-soft);
  box-shadow: 0 6px 14px rgba(27, 26, 23, 0.06);
}
.mela-tile.is-active {
  border-color: var(--kumkum);
  box-shadow: 0 0 0 1px var(--kumkum);
}
.mela-tile .mela-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
}
.mela-tile .mela-name {
  font-family: 'Newsreader', serif;
  font-size: 16px;
  margin-top: 4px;
  color: var(--ink);
  line-height: 1.15;
}
.mela-tile .mela-iast {
  font-family: 'Newsreader', serif;
  font-style: italic;
  font-size: 11px;
  color: var(--ink-soft);
  margin-top: 1px;
}
.mela-tile .mela-hex {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  margin-top: 6px;
  color: var(--ink-2);
  letter-spacing: 0.04em;
}

/* Vivadi badge */
.badge-vivadi {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--kumkum);
  margin-right: 4px;
  vertical-align: middle;
}
.badge-zrelation { color: var(--kumkum); font-weight: 500; }

/* ─── Yantra wheel & SVG ──────────────────────────────────────── */

svg.atlas-svg, svg#atlas-svg {
  background: transparent;
}
.constellation-line {
  stroke: var(--ink);
  stroke-width: 0.45;
  fill: none;
  opacity: 0.55;
}
.constellation-vertex {
  fill: var(--ink);
  opacity: 0.7;
}
.z-triangle-line {
  stroke: var(--kumkum);
  stroke-width: 1;
  fill: none;
  opacity: 0;
  animation: revealLine 1200ms var(--ease-paper) 4200ms forwards;
}
.z-triangle-vertex {
  fill: var(--kumkum);
  opacity: 0;
  animation: revealLine 600ms ease 4400ms forwards;
}
@keyframes revealLine { to { opacity: 1; } }

/* Hamming graph edges, by region */
.edge { fill: none; stroke-linecap: round; }
.edge[data-region="L"] { stroke: var(--indigo); stroke-width: 0.7; opacity: 0.32; }
.edge[data-region="M"] { stroke: var(--brass);  stroke-width: 0.9; opacity: 0.42; }
.edge[data-region="U"] { stroke: var(--ink);    stroke-width: 0.6; opacity: 0.22; }
.edge.is-incident { opacity: 1 !important; stroke-width: 1.6; }
.edge.is-antipode { stroke: var(--kumkum); stroke-width: 0.7; stroke-dasharray: 2 3; opacity: 0.5; }

.vertex {
  fill: var(--vellum);
  stroke: var(--ink);
  stroke-width: 0.8;
  cursor: pointer;
  transition: transform 200ms var(--ease-paper);
}
.vertex.is-active { fill: var(--kumkum); stroke: var(--kumkum); }
.vertex.is-neighbor { fill: var(--indigo); stroke: var(--indigo); }
.vertex:hover { stroke-width: 1.6; }
.vertex-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  fill: var(--ink-soft);
  pointer-events: none;
}

/* Gray walk ring */
.gray-edge { fill: none; stroke: var(--ink); stroke-width: 0.6; opacity: 0.32; }
.gray-edge.m-crossing {
  stroke: var(--kumkum);
  stroke-width: 1.6;
  opacity: 1;
}
.gray-pulse-dot {
  fill: var(--kumkum);
  filter: drop-shadow(0 0 4px rgba(139, 46, 31, 0.65));
}
.gray-step-marker {
  fill: var(--vellum);
  stroke: var(--ink);
  stroke-width: 0.5;
}
.gray-step-marker.is-current { fill: var(--kumkum); stroke: var(--kumkum); }
.gray-step-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 8px;
  fill: var(--ink-soft);
}

/* ─── Z-triangle plate ────────────────────────────────────── */

.icv-bar {
  fill: var(--ink);
  transition: fill 200ms;
}
.icv-bar.is-key { fill: var(--kumkum); }
.icv-axis-line { stroke: var(--rule); stroke-width: 0.5; }
.icv-axis-label { font-family: 'JetBrains Mono', monospace; font-size: 9px; fill: var(--ink-soft); }

.zrel-arc {
  fill: none;
  stroke-width: 1.2;
  opacity: 0.7;
}
.zrel-arc[data-rel="Z"]  { stroke: var(--indigo); }
.zrel-arc[data-rel="T"] { stroke: var(--brass); }
.zrel-arc-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

/* 12-tone clock */
.clock-tick { stroke: var(--rule); stroke-width: 0.5; }
.clock-pc { fill: var(--vellum-2); stroke: var(--ink-soft); stroke-width: 0.6; }
.clock-pc.lit { fill: var(--ink); stroke: var(--ink); }
.clock-pc.lit.sa { fill: var(--brass); stroke: var(--brass); }
.clock-pc.lit.pa { fill: var(--brass); stroke: var(--brass); }
.clock-pc.lit.rough { fill: var(--kumkum); stroke: var(--kumkum); }
.clock-label { font-family: 'JetBrains Mono', monospace; font-size: 8px; fill: var(--ink-soft); }

/* ─── Vivadi nibble grid ──────────────────────────────────── */

.nibble-cell {
  border: 1px solid var(--rule);
  padding: 8px;
  background: var(--vellum);
  transition: opacity 220ms, background 220ms;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
}
.nibble-cell.both-extremal { background: rgba(139, 46, 31, 0.10); border-color: var(--kumkum); }
.nibble-cell.one-extremal  { background: rgba(200, 162, 74, 0.10); border-color: var(--brass); }
.nibble-cell.dimmed { opacity: 0.18; }

/* ─── Distance histogram ─────────────────────────────────── */

.dist-bar {
  fill: var(--ink);
  opacity: 0.32;
  transition: opacity 200ms;
}
.dist-bar.is-key { opacity: 1; fill: var(--kumkum); }

/* ─── Buttons & form controls ────────────────────────────── */

button.paper-btn {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 6px 14px;
  border: 1px solid var(--ink-soft);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: background 200ms, color 200ms, border-color 200ms;
}
button.paper-btn:hover {
  background: var(--ink);
  color: var(--vellum);
  border-color: var(--ink);
}
button.paper-btn.is-on {
  background: var(--kumkum);
  color: var(--vellum);
  border-color: var(--kumkum);
}

input[type="range"].paper-range {
  -webkit-appearance: none; appearance: none;
  height: 2px; background: var(--rule-2);
  outline: none;
}
input[type="range"].paper-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 12px; height: 12px;
  background: var(--ink);
  border-radius: 50%;
  cursor: pointer;
}
input[type="range"].paper-range::-moz-range-thumb {
  width: 12px; height: 12px;
  background: var(--ink);
  border-radius: 50%;
  border: none;
  cursor: pointer;
}

select.paper-select {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.08em;
  background: var(--vellum);
  color: var(--ink);
  border: 1px solid var(--ink-soft);
  padding: 6px 10px;
  cursor: pointer;
}

/* ─── The Console (Perform) ──────────────────────────────── */

#perform-stage {
  --vellum: #1B1A17;   /* invert the local sub-tree */
  --ink: #F4ECD8;
  --ink-2: #D7CDB1;
  --ink-soft: #9A917A;
  --rule: rgba(244, 236, 216, 0.22);
  background: var(--vellum);
  color: var(--ink);
  display: grid;
  grid-template-columns: 280px 1fr 320px;
  grid-template-rows: auto 1fr;
  gap: 24px;
  padding: 24px 32px;
}
#perform-stage .perform-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 12px;
}
#perform-stage .perform-left,
#perform-stage .perform-right {
  display: flex; flex-direction: column; gap: 18px;
}
#perform-stage .perform-center {
  display: flex; align-items: center; justify-content: center;
}

.knob-row { display: flex; flex-direction: column; gap: 4px; }
.knob-row label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* Yantra wheel */
.yantra-svg .yantra-rim-vertex { fill: var(--ink); opacity: 0.55; }
.yantra-svg .yantra-rim-vertex.is-active { fill: var(--kumkum); opacity: 1; }
.yantra-svg .yantra-rim-vertex.is-neighbor { fill: var(--brass); opacity: 0.95; }
.yantra-svg .yantra-rim-label { font-family: 'JetBrains Mono', monospace; font-size: 7px; fill: var(--ink-soft); pointer-events: none; }
.yantra-svg .yantra-active-name { font-family: 'Newsreader', serif; font-size: 28px; fill: var(--ink); text-anchor: middle; }
.yantra-svg .yantra-active-meta { font-family: 'JetBrains Mono', monospace; font-size: 11px; fill: var(--ink-soft); text-anchor: middle; letter-spacing: 0.16em; }
.yantra-svg .yantra-d2-pad { fill: var(--vellum); stroke: var(--ink-soft); stroke-width: 0.6; cursor: pointer; }
.yantra-svg .yantra-d2-pad:hover { fill: var(--brass); stroke: var(--brass); }
.yantra-svg .yantra-k-anchor { fill: var(--vellum); stroke: var(--kumkum); stroke-width: 1; cursor: pointer; }
.yantra-svg .yantra-k-anchor:hover { fill: var(--kumkum); }
.yantra-svg .yantra-k-label { font-family: 'JetBrains Mono', monospace; font-size: 11px; letter-spacing: 0.18em; fill: var(--kumkum); text-anchor: middle; pointer-events: none; }

/* Fretboard / piano-roll inheritances */
.fret-cell { stroke: var(--rule); stroke-width: 0.4; fill: transparent; }
.fret-string { stroke: var(--ink-soft); stroke-width: 0.6; opacity: 0.5; }
.fret-node { fill: var(--vellum); stroke: var(--ink); stroke-width: 0.6; }

/* ─── Reduced motion ───────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-delay: 0ms !important;
    transition-duration: 1ms !important;
  }
  .ink-draw { stroke-dashoffset: 0 !important; }
}

/* ─── Mobile (≥ 375 px) ────────────────────────────────── */

@media (max-width: 720px) {
  .plate-frame { padding: 6vh 5vw 10vh; }
  #plate-index { width: 32px; gap: 1px; }
  .plate-link { font-size: 9px; padding: 2px 0; }
  #perform-stage { grid-template-columns: 1fr; padding: 16px; }
}

/* ─── Plate II · Klein primer panel ───────────────────────────────────
   Top-of-page V₄ exposition. Borrows the bit-cell vocabulary so the
   mask visualisations read as the same language used on every tile. */
.klein-primer {
  background: var(--vellum-2);
  border: 1px solid var(--rule);
  padding: 18px 22px 16px;
  margin-bottom: 28px;
  border-radius: 2px;
}
.klein-primer-title {
  display: inline-block;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 4px;
  margin-bottom: 6px;
}
.klein-primer-prose { max-width: 70ch; }
.klein-primer-grid {
  display: grid;
  grid-template-columns: minmax(240px, 320px) 1fr;
  gap: 32px;
  align-items: start;
}
.klein-primer-col { min-width: 0; }
.klein-col-heading { line-height: 1.4; }

.cayley-table {
  border-collapse: collapse;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 11px;
}
.cayley-table th, .cayley-table td {
  border: 1px solid var(--rule);
  padding: 5px 10px;
  min-width: 38px;
  text-align: center;
  color: var(--ink-2);
  background: var(--vellum);
}
.cayley-table th {
  background: var(--vellum-2);
  color: var(--ink-soft);
  font-weight: 500;
  letter-spacing: 0.06em;
}
.cayley-table td.is-identity {
  color: var(--kumkum);
  background: rgba(139, 46, 31, 0.06);
  font-weight: 600;
}

.k-mask-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.k-mask-strip {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 2px;
  flex: 1;
  max-width: 320px;
}
.k-mask-strip .bit-cell { width: 100%; height: 18px; }

.klein-primer-identity {
  font-size: 11px;
}

/* K-position badge on each tile · brass, kumkum, indigo per Klein index */
.k-badge {
  display: inline-block;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 9px;
  letter-spacing: 0.06em;
  padding: 1px 5px;
  border: 1px solid currentColor;
  border-radius: 2px;
  line-height: 1.3;
  opacity: 0.85;
}
.k-badge-e  { color: var(--ink-soft); }
.k-badge-k1 { color: var(--kumkum); }    /* madhyama swap shares K₂ kumkum cue */
.k-badge-k2 { color: var(--indigo); }    /* antipodal complement */
.k-badge-k3 { color: var(--brass); }     /* both */

