/* Pictura — brand theme + product styling, layered on htmx-ds tokens. */

/* ---------- theme tokens: Paper (light) and Ink (dark) ---------- */
:root,
[data-theme="light"],
[data-theme="pictura-light"] {
  color-scheme: light;
  --background: #fff9ef;
  --foreground: #221b3a;
  --card: #fffdf7;
  --card-foreground: #221b3a;
  --popover: #fffdf7;
  --popover-foreground: #221b3a;
  --primary: #5b2fc9;
  --primary-foreground: #ffffff;
  --secondary: #ffe79a;
  --secondary-foreground: #3a2a00;
  --muted: #f3ebdc;
  --muted-foreground: #625a78;
  --accent: #ede4ff;
  --accent-foreground: #2c1770;
  --destructive: #c8203c;
  --destructive-foreground: #ffffff;
  --success: #1c7c4a;
  --success-foreground: #ffffff;
  --border: #e3d8c3;
  --input: #d6c9b1;
  --ring: #5b2fc9;
  --overlay: rgb(34 27 58 / 0.55);

  --ink: #221b3a;
  --paper: #fff9ef;
  --pop: #ffd23f;
  --pop-2: #ff7a3d;
  --pop-3: #5cc8ff;
  --pop-4: #ff5c8a;
  --halftone: rgb(34 27 58 / 0.12);

  --font-sans: "Nunito", ui-rounded, "Segoe UI", system-ui, sans-serif;
  --font-display: "Baloo 2", "Nunito", ui-rounded, system-ui, sans-serif;
  --radius: 0.75rem;
  --radius-sm: 0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --radius-xl: 1.5rem;
}

.dark,
[data-theme="dark"],
[data-theme="pictura-dark"] {
  color-scheme: dark;
  --background: #17132b;
  --foreground: #f6efe2;
  --card: #221b3a;
  --card-foreground: #f6efe2;
  --popover: #2a2247;
  --popover-foreground: #f6efe2;
  --primary: #c3a8ff;
  --primary-foreground: #1c1040;
  --secondary: #4a3a12;
  --secondary-foreground: #ffe79a;
  --muted: #2b2447;
  --muted-foreground: #b3a9cc;
  --accent: #352a5e;
  --accent-foreground: #ece3ff;
  --destructive: #ff6b81;
  --destructive-foreground: #2a0a12;
  --success: #5bd48f;
  --success-foreground: #05301a;
  --border: #3b3160;
  --input: #4a3f74;
  --ring: #c3a8ff;
  --overlay: rgb(5 3 15 / 0.7);

  --ink: #f6efe2;
  --paper: #17132b;
  --halftone: rgb(246 239 226 / 0.1);
}

