/* ---------- design tokens ---------- */
/* Light is the default theme; [data-theme="dark"] on <html> (set from the persisted cookie,
   both server-side on first paint and client-side by the toggle) swaps every token below. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f2f6;
  --surface-3: #e6e8ee;
  --border: #e2e4ea;
  --text: #1a1c23;
  --text-dim: #6b7280;
  --accent: #c97a12;
  --accent-ink: #ffffff;
  --danger: #d1453b;
  --header-bg: rgba(255, 255, 255, 0.85);
  --chip-bg: rgba(255, 255, 255, 0.6);
  --shadow-lg: 0 20px 50px -20px rgba(15, 23, 42, 0.22);
  --shadow-sm: 0 6px 16px -8px rgba(15, 23, 42, 0.14);
  --discovery-bg: #f3f0e9;
  --discovery-surface: #ffffff;
  --discovery-card: #e7e2d8;
  --discovery-border: #d5cfc3;
  --discovery-text: #171714;
  --discovery-dim: #6e6960;
  --discovery-control: rgba(255, 255, 255, 0.9);
  --discovery-shadow: 0 18px 40px rgba(57, 47, 33, 0.28);
  --discovery-empty-hero: radial-gradient(circle at 72% 30%, #e8cfa9, transparent 30%), linear-gradient(135deg, #fffdf8, #e9e2d6);
  --discovery-tile-fallback: radial-gradient(circle at 80% 10%, #9d6a25, #302719 58%);
  --radius: 14px;
  --radius-sm: 8px;
  --header-h: 60px;
}

:root[data-theme="dark"] {
  --bg: #0b0d12;
  --surface: #12151d;
  --surface-2: #1a1e29;
  --surface-3: #232838;
  --border: #262b38;
  --text: #e8eaf0;
  --text-dim: #9aa1b4;
  --accent: #f2a93b;
  --accent-ink: #241704;
  --danger: #ff6b57;
  --header-bg: rgba(11, 13, 18, 0.85);
  --chip-bg: rgba(18, 21, 29, 0.6);
  --shadow-lg: 0 20px 50px -20px rgba(0, 0, 0, 0.7);
  --shadow-sm: 0 6px 16px -8px rgba(0, 0, 0, 0.6);
  --discovery-bg: #080808;
  --discovery-surface: #141414;
  --discovery-card: #181818;
  --discovery-border: #303030;
  --discovery-text: #f4f4f4;
  --discovery-dim: #aaa;
  --discovery-control: #171717;
  --discovery-shadow: 0 18px 40px rgba(0, 0, 0, 0.7);
  --discovery-empty-hero: radial-gradient(circle at 72% 30%, #3b2208, transparent 28%), linear-gradient(135deg, #171717, #080808);
  --discovery-tile-fallback: radial-gradient(circle at 80% 10%, rgba(242, 169, 59, .24), #151515 55%);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

html { transition: background-color 0.2s ease; }

body {
  font-family: -apple-system, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  min-height: 100dvh;
  padding-top: var(--header-h);
}

a { color: inherit; text-decoration: none; }

h1, h2, h3, p { margin: 0; }

img { max-width: 100%; display: block; }
/* the img{display:block} rule above (an author style) otherwise beats the UA stylesheet's
   [hidden]{display:none} default, since author styles always win regardless of specificity --
   so anything using the hidden attribute needs it reasserted explicitly. */
[hidden] { display: none !important; }

button, input, select {
  font: inherit;
  color: inherit;
}

/* ---------- header ---------- */
/* No bar, no background of its own -- it's just a fixed, invisible positioning strip. Every
   child (brand, title chip, nav buttons) carries its own floating pill styling, so what actually
   renders is a handful of separate chips over the page rather than one full-width div. Fixed (not
   sticky) so it's always exactly viewport-pinned -- the page-nav backdrop and the right-side rail
   both position themselves relative to the viewport too, and any drift between a sticky header
   and their fixed positioning is what caused the scroll glitches we used to see. */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 60;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  pointer-events: none;
}

.site-header > * { pointer-events: auto; }

/* Scoped to header buttons specifically (not .btn everywhere) -- the floating pill/icon buttons
   up here are semi-transparent + blurred so they read as glass chips over the page; buttons
   elsewhere in the app (uploads, save, delete...) stay solid. */
.site-header .btn {
  background: var(--chip-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.brand {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--chip-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow-sm);
}

.brand-mark { height: 22px; width: auto; display: block; }

/* researchcave.svg is a fixed navy-blue file, not inline markup, so its own fill can't be
   targeted with a color/currentColor CSS rule -- brightness(0) flattens it to solid black
   regardless of its source color, then invert(1) flips that to white; the slight opacity dims it
   just a touch so it doesn't compete with the accent color for attention. */
:root[data-theme="dark"] .brand-mark {
  filter: brightness(0) invert(1);
  opacity: 0.92;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.site-nav a {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--chip-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow-sm);
  color: var(--text-dim);
  font-size: 0.9rem;
  transition: all 0.15s ease;
}

.site-nav a:hover { color: var(--text); border-color: var(--accent); }

.manage-link { order: 1; }
.site-nav > .nav-toggle { order: 2; }
.profile-menu { position: relative; order: 4; }

.profile-menu-trigger {
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 10px 3px 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--chip-bg);
  box-shadow: var(--shadow-sm);
  color: var(--text);
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.profile-menu-trigger:hover,
.profile-menu-trigger[aria-expanded="true"] { border-color: var(--accent); }

.profile-menu-trigger:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 30%, transparent);
  outline-offset: 2px;
}

.profile-avatar {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  overflow: hidden;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--border);
}

.profile-initials {
  display: grid;
  place-items: center;
  color: var(--accent-ink);
  background: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
}

