/* racunkomik — design system.
 *
 * The Svelte build leaned on Tailwind utilities plus a token layer. Tailwind is
 * gone, so this file carries both: the tokens, and semantic classes for every
 * component the templates emit. Server-rendered markup means class names are
 * decided in one place (src/web/views), which is why these can stay semantic
 * instead of utility soup.
 */

:root {
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;

  --bg: #0a0a0a;
  --surface-1: #141414;
  --surface-2: #1c1c1c;
  --surface-3: #252525;
  --surface-4: #2f2f2f;

  --fg: #fafafa;
  --fg-muted: #b3b3b3;
  --fg-dim: #7c7c7c;

  --accent: #f97316;
  --accent-hover: #fb923c;
  --accent-dim: #c2410c;
  --accent-soft: rgba(249, 115, 22, 0.12);

  --danger: #f3727f;
  --warning: #ffa42b;
  --info: #539df5;

  --border: #2a2a2a;
  --border-strong: #3d3d3d;

  --radius-card: 12px;
  --radius-pill: 9999px;

  --shadow-card: 0 1px 2px rgb(0 0 0 / 0.4);
  --shadow-elevated: 0 8px 24px rgb(0 0 0 / 0.5);

  --header-h: 4rem;
  --reader-brightness: 1;
}

/* ===== base ============================================================== */

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

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Ambient ornaments — three radial glows pinned to the top of the viewport.
   Animates only `transform` so it stays on the compositor: zero layout or
   paint cost per frame. */
body::before {
  content: "";
  position: fixed;
  inset: -25% -15% auto -15%;
  height: 90vh;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(55% 60% at 18% 18%, rgba(249, 115, 22, 0.32), transparent 70%),
    radial-gradient(50% 55% at 80% 10%, rgba(83, 157, 245, 0.2), transparent 70%),
    radial-gradient(40% 50% at 50% 0%, rgba(217, 70, 239, 0.14), transparent 75%);
  will-change: transform;
  transform: translateZ(0);
  animation: aurora-drift 22s ease-in-out infinite alternate;
}

/* Static film grain so flat backgrounds don't read as plastic. Paint only. */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.06;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.6 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

@keyframes aurora-drift {
  0% { transform: translate3d(-3%, -1%, 0) scale(1); }
  50% { transform: translate3d(3%, 2%, 0) scale(1.08); }
  100% { transform: translate3d(-1%, 3%, 0) scale(1.04); }
}

.app-shell {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main {
  flex: 1;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--surface-4) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 9999px;
  border: 2px solid var(--bg);
}
*::-webkit-scrollbar-thumb:hover { background: var(--surface-4); }