/* ---------- base ---------- */
body {
  font-family: var(--font-sans);
  background:
    radial-gradient(circle at 1px 1px, var(--halftone) 1px, transparent 1.5px) 0 0 / 22px 22px,
    var(--background);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .display {
  font-family: var(--font-display);
  letter-spacing: -0.01em;
  line-height: 1.1;
}

.site { min-height: 100dvh; display: flex; flex-direction: column; }
.site__main { flex: 1; }

.wrap { width: min(1120px, 100% - 2.5rem); margin-inline: auto; }
.wrap--narrow { width: min(720px, 100% - 2.5rem); margin-inline: auto; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in oklab, var(--background) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 2px solid var(--ink);
}
.topbar__inner { display: flex; align-items: center; gap: 0.75rem; height: 3.75rem; }
.brand { display: inline-flex; align-items: center; gap: 0.6rem; text-decoration: none; color: var(--foreground); font-family: var(--font-display); font-weight: 800; font-size: 1.35rem; }
.brand__mark { width: 2rem; height: 2rem; flex: none; }
.brand span { white-space: nowrap; }
.brand:hover .brand__mark { transform: rotate(-6deg); }
.brand__mark { transition: transform 150ms ease; }
.topbar__nav { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; }
.topbar__user { display: inline-flex; align-items: center; gap: 0.5rem; }
.mode-pill {
  font-size: var(--text-xs); font-weight: 700; padding: 0.2rem 0.55rem; border-radius: 999px;
  background: var(--secondary); color: var(--secondary-foreground); border: 1.5px solid var(--ink);
  white-space: nowrap;
}
@media (max-width: 640px) {
  .topbar__hide-sm { display: none; }
  .topbar__inner { gap: 0.4rem; }
  .topbar__nav { gap: 0.25rem; }
  .brand { font-size: 1.2rem; }
  .toolbar .note { flex-basis: 100%; }
}
.site { overflow-x: clip; }

/* ---------- comic panel primitive: the one bold element ---------- */
.panel {
  background: var(--card);
  color: var(--card-foreground);
  border: 3px solid var(--ink);
  border-radius: 0.35rem;
  box-shadow: 6px 6px 0 var(--ink);
}
.panel--pop { background: var(--pop); color: #221b3a; }
.panel--pop2 { background: var(--pop-2); color: #221b3a; }
.panel--pop3 { background: var(--pop-3); color: #221b3a; }
.panel--pop4 { background: var(--pop-4); color: #221b3a; }
.panel--soft { box-shadow: 3px 3px 0 var(--ink); }

.bubble {
  position: relative; display: inline-block;
  background: #fff; color: #221b3a;
  border: 3px solid #221b3a; border-radius: 1.25rem;
  padding: 0.6rem 1rem; font-family: var(--font-display); font-weight: 700;
}
.bubble::after {
  content: ""; position: absolute; left: 1.5rem; bottom: -0.9rem;
  width: 0; height: 0;
  border-left: 0.7rem solid transparent; border-right: 0.2rem solid transparent;
  border-top: 0.9rem solid #221b3a;
}
.bubble::before {
  content: ""; position: absolute; left: 1.62rem; bottom: -0.5rem; z-index: 1;
  width: 0; height: 0;
  border-left: 0.5rem solid transparent; border-right: 0.12rem solid transparent;
  border-top: 0.65rem solid #fff;
}

/* ---------- home ---------- */
.hero { padding: clamp(2.5rem, 7vw, 5.5rem) 0 3rem; }
.hero__grid { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 3rem; align-items: center; }
.hero h1 { font-size: clamp(2.6rem, 6.5vw, 4.6rem); font-weight: 800; margin: 0 0 1rem; }
.hero__lede { font-size: 1.2rem; line-height: 1.55; max-width: 34rem; color: var(--muted-foreground); margin: 0 0 1.75rem; }
.hero__cta { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }
.hero__note { font-size: var(--text-sm); color: var(--muted-foreground); margin-top: 0.75rem; }

.strip { position: relative; height: 23rem; }
.strip__panel {
  position: absolute; padding: 1rem; width: 15rem; min-height: 11rem;
  display: flex; flex-direction: column; justify-content: space-between;
  font-family: var(--font-display); font-weight: 700;
  animation: stamp 500ms cubic-bezier(.2,.9,.3,1.3) both;
}
.strip__panel:nth-child(1) { left: 0; top: 0; transform: rotate(-4deg); animation-delay: 80ms; }
.strip__panel:nth-child(2) { left: 13rem; top: 3.5rem; transform: rotate(2deg); animation-delay: 260ms; z-index: 1; }
.strip__panel:nth-child(3) { left: 3rem; top: 12.5rem; width: 12rem; min-height: 9rem; transform: rotate(-1deg); animation-delay: 440ms; z-index: 2; }
.strip__panel:nth-child(2) .bubble { align-self: flex-end; margin-top: 0.5rem; }
.strip__label { font-size: var(--text-xs); letter-spacing: 0.04em; opacity: 0.8; }
.strip__script { font-family: var(--font-mono); font-size: 0.8rem; white-space: pre-line; line-height: 1.35; }
.strip__cast { display: flex; gap: 0.5rem; }
.strip__face { width: 2.6rem; height: 2.6rem; border-radius: 50%; border: 3px solid #221b3a; background: #fff; display: grid; place-items: center; font-size: 1.3rem; }
.strip__grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.35rem; flex: 1; margin-top: 0.5rem; }
.strip__cell { border: 2.5px solid #221b3a; background: #fff; border-radius: 3px; min-height: 2.2rem; }
.strip__cell:nth-child(3) { grid-column: span 2; }
@keyframes stamp {
  from { opacity: 0; scale: 0.6; }
  to { opacity: 1; scale: 1; }
}

.section { padding: 3rem 0; }
.section__title { font-size: clamp(1.8rem, 3.5vw, 2.4rem); font-weight: 800; margin: 0 0 0.5rem; }
.section__lede { color: var(--muted-foreground); margin: 0 0 2rem; max-width: 40rem; }

.steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.5rem 1.75rem; counter-reset: step; }
.step { padding: 1.25rem; counter-increment: step; position: relative; }
.step::before {
  content: counter(step);
  position: absolute; top: -1rem; left: -1rem;
  width: 2.4rem; height: 2.4rem; display: grid; place-items: center;
  background: var(--pop); color: #221b3a; border: 3px solid #221b3a; border-radius: 50%;
  font-family: var(--font-display); font-weight: 800; font-size: 1.1rem;
}
.step h3 { margin: 0.25rem 0 0.4rem; font-size: 1.25rem; }
.step p { margin: 0; color: var(--muted-foreground); line-height: 1.5; font-size: var(--text-sm); }
.step__glyph { font-size: 1.9rem; line-height: 1; margin-bottom: 0.5rem; }

.styles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.style-tile {
  display: flex; gap: 0.85rem; align-items: flex-start; padding: 1rem; cursor: pointer;
  background: var(--card); border: 2.5px solid var(--border); border-radius: var(--radius-lg);
  transition: border-color 120ms, transform 120ms, box-shadow 120ms;
}
.style-tile:hover { border-color: var(--ink); }
.style-tile:has(input:checked) { border-color: var(--ink); box-shadow: 4px 4px 0 var(--ink); transform: translate(-1px, -1px); background: var(--accent); }
.style-tile:has(input:focus-visible) { outline: 2px solid var(--ring); outline-offset: 2px; }
.style-tile input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.style-tile__emoji { font-size: 1.7rem; line-height: 1; }
.style-tile__name { font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; }
.style-tile__blurb { font-size: var(--text-sm); color: var(--muted-foreground); }

.cta-band { padding: 2.5rem; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1.5rem; }
.cta-band h2 { margin: 0; font-size: 2rem; }

.footer { padding: 2rem 0; font-size: var(--text-sm); color: var(--muted-foreground); display: flex; flex-wrap: wrap; gap: 1rem; justify-content: space-between; }

@media (max-width: 860px) {
  .hero__grid { grid-template-columns: 1fr; }
  .strip { height: 20rem; width: 100%; max-width: 24rem; margin-inline: auto; }
  .steps { grid-template-columns: 1fr 1fr; }
  .styles { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .steps { grid-template-columns: 1fr; gap: 1.75rem; }
  .styles { grid-template-columns: 1fr; }
  .strip { height: 22rem; width: 100%; max-width: 22rem; }
  .strip__panel { width: 12rem; }
  .strip__panel:nth-child(2) { left: 9.5rem; top: 4rem; }
  .strip__panel:nth-child(3) { left: 2rem; top: 12rem; width: 11rem; }
}

/* ---------- auth ---------- */
.auth { padding: 3rem 0; }
.auth__card { max-width: 26rem; margin-inline: auto; padding: 1.75rem; }
.auth h1 { font-size: 2rem; margin: 0 0 0.25rem; }
.auth__lede { color: var(--muted-foreground); margin: 0 0 1.25rem; }
.auth__alt { margin-top: 1.25rem; font-size: var(--text-sm); color: var(--muted-foreground); }
.form { display: flex; flex-direction: column; gap: 1rem; }
.form__actions { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }

/* ---------- library ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; padding: 2.25rem 0 1.5rem; }
.page-head h1 { font-size: 2.4rem; margin: 0; }
.page-head p { margin: 0.25rem 0 0; color: var(--muted-foreground); }

.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 1.5rem; padding-bottom: 3rem; }
.book {
  display: flex; flex-direction: column; text-decoration: none; color: inherit; overflow: hidden;
  transition: transform 150ms ease, box-shadow 150ms ease;
}
.book:hover { transform: translate(-2px, -2px); box-shadow: 8px 8px 0 var(--ink); }
.book:focus-visible { outline: 3px solid var(--ring); outline-offset: 3px; }
.book__cover { aspect-ratio: 3 / 4; background: var(--muted); border-bottom: 3px solid var(--ink); position: relative; overflow: hidden; }
.book__cover img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.book__blank { position: absolute; inset: 0; display: grid; place-items: center; font-size: 3rem; background: repeating-linear-gradient(135deg, var(--muted) 0 12px, var(--card) 12px 24px); }
.book__body { padding: 0.9rem 1rem 1rem; display: flex; flex-direction: column; gap: 0.35rem; }
.book__title { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; line-height: 1.2; }
.book__meta { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; font-size: var(--text-xs); color: var(--muted-foreground); }
.book__logline { font-size: var(--text-sm); color: var(--muted-foreground); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book--new { align-items: center; justify-content: center; text-align: center; min-height: 18rem; gap: 0.5rem; border-style: dashed; box-shadow: none; background: transparent; }
.book--new:hover { box-shadow: none; background: var(--accent); }
.book--new .book__plus { font-size: 3rem; line-height: 1; font-family: var(--font-display); }
.working { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--primary); font-weight: 700; }

/* ---------- story shell + stepper ---------- */
.story-head { padding: 1.75rem 0 1rem; display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.story-head h1 { font-size: clamp(1.7rem, 3.5vw, 2.4rem); margin: 0; }
.story-head__logline { margin: 0.25rem 0 0; color: var(--muted-foreground); max-width: 46rem; }
.story-head__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-top: 0.6rem; }
.story-head__actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.stepper { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; margin: 0.5rem 0 1.75rem; padding: 0; list-style: none; }
.stepper__item { display: flex; align-items: center; gap: 0.6rem; padding: 0.6rem 0.8rem; border: 2.5px solid var(--border); border-radius: var(--radius-lg); text-decoration: none; color: var(--muted-foreground); background: var(--card); font-weight: 700; }
.stepper__item[href]:hover { border-color: var(--ink); color: var(--foreground); }
.stepper__item--done { color: var(--foreground); border-color: var(--border); }
.stepper__item--current { color: var(--foreground); border-color: var(--ink); box-shadow: 4px 4px 0 var(--ink); background: var(--pop); color: #221b3a; }
.stepper__num { width: 1.7rem; height: 1.7rem; border-radius: 50%; display: grid; place-items: center; font-family: var(--font-display); font-size: 0.95rem; border: 2px solid currentColor; flex: none; }
.stepper__item--done .stepper__num { background: var(--success); color: var(--success-foreground); border-color: var(--success); }
.stepper__item--current .stepper__num { background: #221b3a; color: var(--pop); border-color: #221b3a; }
.stepper__label { font-size: var(--text-sm); }
@media (max-width: 720px) {
  .stepper { grid-template-columns: 1fr 1fr; }
  .stepper__label { font-size: var(--text-xs); }
}

/* ---------- job bar ---------- */
.job { padding: 1rem 1.25rem; display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 1.5rem; }
.job__row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.job__title { font-family: var(--font-display); font-weight: 700; font-size: 1.1rem; }
.job__hint { color: var(--muted-foreground); font-size: var(--text-sm); }
.job__time { margin-left: auto; font-variant-numeric: tabular-nums; font-size: var(--text-sm); color: var(--muted-foreground); }

/* ---------- step toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; padding: 1rem 0 1.5rem; }
.toolbar > .note { max-width: 32rem; }
.toolbar__spacer { flex: 1; }
.toolbar--bottom { padding: 1.5rem 0 3rem; border-top: 2px dashed var(--border); margin-top: 1.5rem; }

/* ---------- characters ---------- */
.cast { display: grid; grid-template-columns: repeat(auto-fill, minmax(21rem, 1fr)); gap: 1.75rem 1.5rem; }
.char { display: flex; flex-direction: column; overflow: hidden; }
.char__sheet { position: relative; aspect-ratio: 3 / 2; background: var(--muted); border-bottom: 3px solid var(--ink); overflow: hidden; }
.char__sheet img { width: 100%; height: 100%; object-fit: cover; display: block; }
.char__sheet-btn { all: unset; display: block; width: 100%; height: 100%; cursor: zoom-in; }
.char__sheet-btn:focus-visible { outline: 3px solid var(--ring); outline-offset: -3px; }
.char__state { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 1rem; gap: 0.5rem; }
.char__state--busy { background: repeating-linear-gradient(135deg, var(--muted) 0 12px, var(--card) 12px 24px); }
.char__state-msg { font-family: var(--font-display); font-weight: 700; }
.char__body { padding: 1rem 1.1rem 1.1rem; display: flex; flex-direction: column; gap: 0.6rem; }
.char__name { font-size: 1.35rem; margin: 0; display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.char__tags { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.char__desc { margin: 0; font-size: var(--text-sm); line-height: 1.5; }
.char dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 0.25rem 0.6rem; font-size: var(--text-sm); }
.char dt { color: var(--muted-foreground); font-weight: 700; }
.char dd { margin: 0; }
.char__actions { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.4rem; }
.char details summary { cursor: pointer; font-size: var(--text-sm); color: var(--muted-foreground); font-weight: 700; }
.char details[open] summary { margin-bottom: 0.4rem; }

/* ---------- pages (breakdown) ---------- */
.pages { display: flex; flex-direction: column; gap: 1.5rem; }
.pg { padding: 1.1rem 1.25rem 1.25rem; }
.pg__head { display: flex; align-items: baseline; gap: 0.75rem; flex-wrap: wrap; }
.pg__num { font-family: var(--font-display); font-weight: 800; font-size: 1.6rem; color: var(--primary); }
.pg__title { font-size: 1.3rem; margin: 0; }
.pg__summary { margin: 0.2rem 0 0.9rem; color: var(--muted-foreground); }
.pg__actions { margin-left: auto; display: flex; gap: 0.4rem; }
.panels { display: grid; grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); gap: 0.75rem; }
.pn { border: 2.5px solid var(--ink); border-radius: 4px; padding: 0.7rem 0.8rem; background: var(--card); display: flex; flex-direction: column; gap: 0.45rem; font-size: var(--text-sm); }
.pn__head { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.pn__num { font-family: var(--font-display); font-weight: 800; }
.pn__desc { margin: 0; line-height: 1.45; }
.pn__cast { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.pn__line { background: #fff; color: #221b3a; border: 2px solid #221b3a; border-radius: 1rem; padding: 0.3rem 0.65rem; font-family: var(--font-display); font-weight: 600; }
.pn__line b { color: var(--primary); font-weight: 800; }
.dark .pn__line b { color: #5b2fc9; }
.pn__caption { background: var(--pop); color: #221b3a; border: 2px solid #221b3a; padding: 0.3rem 0.5rem; font-style: italic; }

/* ---------- book ---------- */
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: 1.75rem 1.5rem; }
.leaf { display: flex; flex-direction: column; overflow: hidden; }
.leaf__art { position: relative; aspect-ratio: 2 / 3; background: var(--muted); border-bottom: 3px solid var(--ink); overflow: hidden; }
.leaf__art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.leaf__body { padding: 0.75rem 0.9rem 0.9rem; display: flex; align-items: center; gap: 0.5rem; }
.leaf__num { font-family: var(--font-display); font-weight: 800; font-size: 1.1rem; }
.leaf__title { font-size: var(--text-sm); color: var(--muted-foreground); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.downloads { display: flex; flex-wrap: wrap; gap: 0.5rem; }

/* ---------- misc ---------- */
.feedback-hint { font-size: var(--text-sm); color: var(--muted-foreground); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }
.empty-wrap { padding: 2rem 0 4rem; }
.err-page { padding: 4rem 0; text-align: center; }
.err-page h1 { font-size: 3rem; }
.hidden-input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.script-form .editor__content { font-family: var(--font-mono); font-size: 0.9rem; line-height: 1.55; min-height: 22rem; max-height: 70vh; }
.script-form .editor__content p { margin: 0 0 0.75em; }
.choice-set { border: 0; padding: 0; margin: 0; min-width: 0; }
.choice-set > legend { padding: 0; margin-bottom: 0.4rem; }
.note { font-size: var(--text-sm); color: var(--muted-foreground); }

@media (prefers-reduced-motion: reduce) {
  .strip__panel { animation: none; }
  .book, .brand__mark, .style-tile { transition: none; }
}

/* ---------- skeleton cast while the editor reads ---------- */
.skel { display: grid; grid-template-columns: repeat(auto-fill, minmax(21rem, 1fr)); gap: 1.75rem 1.5rem; opacity: 0.7; }
.skel__card { padding: 0; overflow: hidden; }
.skel__art { aspect-ratio: 3 / 2; border-bottom: 3px solid var(--ink); background: repeating-linear-gradient(135deg, var(--muted) 0 12px, var(--card) 12px 24px); }
.skel__body { padding: 1rem 1.1rem 1.25rem; display: flex; flex-direction: column; gap: 0.6rem; }
.skel__body .skeleton { height: 0.9rem; width: 100%; }
.skel__body .skeleton:first-child { height: 1.5rem; width: 45%; }
.skel__body .skeleton:last-child { width: 60%; }

/* ---------- reference images ---------- */
.refs { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.ref { position: relative; width: 7.5rem; display: flex; flex-direction: column; gap: 0.3rem; }
.ref__link { display: block; }
.ref__img { width: 7.5rem; height: 7.5rem; object-fit: cover; display: block; border: 2.5px solid var(--ink); border-radius: 0.35rem; background: var(--muted); box-shadow: 3px 3px 0 var(--ink); }
.ref__note { font-size: var(--text-xs); color: var(--muted-foreground); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ref__pick { font-size: var(--text-xs); }
.ref__remove-form { position: absolute; top: -0.5rem; right: -0.5rem; }
.ref__remove-form .ref__remove { position: static; }
.ref__remove {
  position: absolute; top: -0.5rem; right: -0.5rem; width: 1.6rem; height: 1.6rem;
  display: grid; place-items: center; padding: 0; cursor: pointer;
  background: var(--card); color: var(--foreground); border: 2px solid var(--ink); border-radius: 50%;
}
.ref__remove:hover { background: var(--destructive); color: var(--destructive-foreground); border-color: var(--destructive); }
.ref__remove:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.ref__remove .icon, .ref__remove svg { width: 0.9rem; height: 0.9rem; }
.char__refs { display: flex; flex-direction: column; gap: 0.5rem; }
.char__refs .ref, .char__refs .ref__img { width: 5rem; height: auto; }
.char__refs .ref__img { height: 5rem; }
.char__sheet--idle { background: repeating-linear-gradient(135deg, var(--muted) 0 12px, var(--card) 12px 24px); }
.char__state--idle { flex-direction: column; align-content: center; gap: 0.25rem; }
.char__initial { font-family: var(--font-display); font-weight: 800; font-size: 4rem; line-height: 1; color: var(--primary); }
.ref-upload { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; }
.ref-upload__pick { cursor: pointer; }
.ref-upload__pick:has(input:focus-visible) { outline: 2px solid var(--ring); outline-offset: 2px; }
.ref-upload__pick:has(input:disabled) { opacity: 0.5; pointer-events: none; }
.ref-upload.htmx-request .ref-upload__pick { opacity: 0.6; }

/* ---------- cast registry ---------- */
.suggest { border-bottom: 3px solid var(--ink); background: var(--secondary); color: var(--secondary-foreground); display: flex; flex-direction: column; }
.suggest__row { display: flex; align-items: center; gap: 0.75rem; padding: 0.7rem 1rem; }
.suggest__row + .suggest__row { border-top: 2px dashed color-mix(in oklab, var(--ink) 30%, transparent); }
.suggest__img { width: 3.25rem; height: 3.25rem; flex: none; object-fit: cover; border: 2px solid var(--ink); border-radius: 0.35rem; background: #fff; }
.suggest__img--blank { display: grid; place-items: center; font-family: var(--font-display); font-weight: 800; color: var(--primary); }
.suggest__text { flex: 1; display: flex; flex-direction: column; gap: 0.1rem; font-size: var(--text-sm); min-width: 0; }
.suggest__text .note { color: inherit; opacity: 0.8; }
.lineage { margin: -0.2rem 0 0; font-size: var(--text-sm); color: var(--muted-foreground); display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem; }
.lineage a { color: var(--primary); font-weight: 700; }
.link-list { display: flex; flex-direction: column; gap: 0.5rem; max-height: 50vh; overflow: auto; }
.link-row { display: flex; align-items: center; gap: 0.75rem; padding: 0.5rem; border: 2px solid var(--border); border-radius: var(--radius); }
.castlib { display: grid; grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); gap: 1.75rem 1.5rem; padding-bottom: 3rem; }
.castlib__card { display: flex; flex-direction: column; overflow: hidden; }
.castlib__art { position: relative; aspect-ratio: 3 / 2; border-bottom: 3px solid var(--ink); background: repeating-linear-gradient(135deg, var(--muted) 0 12px, var(--card) 12px 24px); overflow: hidden; }
.castlib__art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.castlib__body { padding: 0.9rem 1rem 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.castlib__name { margin: 0; font-size: 1.3rem; }
@media (max-width: 560px) {
  .suggest__row { flex-wrap: wrap; }
  .suggest__row form { width: 100%; }
}
.char__failed { padding: 0.75rem 0.9rem 0; }
.char--working { outline: 3px solid var(--primary); outline-offset: 3px; }
.pending { text-align: center; }
.pending__glyph { font-size: 3rem; line-height: 1; margin-bottom: 0.5rem; }
.pending .form__actions { justify-content: center; margin-top: 1rem; }