.profile-trigger-name {
  max-width: 130px;
  overflow: hidden;
  font-size: 0.86rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-chevron {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.15s ease;
}

.profile-menu-trigger[aria-expanded="true"] .profile-chevron { transform: rotate(180deg); }

.profile-menu-panel {
  position: absolute;
  z-index: 90;
  top: calc(100% + 10px);
  right: 0;
  width: min(300px, calc(100vw - 24px));
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  box-shadow: var(--shadow-lg);
  color: var(--text);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.profile-menu-panel[hidden] { display: none; }

.profile-summary {
  min-width: 0;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  align-items: center;
  gap: 11px;
  padding: 10px;
}

.profile-avatar-large { width: 46px; height: 46px; }
.profile-summary-text { min-width: 0; }
.profile-summary strong,
.profile-summary small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.profile-summary strong { font-size: 0.92rem; }
.profile-summary small { margin-top: 2px; color: var(--text-dim); font-size: 0.76rem; }
.profile-divider { height: 1px; margin: 5px 4px; background: var(--border); }
.workspace-label {
    padding: 4px 12px 3px;
    color: var(--text-dim);
    font-size: 0.68rem;
    font-weight: 750;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.workspace-option { width: 100%; }
.workspace-option-active { color: var(--accent) !important; background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.workspace-option-mark {
    display: inline-grid;
    width: 22px;
    height: 22px;
    flex: 0 0 22px;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--surface-2);
    font-size: 0.68rem;
    font-weight: 800;
}
.profile-menu-panel form { margin: 0; }

.site-nav .profile-menu-item {
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  box-shadow: none;
  color: var(--text-dim);
  font-size: 0.84rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.site-nav .profile-menu-item:hover,
.site-nav .profile-menu-item:focus-visible {
  border-color: transparent;
  outline: 0;
  color: var(--text);
  background: var(--surface-2);
}

.profile-menu-item svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.site-nav .profile-menu-signout { color: var(--danger); }

.profile-menu-backdrop { display: none; }

/* .site-nav a's padding/sizing (for text links) would otherwise beat
   .btn-icon's own padding: 0 / fixed width+height by specificity, since it's a class+type
   selector -- this re-asserts the icon-button circle for the icon-only Manage link. */
.site-nav a.btn-icon {
  padding: 0;
  width: 38px;
  height: 38px;
}

/* comic title/author, rendered into the header only on Read (via the HeaderCenter section) --
   its own floating chip, same as everything else up here. flex + nowrap keeps the title and the
   "by ..." meta on one line instead of the meta wrapping under the (block-level) h1. */
.header-comic-info {
  display: none;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  max-width: 360px;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--chip-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
  overflow: hidden;
}

.header-comic-info h1 {
  font-size: 1rem;
  line-height: 1.2;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-comic-info h1 a { display: flex; align-items: center; gap: 6px; }
.header-comic-info h1 a:hover { color: var(--accent); }
.reader-info-mark { display: inline-grid; width: 17px; height: 17px; flex: 0 0 17px; place-items: center; border: 1px solid currentColor; border-radius: 50%; font-size: .66rem; font-weight: 800; }

.header-comic-info .meta {
  color: var(--text-dim);
  font-size: 0.78rem;
  flex-shrink: 0;
}
.header-comic-info .creator-profile-link:hover { color: var(--accent); }

/* flex-shrink: 0 + explicit width/height attributes on the <svg> itself (not just this 100%
   CSS rule) -- a percentage-sized replaced element inside a flex item otherwise has an
   ambiguous/zero min-content size in some browsers, which let the flex algorithm collapse the
   whole icon to 0 width even though it had an explicit width set. */
.nav-toggle-icon {
  display: inline-flex;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
}

.nav-toggle-icon svg { width: 100%; height: 100%; }

.btn-icon {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  font-size: 1rem;
}

.theme-toggle { flex-shrink: 0; order: 3; }

@media (min-width: 900px) {
  .header-comic-info { display: flex; }
}

@media (max-width: 899px) {
  .profile-menu-panel {
    position: fixed;
    top: auto;
    right: 10px;
    bottom: 0;
    left: 10px;
    width: auto;
    max-height: 75vh;
    overflow-y: auto;
    border-radius: 16px 16px 0 0;
    background: var(--surface);
    animation: profile-sheet-in 0.22s ease-out;
  }

  .profile-menu-backdrop:not([hidden]) {
    position: fixed;
    inset: 0;
    z-index: 55;
    display: block;
    background: rgba(0, 0, 0, 0.5);
  }
}

@keyframes profile-sheet-in {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* The reader's header has a third thing competing for space (the page-nav toggle) -- on narrow
   viewports the Manage link is the one that can go, since the toggle is the reader's only way to
   reach the page navigator. */
@media (max-width: 640px) {
  .reader-page .manage-link { display: none; }
  .site-nav { gap: 6px; }
  .profile-menu-trigger { padding-right: 3px; }
  .profile-trigger-name, .profile-chevron { display: none; }
}

/* ---------- buttons / form controls (shared) ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  color: var(--text);
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 600;
  transition: all 0.15s ease;
}

.btn:hover { border-color: var(--accent); color: var(--accent); }

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

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

.btn-primary:hover { filter: brightness(1.08); color: var(--accent-ink); }

.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); }

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

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.field label { font-size: 0.85rem; color: var(--text-dim); }

.field input[type="text"] {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.field input[type="file"] {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border);
  background: var(--surface);
}

/* ---------- comic library ---------- */
.library {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

.library h1 { font-size: 1.6rem; margin-bottom: 4px; }
.library .subtitle { color: var(--text-dim); display: block; }

.library-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 22px;
}

.comic-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.comic-card .cover {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.comic-card:hover .cover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--accent);
}

.comic-card .cover img { width: 100%; height: 100%; object-fit: cover; }

.comic-card .cover .no-cover {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 2rem;
}

.comic-publication-status {
  position: absolute;
  top: 9px;
  left: 9px;
  z-index: 2;
  padding: 4px 7px;
  border: 1px solid color-mix(in srgb, white 28%, transparent);
  border-radius: 999px;
  color: white;
  background: rgba(22, 25, 29, 0.78);
  backdrop-filter: blur(8px);
  font-size: 0.66rem;
  font-weight: 750;
}
.comic-publication-status.is-published { background: rgba(23, 111, 70, 0.88); }
.comic-universe-badge {
  position: absolute;
  right: 9px;
  bottom: 9px;
  z-index: 2;
  max-width: calc(100% - 18px);
  padding: 5px 8px;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, white 25%, transparent);
  border-radius: 8px;
  color: white;
  background: rgba(24, 19, 35, 0.82);
  backdrop-filter: blur(9px);
  font-size: 0.68rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.editors-pick-icon {
  position: absolute;
  top: 9px;
  right: 9px;
  z-index: 4;
  display: grid;
  width: 27px;
  height: 27px;
  place-items: center;
  border: 1px solid color-mix(in srgb, #ffd37a 60%, transparent);
  border-radius: 50%;
  color: #241704;
  background: #ffd37a;
  box-shadow: 0 5px 16px rgba(0, 0, 0, 0.3);
  font-size: 0.9rem;
}
.public-cover > .editors-pick-icon { width: 27px; height: 27px; color: #241704; font-size: .9rem; }
.editors-pick-tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  right: 0;
  top: calc(100% + 9px);
  width: 220px;
  padding: 9px 11px;
  pointer-events: none;
  opacity: 0;
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  font-size: 0.73rem;
  font-weight: 550;
  line-height: 1.4;
  transform: translateY(4px);
  transition: opacity .15s ease, transform .15s ease;
}
.editors-pick-tooltip:hover::after,
.editors-pick-tooltip:focus-visible::after { opacity: 1; transform: translateY(0); }
.editors-pick-inline { margin-left: 8px; color: var(--accent); }

.comic-card .title { font-weight: 600; font-size: 0.95rem; }
.comic-card .meta { color: var(--text-dim); font-size: 0.8rem; }

.comic-card-details { display: flex; flex-direction: column; gap: 5px; }
.comic-edit-link { color: var(--accent); font-size: 0.82rem; font-weight: 600; margin-top: 2px; }
.comic-edit-link:hover { text-decoration: underline; }

.library-more {
  display: flex;
  justify-content: center;
  margin-top: 28px;
}

.empty-state {
  color: var(--text-dim);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
}

/* ---------- reader ---------- */
.reader {
  min-height: calc(100dvh - var(--header-h));
}

.reader-main {
  min-width: 0;
  /* body's padding-top already clears the fixed header band -- this only needs a little
     breathing room under the floating buttons, not a second full gap on top of that. */
  padding: 6px 20px 40px;
  transition: padding-right 0.25s ease;
}

/* The nav is fixed to the viewport (not part of document flow), so it always covers exactly
   the space it's given regardless of how tall the comic below it is -- no sticky-in-grid
   height mismatches, no rubber-banding, and the page can always scroll all the way down. */
.reader-nav {
  position: fixed;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  transition: transform 0.28s ease;
}

.reader-nav-pages {
  overflow-y: auto;
  overflow-x: hidden;
}

/* flex-shrink: 0 + a real min-height stop the browser from quietly compressing every thumbnail
   to squeeze the whole list into view as page count grows (100 pages used to render as 100
   barely-there slivers instead of a properly scrolling list) -- thumbnails now always stay a
   usable size and the *container* scrolls instead. */
.reader-nav .thumb {
  position: relative;
  display: block;
  flex-shrink: 0;
  aspect-ratio: 3 / 4;
  min-height: 110px;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid transparent;
  opacity: 0.65;
  transition: all 0.15s ease;
}

.reader-nav .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.reader-nav .thumb:hover { opacity: 1; }
.reader-nav .thumb.active { opacity: 1; border-color: var(--accent); }

.reader-nav .thumb-label {
  position: absolute;
  right: 4px;
  bottom: 4px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 0.68rem;
  padding: 1px 6px;
  border-radius: 999px;
}

/* Covers the full viewport, header included -- the header sits above it (higher z-index) and
   stays fully opaque/usable regardless, but a full-viewport backdrop plus a truly fixed header
   move in perfect lockstep while scrolling, with no gap or lag between them. */
.reader-nav-backdrop {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

/* ---- mobile: bottom sheet, closed by default ---- */
@media (max-width: 899px) {
  .reader-nav {
    left: 10px;
    right: 10px;
    bottom: 0;
    top: auto;
    max-height: 75vh;
    border-radius: 16px 16px 0 0;
    border-top: 1px solid var(--border);
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    transform: translateY(100%);
  }
  /* A single horizontally-swipeable filmstrip rather than a wrapping grid -- flicking through
     pages with a thumb reads more naturally than scrolling a multi-row grid inside a short sheet. */
  .reader-nav-pages {
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 10px;
    padding: 14px;
    touch-action: pan-x;
    -webkit-overflow-scrolling: touch;
  }
  .reader-nav-pages .thumb { flex: 0 0 92px; }
  body.nav-open .reader-nav { transform: translateY(0); }
  body.nav-open .reader-nav-backdrop { opacity: 1; pointer-events: auto; }
}

/* ---- desktop: right-side rail, open by default, closable via the header toggle ---- */
@media (min-width: 900px) {
  .reader-nav {
    top: var(--header-h);
    right: 0;
    bottom: 0;
    width: 190px;
    border-left: 1px solid var(--border);
    transform: translateX(0);
  }
  /* flex: 1 + min-height: 0 hands this the rail's full remaining height (there's no head bar
     taking a slice anymore) and makes it a properly height-constrained scroll container instead
     of one that just grows to fit all its content. */
  .reader-nav-pages {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    gap: 10px;
    padding: 14px;
  }
  .reader-main { padding-right: 210px; }

  body.nav-closed .reader-nav { transform: translateX(100%); }
  body.nav-closed .reader-main { padding-right: 20px; }
}

/* ---------- comic panels (also used standalone by the prototype) ---------- */
/* touch-action: pan-y on the comic and everything in it means a drag started *anywhere* --
   on a panel image or in the gap between panels -- is treated as a vertical page scroll rather
   than the browser waiting to see if it might be something else (e.g. an image's native
   drag-to-save gesture on Android/iOS, which otherwise can eat the first drag and stall scrolling). */
.comic {
  display: flex;
  flex-direction: column;
  gap: 1vmin;
  max-width: 1100px;
  margin: 0 auto;
  touch-action: pan-y;
}

.comic .row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  /* Must match ComicLayout.RowGapPx exactly -- ImpliedRowHeight() sizes panels to fit
     TargetRowWidth *after* subtracting this many gaps, so a mismatch here throws that budget off
     and rows can wrap unexpectedly again. */
  gap: 8px;
  scroll-margin-top: calc(var(--header-h) + 12px);
  touch-action: pan-y;
}

/* flex-basis has to be pinned from the aspect ratio (via --ar-num) rather than left as the
   default `auto`. With `auto`, a panel with no other definite size falls back to using its
   <img>'s *native file resolution* as its content size -- so two panels with the exact same
   aspect ratio but different source resolutions (e.g. a 512x512 upload next to a 1254x1254 one,
   both square) would get very different flex-basis values despite being the same shape, throwing
   off proportions and even forcing panels onto their own wrapped line within a row that should've
   fit them all on one. Pinning it from the ratio alone means sizing only ever depends on each
   panel's *shape*, never on the pixel size of the file someone happened to upload.
   --row-h (set per-row by ComicPanels.cshtml via ComicLayout.ImpliedRowHeight) is the reference
   height, not an arbitrary constant -- it's exactly the height that makes this row's flex-basis
   values sum to ComicLayout.TargetRowWidth, which is what guarantees the row fits on one line
   instead of wrapping. Using any other reference undershoots or overshoots that sum. */
.comic .panel {
  background-color: #fff;
  border: solid 2px #000;
  box-shadow: var(--shadow-sm);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
  flex-grow: 1;
  flex-shrink: 1;
  flex-basis: calc(var(--row-h, 300px) * var(--ar-num, 1));
  aspect-ratio: var(--ar);
  min-width: 120px;
  touch-action: pan-y;
}

/* ComicLayout only ever refuses to pack a row *thinner* than its floor -- so a portrait/full-page
   image with nothing suitable to pair it with (right after a page break, say, or a "whole page"
   upload with no panel borders for auto-split to find) ends up alone in its row with no upper
   bound, and flex-grow doesn't care about aspect-ratio at all: it fills 100% of the row's width
   regardless, then aspect-ratio derives an enormous height from that.
   This has to stay scoped to :only-child. Applying it to every panel was the previous bug: on a
   real multi-panel row, each panel individually hitting its own cap before it could grow to fill
   its actual share of the row is exactly what left empty gaps on either side -- rows with two or
   more panels are already a reasonable height by construction (that's what the packer's row-height
   floor guarantees) and must stay free to flex-grow edge to edge, uncapped, the way page 1 does.
   max-height alone can't fix the lone-panel case either -- it only constrains the cross axis, so
   it would just clip the height while flex-grow keeps the width pinned to the full row, distorting
   /cropping the image. max-width has to shrink *with* it, in lockstep, which is why it's expressed
   from the same cap via --ar-num (a plain numeric width/height ComicPanels.cshtml computes
   server-side, since calc() can't do arithmetic on --ar's slash-ratio syntax). */
.comic .panel:only-child {
  max-height: min(78vh, 820px);
  max-width: calc(min(78vh, 820px) * var(--ar-num, 3));
}

.comic .panel img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  touch-action: pan-y;
  -webkit-user-drag: none;
  user-select: none;
  -webkit-touch-callout: none;
}

@media (max-width: 640px) {
  .comic .row { flex-direction: column; }
  .comic .panel { flex-basis: auto !important; min-width: 0; }
}

/* Marks where the automatic/manual pagination cut a page, right in the flowing scroll view --
   purely a visual cue (the page navigator is what actually jumps between pages). */
.page-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0;
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.page-divider::before,
.page-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ---------- admin ---------- */
.admin {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px 64px;
}

.admin h1 { font-size: 1.5rem; }

.admin-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.admin-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

/* Wraps the cover + title/meta so the whole thing is one click-through to the reader page,
   instead of a separate "View" button next to Edit. */
.admin-row-link {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
  min-width: 0;
  border-radius: var(--radius-sm);
  transition: opacity 0.15s ease;
}

.admin-row-link:hover { opacity: 0.75; }

.admin-row .thumb {
  width: 42px;
  height: 56px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--surface-2);
  flex-shrink: 0;
}

.admin-row .thumb img { width: 100%; height: 100%; object-fit: cover; }

.admin-row .info { flex: 1; min-width: 0; }
.admin-row .info .t { font-weight: 600; }
.admin-row .info .s { color: var(--text-dim); font-size: 0.82rem; }

.admin-title-link:hover { color: var(--accent); }
.managed-universes { margin-top: 44px; scroll-margin-top: calc(var(--header-h) + 20px); }
.managed-universes .admin-heading { margin-bottom: 12px; }
.managed-universes h2 { font-size: 1.2rem; }
.admin-universe-row { transition: border-color .15s ease, transform .15s ease; }
.admin-universe-row:hover { border-color: var(--accent); transform: translateX(3px); }
.universe-row-glyph { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 50%; background: var(--surface-2); color: var(--accent); font-size: 1.35rem; }
.admin-universe-row .info { display: flex; flex-direction: column; }

.editorial-page { max-width: 1180px; margin: 0 auto; padding: 34px 20px 80px; }
.editorial-hero { display: flex; align-items: end; justify-content: space-between; gap: 28px; padding: 28px 0 34px; border-bottom: 1px solid var(--border); }
.editorial-hero h1 { margin: 5px 0 8px; font-size: clamp(2rem, 5vw, 3.5rem); letter-spacing: -.045em; }
.editorial-hero p { max-width: 650px; color: var(--text-dim); line-height: 1.55; }
.editorial-stats { display: grid; grid-template-columns: repeat(3, minmax(90px, 1fr)); gap: 8px; }
.editorial-stats span { padding: 12px; border: 1px solid var(--border); border-radius: 12px; color: var(--text-dim); background: var(--surface); text-align: center; font-size: .72rem; }
.editorial-stats strong { display: block; color: var(--text); font-size: 1.25rem; }
.editorial-section { margin-top: 42px; }
.editorial-section-heading { display: flex; align-items: end; justify-content: space-between; gap: 22px; margin-bottom: 14px; }
.editorial-section-heading span { color: var(--accent); font-size: .7rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.editorial-section-heading h2 { margin-top: 2px; font-size: 1.45rem; }
.editorial-section-heading p { max-width: 470px; color: var(--text-dim); font-size: .82rem; text-align: right; }
.editorial-list { display: flex; flex-direction: column; gap: 8px; }
.editorial-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 15px 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.editorial-row.is-picked { border-color: color-mix(in srgb, var(--accent) 52%, var(--border)); background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 8%, var(--surface)), var(--surface) 42%); }
.editorial-row-main { min-width: 0; }
.editorial-row-title { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-weight: 750; }
.editorial-row-title a:hover { color: var(--accent); }
.editorial-pick-label { padding: 3px 7px; border-radius: 999px; color: #5d3b00; background: #ffd37a; font-size: .65rem; }
.editorial-meta { margin-top: 4px; color: var(--text-dim); font-size: .76rem; }
.editorial-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.editorial-tags span { padding: 3px 7px; border-radius: 6px; color: var(--text-dim); background: var(--surface-2); font-size: .67rem; }
.editorial-tags .content-status.is-live { color: #177247; background: color-mix(in srgb, #32c778 14%, var(--surface)); }
.editorial-actions { display: flex; align-items: center; gap: 7px; flex: 0 0 auto; }
.confirmation-dialog { max-width: 520px; }
.universe-delete-trigger { margin-top: 18px; background: color-mix(in srgb, var(--surface) 82%, transparent); }

/* ---------- comic information ---------- */
.comic-info-page { max-width: 1200px; margin: 0 auto; padding: 44px 20px 84px; }
.comic-info-hero { display: grid; grid-template-columns: minmax(240px, 370px) minmax(0, 1fr); gap: clamp(34px, 7vw, 88px); align-items: center; }
.comic-info-cover { position: relative; aspect-ratio: 3/4; overflow: hidden; border: 1px solid var(--border); border-radius: 22px; background: var(--surface-2); box-shadow: 0 30px 65px -35px rgba(18, 20, 27, .55); }
.comic-info-cover > img { width: 100%; height: 100%; object-fit: cover; }
.comic-info-cover > span:not(.editors-pick-icon) { width: 100%; height: 100%; display: grid; place-items: center; color: var(--text-dim); font-size: 3rem; }
.comic-info-intro h1 { max-width: 760px; margin: 9px 0 13px; font-size: clamp(2.7rem, 7vw, 5.8rem); line-height: .94; letter-spacing: -.06em; text-wrap: balance; }
.comic-info-byline { color: var(--text-dim); font-size: 1.08rem; }
.comic-info-creator { margin-top: 9px; color: var(--text-dim); }
.comic-info-creator a, .comic-info-creator strong { color: var(--text); font-weight: 750; }
.comic-info-creator a:hover { color: var(--accent); }
.comic-info-creator .sentient-link-mark { margin-left: 8px; color: var(--text-dim); font-size: .7rem; letter-spacing: .04em; text-transform: uppercase; }
.sentient-link-mark { margin-left: 5px; color: var(--accent); font-size: .68rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.comic-info-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; margin: 28px 0; }
.comic-info-actions form { margin: 0; }
.comic-read-button { min-width: 165px; justify-content: space-between; }
.comic-facts { display: grid; grid-template-columns: repeat(5, minmax(82px, 1fr)); gap: 8px; margin: 0; }
.comic-facts > div { min-width: 0; padding: 12px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface); }
.comic-facts dt { color: var(--text-dim); font-size: .66rem; font-weight: 750; letter-spacing: .06em; text-transform: uppercase; }
.comic-facts dd { margin: 5px 0 0; overflow: hidden; font-size: .88rem; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.comic-info-section { margin-top: 72px; }
.comic-info-section-heading { margin-bottom: 18px; }
.comic-info-section-heading h2 { margin-top: 3px; font-size: 1.7rem; }
.comic-universe-info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.comic-universe-info-grid > a { min-height: 170px; padding: 22px; border: 1px solid var(--border); border-radius: 15px; background: radial-gradient(circle at 90% 5%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 35%), var(--surface); transition: transform .18s ease, border-color .18s ease; }
.comic-universe-info-grid > a:hover { border-color: var(--accent); transform: translateY(-3px); }
.comic-universe-info-grid span { color: var(--accent); font-size: .69rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.comic-universe-info-grid h3 { margin: 9px 0 6px; font-size: 1.35rem; }
.comic-universe-info-grid p { color: var(--text-dim); font-size: .82rem; line-height: 1.5; }
.comic-info-page > .catalog-shelf { margin-top: 66px; }
.universe-editorial-action { display: inline-block; margin: 18px 8px 0 0; }

.panel-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
}

.panel-section h2 { font-size: 1.05rem; margin-bottom: 14px; }

.frames-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 4px;
}

.frames-heading h2 { margin-bottom: 0; }

.frames-heading-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
}

.cover-toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 18px 6px 6px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  color: var(--text);
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 600;
  transition: all 0.15s ease;
}

.cover-toolbar-btn:hover { border-color: var(--accent); color: var(--accent); }

.cover-toolbar-thumb {
  position: relative;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 50%;
  overflow: hidden;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
}

.cover-toolbar-thumb img { width: 100%; height: 100%; object-fit: cover; }
.cover-toolbar-placeholder { color: var(--text-dim); font-size: 1rem; }

/* Native <dialog> -- gives us backdrop, ESC-to-close and focus containment for free; only the
   look needs styling. */
dialog.modal {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  padding: 20px;
  width: min(480px, 90vw);
}

dialog.modal::backdrop {
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.modal-head h2 { font-size: 1.05rem; }

.modal-close {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
}

.modal-close:hover { border-color: var(--accent); color: var(--accent); }

.modal-message { margin: 0 0 16px; color: var(--text-dim); line-height: 1.5; }

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.cover-preview {
  width: 120px;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
  margin-bottom: 14px;
}

.cover-preview img { width: 100%; height: 100%; object-fit: cover; }

/* file-picker preview shown between choosing a file and clicking Upload */
.upload-preview {
  width: 100%;
  max-height: 140px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  margin-bottom: 10px;
}

.uploader {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.uploader input[type="file"] {
  flex: 1;
  min-width: 0;
  font-size: 0.82rem;
}

.upload-progress {
  flex-basis: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}

.upload-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.15s ease;
}

.upload-status {
  flex-basis: 100%;
  font-size: 0.78rem;
  color: var(--text-dim);
}

.frame-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 14px;
}

.frame-card {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: grab;
  user-select: none;
}

.frame-card img { aspect-ratio: 3 / 4; object-fit: cover; width: 100%; }

.frame-card-break {
  aspect-ratio: 3 / 4;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-3);
  border-style: dashed;
  border-color: var(--accent);
}

.break-marker {
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-align: center;
  padding: 0 8px;
}

.frame-card .order-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: 999px;
}

