/* Ribosome — a 2048 of the central dogma
   ------------------------------------------------------------------------
   Colour values here are measured, not chosen by eye. Every tile ink clears
   WCAG AA against its own fill, the five residue classes sit on a deliberate
   luminance ladder, and the empty-cell grid is a visible ruler against the
   board. All of it is pinned in test/palette.test.mjs — change a value and
   run the tests. */

:root {
  /* surfaces, coolest to warmest */
  --bg:         #070a0f;
  --panel:      #131a24;
  --panel-2:    #182231;
  --bg-2:       #222e3e;   /* the board */
  --grid-cell:  #070b10;
  --grid-line:  #374b64;
  --line:       #26334a;

  --ink:        #e9eff7;
  --ink-dim:    #94a6ba;
  --ink-faint:  #6a7d92;
  --accent:     #45d3a4;
  --accent-dim: #2b8f70;
  --danger:     #e0a744;

  /* nucleotides — the conventional sequence-logo hues, cohered */
  --nt-A: #3ab674;
  --nt-U: #e07766;
  --nt-G: #e0a744;
  --nt-C: #5a95ef;
  --ink-on-A: #0a0f16;
  --ink-on-U: #0a0f16;
  --ink-on-G: #0a0f16;
  --ink-on-C: #0a0f16;

  /* Residue classes, on a luminance ladder that runs *with* rarity: the
     commonest class is the quietest and the rarest is the brightest, so the
     valuable thing on the board is the thing that catches the eye.
     relL 0.05 / 0.10 / 0.17 / 0.33 / 0.55, all-pairs minimum 1.44. */
  --cls-aliphatic: #384049;   /* 22/64 — recedes */
  --cls-polar:     #1d655c;   /* 20/64 */
  --cls-positive:  #366edc;   /* 10/64 */
  --cls-aromatic:  #be86dc;   /*  5/64 */
  --cls-negative:  #f3b3ba;   /*  4/64 — pops */
  --cls-stop:      #4b5766;

  --ink-on-aliphatic: #f6fafe;
  --ink-on-polar:     #f6fafe;
  --ink-on-positive:  #f6fafe;
  --ink-on-aromatic:  #0a0f16;
  --ink-on-negative:  #0a0f16;

  /* Animation timing, in one place.
     The first pass was tuned by number rather than by watching it and every
     duration came out clipped: a 110ms slide reads as a teleport, and a merge
     that pops in 200ms is over before the eye has found it. These are roughly
     50% longer, and the curves now differ by what the motion *is* — a slide
     decelerates into place, a falling tile accelerates like it has weight. */
  --speed: 1;         /* the one dial; the settings bar sets it */
  --t-slide: calc(175ms  * var(--speed));   /* a tile sliding between cells */
  --t-fall:  calc(280ms  * var(--speed));   /* a tile dropping in from above */
  --t-pop:   calc(260ms  * var(--speed));   /* a merge product arriving */
  --t-fade:  calc(220ms  * var(--speed));   /* a consumed tile leaving */
  --t-float: calc(1200ms * var(--speed));   /* the floating score label */
  --e-slide: cubic-bezier(.2, .75, .3, 1);
  --e-fall:  cubic-bezier(.45, 0, .85, .5);
  --e-pop:   cubic-bezier(.2, 1.3, .4, 1);

  --gap: clamp(5px, 1.1vmin, 9px);
  --r-sm: 7px;
  --r-md: 10px;
  --r-lg: 14px;
  --board-max: 500px;
  --shadow: 0 14px 40px -22px #000c;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(900px 520px at 12% -8%, #16202e 0%, transparent 62%),
    radial-gradient(700px 500px at 100% 0%, #16262c 0%, transparent 55%),
    var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior: none;
}

.app {
  max-width: 940px;
  margin: 0 auto;
  padding: clamp(12px, 2.4vw, 26px) clamp(12px, 3vw, 22px) calc(56px + env(safe-area-inset-bottom));
}

/* ---------------------------------------------------------------- header */

.masthead {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; margin-bottom: 12px;
}
.brand h1 {
  margin: 0; font-size: clamp(23px, 5.4vw, 36px); letter-spacing: -0.025em; line-height: 1.05;
  background: linear-gradient(96deg, var(--accent), var(--nt-C) 58%, var(--cls-aromatic));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tagline { margin: 3px 0 0; color: var(--ink-faint); font-size: 12.5px; }

.scores { display: flex; gap: 8px; flex: none; }
.score-box {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 6px 13px; min-width: 78px; text-align: right;
  display: flex; flex-direction: column;
}
.score-label { font-size: 9px; text-transform: uppercase; letter-spacing: .15em; color: var(--ink-faint); }
.score-box span:last-child { font-size: 19px; font-variant-numeric: tabular-nums; font-weight: 680; line-height: 1.25; }

.pitch {
  color: var(--ink-dim); font-size: 13.5px; line-height: 1.62; max-width: 68ch;
  margin: 0 0 14px;
}
.pitch b { color: var(--ink); font-weight: 600; }

/* --------------------------------------------------------------- toolbar */

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }

.btn {
  background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 8px 13px; font: inherit; font-size: 13.5px;
  cursor: pointer; min-height: 38px;
  transition: background .12s, border-color .12s, transform .07s;
}
.btn:hover:not(:disabled) { background: var(--panel-2); border-color: #33455f; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .35; cursor: default; }
.btn-primary {
  background: linear-gradient(180deg, #23a37f, #178063);
  border-color: #2cb18b; color: #f0fff9; font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: linear-gradient(180deg, #2ab68d, #1a8f6f); }

.sel { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-faint); }
.sel select {
  background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 8px; font: inherit; font-size: 13px; min-height: 38px;
}

.queue-wrap { display: flex; align-items: center; gap: 7px; margin-left: auto; }
.queue-label { font-size: 9px; text-transform: uppercase; letter-spacing: .15em; color: var(--ink-faint); }
.queue { display: flex; gap: 4px; }
.mini-nt {
  width: 25px; height: 25px; border-radius: 6px; display: grid; place-items: center;
  font-weight: 750; font-size: 12.5px;
}
.mini-nt[data-base="A"] { background: var(--nt-A); color: var(--ink-on-A); }
.mini-nt[data-base="U"] { background: var(--nt-U); color: var(--ink-on-U); }
.mini-nt[data-base="G"] { background: var(--nt-G); color: var(--ink-on-G); }
.mini-nt[data-base="C"] { background: var(--nt-C); color: var(--ink-on-C); }

.modes { display: flex; gap: 5px; }
.modes a {
  color: var(--ink-dim); text-decoration: none; font-size: 12.5px; font-weight: 550;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--r-sm);
  min-height: 38px; display: inline-flex; align-items: center;
}
.modes a.on { color: var(--ink); border-color: var(--accent-dim); background: var(--panel-2); }
.modes a:hover { color: var(--ink); background: var(--panel); }

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

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 268px; gap: 18px; align-items: start; }
.board-col { max-width: var(--board-max); width: 100%; margin-inline: auto; }

/* ------------------------------------------------------------- board HUD */

.board-hud { display: flex; align-items: stretch; gap: 10px; margin-bottom: 9px; }
.meter-wrap { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 5px; min-width: 0; }
.meter-head { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--ink-faint); }
.meter-head b { color: var(--ink); font-variant-numeric: tabular-nums; }
.meter { height: 7px; background: #0b1119; border: 1px solid var(--line); border-radius: 99px; overflow: hidden; }
.meter-fill {
  height: 100%; width: 100%; border-radius: 99px;
  background: linear-gradient(90deg, var(--nt-C), var(--accent));
  transition: width .38s var(--e-slide);
}
.meter-fill.low { background: linear-gradient(90deg, var(--nt-G), var(--nt-U)); }

.rf {
  display: flex; align-items: center; gap: 7px; flex: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md);
  color: var(--ink); padding: 5px 11px; font: inherit; cursor: pointer; min-height: 42px;
}
.rf:disabled { opacity: .42; cursor: default; }
.rf.armed { border-color: var(--accent); box-shadow: 0 0 0 1px #45d3a433, 0 0 16px -6px var(--accent); }
.rf-count { font-size: 19px; font-weight: 750; font-variant-numeric: tabular-nums; }
.rf-label { font-size: 8.5px; line-height: 1.15; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-faint); text-align: left; }