::selection { background: var(--accent); color: #000; }

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

img { -webkit-user-drag: none; user-select: none; }

h1, h2, h3, h4 { margin: 0; line-height: 1.15; letter-spacing: -0.02em; }
p { margin: 0; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

input, select, textarea { font: inherit; }

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

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

/* Thin gradient hairline at the very top — the brand line. */
.top-hairline {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 2px;
  z-index: 50;
  pointer-events: none;
  background: linear-gradient(90deg, transparent 0%, rgba(249,115,22,0.7) 25%,
    rgba(217,70,239,0.5) 50%, rgba(83,157,245,0.6) 75%, transparent 100%);
  box-shadow: 0 0 12px rgba(249, 115, 22, 0.3);
}

/* ===== typography helpers ================================================ */

.text-muted { color: var(--fg-muted); }
.text-dim { color: var(--fg-dim); }
.text-accent { color: var(--accent); }
.text-danger { color: var(--danger); }
.tnum { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); }

.clamp-1, .clamp-2, .clamp-3 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.clamp-1 { -webkit-line-clamp: 1; }
.clamp-2 { -webkit-line-clamp: 2; }
.clamp-3 { -webkit-line-clamp: 3; }

/* Decorative gradient underline beneath a page heading. */
.heading-ornament {
  position: relative;
  display: inline-block;
  padding-bottom: 0.7rem;
  font-size: clamp(1.75rem, 4vw, 2.25rem);
  font-weight: 800;
}
.heading-ornament::after {
  content: "";
  position: absolute;
  left: 0; bottom: 0;
  height: 4px; width: 7rem;
  border-radius: 9999px;
  background: linear-gradient(90deg, var(--accent) 0%, rgba(249,115,22,0.6) 50%,
    rgba(83,157,245,0.35) 90%, transparent 100%);
  box-shadow: 0 0 14px rgba(249,115,22,0.55), 0 0 4px rgba(249,115,22,0.4);
  transform-origin: left center;
  animation: ornament-draw 720ms cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes ornament-draw {
  from { transform: scaleX(0); opacity: 0; }
  to { transform: scaleX(1); opacity: 1; }
}

.page-sub {
  margin-top: 0.25rem;
  font-size: 0.875rem;
  color: var(--fg-dim);
}

/* ===== layout ============================================================ */

.container {
  margin-inline: auto;
  max-width: 80rem;
  padding-inline: 1rem;
}
@media (min-width: 640px) { .container { padding-inline: 1.5rem; } }
@media (min-width: 1024px) { .container { padding-inline: 2rem; } }

.container-narrow {
  margin-inline: auto;
  max-width: 48rem;
  padding-inline: 1rem;
}

.page {
  padding-block: 1.5rem 7rem;
}
@media (min-width: 640px) { .page { padding-block: 2.5rem 7rem; } }

.site-footer {
  margin-top: 4rem;
  border-top: 1px solid var(--border);
  padding: 2rem 0;
  font-size: 0.75rem;
  color: var(--fg-dim);
  text-align: center;
  margin-bottom: 4rem;
}
@media (min-width: 768px) { .site-footer { margin-bottom: 0; } }

.row { display: flex; align-items: center; gap: 0.5rem; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 0.75rem; }
.spacer { flex: 1; }

/* ===== header ============================================================ */

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  backdrop-filter: blur(12px);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  border-bottom: 1px solid var(--border);
  transition: transform 240ms ease;
  will-change: transform;
}
.site-header .container {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
@media (min-width: 640px) { .site-header .container { gap: 1.5rem; } }

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}
.brand-mark {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 1.125rem;
  background: var(--accent);
  color: #0a0a0a;
}
.brand-name {
  display: none;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-size: 1.05rem;
}
@media (min-width: 640px) { .brand-name { display: block; } }

.search-form { flex: 1; max-width: 36rem; }
.search-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface-2);
  border-radius: var(--radius-pill);
  padding-inline: 1rem;
  height: 2.5rem;
  border: 1px solid transparent;
  transition: border-color 140ms ease;
}
.search-field:focus-within { border-color: var(--border-strong); }
.search-field input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: inherit;
  font-size: 0.875rem;
}
.search-field input::placeholder { color: var(--fg-dim); }

.search-field-lg {
  height: 3.5rem;
  border-radius: 1rem;
  padding-inline: 1.25rem;
  border-color: var(--border);
  gap: 0.75rem;
}
.search-field-lg input { font-size: 1rem; }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-pill);
  font-weight: 600;
  font-size: 0.875rem;
  white-space: nowrap;
  transition: background 120ms ease, color 120ms ease, transform 120ms ease,
    border-color 120ms ease;
}
.btn:active { transform: scale(0.96); }
.btn[disabled], .btn[aria-disabled="true"] {
  opacity: 0.5;
  pointer-events: none;
}

.btn-accent { background: var(--accent); color: #0a0a0a; }
.btn-accent:hover { background: var(--accent-hover); }

.btn-ghost { background: transparent; color: var(--fg-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--fg); }

.btn-outline {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border-strong);
}
.btn-outline:hover { border-color: var(--fg); }

.btn-danger { background: var(--danger); color: #fff; }

.btn-icon { padding: 0.5rem; }

.link-quiet {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--fg-dim);
}
.link-quiet:hover { color: var(--fg); }

.icon { width: 1rem; height: 1rem; flex-shrink: 0; }
.icon-sm { width: 0.75rem; height: 0.75rem; flex-shrink: 0; }
.icon-lg { width: 1.25rem; height: 1.25rem; flex-shrink: 0; }
.icon-xl { width: 3rem; height: 3rem; }

/* ===== surfaces ========================================================== */

.card {
  background: var(--surface-1);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}
.card-bordered { border: 1px solid var(--border); }

.card-interactive {
  display: block;
  transition: background 160ms ease, transform 220ms cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 220ms ease;
}
.card-interactive:hover {
  background: var(--surface-2);
  box-shadow: var(--shadow-elevated);
  transform: translateY(-2px);
}
.card-interactive:active {
  transform: translateY(0) scale(0.985);
  transition-duration: 90ms;
}
.card-interactive .card-cover { transition: transform 420ms cubic-bezier(0.22, 1, 0.36, 1); }
.card-interactive:hover .card-cover { transform: scale(1.045); }

.elevated { box-shadow: var(--shadow-elevated); }

.card-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-dim);
}
.card-body { padding: 1rem; display: flex; flex-direction: column; gap: 1.25rem; }

.pulse-dot { position: relative; display: inline-block; width: 0.5rem; height: 0.5rem;
  border-radius: 9999px; background: var(--accent); }
