/* paper-printer — production styles.
 *
 * Self-contained on purpose: the Modernist design-system tokens this app uses
 * are inlined below rather than imported, so the deployed page makes ZERO
 * network requests beyond its own origin (fonts included). Look: 2px black
 * rules, Archivo, accent #ec3013, square corners, uppercase micro-labels.
 */

/* ------------------------------------------------------------------- fonts */
/* Archivo variable (latin subset, wght 100–900), self-hosted. */
@font-face {
  font-family: "Archivo";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("fonts/archivo-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ------------------------------------------------------------------ tokens */
:root {
  --bg: #f3f2f2;
  --surface: #eae9e9;
  --text: #201e1d;
  --accent: #ec3013;
  --divider: rgba(32, 30, 29, 0.4);

  --n100: #f8f4f4;
  --n200: #eae7e7;
  --n300: #d7d3d3;
  --n400: #bab6b6;
  --n500: #9b9797;
  --n600: #7d7979;
  --n700: #605d5d;
  --n800: #444141;
  --n900: #2d2b2b;

  --a100: #fff2ef;
  --a200: #ffe0d9;
  --a600: #dd2b0f;
  --a700: #ae1800;
  --a800: #7c1405;
  --a900: #4d170e;

  --font: "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;

  --shadow-sm: 0 1px 2px rgba(45, 43, 43, 0.14);
  --shadow-md: 0 3px 10px rgba(45, 43, 43, 0.16);
  --shadow-lg: 0 12px 32px rgba(45, 43, 43, 0.22);

  --rail: 338px;
}

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

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

:focus {
  outline: none;
}

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

::selection {
  background: rgba(236, 48, 19, 0.3);
}

input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  margin: 0;
  flex: none;
}

/* --------------------------------------------------------------- primitives */
.micro {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--n700);
}

.micro-accent {
  color: var(--a700);
}

.note {
  font-size: 12px;
  color: var(--n700);
  line-height: 1.35;
}

.mono {
  font-family: var(--mono);
}

.num {
  font-variant-numeric: tabular-nums;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  text-decoration: none;
  font-family: var(--font);
  font-weight: 800;
  font-size: 14px;
  line-height: 1.2;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 0;
  padding: 12px 18px;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
}

.btn-primary:not(:disabled):hover {
  background: var(--a600);
}

.btn-primary:not(:disabled):active {
  background: var(--a700);
}

.btn-secondary {
  border-color: var(--divider);
}

.btn-secondary:not(:disabled):hover {
  background: rgba(32, 30, 29, 0.07);
}

.btn-ghost {
  color: var(--a700);
}

.btn-ghost:not(:disabled):hover {
  background: rgba(236, 48, 19, 0.1);
}

.btn-sm {
  padding: 6px 11px;
  font-size: 12px;
}

.input {
  width: 100%;
  min-height: 36px;
  padding: 8px 12px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  caret-color: var(--accent);
  background: #fff;
  border: 1px solid var(--text);
  border-radius: 0;
}

.input:focus-visible {
  border-color: var(--accent);
  outline-offset: 0;
}

.input-strong {
  border-width: 2px;
}

.tag {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  letter-spacing: 0.02em;
  padding: 3px 8px;
  white-space: nowrap;
  flex: none;
}

.tag-accent {
  background: var(--a100);
  color: var(--a800);
}

.tag-neutral {
  background: var(--n100);
  color: var(--n800);
}

.tag-outline {
  border: 1px solid var(--accent);
  color: var(--accent);
}

.seg {
  display: inline-flex;
  border: 1px solid var(--divider);
}

.seg-opt {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  padding: 7px 12px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: transparent;
  border: 0;
  cursor: pointer;
}

.seg-opt + .seg-opt {
  border-left: 1px solid var(--divider);
}

.seg-opt[aria-pressed="true"] {
  background: var(--text);
  color: var(--bg);
}

.seg-opt:not([aria-pressed="true"]):hover {
  background: rgba(32, 30, 29, 0.07);
}

/* ---------------------------------------------------------------- app shell */
.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.brand {
  font-size: 22px;
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1;
}

.brand-sub {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--n700);
}

.head {
  display: flex;
  align-items: stretch;
  border-bottom: 2px solid var(--text);
  background: var(--bg);
  flex: none;
}

.head-brand {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: 14px 24px;
  border-right: 2px solid var(--text);
  width: var(--rail);
  flex: none;
}

.head-code {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  flex: 1;
  min-width: 0;
}

.head-code .micro {
  width: 104px;
  flex: none;
  line-height: 1.3;
}

.code-field {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  width: 340px;
  flex: none;
  padding: 10px 14px;
}