.frame-card .delete-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  cursor: pointer;
  line-height: 1;
  font-size: 0.9rem;
}

.frame-card .delete-btn:hover { background: var(--danger); }

.frame-card.sortable-ghost { opacity: 0.35; }
.frame-card.sortable-chosen { border-color: var(--accent); }

.hint { color: var(--text-dim); font-size: 0.8rem; margin-top: 8px; }
.frame-layout-hint { margin-bottom: 18px; }

.save-indicator {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-left: 10px;
}

/* ---------- publishing and discovery ---------- */
.publish-notice { margin: 16px 0; padding: 12px 16px; border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border)); border-radius: var(--radius-sm); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.publishing-panel { margin: 20px 0; padding: 18px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.publishing-state { display: flex; align-items: center; gap: 12px; }
.publishing-state > div { display: grid; gap: 3px; }
.publishing-state small { color: var(--text-dim); }
.status-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--text-dim); box-shadow: 0 0 0 5px color-mix(in srgb, var(--text-dim) 14%, transparent); }
.status-dot.is-public { background: #32c778; box-shadow: 0 0 0 5px rgba(50, 199, 120, 0.14); }
.publishing-actions, .admin-heading-actions, .review-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.publishing-actions form, .review-actions form { margin: 0; }
.comic-details-panel { align-items: flex-start; }
.comic-details-panel > div { display: grid; gap: 4px; }
.comic-details-panel small { color: var(--text-dim); }
.comic-details-form { min-width: min(520px, 100%); display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)) auto; align-items: end; gap: 10px; }
.comic-details-form label { display: grid; gap: 5px; color: var(--text-dim); font-size: .76rem; font-weight: 700; }
.comic-details-form input { min-width: 0; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: inherit; }
.comic-details-form input:focus { border-color: var(--accent); outline: 0; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.universe-associations { margin-bottom: 20px; padding: 18px; display: grid; gap: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.universe-associations h2 { font-size: 1.05rem; }
.association-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.association-chips a { padding: 6px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text-dim); font-size: 0.78rem; }
.associate-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.associate-form select, .universe-form textarea { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); }