.pulse-dot::before, .pulse-dot::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 9999px;
  background: var(--accent);
  pointer-events: none;
  will-change: transform, opacity;
  animation: pulse-ring 2s cubic-bezier(0.22, 1, 0.36, 1) infinite;
}
.pulse-dot::after { animation-delay: 1s; }
@keyframes pulse-ring {
  0% { transform: scale(0.9); opacity: 0.75; }
  80%, 100% { transform: scale(2.6); opacity: 0; }
}

.source-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--fg);
  transition: background 120ms ease, border-color 120ms ease;
}
.source-chip:hover { background: var(--surface-3); border-color: var(--border-strong); }
.source-chip strong { font-size: 1rem; font-weight: 700; }

.badge {
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--fg-muted);
}

/* ===== grid + cards ====================================================== */

.komik-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
@media (min-width: 640px) { .komik-grid { gap: 1rem; } }

.komik-grid-sm { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }

.komik-card { padding: 0.75rem; }
.komik-card .card-cover {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: 0.5rem;
  overflow: hidden;
  background: var(--surface-3);
  margin-bottom: 0.75rem;
}
.komik-card h3 {
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.35;
}
.komik-card .card-meta {
  margin-top: 0.25rem;
  font-size: 0.6875rem;
  color: var(--fg-dim);
}

.cover-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  text-align: center;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-dim);
  background: linear-gradient(135deg, var(--surface-2), var(--surface-3));
}

.cover-tag {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.cover-cluster {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.nsfw-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 9999px;
  background: var(--danger);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.55);
}

.bookmark-pin {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 9999px;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  color: var(--accent);
}

.chapter-badge {
  position: absolute;
  bottom: 0.5rem;
  right: 0.5rem;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--accent);
  color: #0a0a0a;
  max-width: calc(100% - 1rem);
}
.chapter-badge span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-strip {
  position: absolute;
  left: 0.25rem;
  right: 0.25rem;
  bottom: 0.25rem;
  height: 4px;
  border-radius: 9999px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.6);
}
.progress-strip > i { display: block; height: 100%; background: var(--accent); }

/* Lazy image: reserve space so the grid doesn't reflow as covers arrive. */
.lazy-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: var(--surface-3);
}
.lazy-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 260ms ease;
}
.lazy-img img.is-loaded { opacity: 1; }
.lazy-img.is-broken::after {
  content: "image unavailable";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: var(--fg-dim);
}

/* ===== skeletons ========================================================= */

.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--surface-2);
  border-radius: var(--radius-card);
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.04), transparent);
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }
.skeleton-card { padding: 0.75rem; }
.skeleton-cover { aspect-ratio: 2 / 3; border-radius: 0.5rem; }
.skeleton-line { height: 0.7rem; border-radius: 4px; margin-top: 0.6rem; }
.skeleton-line.short { width: 60%; }

/* htmx paints this while a request is in flight. */
.htmx-indicator { opacity: 0; transition: opacity 160ms ease; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { opacity: 1; }

/* ===== empty + error states ============================================= */

.empty-state {
  margin-inline: auto;
  max-width: 28rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 4rem 1.5rem;
}
.empty-state .icon-xl { color: var(--fg-muted); opacity: 0.55; margin-bottom: 1rem; }
.empty-state h2 { font-size: 1.125rem; font-weight: 700; }
.empty-state p { margin-top: 0.375rem; font-size: 0.875rem; color: var(--fg-dim); }
.empty-state .btn { margin-top: 1.25rem; }

.alert {
  border-radius: var(--radius-card);
  border: 1px solid var(--border);
  padding: 0.75rem 1rem;
  font-size: 0.8125rem;
  margin-bottom: 1rem;
}
.alert-danger { color: var(--danger); background: rgba(243, 114, 127, 0.08); }

.error-shell {
  min-height: calc(100vh - var(--header-h) - 4rem);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 4rem 1.5rem;
  margin-inline: auto;
  max-width: 48rem;
}
.error-code {
  font-size: clamp(7rem, 22vw, 11rem);
  font-weight: 900;
  line-height: 0.9;
  letter-spacing: -0.04em;
  background: linear-gradient(180deg, var(--fg) 0%, var(--fg-dim) 55%, transparent 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.error-eyebrow {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-weight: 600;
  color: var(--fg-dim);
}
.error-shell h1 { margin-top: 0.75rem; font-size: clamp(1.5rem, 4vw, 2.25rem); font-weight: 800; }
.error-shell > p { margin-top: 1rem; max-width: 28rem; font-size: 0.95rem;
  color: var(--fg-muted); line-height: 1.6; }
.error-icon { color: var(--accent); opacity: 0.85; margin: 0.5rem 0 1.25rem; }
.error-detail {
  display: inline-flex;
  margin-top: 1.5rem;
  padding: 0.6rem 0.9rem;
  border-radius: 10px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  max-width: 100%;
}
.error-detail code {
  font-size: 0.75rem;
  color: var(--fg-muted);
  font-family: var(--font-mono);
  word-break: break-word;
  text-align: left;
}
.error-actions { margin-top: 2rem; display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; }
.error-links {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
  width: 100%;
  max-width: 28rem;
}
@media (min-width: 640px) { .error-links { grid-template-columns: repeat(3, 1fr); } }
.quick-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1rem;
  border-radius: 10px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  color: var(--fg-muted);
  font-size: 0.875rem;
  font-weight: 600;
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease,
    transform 140ms ease;
}
.quick-link:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
  color: var(--fg);
  transform: translateY(-1px);
}
.quick-link svg { color: var(--accent); }

/* ===== bottom nav (mobile) ============================================== */

.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 35;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom, 0);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
@media (min-width: 768px) { .bottom-nav { display: none; } }
html.in-reader .bottom-nav { display: none; }