/* ----------------------------------------------------------------- board */

.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--gap);
  touch-action: none;
  user-select: none; -webkit-user-select: none;
  box-shadow: var(--shadow);
}

.cell-grid {
  position: absolute; inset: var(--gap);
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
  gap: var(--gap);
}
.cell { background: var(--grid-cell); border: 1px solid var(--grid-line); border-radius: var(--r-md); }

.tile-layer, .fx-layer { position: absolute; inset: var(--gap); pointer-events: none; }
.fx-layer { z-index: 5; }

.tile {
  position: absolute;
  width: calc((100% - (var(--n) - 1) * var(--gap)) / var(--n));
  height: calc((100% - (var(--n) - 1) * var(--gap)) / var(--n));
  left: calc(var(--c) * (100% + var(--gap)) / var(--n));
  top:  calc(var(--r) * (100% + var(--gap)) / var(--n));
  border-radius: var(--r-md);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px;
  transition: left var(--t-slide) var(--e-slide), top var(--t-slide) var(--e-slide),
              opacity var(--t-fade) ease, transform var(--t-fade) ease;
  will-change: left, top;
  overflow: hidden;
  pointer-events: auto;
}
.tile .glyph { font-weight: 760; line-height: 1; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: clamp(7px, 1.4vmin, 10px); opacity: .78; letter-spacing: .02em; }
.tile .sub.seq { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: clamp(6.5px, 1.2vmin, 9px); }