/* ---------- discovery tags chips editor (tageditor) ---------- */
.tags-panel { flex-direction: column; align-items: stretch; gap: 12px; }
.tags-form { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 10px; }
.tags-form > .btn { min-height: 46px; }
.tags-form .tag-editor {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: text;
  display: flex;
  flex: 1 1 320px;
  flex-wrap: wrap;
  font: inherit;
  gap: 6px;
  line-height: 1.35;
  margin: 0;
  min-height: 46px;
  overflow: visible;
  padding: 7px 10px;
  transition: border-color 0.16s, box-shadow 0.16s;
}
.tags-form .tag-editor:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.tags-form .tag-editor li, .tags-form .tag-editor div { float: none; }
.tags-form .tag-editor li { align-items: center; display: inline-flex; margin: 0; max-width: 100%; }
.tags-form .tag-editor .placeholder { color: var(--text-dim); padding: 0 4px; }
.tags-form .tag-editor .tag-editor-spacer { display: none; }
.tags-form .tag-editor .tag-editor-tag {
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-right: 0;
  border-radius: 999px 0 0 999px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  max-width: min(280px, 72vw);
  overflow: hidden;
  padding: 5px 3px 5px 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tags-form .tag-editor .tag-editor-tag.active { border: 0; max-width: 100%; padding: 0 4px; background: none; }
.tags-form .tag-editor .tag-editor-tag.active + .tag-editor-delete { display: none; }
.tags-form .tag-editor input { color: var(--text); min-width: 130px; }
.tags-form .tag-editor .tag-editor-delete {
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-left: 0;
  border-radius: 0 999px 999px 0;
  cursor: pointer;
  display: inline-flex;
  padding: 5px 8px 5px 2px;
}
.tags-form .tag-editor .tag-editor-delete i:before { color: color-mix(in srgb, var(--accent) 65%, var(--text-dim)); font-size: 15px; line-height: 1; }
.tags-form .tag-editor .tag-editor-delete:hover i:before { color: var(--danger); }

/* tag suggestions dropdown */
.ui-autocomplete.ui-front.ui-menu.ui-widget.ui-widget-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  color: var(--text);
  overflow: hidden;
  padding: 4px;
}
.ui-autocomplete.ui-front.ui-menu .ui-menu-item a { color: var(--text); display: block; padding: 7px 10px; border-radius: var(--radius-sm); text-decoration: none; }
.ui-autocomplete.ui-widget-content .ui-state-hover,
.ui-autocomplete.ui-widget-content .ui-state-focus { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); color: var(--accent); }
.ui-autocomplete.ui-front .ui-menu-item[aria-selected="true"] > a { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); color: var(--accent); }