.bn-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  padding: 0.6rem 0.25rem 0.5rem;
  color: var(--fg-muted);
  font-size: 0.65rem;
  font-weight: 600;
  transition: color 140ms ease;
}
.bn-item:hover { color: var(--fg); }
.bn-item[aria-current="page"] { color: var(--accent); }
.bn-icon { position: relative; display: inline-flex; }
.bn-badge {
  position: absolute;
  top: -4px; right: -10px;
  min-width: 1rem; height: 1rem;
  padding: 0 0.25rem;
  border-radius: 9999px;
  background: var(--accent);
  color: #0a0a0a;
  font-size: 0.55rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ===== source picker ==================================================== */

.picker-anchor { position: relative; flex-shrink: 0; }
.picker-scrim { position: fixed; inset: 0; z-index: 44; background: transparent; }
.source-picker {
  position: absolute;
  right: 0;
  top: calc(100% + 0.5rem);
  z-index: 45;
  width: min(24rem, calc(100vw - 2rem));
  max-height: min(28rem, calc(100vh - 6rem));
  overflow-y: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 1rem;
  box-shadow: var(--shadow-elevated);
  padding: 0.5rem;
}
.picker-section {
  padding: 0.5rem 0.65rem 0.25rem;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--fg-dim);
}
.picker-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.55rem 0.65rem;
  border-radius: 0.6rem;
  text-align: left;
  transition: background 120ms ease;
}
.picker-item:hover { background: var(--surface-3); }
.picker-item[aria-current="true"] { background: var(--accent-soft); color: var(--accent); }
.picker-item .picker-name { flex: 1; font-size: 0.875rem; font-weight: 600; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-lang {
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--fg-dim);
}
.picker-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem;
  margin-top: 0.25rem;
  border-top: 1px solid var(--border);
  font-size: 0.8125rem;
}

/* ===== pagination rail ================================================== */

.pagination-rail {
  position: fixed;
  bottom: 4.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.5rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-elevated);
}
@media (min-width: 768px) { .pagination-rail { bottom: 1rem; } }
.page-indicator {
  padding-inline: 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--fg-muted);
  min-width: 3.5rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.btn-label { display: none; }
@media (min-width: 640px) { .btn-label { display: inline; } }

/* ===== continue-reading rail ============================================ */

.continue-rail {
  display: flex;
  gap: 0.75rem;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  padding-bottom: 0.5rem;
}
.continue-rail::-webkit-scrollbar { height: 6px; }
.continue-rail::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; }
.continue-card { scroll-snap-align: start; padding: 0.5rem; flex-shrink: 0; }
.continue-card .card-cover {
  position: relative;
  width: 8rem;
  aspect-ratio: 2 / 3;
  border-radius: 0.5rem;
  overflow: hidden;
  background: var(--surface-3);
}
@media (min-width: 640px) { .continue-card .card-cover { width: 9rem; } }
.continue-card .card-text { margin-top: 0.5rem; width: 8rem; }
@media (min-width: 640px) { .continue-card .card-text { width: 9rem; } }
.continue-card h3 { font-size: 0.75rem; font-weight: 600; }
.continue-card p { margin-top: 0.15rem; font-size: 0.6875rem; color: var(--fg-dim); }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  gap: 0.75rem;
}
.section-head h2 { font-size: 1.125rem; font-weight: 700; }
@media (min-width: 640px) { .section-head h2 { font-size: 1.25rem; } }

/* ===== detail (show) page =============================================== */