.head-meta {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
  flex: none;
}

.banner {
  background: var(--accent);
  color: #fff;
  padding: 10px 24px;
  font-size: 13px;
  font-weight: 700;
  flex: none;
}

.cols {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* -------------------------------------------------------------------- rail */
.rail {
  width: var(--rail);
  flex: none;
  border-right: 2px solid var(--text);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.rail-block {
  padding: 14px 24px;
  border-bottom: 2px solid var(--text);
  flex: none;
}

.rail-rows {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.rail-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.rail-row > .micro {
  width: 60px;
  flex: none;
}

.check {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.tier-seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 100%;
}

.select {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--text);
  border-radius: 0;
  min-height: 32px;
}

/* topics tree */
.topics {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-bottom: 2px solid var(--text);
}

.topics-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px 8px;
  flex: none;
}

.topics-list {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.strand-row,
.sub-row {
  display: flex;
  align-items: center;
  gap: 10px;
  border-top: 1px solid var(--divider);
  cursor: pointer;
}

.strand-row {
  padding: 10px 24px;
}

.sub-row {
  padding: 7px 24px 7px 58px;
  background: var(--a100);
}

.strand-row[data-open="1"] {
  background: var(--a100);
}

.strand-row[data-open="1"] .strand-name {
  font-weight: 700;
}

.twisty {
  font-size: 12px;
  color: var(--n600);
  width: 10px;
  flex: none;
  text-align: center;
}

.strand-name {
  font-size: 14px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
}

.sub-code {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  width: 52px;
  flex: none;
}

.sub-title {
  font-size: 13px;
  flex: 1;
  min-width: 0;
  color: var(--n800);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sub-count {
  font-size: 11px;
  font-weight: 700;
  color: var(--n700);
  flex: none;
}

.sub-row[data-empty="1"],
.strand-row[data-empty="1"] {
  opacity: 0.4;
  cursor: not-allowed;
}

/* year excludes */
.chipbox {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--text);
  background: #fff;
  padding: 4px 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  min-height: 32px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  padding: 2px 6px;
  background: var(--n100);
  color: var(--n800);
  border: 0;
  font-family: var(--font);
  cursor: pointer;
}

.chip:hover {
  background: var(--a100);
  color: var(--a800);
}

.chip-add {
  border: 0;
  background: transparent;
  font-family: var(--font);
  font-size: 12px;
  color: var(--n600);
  padding: 2px;
  cursor: pointer;
  min-height: 0;
  width: auto;
}

.readout {
  padding: 12px 24px;
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex: none;
}

.readout-n {
  font-size: 32px;
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.readout-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--n700);
  line-height: 1.3;
}

/* -------------------------------------------------------------------- main */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.actions {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  border-bottom: 2px solid var(--text);
  flex: none;
}

.results-head {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 24px;
  border-bottom: 2px solid var(--text);
  flex: none;
}

.results-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
  flex: none;
}

.pager {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
}

.pager-pos {
  font-size: 13px;
  font-weight: 800;
  padding: 0 8px;
  white-space: nowrap;
}

.qnav {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  flex: none;
}

