/* ============================================================================
   PROCatchem Script Builder
   Shares the Pokédex design language of the API reference: a red shell holding
   a green LCD, warm paper for the reading surface, and chunky pressable chrome.
   ========================================================================== */

:root {
  --dex-red: #E3350D;
  --dex-red-hi: #F04A2A;
  --dex-red-deep: #7F1B06;
  --shell-ink: #20242B;
  --paper: #FDFBF4;
  --paper-line: #E7E0CC;
  --paper-dash: #E3DCC6;
  --ink: #252B38;
  --muted-ink: #6F684F;
  --lcd: #0B1E16;
  --lcd-hi: #0F241B;
  --lcd-frame: #1E4A35;
  --lcd-text: #D7F5DF;
  --lcd-dim: #6FA383;
  --gold: #F2C94C;
  --leaf: #78C850;
  --sea: #6890F0;
  --danger: #C03028;
  --warn: #E8A33D;

  /* Reading surfaces, lightest first. Named rather than repeated as literals so
     a nested control can go one shade deeper without inventing a colour — and
     so the dark palette is a matter of redefining these, not of hunting through
     the rules for hex codes. */
  --surface-raised: #FFFFFF;
  --surface-input: #FFFDF7;
  --surface-card: #FFFBF0;
  --surface-nested: #FBF7EA;
  --surface-sunk: #F7F2E2;
  --surface-highlight: #FFF7E2;
  --surface-code: #F1ECDC;

  /* Inks that are not the body colour. */
  --prose-ink: #4A4636;
  --note-ink: #5A4A22;
  --hint-ink: #78715C;
  --placeholder-ink: #B8B097;
  --code-ink: #3B3325;
  --ok-ink: #2E7D4F;
  --heading-ink: var(--shell-ink);
  --line-hover: #D8CFB4;

  /* The warm red wash a selected control carries. */
  --tint-active: #FFF1EC;
  --tint-active-deep: #FFE3DA;
  --tint-active-ink: #A0553F;

  /* Text that is never translated keeps the pixel face through -latin; the
     plain token falls back to the body face while a translation is active
     (see assets/i18n/i18n.css), because Press Start 2P has no Vietnamese. */
  --ff-pixel-latin: 'Press Start 2P', ui-monospace, monospace;
  --ff-pixel: var(--ff-pixel-latin);
  --ff-body: 'Nunito', system-ui, 'Segoe UI', sans-serif;
  --ff-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --sidebar-w: 300px;
  --ease: cubic-bezier(.22, .61, .36, 1);
}

* { box-sizing: border-box; }

/*
 * Declaring the schemes this page supports is not optional decoration: without
 * it Chromium applies its own dark treatment to form controls when the system
 * is dark, which overrides the authored background even when it is a literal.
 * It also gets scrollbars and the caret right for free.
 */
:root { color-scheme: light dark; }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--ff-body);
  font-size: 15px;
  color: var(--ink);
  background: var(--paper);
}

/*
 * Form controls do not inherit font-family — the UA stylesheet pins them to
 * its own face — so every button that does not name a font of its own renders
 * outside the design. That went unnoticed while the UI was English, because
 * the UA face is close enough to pass at a glance; in Vietnamese it broke
 * loudly, since Arial Bold carries no precomposed Vietnamese glyphs and
 * "Bắt đúng con khớp bộ lọc" fell back glyph by glyph mid-word.
 *
 * Inheriting fixes every control at once, including ones added later. Only the
 * family is inherited: size, weight and line-height stay with the component,
 * so nothing here changes any control's proportions.
 */
button, input, select, textarea { font-family: inherit; }

::selection { background: var(--gold); color: var(--shell-ink); }
:focus-visible { outline: 3px dashed var(--gold); outline-offset: 2px; }