.hero { position: relative; }
.hero-backdrop {
  position: absolute;
  inset: 0 0 auto 0;
  height: 320px;
  overflow: hidden;
  z-index: -1;
}
.hero-backdrop img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.1);
  filter: blur(40px) brightness(0.4);
}
.hero-backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, transparent 0%, var(--bg) 100%);
}
.hero-body {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding-top: 2rem;
}
@media (min-width: 640px) {
  .hero-body { flex-direction: row; gap: 2rem; padding-top: 3rem; }
}
.hero-cover {
  position: relative;
  width: 11rem;
  aspect-ratio: 2 / 3;
  border-radius: 1rem;
  overflow: hidden;
  background: var(--surface-3);
  box-shadow: var(--shadow-elevated);
  flex-shrink: 0;
  margin-inline: auto;
}
@media (min-width: 640px) { .hero-cover { width: 14rem; margin-inline: 0; } }
.hero-main { flex: 1; min-width: 0; }
.hero-kicker {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-dim);
  margin-bottom: 0.5rem;
}
.hero-main h1 { font-size: clamp(1.75rem, 5vw, 3rem); font-weight: 800; }
.hero-alt { margin-top: 0.5rem; font-size: 0.875rem; color: var(--fg-muted); }
.hero-author { margin-top: 0.75rem; font-size: 0.875rem; }
.genre-row { display: flex; flex-wrap: wrap; gap: 0.375rem; margin-top: 1rem; }
.genre-tag {
  font-size: 0.75rem;
  padding: 0.25rem 0.625rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--fg-muted);
  transition: color 120ms ease, border-color 120ms ease;
}
.genre-tag:hover { color: var(--fg); border-color: var(--border-strong); }
.hero-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1.5rem; }

.synopsis { margin-top: 2rem; max-width: 48rem; }
.synopsis h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-dim);
  margin-bottom: 0.5rem;
}
.synopsis p {
  font-size: 0.875rem;
  line-height: 1.7;
  color: var(--fg-muted);
  white-space: pre-line;
}
/* Progressive disclosure with no JS: the checkbox drives the clamp. */
.synopsis input { position: absolute; opacity: 0; pointer-events: none; }
.synopsis input:not(:checked) ~ p {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.synopsis label {
  display: inline-block;
  margin-top: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
}
.synopsis input:not(:checked) ~ label .less,
.synopsis input:checked ~ label .more { display: none; }

.chapter-list { border-radius: var(--radius-card); overflow: hidden; }
.chapter-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  transition: background 120ms ease;
}
.chapter-row:last-child { border-bottom: none; }
.chapter-row:hover { background: var(--surface-2); }
.chapter-num {
  font-size: 0.75rem;
  color: var(--fg-dim);
  width: 2.5rem;
  text-align: right;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.chapter-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 9999px;
  background: var(--accent);
  flex-shrink: 0;
}
.chapter-title {
  flex: 1;
  min-width: 0;
  font-size: 0.875rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chapter-date { font-size: 0.75rem; color: var(--fg-dim); flex-shrink: 0; }
.chapter-row.is-read { opacity: 0.55; }
.chapter-row.is-read:hover { opacity: 0.85; }
.chapter-row.is-read .chapter-dot { background: transparent; border: 1px solid var(--border); }
.chapter-row.is-current { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.chapter-now {
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--accent);
  color: #0a0a0a;
  flex-shrink: 0;
}

/* ===== library + settings =============================================== */

.tabs {
  display: inline-flex;
  gap: 0.25rem;
  padding: 0.25rem;
  border-radius: 999px;
  background: var(--surface-2);
  margin-bottom: 1.5rem;
}

.history-list { border-radius: var(--radius-card); overflow: hidden; }
.history-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
}
.history-row:last-child { border-bottom: none; }
.history-row:hover { background: var(--surface-2); }
.history-thumb {
  position: relative;
  width: 3rem;
  height: 4rem;
  border-radius: 0.375rem;
  overflow: hidden;
  background: var(--surface-3);
  flex-shrink: 0;
}
.history-main { flex: 1; min-width: 0; }
.history-main h3 { font-size: 0.875rem; font-weight: 600; }
.history-main p { margin-top: 0.15rem; font-size: 0.75rem; color: var(--fg-dim); }
.history-bar {
  margin-top: 0.375rem;
  height: 4px;
  width: 100%;
  max-width: 10rem;
  border-radius: 9999px;
  overflow: hidden;
  background: var(--surface-3);
}
.history-bar > i { display: block; height: 100%; background: var(--accent); }