.qnav-cell {
  width: 22px;
  height: 22px;
  border: 1px solid var(--text);
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.qnav-cell[aria-current="true"] {
  background: var(--text);
  color: var(--bg);
}

.qnav-cell[data-dropped="1"] {
  background: var(--n300);
  color: var(--n600);
}

.results-hint {
  font-size: 12px;
  font-weight: 600;
  color: var(--n700);
  margin-left: auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.results {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

/* ------------------------------------------------------------ question card */
.qcard {
  display: flex;
  flex-direction: column;
  border-bottom: 2px solid var(--text);
  scroll-margin-top: 4px;
}

.qcard[data-dropped="1"] {
  background: var(--n200);
}

.qcard[data-focus="1"] {
  background: var(--a100);
}

.qcard-head {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--divider);
}

.qcard-ident {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
  flex-wrap: wrap;
}

.qcard-ref {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 700;
}

.qcard-pages {
  font-size: 12px;
  font-weight: 600;
  color: var(--n700);
  white-space: nowrap;
}

.qcard-marks {
  display: flex;
  align-items: baseline;
  gap: 5px;
}

.qcard-marks b {
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
}

.qcard-marks span {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--n700);
}

.qcard-body {
  display: flex;
  gap: 10px;
  padding: 10px 24px 12px 56px;
  overflow-x: auto;
}

.thumbs {
  display: flex;
  gap: 10px;
  flex: none;
}

.thumb {
  width: 130px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.thumb-page {
  height: 184px;
  border: 1px solid var(--n400);
  background: #fff;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.thumb-badge {
  position: absolute;
  left: 0;
  background: var(--accent);
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  padding: 2px 5px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.thumb-badge[data-cont="1"] {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--text);
}

.qcard[data-dropped="1"] .thumb-badge {
  background: var(--n600);
  border-color: var(--n600);
  color: #fff;
}

.thumb-source {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 10px;
  border-top: 1px solid var(--n300);
  padding-top: 4px;
  font-size: 7px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--n600);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thumb-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 600;
  color: var(--n700);
}

.thumb-note {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.qcard-side {
  flex: 1;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 2px;
}

.qcard-stem {
  font-size: 13px;
  line-height: 1.45;
  color: var(--n800);
  max-width: 340px;
}

.qcard-span {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--n700);
}

.qcard-tools {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: auto;
}

/* ------------------------------------------------------------------- panels */
.panel {
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-title {
  font-size: 26px;
  font-weight: 900;
  letter-spacing: -0.02em;
  max-width: 480px;
  line-height: 1.1;
}

.panel-detail {
  font-size: 14px;
  color: var(--n700);
  max-width: 520px;
  line-height: 1.45;
}

.panel-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.progress {
  width: 160px;
  height: 6px;
  background: var(--n300);
  position: relative;
  flex: none;
}

.progress > i {
  position: absolute;
  inset: 0 100% 0 0;
  background: var(--accent);
  display: block;
}

.loader-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
}

.loader-row {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 12px;
}

.loader-row [data-pp-field="key"] {
  font-family: var(--mono);
}

.fail {
  background: var(--accent);
  color: #fff;
  padding: 16px 20px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.fail-bang {
  font-size: 24px;
  font-weight: 900;
  line-height: 1;
}

.fail h3 {
  font-size: 15px;
  font-weight: 800;
  margin: 0 0 4px;
}

.fail p {
  font-size: 13px;
  line-height: 1.4;
  margin: 0;
  opacity: 0.92;
}

/* --------------------------------------------------------------------- tray */
.tray {
  border-top: 2px solid var(--text);
  background: var(--a100);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 24px;
  flex: none;
}

.tray-list {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  flex: 1;
  min-width: 0;
}

.tray-chip {
  border: 1px solid var(--accent);
  color: var(--accent);
  background: transparent;
  font-family: var(--font);
  font-size: 11px;
  padding: 3px 8px;
  white-space: nowrap;
  cursor: pointer;
  flex: none;
}

.selbar {
  border-top: 2px solid var(--text);
  background: var(--text);
  color: var(--bg);
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 16px 24px;
  flex: none;
  flex-wrap: wrap;
}

.selbar-stats {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
}

.selbar-stats i {
  opacity: 0.5;
  font-style: normal;
}

.selbar-stats em {
  opacity: 0.7;
  font-style: normal;
}

.codechip {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--n500);
  padding: 6px 10px;
  min-width: 0;
}

.codechip[data-stale="1"] {
  opacity: 0.45;
  border-style: dashed;
}

.codechip-value {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.codechip button {
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  opacity: 0.7;
  text-decoration: underline;
  background: none;
  border: 0;
  color: inherit;
  cursor: pointer;
  padding: 0;
}

.selbar-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.btn-onDark {
  background: transparent;
  color: var(--bg);
  border: 2px solid var(--n500);
  padding: 11px 16px;
}

.btn-onDark:not(:disabled):hover {
  border-color: var(--bg);
}

/* ------------------------------------------------------------------- toasts */
.toasts {
  position: fixed;
  right: 24px;
  bottom: 96px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  z-index: 40;
  pointer-events: none;
}

.toast {
  background: var(--text);
  color: var(--bg);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
}

.toast[data-kind="alert"] {
  background: var(--accent);
  color: #fff;
}

.toast-dot {
  width: 8px;
  height: 8px;
  background: var(--accent);
  flex: none;
}

.toast[data-kind="alert"] .toast-dot,
.toast[data-kind="done"] .toast-dot {
  background: #fff;
}

.toast-text {
  font-size: 13px;
  font-weight: 600;
}

.toast button {
  font-family: var(--font);
  font-size: 12px;
  text-decoration: underline;
  background: none;
  border: 0;
  color: inherit;
  cursor: pointer;
  padding: 0;
}

/* ------------------------------------------------------------------ library */
.lib-head {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 2px solid var(--text);
  flex: none;
  flex-wrap: wrap;
}

.lib-title {
  font-size: 20px;
  font-weight: 900;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.lib-cols {
  display: flex;
  flex: 1;
  min-height: 0;
}

.lib-list {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.lib-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 84px 84px 150px 210px;
  gap: 16px;
  padding: 12px 24px;
  align-items: center;
}

.lib-grid.is-head {
  border-bottom: 2px solid var(--text);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--n700);
  flex: none;
}

.lib-rows {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.lib-row {
  border-bottom: 1px solid var(--divider);
}

.lib-row[data-kind="collection"] {
  background: transparent;
}

.lib-row-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.lib-row-title > b {
  font-size: 15px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kindtag {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 2px 5px;
  flex: none;
  border: 1px solid var(--n500);
  color: var(--n700);
}

.lib-row[data-kind="collection"] .kindtag {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.lib-topics {
  font-size: 12px;
  color: var(--n700);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lib-saved {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.lib-saved > span {
  font-size: 12px;
  color: var(--n700);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.lib-save {
  width: 392px;
  flex: none;
  border-left: 2px solid var(--text);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.lib-save-head {
  padding: 14px 20px;
  border-bottom: 2px solid var(--text);
  flex: none;
}

.lib-save-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

.statrow {
  display: flex;
  border-top: 2px solid var(--text);
  border-bottom: 2px solid var(--text);
}

.statrow > div {
  flex: 1;
  padding: 10px 0;
}

.statrow b {
  display: block;
  font-size: 20px;
  font-weight: 900;
  line-height: 1.2;
}

.statrow span {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--n700);
}

.notice {
  background: var(--a100);
  padding: 12px 14px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--a900);
}

.codebox {
  border: 2px solid var(--text);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.codebox-value {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.06em;
  word-break: break-all;
}

.lib-foot {
  margin-top: auto;
  border-top: 1px solid var(--divider);
  padding: 14px 20px;
  font-size: 12px;
  color: var(--n700);
  line-height: 1.45;
  flex: none;
}

/* --------------------------------------------------------------------- gate */
.gate {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.gate-head {
  padding: 20px 32px;
  border-bottom: 2px solid var(--text);
  flex: none;
}

.gate-mid {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.gate-card {
  width: min(480px, 100%);
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.gate-lede {
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-top: 2px solid var(--text);
  padding-top: 20px;
}

.gate-h {
  font-size: 44px;
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1;
}

.gate-row {
  display: flex;
  gap: 8px;
}

.gate-key {
  flex: 1;
  border-width: 2px;
  padding: 13px 14px;
  font-size: 15px;
  font-family: var(--mono);
}

.gate-foot {
  display: flex;
  flex-direction: column;
  gap: 5px;
  border-top: 1px solid var(--divider);
  padding-top: 14px;
}

.gate-msg {
  font-size: 13px;
  line-height: 1.45;
  color: var(--n700);
  min-height: 19px;
}

.gate[data-state="error"] .gate-key {
  border-color: var(--accent);
}

.gate[data-state="error"] .gate-msg {
  color: var(--a700);
  font-weight: 600;
}

.gate[data-state="checking"] .gate-key,
.gate[data-state="unlocked"] .gate-key {
  background: var(--n100);
  border-color: var(--n500);
  opacity: 0.6;
}

.gate[data-state="unlocked"] .gate-msg {
  color: var(--a700);
  font-weight: 600;
}

/* ------------------------------------------------------------------ preview */
.preview {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.preview-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 2px solid var(--text);
  flex: none;
  flex-wrap: wrap;
}

.preview-code {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--n700);
}

.preview-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.preview-stage {
  flex: 1;
  min-height: 0;
  background: var(--n300);
}

.preview-stage iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

.preview-busy {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-size: 14px;
  font-weight: 700;
  color: var(--n700);
}

/* --------------------------------------------------------------- responsive */
@media (max-width: 1180px) {
  :root {
    --rail: 300px;
  }
  .head-code .note,
  .actions .note {
    display: none;
  }
}

@media (max-width: 900px) {
  .app {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }
  .cols {
    flex-direction: column;
  }
  .rail {
    width: 100%;
    border-right: 0;
    border-bottom: 2px solid var(--text);
  }
  .head {
    flex-wrap: wrap;
  }
  .head-brand {
    width: 100%;
    border-right: 0;
  }
  .code-field {
    width: 100%;
  }
  .lib-cols {
    flex-direction: column;
  }
  .lib-save {
    width: 100%;
    border-left: 0;
    border-top: 2px solid var(--text);
  }
  .lib-grid {
    grid-template-columns: minmax(0, 1fr) 64px 64px;
  }
  .lib-grid > :nth-child(4),
  .lib-grid > :nth-child(5) {
    grid-column: 1 / -1;
  }
}