.discovery-page { background: var(--discovery-bg); color: var(--discovery-text); }
.discovery-page main { overflow: hidden; }
.discovery-home { min-height: calc(100dvh - var(--header-h)); background: var(--discovery-bg); }
.comic-hero { position: relative; min-height: min(72vh, 720px); display: flex; align-items: flex-end; padding: clamp(100px, 14vw, 180px) clamp(22px, 6vw, 84px) 74px; overflow: hidden; background: var(--discovery-card) var(--hero-image) center 28% / cover no-repeat; color: #f4f4f4; }
.comic-hero::before { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(0,0,0,.9) 0%, rgba(0,0,0,.38) 54%, transparent 78%); }
.comic-hero::after { content: ""; position: absolute; inset: auto 0 0; height: 42%; background: linear-gradient(transparent, var(--discovery-bg)); }
.comic-hero-shade { position: absolute; inset: 0; background: radial-gradient(circle at 70% 20%, transparent 0 20%, rgba(0,0,0,.2) 72%); }
.comic-hero-content { position: relative; z-index: 2; width: min(620px, 100%); display: grid; gap: 14px; }
.comic-hero-content h1 { font-size: clamp(2.8rem, 7vw, 6.6rem); line-height: .88; letter-spacing: -.055em; text-wrap: balance; }
.comic-hero-content p { max-width: 560px; color: #d0d0d0; font-size: clamp(.95rem, 1.5vw, 1.12rem); line-height: 1.55; }
.hero-kicker { color: #f2a93b; font-size: .72rem; font-weight: 800; letter-spacing: .18em; text-transform: uppercase; }
.hero-actions { display: flex; align-items: center; gap: 16px; color: #b7b7b7; }
.comic-hero-empty { min-height: 430px; background: var(--discovery-empty-hero); color: var(--discovery-text); }
.comic-hero-empty::before { background: linear-gradient(90deg, color-mix(in srgb, var(--discovery-bg) 82%, transparent), transparent 82%); }
.comic-hero-empty .comic-hero-content p { color: var(--discovery-dim); }
.discovery-shelves { position: relative; z-index: 3; margin-top: -34px; padding-bottom: 64px; }
.discovery-page .library { max-width: none; padding: 22px clamp(20px, 4vw, 58px); color: var(--discovery-text); }
.discovery-page .library .subtitle, .discovery-page .comic-card .meta { color: var(--discovery-dim); }
.discovery-page .comic-card .cover { border-color: var(--discovery-border); background: var(--discovery-card); }
.catalog-shelf { padding: 20px clamp(20px, 4vw, 58px); }
.shelf-heading { margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.shelf-heading h2 { font-size: clamp(1.15rem, 2vw, 1.55rem); }
.shelf-heading > a { color: var(--discovery-dim); font-size: .84rem; }
.shelf-controls { display: flex; gap: 5px; }
.shelf-controls button { width: 34px; height: 34px; border: 1px solid var(--discovery-border); border-radius: 50%; background: var(--discovery-control); color: var(--discovery-text); cursor: pointer; box-shadow: var(--shadow-sm); }
.comic-shelf-row { display: flex; gap: 10px; overflow-x: auto; overflow-y: hidden; padding: 5px 2px 18px; scroll-snap-type: x proximity; scrollbar-width: none; }
.comic-shelf-row::-webkit-scrollbar { display: none; }
.public-comic-card { flex: 0 0 clamp(145px, 15vw, 220px); scroll-snap-align: start; }
.public-cover { position: relative; aspect-ratio: 3 / 4; overflow: hidden; border: 1px solid var(--discovery-border); border-radius: 8px; background: var(--discovery-card); transition: transform .2s ease, box-shadow .2s ease; }
.public-cover > img { width: 100%; height: 100%; object-fit: cover; }
.public-cover > span { height: 100%; display: grid; place-items: center; color: var(--discovery-dim); font-size: 2rem; }
.public-comic-card:hover .public-cover { z-index: 2; transform: scale(1.045); box-shadow: var(--discovery-shadow); }
.public-card-overlay { position: absolute; inset: auto 0 0; padding: 42px 12px 12px; display: grid; gap: 3px; background: linear-gradient(transparent, rgba(0,0,0,.94)); color: #f4f4f4; }
.public-card-overlay strong { line-height: 1.15; }
.public-card-overlay small { color: #bbb; font-size: .72rem; }
.universe-row { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; }
.universe-tile { position: relative; flex: 0 0 min(330px, 78vw); min-height: 150px; padding: 22px; display: flex; flex-direction: column; justify-content: flex-end; border: 1px solid var(--discovery-border); border-radius: 10px; background-image: linear-gradient(0deg, rgba(8,8,8,.94), rgba(8,8,8,.12) 78%), var(--universe-cover, var(--discovery-tile-fallback)); background-position: center; background-size: cover; color: #f4f4f4; box-shadow: var(--shadow-sm); transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease; }
.universe-tile:hover { z-index: 2; transform: scale(1.035); border-color: color-mix(in srgb, #fff 24%, var(--discovery-border)); box-shadow: var(--discovery-shadow); }
.universe-tile span, .universe-tile small { color: #999; font-size: .76rem; }
.universe-tile strong { margin: 8px 0 3px; font-size: 1.4rem; }

.creator-page { width: min(1200px, calc(100% - 40px)); margin: 0 auto; padding: 54px 0 84px; }
.creator-profile-card { padding: clamp(24px, 5vw, 58px); display: grid; grid-template-columns: minmax(150px, 230px) minmax(0, 1fr); gap: clamp(28px, 6vw, 70px); align-items: center; border: 1px solid var(--discovery-border); border-radius: 22px; background: var(--discovery-card); box-shadow: var(--shadow-lg); }
.creator-avatar { aspect-ratio: 1; overflow: hidden; display: grid; place-items: center; border: 1px solid var(--discovery-border); border-radius: 50%; background: var(--discovery-tile-fallback); color: var(--discovery-dim); font-size: clamp(3rem, 8vw, 6rem); font-weight: 800; }
.creator-avatar img { width: 100%; height: 100%; object-fit: cover; }
.creator-profile-copy h1 { margin: 8px 0 2px; font-size: clamp(2.5rem, 7vw, 5.5rem); line-height: .95; letter-spacing: -.055em; text-wrap: balance; }
.creator-username, .creator-summary { color: var(--discovery-dim); }
.creator-summary { margin-top: 20px; line-height: 1.6; }
.creator-profile-actions { margin-top: 24px; display: flex; flex-wrap: wrap; gap: 9px; }
.creator-stats { margin-top: 30px; display: flex; flex-wrap: wrap; gap: 12px; }
.creator-stats > div { min-width: 150px; padding: 13px 16px; border: 1px solid var(--discovery-border); border-radius: 10px; background: var(--discovery-control); }
.creator-stats dt { color: var(--discovery-dim); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; }
.creator-stats dd { margin-top: 4px; font-size: 1.25rem; font-weight: 800; }
.creator-page > .catalog-shelf { margin-top: 42px; padding-right: 0; padding-left: 0; }

.universe-directory { width: min(1200px, calc(100% - 40px)); margin: 0 auto; padding: 48px 0 80px; }
.universe-page { width: 100%; margin: calc(-1 * var(--header-h)) 0 0; padding: 0 0 80px; }
.universe-page > :not(.universe-header):not(dialog) { width: min(1200px, calc(100% - 40px)); margin-right: auto; margin-left: auto; }
.directory-heading { margin-bottom: 34px; display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }
.directory-heading h1, .universe-header h1 { margin: 8px 0; font-size: clamp(2.5rem, 6vw, 5rem); letter-spacing: -.045em; }
.directory-heading p, .universe-header p { max-width: 700px; color: var(--text-dim); line-height: 1.6; }
.universe-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); gap: 16px; }
.universe-directory-card { position: relative; min-height: 230px; padding: 24px; display: flex; flex-direction: column; justify-content: flex-end; border: 1px solid var(--border); border-radius: var(--radius); background-image: linear-gradient(0deg, color-mix(in srgb, var(--surface) 96%, transparent), color-mix(in srgb, var(--surface) 15%, transparent) 78%), var(--universe-cover, radial-gradient(circle at 78% 12%, color-mix(in srgb, var(--accent) 20%, transparent), var(--surface) 58%)); background-position: center; background-size: cover; }
.universe-tile > .editors-pick-icon,
.universe-directory-card > .editors-pick-icon { width: 27px; height: 27px; color: #241704; font-size: .9rem; }
.universe-directory-card > span, .universe-directory-card small { color: var(--text-dim); font-size: .76rem; }
.universe-directory-card h2 { margin: 12px 0 7px; font-size: 1.65rem; }
.universe-directory-card p { flex: 1; color: var(--text-dim); line-height: 1.5; }
.universe-header { position: relative; min-height: min(78vh, 760px); padding: clamp(110px, 15vw, 180px) max(20px, calc((100vw - 1200px) / 2)) 72px; display: flex; align-items: flex-end; overflow: hidden; border-bottom: 1px solid var(--border); background-image: var(--universe-cover, radial-gradient(circle at 72% 24%, color-mix(in srgb, var(--accent) 28%, transparent), var(--surface-2) 58%)); background-position: center; background-size: cover; }
.universe-header-shade { position: absolute; inset: 0; background: linear-gradient(0deg, color-mix(in srgb, var(--bg) 96%, transparent), color-mix(in srgb, var(--bg) 10%, transparent) 80%); }
.universe-header-content { position: relative; z-index: 1; width: min(760px, 100%); }
.universe-header-content > div { margin-top: 20px; color: var(--text-dim); }
.universe-cover-edit { position: absolute; right: max(20px, calc((100vw - 1200px) / 2)); bottom: 72px; z-index: 2; opacity: 0; transform: translateY(6px); transition: opacity .18s ease, transform .18s ease; }
.universe-header:hover .universe-cover-edit, .universe-cover-edit:focus-within, .universe-cover-edit.is-empty { opacity: 1; transform: translateY(0); }
.universe-cover-edit label { padding: 9px 12px; display: flex; align-items: center; gap: 8px; border: 1px solid rgba(255,255,255,.3); border-radius: 999px; background: rgba(8,8,8,.62); color: #fff; box-shadow: 0 8px 28px rgba(0,0,0,.28); backdrop-filter: blur(12px); cursor: pointer; }
.universe-cover-edit label:hover { background: rgba(8,8,8,.78); border-color: rgba(255,255,255,.56); }
.universe-cover-edit svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.universe-cover-edit small { padding-left: 8px; border-left: 1px solid rgba(255,255,255,.24); color: rgba(255,255,255,.68); font-size: .68rem; }
.universe-cover-edit input[type="file"] { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.canon-review, .canon-library { margin-top: 36px; }
.review-heading { margin-bottom: 14px; }
.review-heading p { margin-top: 4px; color: var(--text-dim); font-size: .84rem; }
.canon-review article { padding: 15px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.canon-review article + article { margin-top: 8px; }
.canon-review article > div:first-child { display: grid; gap: 4px; }
.canon-review small { color: var(--text-dim); }
.canon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(175px, 1fr)); gap: 20px; }
.canon-card { display: grid; gap: 10px; }
.canon-card-cover { aspect-ratio: 3/4; display: block; overflow: hidden; border-radius: var(--radius); background: var(--surface-2); box-shadow: var(--shadow-sm); }
.canon-card-cover > img { width: 100%; height: 100%; object-fit: cover; }
.canon-card-cover > span { width: 100%; height: 100%; display: grid; place-items: center; color: var(--text-dim); font-size: 1.5rem; }
.canon-card > div { display: grid; gap: 3px; }
.canon-card span, .canon-card small { color: var(--text-dim); font-size: .77rem; }
.canon-card > .canon-card-actions { margin-top: 3px; display: flex; flex-wrap: wrap; gap: 6px; }
.canon-card-actions .btn { flex: 1 1 auto; font-size: .7rem; }
.association-decision-dialog > p { color: var(--text-dim); line-height: 1.55; }
.association-decision-note { margin: 16px 0 20px; padding: 13px 14px; border-left: 3px solid var(--accent); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; background: var(--surface-2); color: var(--text-dim); font-size: .84rem; line-height: 1.5; }
.association-decision-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.association-decision-actions form { margin: 0; }
.universe-form-page > h1 { margin: 8px 0; }
.universe-form-page > p { max-width: 650px; margin-bottom: 20px; }
.universe-form { max-width: 680px; }
.universe-form textarea { width: 100%; resize: vertical; }

@media (max-width: 700px) {
  .publishing-panel, .directory-heading, .canon-review article { align-items: stretch; flex-direction: column; }
  .comic-details-form { min-width: 0; grid-template-columns: 1fr; }
  .universe-cover-edit { right: 20px; bottom: 24px; opacity: 1; transform: none; }
  .universe-cover-edit small { display: none; }
  .publishing-actions { width: 100%; }
  .comic-hero { min-height: 560px; padding-bottom: 64px; background-position: center top; }
  .comic-hero::before { background: linear-gradient(0deg, rgba(0,0,0,.95) 0%, rgba(0,0,0,.34) 72%, rgba(0,0,0,.15)); }
  .comic-hero-content h1 { font-size: clamp(2.7rem, 14vw, 4.5rem); }
  .shelf-controls { display: none; }
  .public-comic-card { flex-basis: 42vw; }
  .editorial-hero, .editorial-section-heading, .editorial-row { align-items: stretch; flex-direction: column; }
  .editorial-section-heading p { text-align: left; }
  .editorial-stats { width: 100%; }
  .editorial-actions { flex-wrap: wrap; }
  .comic-info-hero { grid-template-columns: 1fr; }
  .comic-info-cover { width: min(78vw, 360px); margin: 0 auto; }
  .comic-facts { grid-template-columns: repeat(2, 1fr); }
  .creator-profile-card { grid-template-columns: 1fr; }
  .creator-avatar { width: min(52vw, 190px); }
}

@media (prefers-reduced-motion: reduce) {
  .universe-tile { transition: none; }
  .universe-tile:hover { transform: none; }
}