.library-remove {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 9999px;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  color: #fff;
  opacity: 0;
  transition: opacity 160ms ease;
}
.card-interactive:hover .library-remove,
.library-remove:focus-visible { opacity: 1; }
.library-remove:hover { background: var(--danger); }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.setting-row strong { display: block; font-size: 0.875rem; font-weight: 600; }
.setting-row small { display: block; font-size: 0.75rem; color: var(--fg-dim); }

.tile-row { display: grid; gap: 0.5rem; grid-template-columns: 1fr; }
@media (min-width: 640px) { .tile-row { grid-template-columns: repeat(3, 1fr); } }
.tile {
  padding: 0.75rem;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface-1);
  transition: border-color 140ms ease, background 140ms ease;
}
.tile:hover { border-color: var(--border-strong); }
.tile strong { display: block; font-size: 0.875rem; font-weight: 600; }
.tile small { display: block; margin-top: 0.15rem; font-size: 0.75rem; color: var(--fg-dim); }
.tile[aria-pressed="true"] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

input[type="range"] { accent-color: var(--accent); width: 100%; }
input[type="checkbox"] { width: 1.25rem; height: 1.25rem; accent-color: var(--accent); }

.switch {
  position: relative;
  width: 2.25rem;
  height: 1.25rem;
  border-radius: 9999px;
  background: var(--surface-3);
  transition: background 160ms ease;
  flex-shrink: 0;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: calc(1.25rem - 4px);
  height: calc(1.25rem - 4px);
  border-radius: 9999px;
  background: var(--fg);
  transition: transform 160ms ease;
}
.switch[data-on="true"] { background: var(--accent); }
.switch[data-on="true"]::after { transform: translateX(1rem); background: #0a0a0a; }

/* ===== search =========================================================== */

.filter-panel { border: 1px solid var(--border); border-radius: var(--radius-card);
  background: var(--surface-1); margin-bottom: 1.5rem; }
.filter-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
.filter-summary::-webkit-details-marker { display: none; }
.filter-summary .chev { transition: transform 160ms ease; }
details[open] .filter-summary .chev { transform: rotate(180deg); }
.filter-body {
  padding: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.filter-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-dim);
  margin-bottom: 0.5rem;
}
.chip-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.search-tabs { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1rem; }
.tab-count {
  font-size: 0.625rem;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.25);
  font-variant-numeric: tabular-nums;
}
.load-more { display: flex; align-items: center; justify-content: center;
  min-height: 5rem; margin-top: 1.5rem; }

/* ===== reader =========================================================== */

html.in-reader .site-footer { display: none; }
html.in-reader body::before,
html.in-reader body::after,
html.in-reader .top-hairline { display: none; }
html.in-reader.controls-hidden .site-header { transform: translateY(-100%); }

.reader-progress {
  position: fixed;
  top: var(--header-h);
  left: 0; right: 0;
  z-index: 40;
  pointer-events: none;
  transition: top 240ms ease;
  will-change: top;
}
html.controls-hidden .reader-progress { top: 0; }
.reader-progress-bar {
  height: 3px;
  background: var(--accent);
  transition: width 120ms linear;
}
.reader-progress-label {
  font-size: 0.7rem;
  padding: 0.25rem 0.75rem;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}
.reader-progress-label .title {
  max-width: 60vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}
html.in-reader:fullscreen .reader-progress { display: none; }

.reader-stream {
  padding-bottom: 6rem;
  padding-top: 2rem;
  cursor: pointer;
  filter: brightness(var(--reader-brightness, 1));
  transition: filter 160ms ease;
}
.chapter-panel + .chapter-panel { margin-top: 2rem; }
.chapter-panel { overflow-anchor: auto; }
.chapter-pages { display: flex; flex-direction: column; }
.reader-stream[data-mode="long-strip"] .chapter-pages {
  max-width: 48rem;
  margin-inline: auto;
}
.reader-stream[data-mode="fit-width"] .chapter-pages { width: 100%; }
.chapter-page { position: relative; }
/* Reserve height so the sliding window can't collapse the scroll position
   out from under the reader while a page is still loading. */
.chapter-page .lazy-img {
  position: relative;
  inset: auto;
  min-height: 60vh;
  height: auto;
  display: block;
}
.chapter-page .lazy-img img {
  width: 100%;
  height: auto;
  object-fit: contain;
  display: block;
}
.reader-stream[data-mode="paged"] .chapter-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  scroll-snap-align: start;
}
.reader-stream[data-mode="paged"] .chapter-page .lazy-img {
  min-height: 0;
  max-height: 100vh;
  background: transparent;
}
.reader-stream[data-mode="paged"] .chapter-page img {
  max-height: 100vh;
  width: auto;
  object-fit: contain;
}
.reader-status { padding: 3rem 0; text-align: center; }
.reader-status .stack { align-items: center; }
.prefetch-sentinel { height: 1px; overflow-anchor: none; }
.reader-status { overflow-anchor: none; }