/* the class mark: a redundant, non-colour channel for class identity */
.tile .mark {
  position: absolute; top: 3px; left: 5px;
  font-size: clamp(8px, 1.6vmin, 12px); line-height: 1;
  opacity: .8; font-weight: 800; pointer-events: none;
}

.tile-nt .glyph { font-size: clamp(17px, 4.6vmin, 30px); }
.tile-nt[data-base="A"] { background: var(--nt-A); color: var(--ink-on-A); }
.tile-nt[data-base="U"] { background: var(--nt-U); color: var(--ink-on-U); }
.tile-nt[data-base="G"] { background: var(--nt-G); color: var(--ink-on-G); }
.tile-nt[data-base="C"] { background: var(--nt-C); color: var(--ink-on-C); }

.tile-pep { box-shadow: inset 0 0 0 1px #ffffff1f; }
.tile-pep .glyph { font-size: clamp(15px, 3.9vmin, 27px); }
.tile-pep[data-cls="aliphatic"] { background: var(--cls-aliphatic); color: var(--ink-on-aliphatic); }
.tile-pep[data-cls="polar"]     { background: var(--cls-polar);     color: var(--ink-on-polar); }
.tile-pep[data-cls="positive"]  { background: var(--cls-positive);  color: var(--ink-on-positive); }
.tile-pep[data-cls="aromatic"]  { background: var(--cls-aromatic);  color: var(--ink-on-aromatic); }
.tile-pep[data-cls="negative"]  { background: var(--cls-negative);  color: var(--ink-on-negative); }

/* escalation by tier — chain lengths stopped being powers of two once
   elongation was added, so an exact-length selector no longer works */
.tile-pep[data-tier="1"] { box-shadow: inset 0 0 0 1px #ffffff33; }
.tile-pep[data-tier="2"] { box-shadow: inset 0 0 0 2px #ffffff4d, 0 0 14px -4px #fff6; }
.tile-pep[data-tier="3"] {
  box-shadow: inset 0 0 0 2px #ffffff99, 0 0 22px -5px #fff;
  animation: shimmer 2.6s ease-in-out infinite;
}
@keyframes shimmer { 0%,100% { filter: brightness(1); } 50% { filter: brightness(1.16); } }

.tile-stop {
  background: repeating-linear-gradient(45deg, #47525f 0 7px, #333d48 7px 14px);
  color: #ffd9d9; box-shadow: inset 0 0 0 2px #6b7783;
}
.tile-stop .glyph { font-size: clamp(9px, 2vmin, 13px); letter-spacing: .07em; }
.tile-stop .mark { color: #ffd9d9; opacity: 1; }

.tile.spawn  { animation: pop-in var(--t-pop) var(--e-pop); }
.tile.appear { animation: pop-merge var(--t-pop) var(--e-pop); }
@keyframes pop-in {
  0%   { transform: scale(.3); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes pop-merge {
  0%   { transform: scale(.58); }
  55%  { transform: scale(1.14); }
  100% { transform: scale(1); }
}
/* A consumed tile slides into its product and fades — it should still be
   visible when the product pops, so the fade is not the fastest thing here. */
.tile.ghost { opacity: 0; transform: scale(.72); z-index: 1; }

/* Two steps: parked above the board with no transition, then released. The
   curve accelerates, so it reads as weight rather than as a slide. */
.tile.pre-fall { transition: none; }
.tile.falling {
  transition: left var(--t-fall) var(--e-fall), top var(--t-fall) var(--e-fall),
              opacity var(--t-fade) ease;
}

/* a chain a held charge could bank right now */
.tile.terminable { box-shadow: inset 0 0 0 2px #fff, 0 0 0 2px var(--accent); cursor: pointer; }
.tile.terminable::after {
  content: "\2715"; position: absolute; right: 4px; bottom: 3px;
  font-size: 10px; opacity: .85; font-weight: 800;
}

.float {
  position: absolute;
  left: calc(var(--c) * (100% + var(--gap)) / var(--n));
  top:  calc(var(--r) * (100% + var(--gap)) / var(--n));
  width: calc((100% - (var(--n) - 1) * var(--gap)) / var(--n));
  text-align: center;
  font-size: clamp(8.5px, 1.6vmin, 11.5px); font-weight: 750;
  color: #fff; text-shadow: 0 1px 5px #000d;
  animation: rise var(--t-float) cubic-bezier(.15, .7, .3, 1) forwards;
}
.float-stop { color: #ffb8b8; }
.float-release { color: var(--accent); }
/* Holds legible for most of its life, then leaves. The old one spent a third
   of its duration fading in and was gone before it could be read. */
@keyframes rise {
  0%   { transform: translateY(6px)   scale(.9); opacity: 0; }
  14%  { transform: translateY(0)     scale(1);  opacity: 1; }
  68%  { transform: translateY(-20px) scale(1);  opacity: 1; }
  100% { transform: translateY(-36px) scale(1);  opacity: 0; }
}

.landing {
  position: absolute;
  left: calc(var(--c) * (100% + var(--gap)) / var(--n));
  top:  calc(var(--r) * (100% + var(--gap)) / var(--n));
  width: calc((100% - (var(--n) - 1) * var(--gap)) / var(--n));
  height: calc((100% - (var(--n) - 1) * var(--gap)) / var(--n));
  border: 2px dashed var(--accent); border-radius: var(--r-md);
  opacity: 0; transition: opacity .14s, left .14s var(--e-slide), top .14s var(--e-slide);
  pointer-events: none;
}
.landing.shown { opacity: .85; }

/* --------------------------------------------------------- drop controls */

.columns {
  display: grid; grid-template-columns: repeat(var(--n), 1fr);
  gap: var(--gap); padding: 0 var(--gap); margin-bottom: 7px;
}
.columns button {
  background: var(--panel); border: 1px solid var(--line); color: var(--ink-faint);
  border-radius: var(--r-sm) var(--r-sm) 3px 3px; padding: 9px 0; font: inherit;
  font-size: 12px; font-weight: 600; cursor: pointer; min-height: 36px;
  transition: background .1s, color .1s, border-color .1s;
}
.columns button:hover:not(:disabled), .columns button.aimed {
  background: var(--panel-2); color: var(--ink); border-color: var(--accent);
}
.columns button:disabled { opacity: .28; cursor: not-allowed; }

/* The preview is this mode's central affordance: a bot that reads the codon it
   is completing scores 2.6x one that does not, so the player must read it too. */
.preview {
  display: flex; align-items: center; gap: 9px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 9px 12px; margin-top: 9px; min-height: 44px; font-size: 13px;
}
.preview .pv-codon { font-family: ui-monospace, Menlo, monospace; font-size: 15px; font-weight: 750; letter-spacing: .11em; }
.preview .pv-arrow { color: var(--ink-faint); }
.preview .pv-chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 99px; font-weight: 650; }
.preview .pv-chip[data-cls="aliphatic"] { background: var(--cls-aliphatic); color: var(--ink-on-aliphatic); }
.preview .pv-chip[data-cls="polar"]     { background: var(--cls-polar);     color: var(--ink-on-polar); }
.preview .pv-chip[data-cls="positive"]  { background: var(--cls-positive);  color: var(--ink-on-positive); }
.preview .pv-chip[data-cls="aromatic"]  { background: var(--cls-aromatic);  color: var(--ink-on-aromatic); }
.preview .pv-chip[data-cls="negative"]  { background: var(--cls-negative);  color: var(--ink-on-negative); }
.preview .pv-chip[data-cls="stop"]      { background: #3a444f; color: #ffb8b8; }
.preview .pv-note { color: var(--ink-dim); }
.preview .pv-good { color: var(--accent); font-weight: 650; }
.preview .pv-bad  { color: var(--danger); font-weight: 650; }
.preview.idle { color: var(--ink-faint); }

/* ------------------------------------------------------------------ dpad */

.dpad {
  display: grid; grid-template-columns: repeat(3, 46px); grid-template-rows: repeat(2, 42px);
  gap: 6px; justify-content: center; margin: 12px auto 0;
  grid-template-areas: ". u ." "l d r";
}
.dpad button {
  background: var(--panel); border: 1px solid var(--line); color: var(--ink);
  border-radius: var(--r-sm); font-size: 17px; cursor: pointer;
}
.dpad button:hover { background: var(--panel-2); }
.dpad [data-dir="up"] { grid-area: u; }
.dpad [data-dir="left"] { grid-area: l; }
.dpad [data-dir="down"] { grid-area: d; }
.dpad [data-dir="right"] { grid-area: r; }
@media (hover: none) { .dpad { display: none; } }

.statline {
  display: flex; gap: 14px; justify-content: center; flex-wrap: wrap;
  color: var(--ink-faint); font-size: 12.5px; margin-top: 11px;
}
.statline b { color: var(--ink); }
.warn { color: var(--danger); font-weight: 600; }
.combo { display: inline-flex; align-items: baseline; gap: 5px; color: var(--accent); font-weight: 750; }

/* --------------------------------------------------------------- panels */

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 13px 15px; margin-bottom: 13px;
}
.panel h2 { margin: 0 0 9px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .16em; color: var(--ink-faint); }
.note { font-size: 11.5px; color: var(--ink-dim); line-height: 1.55; margin: 9px 0 0; }
.note b { color: var(--ink); }
.empty { font-size: 12px; color: var(--ink-dim); line-height: 1.55; margin: 0; }

.prot-total { font-size: 10.5px; color: var(--ink-faint); margin-bottom: 7px; }
.prot-list { list-style: none; margin: 0; padding: 0; max-height: 290px; overflow-y: auto; display: grid; gap: 6px; }
.prot { background: var(--panel-2); border-radius: var(--r-sm); padding: 7px 9px; border-left: 3px solid var(--cls-aliphatic); }
.prot[data-cls="polar"] { border-left-color: var(--cls-polar); }
.prot[data-cls="positive"] { border-left-color: var(--cls-positive); }
.prot[data-cls="aromatic"] { border-left-color: var(--cls-aromatic); }
.prot[data-cls="negative"] { border-left-color: var(--cls-negative); }
.prot-head { display: flex; align-items: baseline; gap: 6px; font-size: 11.5px; }
.prot-mark { font-weight: 800; opacity: .9; }
.prot-len { font-weight: 750; font-size: 13.5px; }
.prot-name { color: var(--ink-faint); }
.prot-pts { margin-left: auto; color: var(--accent); font-weight: 650; }
.prot-seq { font-family: ui-monospace, Menlo, monospace; font-size: 11px; word-break: break-all; margin: 3px 0 2px; }
.prot-meta { font-size: 10px; color: var(--ink-faint); }

.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 11.5px; }
.swatch {
  display: grid; place-items: center; width: 16px; height: 16px; border-radius: 4px;
  font-size: 9px; font-weight: 800; flex: none;
  background: var(--cls-aliphatic); color: var(--ink-on-aliphatic);
}
.legend [data-cls="polar"] .swatch     { background: var(--cls-polar);     color: var(--ink-on-polar); }
.legend [data-cls="positive"] .swatch  { background: var(--cls-positive);  color: var(--ink-on-positive); }
.legend [data-cls="aromatic"] .swatch  { background: var(--cls-aromatic);  color: var(--ink-on-aromatic); }
.legend [data-cls="negative"] .swatch  { background: var(--cls-negative);  color: var(--ink-on-negative); }
.legend [data-cls="stop"] .swatch      { background: #3a444f; color: #ffb8b8; }
.lg-name { min-width: 62px; }
.lg-res { font-family: ui-monospace, Menlo, monospace; color: var(--ink-faint); letter-spacing: .05em; font-size: 11px; }
.lg-count { margin-left: auto; color: var(--ink-faint); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ help */

.help summary {
  cursor: pointer; font-size: 13px; font-weight: 600; list-style: none;
  min-height: 30px; display: flex; align-items: center;
}
.help summary::-webkit-details-marker { display: none; }
.help summary::before { content: "\25B8"; color: var(--ink-faint); margin-right: 7px; }
.help[open] summary::before { content: "\25BE"; }
.hint { color: var(--ink-faint); font-weight: 400; font-size: 11px; margin-left: 6px; }
.help-body { margin-top: 11px; max-width: 74ch; overflow-x: auto; }
.help-body h3 { font-size: 12.5px; margin: 15px 0 4px; color: var(--accent); }
.help-body p { font-size: 13px; line-height: 1.65; color: #c3d1e1; margin: 0 0 6px; }
.help-body code { font-family: ui-monospace, Menlo, monospace; background: #0b1119; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

.codon-table { border-collapse: collapse; font-size: 10.5px; }
.codon-table th { color: var(--ink-faint); font-weight: 600; padding: 3px 5px; }
.codon-table td {
  padding: 3px 5px; text-align: center; border-radius: 4px; line-height: 1.15;
  background: var(--cls-aliphatic); color: var(--ink-on-aliphatic); min-width: 48px;
}
.codon-table td[data-cls="polar"]    { background: var(--cls-polar);    color: var(--ink-on-polar); }
.codon-table td[data-cls="positive"] { background: var(--cls-positive); color: var(--ink-on-positive); }
.codon-table td[data-cls="aromatic"] { background: var(--cls-aromatic); color: var(--ink-on-aromatic); }
.codon-table td[data-cls="negative"] { background: var(--cls-negative); color: var(--ink-on-negative); }
.codon-table td[data-cls="stop"]     { background: #3a444f; color: #ffb8b8; }
.ct-codon { display: block; font-family: ui-monospace, Menlo, monospace; font-size: 9.5px; opacity: .82; }
.ct-aa { display: block; font-weight: 750; font-size: 11.5px; }
.ct-aa i { font-style: normal; opacity: .75; font-size: 9.5px; }

kbd {
  font-family: ui-monospace, Menlo, monospace; font-size: 10.5px;
  background: #0b1119; border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 4px; padding: 1px 5px; color: var(--ink-dim);
}
.foot { margin-top: 18px; font-size: 11.5px; color: var(--ink-faint); }

/* -------------------------------------------------------- toasts & modal */

.toasts {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 40;
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: grid; gap: 7px; width: max-content; max-width: min(92vw, 420px);
}
.toast {
  background: #17222f; border: 1px solid var(--line); border-left: 3px solid var(--accent);
  color: var(--ink); padding: 9px 13px; border-radius: var(--r-sm); font-size: 12.5px;
  box-shadow: var(--shadow); animation: toast-in .3s var(--e-slide);
}
.toast.out { opacity: 0; transform: translateY(6px); transition: opacity .45s, transform .45s; }
.toast-warn { border-left-color: var(--danger); }
@keyframes toast-in { from { transform: translateY(14px) scale(.97); opacity: 0; } }

.overlay {
  position: fixed; inset: 0; background: #050810cc; backdrop-filter: blur(3px);
  display: grid; place-items: center; z-index: 60; padding: 18px;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.overlay.shown { opacity: 1; pointer-events: auto; }
.overlay-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 24px 26px; max-width: 400px; text-align: center; box-shadow: var(--shadow);
}
.overlay-card h2 { margin: 0 0 8px; font-size: 20px; }
.overlay-card p { color: var(--ink-dim); font-size: 13.5px; line-height: 1.6; margin: 0 0 16px; }

/* ---------------------------------------------------------- focus & a11y */

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 5px; }
.tile:focus { outline: none; }
.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;
}

/* ------------------------------------------------------------ responsive */

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; gap: 14px; }
  .side { max-width: var(--board-max); width: 100%; margin-inline: auto; }
}

/* Phone. The board has to be reachable without scrolling, so everything that
   is explanation rather than play collapses out of the way. */
@media (max-width: 620px) {
  :root { --board-max: 100%; }
  /* Four modes plus two settings controls is a lot of chrome for a phone.
     The nav gets its own scrollable strip rather than wrapping into three
     ragged rows above the board. */
  .modes {
    margin-left: 0; order: 9; width: 100%;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none; padding-bottom: 2px;
  }
  .modes::-webkit-scrollbar { display: none; }
  .modes a { flex: 1 0 auto; justify-content: center; white-space: nowrap; }
  .settings { order: 4; }
  .rack { gap: 5px; }
  .rack .slot { padding: 7px 8px; min-height: 42px; gap: 5px; }
  .app { padding-top: 10px; }
  .masthead { margin-bottom: 9px; }
  .tagline { display: none; }
  .pitch { display: none; }
  .toolbar { gap: 6px; margin-bottom: 10px; row-gap: 8px; }
  .toolbar .sel span { display: none; }
  .queue-wrap { margin-left: 0; order: 5; }
  .modes { margin-left: auto; }
  .btn, .sel select, .modes a { font-size: 12.5px; padding: 8px 10px; }
  .score-box { min-width: 66px; padding: 5px 10px; }
  .score-box span:last-child { font-size: 17px; }
  .panel { padding: 11px 13px; }
  .prot-list { max-height: 220px; }
  .board { border-radius: 12px; }
  /* the codon table is 4 columns of 4 rows; let it scroll rather than squash */
  .help-body { -webkit-overflow-scrolling: touch; }
}

@media (max-width: 400px) {
  .columns button { font-size: 10.5px; padding: 8px 0; }
  .statline { gap: 9px; font-size: 11.5px; }
}

/* Reduced motion, as a substitution rather than a strip. The tile slide is what
   tells the player which tiles merged and where they went; removing it deletes
   that channel. So: drop the trajectory, keep the duration, and carry the event
   on an opacity flash instead (opacity is exempt from WCAG 2.3.3). */
@media (prefers-reduced-motion: reduce) {
  .tile, .tile.falling { transition: opacity .2s ease; }
  .tile.spawn, .tile.appear { animation: flash-in .3s ease-out; }
  .tile-pep[data-tier="3"] { animation: none; }
  .float { animation: fade-only .9s ease-out forwards; }
  @keyframes flash-in { 0% { opacity: .35; box-shadow: inset 0 0 0 3px #fff; } 100% { opacity: 1; } }
  @keyframes fade-only { 0% { opacity: 0; } 20% { opacity: 1; } 100% { opacity: 0; } }
}

.runlist { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }
.runlist li { display: flex; justify-content: space-between; align-items: baseline; font-size: 11.5px; color: var(--ink-dim); }
.runlist b { color: var(--ink); font-variant-numeric: tabular-nums; font-size: 13px; }

/* ----------------------------------------------------------- tumble mode */

.ghost-cell {
  position: absolute;
  left: calc(var(--c) * (100% + var(--gap)) / var(--n));
  top:  calc(var(--r) * (100% + var(--gap)) / var(--n));
  width: calc((100% - (var(--n) - 1) * var(--gap)) / var(--n));
  height: calc((100% - (var(--n) - 1) * var(--gap)) / var(--n));
  border: 2px dashed var(--accent); border-radius: var(--r-md);
  display: grid; place-items: center;
  font-weight: 750; font-size: clamp(12px, 3vmin, 20px); color: #ffffffa8;
  opacity: 0; transition: opacity .14s, left .14s var(--e-slide), top .14s var(--e-slide);
  pointer-events: none;
}
.ghost-cell.shown { opacity: .9; }
.ghost-cell[data-base="A"] { border-color: var(--nt-A); color: var(--nt-A); }
.ghost-cell[data-base="U"] { border-color: var(--nt-U); color: var(--nt-U); }
.ghost-cell[data-base="G"] { border-color: var(--nt-G); color: var(--nt-G); }
.ghost-cell[data-base="C"] { border-color: var(--nt-C); color: var(--nt-C); }

.frag-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 9px; }
.frag {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 7px 11px;
}
.frag-label { font-size: 9px; text-transform: uppercase; letter-spacing: .14em; color: var(--ink-faint); }
.frag-cells { display: grid; gap: 3px; }
.frag-cells.vertical { grid-auto-flow: row; }
.frag-cells.horizontal { grid-auto-flow: column; }
.frag-cells span {
  width: 24px; height: 24px; border-radius: 5px; display: grid; place-items: center;
  font-weight: 750; font-size: 12px;
}
.frag-cells span[data-base="A"] { background: var(--nt-A); color: var(--ink-on-A); }
.frag-cells span[data-base="U"] { background: var(--nt-U); color: var(--ink-on-U); }
.frag-cells span[data-base="G"] { background: var(--nt-G); color: var(--ink-on-G); }
.frag-cells span[data-base="C"] { background: var(--nt-C); color: var(--ink-on-C); }
.frag-5 { font-size: 9px; color: var(--ink-faint); letter-spacing: .06em; }
.next-frags { display: flex; gap: 8px; align-items: center; }
.next-frags .frag-cells span { width: 15px; height: 15px; font-size: 9px; border-radius: 3px; }
.pv-topple { color: var(--danger); font-weight: 700; }

/* ---------------------------------------------------------- cytosol mode */

.vessel-wrap { display: flex; justify-content: center; }
#vessel {
  border-radius: var(--r-lg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  touch-action: none;
  cursor: crosshair;
  display: block;
}

.rack { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 10px; }
.rack .slot {
  display: flex; align-items: center; gap: 7px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 8px 10px; min-height: 46px; font: inherit; color: var(--ink);
  border-left-width: 3px; text-align: left; overflow: hidden;
}
.rack .slot.empty { color: var(--ink-faint); font-size: 11.5px; justify-content: center; border-left-color: var(--line); }
.rack button.slot { cursor: default; }
.rack button.slot.armed { cursor: pointer; border-color: var(--accent); box-shadow: 0 0 0 1px #45d3a433; }
.rack button.slot.armed:hover { background: var(--panel-2); }
.rack .slot[data-cls="aliphatic"] { border-left-color: var(--cls-aliphatic); }
.rack .slot[data-cls="polar"]     { border-left-color: var(--cls-polar); }
.rack .slot[data-cls="positive"]  { border-left-color: var(--cls-positive); }
.rack .slot[data-cls="aromatic"]  { border-left-color: var(--cls-aromatic); }
.rack .slot[data-cls="negative"]  { border-left-color: var(--cls-negative); }
.slot-mark { font-weight: 800; opacity: .85; }
.slot-len { font-size: 17px; font-weight: 750; font-variant-numeric: tabular-nums; }
.slot-seq { font-family: ui-monospace, Menlo, monospace; font-size: 10px; color: var(--ink-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 420px) { .slot-seq { display: none; } }


.btn-icon {
  min-width: 40px; padding: 8px 10px; font-size: 15px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-icon.off { color: var(--ink-faint); }
.settings { display: flex; align-items: center; gap: 7px; }

/* ------------------------------------------------------------ fold panel */

.overlay-card.with-fold { max-width: 460px; }

.fold-panel { text-align: left; margin-top: 6px; }
.fold-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.fold-title { font-size: 10.5px; text-transform: uppercase; letter-spacing: .14em; color: var(--ink-faint); }
.fold-toggle { padding: 5px 11px; font-size: 12px; min-height: 30px; }

.fold-canvas {
  display: block; margin: 0 auto; width: 100%; max-width: 280px; aspect-ratio: 1 / 1;
  background: var(--grid-cell); border: 1px solid var(--line); border-radius: var(--r-md);
  touch-action: none; cursor: grab;
}
.fold-canvas:active { cursor: grabbing; }

.fold-meta { display: flex; align-items: center; gap: 7px; margin-top: 10px; font-size: 12px; color: var(--ink-dim); }
.fold-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 5px; font-size: 10px; font-weight: 800;
  background: var(--cls-aliphatic); color: var(--ink-on-aliphatic); flex: none;
}
.fold-mark[data-cls="polar"]     { background: var(--cls-polar);     color: var(--ink-on-polar); }
.fold-mark[data-cls="positive"]  { background: var(--cls-positive);  color: var(--ink-on-positive); }
.fold-mark[data-cls="aromatic"]  { background: var(--cls-aromatic);  color: var(--ink-on-aromatic); }
.fold-mark[data-cls="negative"]  { background: var(--cls-negative);  color: var(--ink-on-negative); }

.fold-seq {
  font-family: ui-monospace, Menlo, monospace; font-size: 11px; color: var(--ink-faint);
  word-break: break-all; margin-top: 4px;
}
.fold-actions { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.fold-copied { font-size: 11.5px; color: var(--accent); }

/* --------------------------------------------------------------- fold.html */

.fold-page { max-width: 480px; }
.fold-empty { text-align: center; }
.fold-empty h2 {
  margin: 0 0 8px; font-size: 18px; font-weight: 700;
  text-transform: none; letter-spacing: normal; color: var(--ink);
}
.fold-empty p { color: var(--ink-dim); font-size: 13.5px; line-height: 1.6; margin: 0 0 16px; }
.fold-share-card .fold-canvas-large { max-width: 360px; }