code {
  background: var(--surface-code);
  border: 1px solid var(--paper-dash);
  color: var(--code-ink);
  padding: 2px 6px;
  border-radius: 5px;
  font: 600 12.5px var(--ff-mono);
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* ============================================================ Pokédex shell */

.sidebar {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  overflow: auto;
  padding: 18px 0 24px;
  background: linear-gradient(160deg, var(--dex-red-hi), var(--dex-red) 42%, #B4230A);
  border-right: 4px solid var(--dex-red-deep);
  box-shadow: inset -6px 0 14px rgba(0, 0, 0, .18);
  z-index: 20;
}
.sidebar::-webkit-scrollbar { width: 10px; }
.sidebar::-webkit-scrollbar-thumb {
  background: var(--dex-red-deep); border-radius: 8px; border: 2px solid var(--dex-red);
}
.sidebar::-webkit-scrollbar-track { background: transparent; }

.brand { padding: 0 20px 16px; }
.dex-top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.dex-lens {
  width: 46px; height: 46px; border-radius: 50%; flex: none; position: relative;
  background: radial-gradient(circle at 32% 30%, #EAF6FF 0 13%, #7CC7FF 14% 45%, #1877D2 46% 78%, #0B3E7A 79% 100%);
  border: 4px solid #FCFCFC;
  box-shadow: 0 3px 6px rgba(0, 0, 0, .4), inset -3px -4px 8px rgba(0, 0, 0, .3);
}
.dex-lens::after {
  content: ''; position: absolute; left: 7px; top: 6px;
  /* A specular highlight on the shell's lens, not a reading surface: it stays
     white whatever the theme does. */
  width: 10px; height: 10px; border-radius: 50%; background: #fff; opacity: .92;
}
.dex-leds { display: flex; gap: 7px; }
.dex-leds i {
  width: 11px; height: 11px; border-radius: 50%;
  box-shadow: inset 0 -2px 2px rgba(0, 0, 0, .4), 0 0 7px currentColor;
}
.dex-leds i:nth-child(1) { color: #FF5A5A; background: #FF5A5A; }
.dex-leds i:nth-child(2) { color: #FFD84D; background: #FFD84D; }
.dex-leds i:nth-child(3) { color: #5AFF7A; background: #5AFF7A; }

.brand-row { display: flex; align-items: center; gap: 12px; }
.pokeball {
  width: 34px; height: 34px; border-radius: 50%; flex: none; position: relative;
  background: linear-gradient(180deg, #FF5A44 0 44%, var(--shell-ink) 44% 56%, #F6F6F6 56% 100%);
  border: 3px solid var(--shell-ink);
  box-shadow: 0 2px 4px rgba(0, 0, 0, .35);
}
.pokeball::after {
  content: ''; position: absolute; inset: 0; margin: auto;
  width: 9px; height: 9px; border-radius: 50%;
  background: #F6F6F6; border: 3px solid var(--shell-ink);
}
.brand-row:hover .pokeball { animation: wiggle .55s ease; }
@keyframes wiggle {
  20% { transform: rotate(-16deg); }
  45% { transform: rotate(13deg); }
  70% { transform: rotate(-7deg); }
  100% { transform: rotate(0); }
}

.brand h1 {
  font-family: var(--ff-pixel-latin); font-size: 13px; line-height: 1.55;
  color: #fff; text-shadow: 0 2px 0 var(--dex-red-deep); margin: 0;
}
.brand-sub { margin: 12px 0 0; color: #FFD9CC; font-size: 12px; font-weight: 600; }
.brand-sub .ver {
  background: var(--gold); color: #5A3E00; font-weight: 800; font-size: 11px;
  padding: 2px 9px; border-radius: 999px; margin-left: 4px;
}

/* nav = LCD screen inside the shell */
.side-nav {
  display: flex; flex-direction: column;
  margin: 0 14px 16px; padding: 8px;
  background: linear-gradient(180deg, #101D16, #0A1510);
  border: 3px solid var(--dex-red-deep); border-radius: 14px;
  box-shadow: inset 0 2px 12px rgba(0, 0, 0, .65), 0 2px 0 var(--dex-red-deep);
}
.side-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 8px;
  color: var(--lcd-dim); text-decoration: none;
  font: 600 13px var(--ff-body);
  transition: background .16s var(--ease), color .16s var(--ease), transform .16s var(--ease);
}
.side-nav a span { font-size: 14px; width: 18px; text-align: center; color: var(--leaf); }
.side-nav a:hover { background: rgba(120, 200, 80, .12); color: var(--lcd-text); transform: translateX(3px); }

.side-block { margin: 0 14px 16px; }
.side-h {
  margin: 0 0 8px; font-family: var(--ff-pixel); font-size: 8px; letter-spacing: .06em;
  color: #FFE2D8; text-shadow: 0 2px 0 var(--dex-red-deep);
}
.side-note { margin: 0 0 10px; font-size: 12px; line-height: 1.6; color: #FFD9CC; }
.side-note code { background: rgba(0, 0, 0, .28); border-color: rgba(0, 0, 0, .3); color: #FFE9B8; }
.side-actions { display: flex; flex-direction: column; gap: 8px; }

.graph-status {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 11px; margin-bottom: 10px; border-radius: 9px;
  background: rgba(0, 0, 0, .3); border: 2px solid rgba(0, 0, 0, .25);
  font: 600 11.5px var(--ff-mono); color: #FFD9CC; line-height: 1.4;
}
.graph-dot {
  width: 10px; height: 10px; border-radius: 50%; flex: none;
  background: #7F3B2C; box-shadow: inset 0 -2px 2px rgba(0, 0, 0, .45);
}
.graph-dot.is-on { background: #5AFF7A; box-shadow: 0 0 8px #5AFF7A, inset 0 -2px 2px rgba(0, 0, 0, .3); }

.side-back {
  display: block; margin: 0 14px; padding: 10px;
  text-align: center; border-radius: 999px;
  background: rgba(0, 0, 0, .22); color: #FFE2D8;
  font-size: 12px; font-weight: 700; text-decoration: none;
  transition: background .16s var(--ease), transform .16s var(--ease);
}
.side-back:hover { background: rgba(0, 0, 0, .34); transform: translateY(-1px); }

/* ==================================================================== main */

.content { margin-left: var(--sidebar-w); }

.hero {
  padding: 40px 34px 30px;
  background:
    radial-gradient(1100px 300px at 8% -30%, rgba(227, 53, 13, .12), transparent 60%),
    linear-gradient(180deg, var(--surface-raised), var(--paper));
  border-bottom: 2px dashed var(--paper-dash);
}
.hero-eyebrow {
  margin: 0 0 10px; font-family: var(--ff-pixel); font-size: 8px;
  letter-spacing: .1em; color: var(--dex-red);
}
.hero h1 {
  margin: 0 0 14px; font-family: var(--ff-pixel-latin); font-size: 26px; line-height: 1.45;
  color: var(--heading-ink); text-shadow: 0 3px 0 var(--paper-line);
}
.hero h1 span { color: var(--dex-red); }
.hero-tag { margin: 0 0 18px; max-width: 62ch; font-size: 15.5px; line-height: 1.75; color: var(--prose-ink); }

.hero-note {
  margin: 0; padding: 13px 16px; max-width: 74ch;
  background: var(--surface-highlight); border: 2px solid var(--paper-line);
  border-left: 6px solid var(--gold); border-radius: 10px;
  font-size: 13.5px; line-height: 1.7; color: var(--note-ink);
  box-shadow: 0 2px 0 var(--paper-line);
}

/* workbench = controls on the left, sticky preview on the right */
.workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(430px, 44%);
  gap: 0;
  align-items: start;
}
.controls { padding: 24px 30px 60px; min-width: 0; }
.preview {
  position: sticky; top: 0;
  align-self: start;
  padding: 24px 30px 40px 26px;
  border-left: 2px dashed var(--paper-dash);
  max-height: 100vh; overflow: auto;
}
.preview::-webkit-scrollbar { width: 8px; }
.preview::-webkit-scrollbar-thumb { background: var(--paper-line); border-radius: 8px; }

/* ================================================================== panels */

.panel {
  margin: 0 0 22px;
  background: var(--surface-raised);
  border: 2px solid var(--paper-line);
  border-radius: 14px;
  box-shadow: 0 3px 0 var(--paper-line);
  overflow: hidden;
  scroll-margin-top: 20px;
}
.panel.rv { opacity: 0; transform: translateY(12px); }
.panel.in { opacity: 1; transform: none; transition: opacity .5s var(--ease), transform .5s var(--ease); }

.panel.pulse { animation: panelPulse 1.1s var(--ease); }
@keyframes panelPulse {
  0% { box-shadow: 0 3px 0 var(--paper-line), 0 0 0 0 rgba(227, 53, 13, .45); }
  40% { box-shadow: 0 3px 0 var(--paper-line), 0 0 0 12px rgba(227, 53, 13, 0); }
  100% { box-shadow: 0 3px 0 var(--paper-line), 0 0 0 0 rgba(227, 53, 13, 0); }
}

.panel-head {
  display: flex; align-items: center; gap: 13px;
  padding: 15px 18px;
  background: linear-gradient(180deg, var(--surface-raised), var(--surface-sunk));
  border-bottom: 2px solid var(--paper-line);
}
.panel-icon {
  width: 36px; height: 36px; flex: none;
  display: grid; place-items: center;
  border-radius: 10px; font-size: 17px;
  background: var(--dex-red); color: #fff;
  border: 2px solid var(--shell-ink);
  box-shadow: 0 2px 0 var(--shell-ink);
}
.panel-titles { min-width: 0; }
.panel-title {
  margin: 0; font-family: var(--ff-pixel); font-size: 11px; line-height: 1.6;
  color: var(--heading-ink);
}
.panel-sub { margin: 5px 0 0; font-size: 12.5px; color: var(--muted-ink); }
.panel-body { padding: 18px; display: grid; gap: 16px; }

/* =================================================================== fields */

.field { display: grid; gap: 7px; }
.field-label {
  font-size: 11px; font-weight: 800; letter-spacing: .12em;
  text-transform: uppercase; color: var(--muted-ink);
}
.field-hint { margin: 0; font-size: 12.5px; line-height: 1.6; color: var(--hint-ink); }

.input {
  width: 100%; padding: 10px 12px;
  font: 600 14px var(--ff-body); color: var(--ink);
  background: var(--surface-input);
  border: 2px solid var(--paper-line); border-radius: 9px;
  transition: border-color .16s var(--ease), box-shadow .16s var(--ease), background .16s var(--ease);
}
.input::placeholder { color: var(--placeholder-ink); font-weight: 600; }
.input:hover { border-color: var(--line-hover); }
.input:focus {
  outline: none; background: var(--surface-raised);
  border-color: var(--dex-red);
  box-shadow: 0 0 0 3px rgba(227, 53, 13, .14);
}
.select {
  appearance: none; cursor: pointer; padding-right: 34px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted-ink) 50%),
                    linear-gradient(135deg, var(--muted-ink) 50%, transparent 50%);
  background-position: calc(100% - 17px) 55%, calc(100% - 12px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

/* segmented control */
.segmented { display: flex; flex-wrap: wrap; gap: 8px; }
.seg {
  flex: 1 1 150px; min-width: 0;
  display: grid; gap: 3px; padding: 10px 13px; cursor: pointer; text-align: left;
  background: var(--surface-input); color: var(--ink);
  border: 2px solid var(--paper-line); border-radius: 10px;
  transition: transform .14s var(--ease), border-color .14s var(--ease),
              background .14s var(--ease), box-shadow .14s var(--ease);
}
.seg:hover { transform: translateY(-1px); border-color: var(--line-hover); box-shadow: 0 3px 0 var(--paper-line); }
.seg:active { transform: translateY(1px); box-shadow: none; }
.seg-label { font-size: 13.5px; font-weight: 800; }
.seg-hint { font-size: 11.5px; color: var(--muted-ink); line-height: 1.5; }
.seg.is-active {
  background: linear-gradient(180deg, var(--tint-active), var(--tint-active-deep));
  border-color: var(--dex-red);
  box-shadow: 0 3px 0 rgba(227, 53, 13, .3);
}
.seg.is-active .seg-label { color: var(--dex-red-deep); }
.seg.is-active .seg-hint { color: var(--tint-active-ink); }

/* toggle */
.field-toggle { gap: 0; }
.toggle {
  display: flex; align-items: flex-start; gap: 12px; cursor: pointer;
  padding: 10px 12px; border-radius: 10px;
  border: 2px solid transparent;
  transition: background .16s var(--ease), border-color .16s var(--ease);
}
.toggle:hover { background: var(--surface-card); border-color: var(--paper-line); }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: relative; flex: none; margin-top: 2px;
  width: 44px; height: 24px; border-radius: 999px;
  background: var(--paper-dash); border: 2px solid var(--shell-ink);
  transition: background .2s var(--ease);
}
.toggle-thumb {
  position: absolute; top: 1px; left: 1px;
  width: 18px; height: 18px; border-radius: 50%;
  background: linear-gradient(180deg, var(--surface-raised) 0 48%, var(--paper-dash) 48% 100%);
  border: 2px solid var(--shell-ink);
  transition: transform .2s var(--ease);
}
.toggle input:checked + .toggle-track { background: var(--leaf); }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(20px); }
.toggle input:focus-visible + .toggle-track { outline: 3px dashed var(--gold); outline-offset: 2px; }
.toggle-text { display: grid; gap: 3px; min-width: 0; }
.toggle-label { font-size: 14px; font-weight: 700; }
.toggle-hint { font-size: 12.5px; color: var(--muted-ink); line-height: 1.55; }

/* chips */
.chips {
  display: flex; flex-wrap: wrap; gap: 7px; align-items: center;
  min-height: 44px; padding: 8px 10px; cursor: text;
  background: var(--surface-input); border: 2px solid var(--paper-line); border-radius: 9px;
  transition: border-color .16s var(--ease), box-shadow .16s var(--ease);
}
.chips:focus-within {
  background: var(--surface-raised); border-color: var(--dex-red);
  box-shadow: 0 0 0 3px rgba(227, 53, 13, .14);
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 5px 4px 11px; border-radius: 999px;
  background: linear-gradient(180deg, var(--tint-active), var(--tint-active-deep));
  border: 2px solid var(--dex-red);
  font-size: 12.5px; font-weight: 800; color: var(--dex-red-deep);
  animation: chipIn .2s var(--ease);
}
@keyframes chipIn { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.chip-x {
  width: 19px; height: 19px; display: grid; place-items: center;
  border: 0; border-radius: 50%; cursor: pointer;
  background: rgba(227, 53, 13, .16); color: var(--dex-red-deep);
  font-size: 14px; line-height: 1;
  transition: background .14s var(--ease), transform .14s var(--ease);
}
.chip-x:hover { background: var(--dex-red); color: #fff; transform: rotate(90deg); }
.chip-input {
  flex: 1 1 130px; min-width: 110px;
  border: 0; background: transparent; outline: none;
  font: 600 13.5px var(--ff-body); color: var(--ink);
}
.chip-input::placeholder { color: var(--placeholder-ink); }

/* ball ladder */
.ladder { display: grid; gap: 8px; }
.ladder-row {
  display: grid; align-items: center; gap: 8px;
  grid-template-columns: 26px minmax(0, 1fr) minmax(0, 150px) auto;
  padding: 7px; border-radius: 10px;
  background: var(--surface-card); border: 2px solid var(--paper-line);
  animation: chipIn .18s var(--ease);
}
.ladder-rank {
  display: grid; place-items: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--shell-ink); color: #fff;
  font: 800 12px var(--ff-mono);
}
.ladder-row .input { padding: 7px 10px; font-size: 13px; }
.ladder-tools { display: flex; gap: 4px; }
.ladder-empty { margin: 0; padding: 12px; text-align: center; background: var(--surface-highlight); border-radius: 9px; }
.ladder-add { justify-self: start; }

.icon-btn {
  width: 27px; height: 27px; display: grid; place-items: center; cursor: pointer;
  background: var(--surface-raised); color: var(--shell-ink);
  border: 2px solid var(--paper-line); border-radius: 7px;
  font-size: 11px; line-height: 1;
  transition: background .14s var(--ease), border-color .14s var(--ease), transform .14s var(--ease);
}
.icon-btn:hover:not(:disabled) { background: var(--gold); border-color: var(--shell-ink); transform: translateY(-1px); }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.icon-btn-danger:hover:not(:disabled) { background: var(--danger); border-color: var(--shell-ink); color: #fff; }

/* mode cards */
.mode-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 11px; }
.mode-card {
  position: relative; overflow: hidden;
  display: grid; gap: 5px; padding: 15px 14px; cursor: pointer; text-align: left;
  background: var(--surface-input); color: var(--ink);
  border: 2px solid var(--paper-line); border-radius: 13px;
  transition: transform .16s var(--ease), border-color .16s var(--ease),
              box-shadow .16s var(--ease), background .16s var(--ease);
}
.mode-card::after {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(220px 90px at 50% 0%, rgba(227, 53, 13, .1), transparent 70%);
  opacity: 0; transition: opacity .22s var(--ease); pointer-events: none;
}
.mode-card:hover { transform: translateY(-3px); box-shadow: 0 5px 0 var(--paper-line); border-color: var(--line-hover); }
.mode-card:hover::after { opacity: 1; }
.mode-card:active { transform: translateY(0); box-shadow: 0 2px 0 var(--paper-line); }
.mode-icon { font-size: 22px; color: var(--dex-red); line-height: 1; }
.mode-name { font-family: var(--ff-pixel); font-size: 10px; line-height: 1.5; color: var(--heading-ink); }
.mode-tagline { font-size: 12.5px; font-weight: 800; color: var(--dex-red); }
.mode-desc { font-size: 12px; line-height: 1.6; color: var(--muted-ink); }
.mode-card.is-active {
  background: linear-gradient(180deg, var(--tint-active), var(--tint-active-deep));
  border-color: var(--dex-red);
  box-shadow: 0 4px 0 rgba(227, 53, 13, .32);
}
.mode-card.is-active .mode-icon { animation: pop .4s var(--ease); }
@keyframes pop { 0% { transform: scale(1); } 45% { transform: scale(1.35) rotate(-8deg); } 100% { transform: scale(1); } }

/* ============================================================ LCD preview */

.preview-inner { display: grid; gap: 14px; }

.screen {
  position: relative;
  border-radius: 14px;
  background: linear-gradient(180deg, var(--lcd-hi), var(--lcd));
  border: 3px solid var(--shell-ink);
  box-shadow: inset 0 0 0 2px var(--lcd-frame), inset 0 12px 30px rgba(0, 0, 0, .4);
  overflow: hidden;
}
.screen.flash { animation: screenFlash .5s var(--ease); }
@keyframes screenFlash {
  0% { box-shadow: inset 0 0 0 2px var(--leaf), inset 0 12px 30px rgba(0, 0, 0, .4); }
  100% { box-shadow: inset 0 0 0 2px var(--lcd-frame), inset 0 12px 30px rgba(0, 0, 0, .4); }
}

.screen-bar {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 13px;
  background: rgba(0, 0, 0, .32);
  border-bottom: 2px solid var(--lcd-frame);
}
.screen-lights { display: flex; gap: 5px; }
.screen-lights i { width: 9px; height: 9px; border-radius: 50%; background: #2C5C43; }
.screen-lights i:nth-child(1) { background: #FF5A5A; }
.screen-lights i:nth-child(2) { background: #FFD84D; }
.screen-lights i:nth-child(3) { background: #5AFF7A; }
.screen-name {
  font-family: var(--ff-pixel); font-size: 7px; letter-spacing: .06em; color: var(--lcd-dim);
}
.screen-stats { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }

.stat-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  background: rgba(120, 200, 80, .12); border: 1px solid var(--lcd-frame);
  font: 600 10.5px var(--ff-mono); color: var(--lcd-dim);
}
.stat-pill b { color: var(--lcd-text); font-size: 11px; }
.stat-ok { background: rgba(120, 200, 80, .2); border-color: var(--leaf); }
.stat-ok b, .stat-ok span { color: #A9F5C4; }
.stat-bad { background: rgba(192, 48, 40, .22); border-color: #E36B62; }
.stat-bad b, .stat-bad span { color: #FFC2BC; }

.screen-code {
  position: relative;
  margin: 0; padding: 16px 18px;
  max-height: 56vh; overflow: auto;
  color: var(--lcd-text);
  font: 12.5px/1.75 var(--ff-mono);
  white-space: pre; tab-size: 4;
}
.screen-code::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(0deg, transparent 0 2px, rgba(255, 255, 255, .035) 2px 3px);
}
.screen-code::-webkit-scrollbar { height: 9px; width: 9px; }
.screen-code::-webkit-scrollbar-thumb { background: var(--lcd-frame); border-radius: 8px; }
.screen-code code { background: transparent; border: 0; color: inherit; padding: 0; font: inherit; }

.tok-c { color: #6FA383; font-style: italic; }
.tok-s { color: #FFD98A; }
.tok-n { color: #8FD3FF; }
.tok-k { color: #FF9AA8; font-weight: 600; }
.tok-f { color: #7CF2B0; }

/* =================================================================== buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; cursor: pointer;
  font: 800 13px var(--ff-body);
  border: 2px solid var(--shell-ink); border-radius: 10px;
  box-shadow: 0 3px 0 var(--shell-ink);
  transition: transform .14s var(--ease), box-shadow .14s var(--ease), filter .14s var(--ease);
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 5px 0 var(--shell-ink); filter: brightness(1.04); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--shell-ink); }

.btn-primary { background: var(--leaf); color: #0A1811; }
.btn-secondary { background: var(--gold); color: #5A3E00; }
.btn-ghost {
  background: var(--surface-raised); color: var(--shell-ink);
  border-color: var(--paper-line); box-shadow: 0 3px 0 var(--paper-line);
}
.btn-ghost:hover { box-shadow: 0 5px 0 var(--paper-line); }
.btn-ghost:active { box-shadow: 0 1px 0 var(--paper-line); }

.btn-lcd {
  background: #0E1B14; color: var(--lcd-text);
  border-color: var(--dex-red-deep);
  box-shadow: 0 3px 0 var(--dex-red-deep);
  font-size: 12.5px;
}
.btn-lcd:hover { background: #14281D; box-shadow: 0 5px 0 var(--dex-red-deep); }
.btn-lcd:active { box-shadow: 0 1px 0 var(--dex-red-deep); }
.btn-quiet { opacity: .82; font-weight: 700; }

.preview-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.preview-actions .btn { flex: 1 1 auto; }

/* =============================================================== diagnostics */

.diagnostics {
  background: var(--surface-raised);
  border: 2px solid var(--paper-line); border-radius: 13px;
  box-shadow: 0 3px 0 var(--paper-line);
  overflow: hidden;
}
.diag-h {
  margin: 0; padding: 12px 15px;
  font-family: var(--ff-pixel); font-size: 9px; color: var(--heading-ink);
  background: linear-gradient(180deg, var(--surface-raised), var(--surface-sunk));
  border-bottom: 2px solid var(--paper-line);
}
.findings { display: grid; gap: 1px; background: var(--paper-line); }

.finding {
  display: flex; align-items: flex-start; gap: 11px;
  width: 100%; padding: 12px 15px; text-align: left;
  background: var(--surface-raised); border: 0; font: inherit; font-size: 13px; line-height: 1.6;
  color: var(--ink);
  animation: findingIn .25s var(--ease);
}
@keyframes findingIn { from { opacity: 0; transform: translateX(-6px); } to { opacity: 1; transform: none; } }
button.finding { cursor: pointer; transition: background .14s var(--ease); }
button.finding:hover { background: var(--surface-card); }

.finding-icon {
  flex: none; width: 21px; height: 21px; margin-top: 1px;
  display: grid; place-items: center; border-radius: 50%;
  font: 800 11px var(--ff-mono); color: #fff;
}
.finding-text { min-width: 0; }
.finding-error .finding-icon { background: var(--danger); }
.finding-warning .finding-icon { background: var(--warn); color: #4A3405; }
.finding-info .finding-icon { background: var(--sea); }
.finding-ok .finding-icon { background: var(--leaf); color: #0A1811; }
.finding-error { border-left: 5px solid var(--danger); }
.finding-warning { border-left: 5px solid var(--warn); }
.finding-info { border-left: 5px solid var(--sea); }
.finding-ok { border-left: 5px solid var(--leaf); }

/* ==================================================================== toasts */

.toasts {
  position: fixed; right: 22px; bottom: 22px; z-index: 90;
  display: grid; gap: 9px; justify-items: end;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 17px; max-width: 380px;
  background: var(--shell-ink); color: #fff;
  border: 2px solid #000; border-radius: 11px;
  box-shadow: 0 6px 20px rgba(32, 36, 43, .35);
  font-size: 13px; font-weight: 700;
  animation: toastIn .28s var(--ease);
}
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(.96); } to { opacity: 1; transform: none; } }
.toast.is-leaving { animation: toastOut .3s var(--ease) forwards; }
@keyframes toastOut { to { opacity: 0; transform: translateY(10px) scale(.97); } }
.toast-icon {
  flex: none; width: 21px; height: 21px; display: grid; place-items: center;
  border-radius: 50%; font: 800 12px var(--ff-mono);
}
.toast-ok .toast-icon { background: var(--leaf); color: #0A1811; }
.toast-error .toast-icon { background: var(--danger); color: #fff; }

/* ================================================================ drop veil */

.drop-veil {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-items: center;
  background: rgba(32, 36, 43, .72);
  opacity: 0; pointer-events: none;
  transition: opacity .2s var(--ease);
}
.drop-veil span {
  padding: 22px 30px;
  background: var(--paper);
  border: 4px dashed var(--gold); border-radius: 16px;
  font-family: var(--ff-pixel); font-size: 11px; line-height: 1.7; color: var(--heading-ink);
  text-align: center;
}
body.is-dropping .drop-veil { opacity: 1; }

.noscript {
  margin: 24px 30px; padding: 16px;
  background: var(--surface-highlight); border: 2px solid var(--gold); border-radius: 10px;
}

/* =============================================== responsive + reduced motion */

@media (max-width: 1180px) {
  .workbench { grid-template-columns: 1fr; }
  .preview {
    position: static; max-height: none;
    border-left: 0; border-top: 2px dashed var(--paper-dash);
    padding: 24px 30px 40px;
  }
  .screen-code { max-height: 60vh; }
}

@media (max-width: 980px) {
  .sidebar {
    position: static; width: auto; height: auto;
    border-right: 0; border-bottom: 4px solid var(--dex-red-deep);
  }
  .content { margin-left: 0; }
  .hero { padding: 26px 20px 22px; }
  .hero h1 { font-size: 20px; }
  .controls, .preview { padding: 20px; }
  .side-nav { flex-direction: row; flex-wrap: wrap; }
  .side-nav a { flex: 1 1 140px; }
  .toasts { right: 12px; left: 12px; bottom: 12px; justify-items: stretch; }
  .toast { max-width: none; }
}

@media (max-width: 560px) {
  .ladder-row { grid-template-columns: 26px minmax(0, 1fr); grid-auto-rows: auto; }
  .ladder-row .ladder-when { grid-column: 2; }
  .ladder-tools { grid-column: 2; justify-content: flex-end; }
  .preview-actions { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .panel.rv { opacity: 1; transform: none; }
}

/* ====================================================== V4 feature controls */

/* ---- plain list rows (zones, unique ids) */
.list-rows { display: grid; gap: 8px; }
.list-row, .stop-row {
  display: grid; align-items: center; gap: 8px;
  padding: 7px; border-radius: 10px;
  background: var(--surface-card); border: 2px solid var(--paper-line);
  animation: chipIn .18s var(--ease);
}
.list-row { grid-template-columns: 26px minmax(0, 1fr) auto; }
.stop-row { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr) auto; }
.list-row .input, .stop-row .input { padding: 7px 10px; font-size: 13px; }

/* ---- condition tree */
.cond-group {
  border: 2px solid var(--paper-line); border-radius: 11px;
  background: var(--surface-input); overflow: hidden;
}
.cond-group[data-depth="1"] { background: var(--surface-nested); }
.cond-group[data-depth="2"] { background: var(--surface-sunk); }

.cond-head {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 10px;
  background: linear-gradient(180deg, var(--surface-raised), var(--surface-sunk));
  border-bottom: 2px solid var(--paper-line);
}
.cond-label {
  font-size: 11px; font-weight: 800; letter-spacing: .12em;
  text-transform: uppercase; color: var(--muted-ink);
}
.cond-spacer { flex: 1 1 auto; }

.cond-op { display: inline-flex; border: 2px solid var(--shell-ink); border-radius: 8px; overflow: hidden; }
.cond-op-btn {
  padding: 4px 10px; cursor: pointer; border: 0;
  background: var(--surface-raised); color: var(--muted-ink);
  font: 800 10px var(--ff-mono); letter-spacing: .08em;
  transition: background .14s var(--ease), color .14s var(--ease);
}
.cond-op-btn + .cond-op-btn { border-left: 2px solid var(--shell-ink); }
.cond-op-btn.is-active { background: var(--sea); color: #fff; }

.cond-not {
  padding: 4px 9px; cursor: pointer; border-radius: 8px;
  background: var(--surface-raised); color: var(--muted-ink);
  border: 2px solid var(--paper-line);
  font: 800 10px var(--ff-mono); letter-spacing: .08em;
  transition: background .14s var(--ease), color .14s var(--ease), border-color .14s var(--ease);
}
.cond-not.is-active { background: var(--danger); color: #fff; border-color: var(--shell-ink); }

.cond-add { width: auto; min-width: 130px; padding: 5px 28px 5px 9px; font-size: 12px; }
.cond-mini { padding: 6px 11px; font-size: 12px; box-shadow: 0 2px 0 var(--paper-line); }
.cond-mini:hover { box-shadow: 0 3px 0 var(--paper-line); }

.cond-items { display: grid; gap: 6px; padding: 9px; }
.cond-empty { margin: 0; padding: 6px 2px; font-size: 12.5px; color: var(--hint-ink); }

.cond-leaf {
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  padding: 7px 9px; border-radius: 9px;
  background: var(--surface-raised); border: 2px solid var(--paper-line);
  animation: chipIn .16s var(--ease);
}
.cond-kind { font-size: 13px; font-weight: 800; color: var(--heading-ink); }
.cond-param { padding: 5px 8px; font-size: 12.5px; }
.cond-cmp { width: auto; min-width: 62px; padding-right: 24px; }
.cond-num { width: 82px; }
.cond-text { flex: 1 1 130px; min-width: 110px; }
.cond-unknown { border-color: var(--danger); color: var(--danger); }

.cond-nested { position: relative; }
.cond-nested > .cond-remove { position: absolute; top: 8px; right: 8px; z-index: 1; }

/* ---- rules */
.rules { display: grid; gap: 14px; }
.rule {
  border: 2px solid var(--paper-line); border-radius: 13px;
  background: var(--surface-raised); box-shadow: 0 3px 0 var(--paper-line); overflow: hidden;
  animation: chipIn .2s var(--ease);
}
.rule-head {
  display: flex; align-items: center; gap: 9px;
  padding: 10px 12px;
  background: linear-gradient(180deg, var(--tint-active), var(--tint-active-deep));
  border-bottom: 2px solid var(--paper-line);
}
.rule-rank {
  display: grid; place-items: center; flex: none;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--dex-red); color: #fff; font: 800 12px var(--ff-mono);
}
.rule-name { flex: 1 1 auto; padding: 7px 10px; font-size: 13.5px; font-weight: 800; }
.rule-body { padding: 12px; display: grid; gap: 12px; }
.rule-steps { display: grid; gap: 8px; }

.step {
  display: grid; gap: 7px; padding: 9px;
  border-radius: 10px; background: var(--surface-card); border: 2px solid var(--paper-line);
}
.step-head { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.step-rank {
  display: grid; place-items: center; flex: none;
  width: 22px; height: 22px; border-radius: 6px;
  background: var(--shell-ink); color: #fff; font: 800 11px var(--ff-mono);
}
.step-action { width: auto; min-width: 150px; padding: 6px 26px 6px 9px; font-size: 12.5px; }
.step-slot { width: auto; min-width: 92px; padding: 6px 26px 6px 9px; font-size: 12.5px; }
.step-input { flex: 1 1 130px; min-width: 110px; padding: 6px 9px; font-size: 12.5px; }
.step-wide { flex: 2 1 200px; }
.step-once {
  display: inline-flex; align-items: center; gap: 5px; cursor: pointer;
  font: 700 11.5px var(--ff-body); color: var(--muted-ink);
}
.step-once input { width: 15px; height: 15px; accent-color: var(--dex-red); }

.step-list { display: grid; gap: 8px; }

/* A group holds its own step list, so it needs to read as a container rather
   than as one more row in the ladder. */
.step-group { background: var(--surface-sunk); border-color: var(--paper-dash); }
.step-children {
  margin-left: 11px; padding-left: 11px;
  border-left: 3px solid var(--paper-dash);
}

.chain { display: grid; gap: 6px; }
.chain-link { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.chain-link .select { width: auto; min-width: 150px; padding: 6px 26px 6px 9px; font-size: 12.5px; }
.chain-rank {
  display: grid; place-items: center; flex: none;
  width: 20px; height: 20px; border-radius: 6px;
  background: var(--paper-dash); color: var(--ink); font: 800 10.5px var(--ff-mono);
}
.chain-value { flex: 1 1 120px; min-width: 100px; padding: 6px 9px; font-size: 12.5px; }

@media (max-width: 720px) {
  .chain-link .select, .chain-value { flex-basis: 100%; width: 100%; }

  .stop-row { grid-template-columns: minmax(0, 1fr) auto; }
  .stop-row .select { grid-column: 1; }
  .cond-text, .step-input { flex-basis: 100%; }
}

/* ================================================ preparation-move controls */
.helpers { display: grid; gap: 8px; }
.helper-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 7px 9px; border-radius: 10px;
  background: var(--surface-card); border: 2px solid var(--paper-line);
  animation: chipIn .18s var(--ease);
}
.helper-row .input { padding: 6px 9px; font-size: 12.5px; }
.helper-move { flex: 1 1 130px; min-width: 110px; font-weight: 800; }
.helper-when { width: auto; min-width: 160px; padding-right: 26px; }
.helper-arg { flex: 1 1 110px; min-width: 90px; }
.helper-wide { flex: 2 1 160px; }
.helper-slot { width: auto; min-width: 90px; padding-right: 26px; }
.helper-add { display: flex; gap: 7px; flex-wrap: wrap; align-items: center; }
.helper-preset { border-style: dashed; opacity: .9; }
.helper-preset::before { content: '+ '; opacity: .6; }

/* ======================================================== preview visibility */
.screen-hide {
  margin-left: 6px; padding: 3px 9px; cursor: pointer;
  background: transparent; color: var(--lcd-dim);
  border: 1px solid var(--lcd-frame); border-radius: 999px;
  font: 700 10.5px var(--ff-mono);
  transition: background .14s var(--ease), color .14s var(--ease);
}
.screen-hide:hover { background: rgba(120, 200, 80, .16); color: var(--lcd-text); }

.preview-toggle {
  position: fixed; right: 24px; bottom: 24px; z-index: 60;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 17px; cursor: pointer;
  background: var(--shell-ink); color: var(--lcd-text);
  border: 3px solid #000; border-radius: 999px;
  box-shadow: 0 4px 0 #000, 0 10px 22px rgba(32, 36, 43, .3);
  font: 800 12.5px var(--ff-body);
  transition: transform .16s var(--ease), box-shadow .16s var(--ease), background .16s var(--ease);
}
.preview-toggle span[aria-hidden] { font: 700 13px var(--ff-mono); color: var(--leaf); }
.preview-toggle:hover { transform: translateY(-2px); box-shadow: 0 6px 0 #000, 0 12px 26px rgba(32, 36, 43, .32); }
.preview-toggle:active { transform: translateY(2px); box-shadow: 0 2px 0 #000; }

/*
 * Collapsed: only the code screen goes away. Copy, Download and Diagnostics
 * stay put — hiding the whole column would strand the buttons the panel exists
 * to provide. The column narrows to what is left, so the form gains the room.
 */
body.preview-hidden .screen { display: none; }
body.preview-hidden .workbench { grid-template-columns: minmax(0, 1fr) minmax(260px, 28%); }
body.preview-hidden .preview-toggle { background: var(--leaf); color: #0A1811; }
body.preview-hidden .preview-toggle span[aria-hidden] { color: #0A1811; }

@media (max-width: 980px) {
  .preview-toggle { right: 12px; bottom: 12px; padding: 10px 14px; }
  .preview-toggle-text { display: none; }
  .helper-when, .helper-slot { flex: 1 1 100%; width: 100%; }
}

/* ============================================================================
   Tool dialogs
   Work that operates on the map data rather than on the script being built.
   ========================================================================== */

.tool-dialog {
  width: min(760px, calc(100vw - 32px));
  max-height: min(88vh, 900px);
  padding: 0 18px 18px;
  border: 3px solid var(--shell-ink);
  border-radius: 16px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 18px 60px rgba(32, 36, 43, .38);
  overflow: auto;
}
.tool-dialog::backdrop { background: rgba(20, 24, 31, .55); }

.tool-head {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; gap: 10px;
  margin: 0 -18px 12px; padding: 14px 18px;
  background: var(--dex-red); border-bottom: 3px solid var(--shell-ink);
}
.tool-title { flex: 1 1 auto; margin: 0; font: 700 10px var(--ff-pixel); line-height: 1.6; color: #fff; }
.tool-head .icon-btn { background: var(--paper); }

.tool-lead { margin: 0 0 14px; font-size: 13px; font-weight: 700; color: var(--muted-ink); }

.tool-section {
  display: grid; gap: 9px;
  margin-bottom: 14px; padding: 13px;
  border: 2px solid var(--paper-line); border-radius: 12px;
  background: var(--surface-card);
}
.tool-subtitle { margin: 0; font: 700 8.5px var(--ff-pixel); line-height: 1.6; color: var(--dex-red-deep); }
.tool-hint { margin: 0; font-size: 12.5px; line-height: 1.55; color: var(--muted-ink); }

.tool-textarea {
  width: 100%; resize: vertical;
  font: 400 12.5px/1.55 var(--ff-mono);
  white-space: pre; overflow-wrap: normal; overflow-x: auto;
}
.tool-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.tool-row { display: flex; flex-wrap: wrap; gap: 8px; }
.tool-row .input { flex: 1 1 160px; min-width: 130px; }

.tool-result:empty { display: none; }
.tool-ok, .tool-error { margin: 0; font-size: 12.5px; font-weight: 800; }
.tool-ok { color: var(--ok-ink); }
.tool-error { color: var(--danger); }

.tool-hops { margin: 6px 0 0; padding-left: 22px; display: grid; gap: 4px; font-size: 12.5px; }
.tool-hops code { font: 600 12px var(--ff-mono); color: var(--sea); }
.tool-notes { margin: 4px 0 0; padding-left: 22px; display: grid; gap: 4px; font-size: 12.5px; color: var(--muted-ink); }

@media (max-width: 560px) {
  .tool-row .input, .tool-row .btn { flex-basis: 100%; }
}

/* The template picker sits on the red shell, so it needs the LCD treatment
   rather than the paper one the form controls use. */
.side-select {
  width: 100%;
  background-color: rgba(0, 0, 0, .28);
  border-color: rgba(0, 0, 0, .3);
  color: #FFE9B8;
  font-weight: 700;
}
.side-select option { background: var(--paper); color: var(--ink); }
#template-about { margin: 2px 0 4px; font-size: 11.5px; }
#template-about:empty { display: none; }

/* ================================================== API browser & structure */

.tool-dialog-wide { width: min(980px, calc(100vw - 32px)); }

.api-filters { margin-bottom: 12px; }
.api-filters .input[type="search"] { flex: 2 1 240px; }

/* The "load a newer spec" footer sits under the results, out of the way of the
   search it would otherwise compete with. */
.api-spec {
  margin-top: 12px; padding-top: 10px;
  align-items: center;
  border-top: 2px dashed var(--paper-dash);
}
.api-spec .tool-hint { flex: 1 1 200px; }
.api-spec-result { display: grid; gap: 3px; margin-top: 8px; }

.api-body {
  display: grid; gap: 12px;
  grid-template-columns: minmax(180px, 260px) minmax(0, 1fr);
  align-items: start;
}
.api-list {
  display: grid; gap: 4px;
  max-height: 52vh; overflow: auto;
  padding: 6px; border: 2px solid var(--paper-line); border-radius: 12px;
  background: var(--surface-card);
}
.api-item {
  display: grid; gap: 1px; text-align: left;
  padding: 7px 9px; border: 2px solid transparent; border-radius: 8px;
  background: transparent; color: var(--ink); cursor: pointer;
  transition: background .14s var(--ease), border-color .14s var(--ease);
}
.api-item:hover { background: var(--surface-sunk); }
.api-item.is-active { background: var(--gold); border-color: var(--shell-ink); }
.api-item-name { font: 700 12.5px var(--ff-mono); }
.api-item-group { font-size: 10.5px; font-weight: 700; color: var(--muted-ink); }
.api-item.is-active .api-item-group { color: #5A3E00; }

.api-detail {
  min-width: 0;
  padding: 14px; border: 2px solid var(--paper-line); border-radius: 12px;
  background: var(--surface-card);
}
.api-detail:empty { display: none; }
.api-name { margin: 0 0 3px; font: 700 12px var(--ff-mono); color: var(--dex-red-deep); }
.api-kind { margin: 0 0 10px; font-size: 11.5px; font-weight: 700; color: var(--muted-ink); }
.api-signature {
  margin: 0 0 10px; padding: 9px 11px; overflow-x: auto;
  border: 2px solid var(--paper-dash); border-radius: 9px; background: var(--surface-sunk);
}
.api-signature code { background: none; border: 0; padding: 0; font-size: 12.5px; }
.api-summary { margin: 0 0 10px; font-size: 13px; line-height: 1.6; }
.api-subhead { margin: 0 0 5px; font: 700 8px var(--ff-pixel); color: var(--dex-red-deep); }
.api-params ul { margin: 0 0 10px; padding-left: 20px; display: grid; gap: 5px; font-size: 12.5px; line-height: 1.55; }
.api-type { margin-left: 6px; font: 600 11px var(--ff-mono); color: var(--sea); }
.api-optional { margin-left: 6px; font-size: 10.5px; font-weight: 800; color: var(--muted-ink); }
.api-returns { margin: 0 0 12px; font-size: 12.5px; font-weight: 700; color: var(--muted-ink); }

@media (max-width: 720px) {
  .api-body { grid-template-columns: minmax(0, 1fr); }
  .api-list { max-height: 30vh; }
}

/* The structure view: nesting is the whole message, so children are indented
   from a rail rather than drawn as separate boxes. */
.flow { display: grid; gap: 8px; }
.flow-node { display: grid; gap: 6px; }
.flow-label {
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
  padding: 8px 11px; border-radius: 9px;
  border: 2px solid var(--paper-line); background: var(--surface-card);
}
.flow-title { font-size: 13px; font-weight: 800; }
.flow-detail { font-size: 11.5px; font-weight: 700; color: var(--muted-ink); }
.flow-children {
  display: grid; gap: 6px;
  margin-left: 12px; padding-left: 12px;
  border-left: 3px solid var(--paper-dash);
}
.flow-callback > .flow-label {
  background: var(--shell-ink); border-color: #000; color: var(--lcd-text);
}
.flow-callback > .flow-label .flow-title { font-family: var(--ff-mono); font-size: 12.5px; }
.flow-callback > .flow-label .flow-detail { color: var(--lcd-dim); }
.flow-check > .flow-label { background: var(--surface-highlight); border-color: var(--gold); }
.flow-note > .flow-label {
  padding: 3px 9px; border-style: dashed; background: transparent;
}
.flow-note > .flow-label .flow-title { font-size: 11.5px; color: var(--muted-ink); }

/* ============================================================================
   Dark palette
   Only the tokens change: every rule above already reads its colours from them.
   The Pokédex shell keeps its red, because that is the identity of the page —
   what turns down is the paper it holds.
   ========================================================================== */


/* System preference, unless the reader has explicitly chosen light. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #12151B;
    --paper-line: #2A303C;
    --paper-dash: #363D4B;
    --ink: #E7E3D6;
    --muted-ink: #9C9682;

    --surface-raised: #1B202A;
    --surface-input: #171C25;
    --surface-card: #1A1F29;
    --surface-nested: #171C25;
    --surface-sunk: #141922;
    --surface-highlight: #2B2413;
    --surface-code: #222834;

    --prose-ink: #CFCABA;
    --note-ink: #E2C77A;
    --hint-ink: #979181;
    --placeholder-ink: #8A8471;
    --code-ink: #E2DECF;
    --ok-ink: #6FD79B;
    --heading-ink: var(--ink);
    --line-hover: #475061;

    --tint-active: #3A1D14;
    --tint-active-deep: #4A2418;
    --tint-active-ink: #FFB49B;
  }
}

/* An explicit choice wins in both directions. */
:root[data-theme="dark"] {
  --paper: #12151B;
  --paper-line: #2A303C;
  --paper-dash: #363D4B;
  --ink: #E7E3D6;
  --muted-ink: #9C9682;

  --surface-raised: #1B202A;
  --surface-input: #171C25;
  --surface-card: #1A1F29;
  --surface-nested: #171C25;
  --surface-sunk: #141922;
  --surface-highlight: #2B2413;
  --surface-code: #222834;

  --prose-ink: #CFCABA;
  --note-ink: #E2C77A;
  --hint-ink: #979181;
  --placeholder-ink: #8A8471;
  --code-ink: #E2DECF;
  --ok-ink: #6FD79B;
  --heading-ink: var(--ink);
  --line-hover: #475061;

  --tint-active: #3A1D14;
  --tint-active-deep: #4A2418;
  --tint-active-ink: #FFB49B;
}

/* Everything above reads its colours from the tokens, so nothing else needs a
   dark rule of its own — the hero's gradient included. */

.theme-icon { margin-right: 7px; font-size: 13px; }

/* Drag-to-reorder. The rank doubles as the handle, so a row gains a gesture
   without gaining a control. */
[data-drag-handle] { cursor: grab; }
[data-drag-handle]:active { cursor: grabbing; }
.ladder-row.is-dragging { opacity: .45; }
.ladder-row.is-drop-target { outline: 3px dashed var(--dex-red); outline-offset: 2px; }

/* ================================================================= Handbook */

.handbook-toc {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-bottom: 14px; padding: 11px;
  border: 2px solid var(--paper-line); border-radius: 12px;
  background: var(--surface-sunk);
}
.handbook-toc a {
  padding: 5px 10px; border-radius: 999px;
  background: var(--surface-raised); border: 2px solid var(--paper-line);
  color: var(--ink); text-decoration: none;
  font-size: 12px; font-weight: 700;
}
.handbook-toc a:hover { background: var(--gold); border-color: var(--shell-ink); color: var(--shell-ink); }

.handbook-text { margin: 0; font-size: 13.5px; line-height: 1.7; color: var(--prose-ink); }
.handbook-lua {
  margin: 2px 0 0; padding: 11px 13px; overflow-x: auto;
  border: 2px solid var(--lcd-frame); border-radius: 10px;
  background: var(--lcd);
}
.handbook-lua code {
  background: none; border: 0; padding: 0;
  font: 400 12.5px/1.65 var(--ff-mono); color: var(--lcd-text);
  white-space: pre;
}

/* The generated "choice → Lua" reference. Two columns where there is room, so
   the label and the code it produces sit side by side; stacked when there is
   not, because the code is the half that must stay readable. */
.emit-group { margin-top: 14px; }
.emit-group-title {
  margin: 0 0 6px;
  font-size: 11px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase;
  color: var(--muted-ink);
}
.emit-table {
  display: grid; gap: 4px 14px; margin: 0;
  grid-template-columns: minmax(140px, 240px) minmax(0, 1fr);
  align-items: baseline;
}
.emit-label { margin: 0; font-size: 13px; font-weight: 700; color: var(--prose-ink); }
.emit-lua { margin: 0; min-width: 0; overflow-x: auto; }
.emit-lua code {
  font: 400 12px/1.6 var(--ff-mono);
  color: var(--syn-n);
  white-space: pre;
}

@media (max-width: 640px) {
  .emit-table { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .emit-lua { margin-bottom: 8px; }
}

/* ===================================================================== quick */

.quick-body { display: grid; gap: 2px; margin: 12px 0; }
.quick-actions { margin-top: 4px; }
.quick-actions .btn { flex: 1 1 160px; }

/* ============================================== translated-heading proportions
   The face swap itself lives in assets/i18n/i18n.css, which retargets
   --ff-pixel for every element at once. What is left here is proportion: the
   pixel face is tuned at 7–11px, sizes at which the body face reads far too
   small, so each slot restates the size it wants once a translation is active.
   Missing one of these costs a little visual weight, never a broken glyph. */
html:not([data-doc-lang="en"]) .side-h { font-weight: 800; font-size: 12.5px; }
html:not([data-doc-lang="en"]) .panel-title { font-weight: 800; font-size: 17px; }
html:not([data-doc-lang="en"]) .mode-name { font-weight: 800; font-size: 15px; }
html:not([data-doc-lang="en"]) .screen-name { font-weight: 800; font-size: 11px; letter-spacing: .02em; }
html:not([data-doc-lang="en"]) .diag-h { font-weight: 800; font-size: 14px; }
html:not([data-doc-lang="en"]) .tool-title { font-weight: 800; font-size: 15px; }
html:not([data-doc-lang="en"]) .tool-subtitle { font-weight: 800; font-size: 13px; }
html:not([data-doc-lang="en"]) .api-subhead { font-weight: 800; font-size: 12.5px; }
html:not([data-doc-lang="en"]) .drop-veil span { font-weight: 800; font-size: 17px; }