.reader-rail {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.5rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-elevated);
  transition: transform 240ms ease, opacity 200ms ease;
  will-change: transform, opacity;
}
html.controls-hidden .reader-rail {
  transform: translate(-50%, calc(100% + 1rem));
  opacity: 0;
  pointer-events: none;
}
.reader-rail .is-active { color: var(--accent); }

.scroll-top-fab {
  position: fixed;
  right: 1rem;
  bottom: 5rem;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 9999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-elevated);
  color: var(--fg);
  transition: opacity 200ms ease, transform 200ms ease;
}
@media (min-width: 640px) { .scroll-top-fab { right: 1.5rem; bottom: 1.5rem; } }
.scroll-top-fab:hover { color: var(--accent); }
.scroll-top-fab[hidden] { display: none; }
html.controls-hidden .scroll-top-fab,
.scroll-top-fab.is-hidden { opacity: 0; transform: translateY(8px); pointer-events: none; }

/* ===== dialogs (settings popover, chapter sheet, image menu) ============= */

dialog {
  border: none;
  padding: 0;
  background: transparent;
  color: inherit;
  max-width: 100vw;
  max-height: 100vh;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(2px); }

.reader-settings {
  width: min(360px, calc(100vw - 2rem));
  padding: 1rem;
  border-radius: 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-elevated);
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  margin: auto auto 5rem;
}
.settings-section { display: flex; flex-direction: column; gap: 0.5rem; }
.settings-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-muted);
  font-weight: 600;
}
.settings-footer {
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
  font-size: 0.65rem;
  color: var(--fg-dim);
  line-height: 1.5;
}

.chapter-sheet {
  width: min(30rem, 100vw);
  height: 100vh;
  max-height: 100vh;
  margin: 0 0 0 auto;
  background: var(--surface-1);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.chapter-sheet header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}
.chapter-sheet h2 { font-size: 1rem; font-weight: 700; }
.chapter-sheet .sheet-body { flex: 1; overflow-y: auto; }

.img-menu {
  position: fixed;
  z-index: 61;
  min-width: 200px;
  padding: 0.35rem;
  border-radius: 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-elevated);
  display: flex;
  flex-direction: column;
}
.img-menu[hidden] { display: none; }
.img-menu-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.65rem;
  border-radius: 0.5rem;
  font-size: 0.85rem;
  font-weight: 500;
  text-align: left;
}
.img-menu-item:hover { background: var(--surface-3); }

/* ===== tooltip ========================================================== */

.tooltip-floating {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
  display: none;
  padding: 4px 8px;
  background: var(--surface-3);
  color: var(--fg);
  border: 1px solid var(--border);
  font-size: 11px;
  line-height: 1.3;
  font-weight: 500;
  border-radius: 6px;
  white-space: nowrap;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35), 0 2px 6px rgba(0, 0, 0, 0.2);
  max-width: 280px;
  transition: opacity 90ms ease;
}
.tooltip-floating.is-visible { display: block; }

/* ===== toast ============================================================ */

.toast {
  position: fixed;
  left: 50%;
  bottom: 6rem;
  transform: translateX(-50%);
  z-index: 70;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-elevated);
  font-size: 0.8125rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, -0.5rem); }

/* ===== reduced motion =================================================== */

@media (prefers-reduced-motion: reduce) {
  body::before { animation: none; }
  .heading-ornament::after { animation: none; }
  .pulse-dot::before, .pulse-dot::after { animation: none; opacity: 0; }
  .skeleton::after { animation: none; }
}
/* The in-app override mirrors the OS preference so the setting has teeth
   even when the OS says nothing. */
html[data-reduce-motion="true"] *,
html[data-reduce-motion="true"] *::before,
html[data-reduce-motion="true"] *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
  scroll-behavior: auto !important;
}

/* ── Search page ─────────────────────────────────────────────────────────── */

.search-hero {
  position: relative;
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-top: 1.25rem;
}
.search-hero .search-field { flex: 1; }
.quoted { font-weight: 600; color: var(--fg); }

.alert-warn {
  color: #f0b429;
  background: rgba(240, 180, 41, 0.07);
  border-color: rgba(240, 180, 41, 0.25);
}
.alert-warn summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-weight: 600;
  list-style: none;
}
.alert-warn summary::-webkit-details-marker { display: none; }
.error-list {
  margin: 0.75rem 0 0;
  padding-left: 0;
  list-style: none;
  display: grid;
  gap: 0.375rem;
  font-size: 0.8125rem;
  color: var(--fg-muted);
}

.filter-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0.875rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-dim);
}
.filter-foot {
  padding: 0.625rem 0.875rem;
  border-top: 1px solid var(--border);
}
.filter-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.875rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.filter-item:hover { background: var(--surface-3); }
.filter-item .picker-name {
  flex: 1;
  font-size: 0.875rem;
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Library ─────────────────────────────────────────────────────────────── */

.tab-rail {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin: 1.25rem 0 1rem;
  border-bottom: 1px solid var(--border);
}
.tab-spacer { flex: 1; }
.tab {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 0.875rem;
  margin-bottom: -1px;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--fg-muted);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 160ms ease, border-color 160ms ease;
}
.tab:hover { color: var(--fg); }
.tab[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); }

.library-list { display: grid; gap: 0.5rem; }
.library-item {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface-1);
  transition: border-color 200ms ease, background 200ms ease, opacity 200ms ease;
}
.library-item:hover { border-color: var(--border-strong); background: var(--surface-2); }
.library-item.htmx-swapping { opacity: 0; transform: translateX(-0.5rem); }
.library-link {
  display: flex;
  flex: 1;
  gap: 0.875rem;
  min-width: 0;
  align-items: center;
}
.library-cover {
  position: relative;
  width: 3.5rem;
  aspect-ratio: 3 / 4;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-3);
}
.library-text { min-width: 0; flex: 1; }
.library-text h3 { font-size: 0.9375rem; font-weight: 600; }
.library-text .card-meta { margin-top: 0.15rem; font-size: 0.75rem; color: var(--fg-muted); }
.library-text .card-meta.text-dim { color: var(--fg-dim); }
.library-actions { display: flex; align-items: center; gap: 0.125rem; flex-shrink: 0; }

/* ── Settings ────────────────────────────────────────────────────────────── */

.settings-page { max-width: 44rem; }
.settings-card { padding: 1.25rem; margin-top: 1.25rem; }
.settings-card > h2 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1rem;
  font-weight: 700;
}
.settings-card > h2 .icon { color: var(--accent); }
.setting-block { margin-top: 1.25rem; }
.setting-hint { margin-top: 0.375rem; font-size: 0.75rem; color: var(--fg-dim); line-height: 1.5; }
.setting-text { display: grid; gap: 0.125rem; min-width: 0; }
.setting-text .setting-hint { margin-top: 0; }

.option-list { display: grid; gap: 0.5rem; margin-top: 0.625rem; }
.option {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.25rem 0.75rem;
  padding: 0.75rem 0.875rem;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease;
}
.option:hover { border-color: var(--border-strong); }
.option.is-selected { border-color: var(--accent); background: var(--accent-soft); }
.option-main { font-size: 0.875rem; font-weight: 600; }
.option-hint { grid-column: 1; font-size: 0.75rem; color: var(--fg-dim); }
.option .icon { grid-row: 1 / span 2; }

.select {
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--fg);
  font: inherit;
  font-size: 0.875rem;
}
.select:focus { outline: none; border-color: var(--accent); }

.stat-row { display: flex; gap: 2rem; margin-top: 1rem; }
.stat { display: grid; gap: 0.125rem; }
.stat strong { font-size: 1.5rem; font-weight: 800; line-height: 1; }
.stat span { font-size: 0.75rem; color: var(--fg-dim); }

.about-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem 1.25rem;
  margin-top: 1rem;
  font-size: 0.875rem;
}
.about-list dt { color: var(--fg-dim); }
.about-list dd { text-align: right; font-weight: 600; }

/* ── Error surfaces ──────────────────────────────────────────────────────── */

.error-page {
  max-width: 34rem;
  padding-block: 4rem 5rem;
  text-align: center;
}
.error-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 4.5rem;
  height: 4.5rem;
  margin-bottom: 1.25rem;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--fg-muted);
}
.error-page h1 { font-size: 1.5rem; font-weight: 800; }
.error-hint {
  margin-top: 0.75rem;
  font-size: 0.9375rem;
  line-height: 1.65;
  color: var(--fg-muted);
}
.error-page .error-detail { margin-top: 1.5rem; text-align: left; }
.error-page pre {
  margin-top: 0.5rem;
  padding: 0.75rem;
  overflow-x: auto;
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--fg-dim);
}

.error-inline {
  display: grid;
  gap: 0.5rem;
  justify-items: start;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface-1);
}
.error-inline p { font-size: 0.875rem; color: var(--fg-muted); line-height: 1.6; }
.error-inline .error-raw { font-size: 0.75rem; color: var(--fg-dim); word-break: break-word; }
