/* JM Reader — modern reading product, dual theme (indigo accent) */

:root {
  /* Structural tokens (shared) */
  --radius: 12px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --font: "Inter", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --topbar-h: 3.5rem;
  --page-pad-x: 1rem;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --touch: 44px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --z-topbar: 30;
  --z-reader-chrome: 25;
  --z-loading: 40;
  --z-overlay: 50;
  --z-toast: 60;
  --theme-color: #0b0c10;
}

/* ── Dark theme (default) ── */
:root,
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0c10;
  --bg-elevated: #14151c;
  --bg-soft: #1c1e28;
  --surface: rgba(255, 255, 255, 0.04);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f4f4f5;
  --muted: #9ca3af;
  --muted-2: #6b7280;
  --primary: #6366f1;
  --primary-ink: #ffffff;
  --primary-soft: rgba(99, 102, 241, 0.16);
  --primary-ring: rgba(99, 102, 241, 0.35);
  --primary-shadow: 0 8px 22px rgba(99, 102, 241, 0.28);
  --danger: #f87171;
  --success: #34d399;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
  --topbar-bg: rgba(11, 12, 16, 0.82);
  --reader-chrome-from: rgba(11, 12, 16, 0.94);
  --reader-chrome-mid: rgba(11, 12, 16, 0.72);
  --overlay-scrim: rgba(0, 0, 0, 0.68);
  --loading-scrim: rgba(11, 12, 16, 0.55);
  --body-glow-a: rgba(99, 102, 241, 0.1);
  --body-glow-b: rgba(14, 165, 233, 0.06);
  --hero-wash: rgba(255, 255, 255, 0.03);
  --theme-color: #0b0c10;
}

/* ── Light theme ── */
[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f7fb;
  --bg-elevated: #ffffff;
  --bg-soft: #eef0f6;
  --surface: rgba(15, 23, 42, 0.03);
  --border: rgba(15, 23, 42, 0.1);
  --border-strong: rgba(15, 23, 42, 0.16);
  --text: #0f172a;
  --muted: #64748b;
  --muted-2: #94a3b8;
  --primary: #4f46e5;
  --primary-ink: #ffffff;
  --primary-soft: rgba(79, 70, 229, 0.12);
  --primary-ring: rgba(79, 70, 229, 0.28);
  --primary-shadow: 0 8px 22px rgba(79, 70, 229, 0.22);
  --danger: #dc2626;
  --success: #059669;
  --shadow: 0 14px 36px rgba(15, 23, 42, 0.1);
  --topbar-bg: rgba(246, 247, 251, 0.86);
  --reader-chrome-from: rgba(246, 247, 251, 0.96);
  --reader-chrome-mid: rgba(246, 247, 251, 0.78);
  --overlay-scrim: rgba(15, 23, 42, 0.42);
  --loading-scrim: rgba(246, 247, 251, 0.62);
  --body-glow-a: rgba(79, 70, 229, 0.08);
  --body-glow-b: rgba(14, 165, 233, 0.05);
  --hero-wash: rgba(79, 70, 229, 0.04);
  --theme-color: #f6f7fb;
}

/* ── Reader letterbox (independent of shell theme) ── */
html[data-reader-bg="dark"] {
  --reader-page-bg: #000000;
  --reader-placeholder-a: #111111;
  --reader-placeholder-b: #1a1a1a;
  --reader-error-bg: #0d0d0d;
  --page-label-bg: rgba(0, 0, 0, 0.58);
  --page-label-fg: #ffffff;
}

html[data-reader-bg="light"] {
  --reader-page-bg: #f1f5f9;
  --reader-placeholder-a: #e2e8f0;
  --reader-placeholder-b: #f8fafc;
  --reader-error-bg: #e2e8f0;
  --page-label-bg: rgba(15, 23, 42, 0.55);
  --page-label-fg: #ffffff;
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  touch-action: manipulation;
  overscroll-behavior-y: contain;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
  background:
    radial-gradient(880px 400px at 10% -12%, var(--body-glow-a), transparent 55%),
    radial-gradient(720px 340px at 92% 0%, var(--body-glow-b), transparent 50%),
    var(--bg);
}

img,
canvas {
  max-width: 100%;
  height: auto;
}

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

a {
  color: var(--primary);
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: var(--bg-soft);
  padding: 0.12em 0.4em;
  border-radius: 6px;
  border: 1px solid var(--border);
}

:focus-visible {
  outline: 2px solid var(--primary);
  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;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -100px;
  z-index: 100;
  background: var(--primary);
  color: var(--primary-ink);
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  text-decoration: none;
}

.skip-link:focus {
  top: calc(0.75rem + var(--safe-top));
}

/* ── Topbar ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-height: var(--topbar-h);
  padding: calc(0.45rem + var(--safe-top)) max(0.65rem, var(--safe-right)) 0.45rem max(0.65rem, var(--safe-left));
  background: var(--topbar-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

/* Topbar stays visible in reader so Home / Settings remain reachable.
   Only .reader-chrome auto-hides for immersion. */

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.brand {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  min-width: 2rem;
  height: 1.65rem;
  padding: 0 0.4rem;
  border-radius: 8px;
  background: var(--primary);
  color: var(--primary-ink);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.brand-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
  font-size: 0.98rem;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: var(--touch);
  height: var(--touch);
  min-width: var(--touch);
  min-height: var(--touch);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.18s var(--ease), border-color 0.18s var(--ease), transform 0.12s var(--ease);
}

.icon-btn:hover {
  border-color: var(--border-strong);
  background: var(--bg-soft);
}

.icon-btn:active {
  transform: scale(0.96);
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.theme-icon-moon {
  display: none;
}

[data-theme="light"] .theme-icon-sun {
  display: none;
}

[data-theme="light"] .theme-icon-moon {
  display: block;
}

/* ── Layout ── */
main {
  max-width: 760px;
  margin: 0 auto;
  padding: 0.85rem max(var(--page-pad-x), var(--safe-right)) calc(1.75rem + var(--safe-bottom)) max(var(--page-pad-x), var(--safe-left));
}

.view[hidden] {
  display: none !important;
}

.view-reader {
  max-width: none;
  margin: 0;
  /* full-bleed reader: cancel main side padding */
  width: 100vw;
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);
  padding: 0 0 calc(1.25rem + var(--safe-bottom));
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: var(--touch);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.65rem 1rem;
  cursor: pointer;
  background: var(--bg-soft);
  color: var(--text);
  font-weight: 600;
  transition: transform 0.12s var(--ease), background 0.18s var(--ease), border-color 0.18s var(--ease), opacity 0.18s;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn.primary {
  background: var(--primary);
  color: var(--primary-ink);
  box-shadow: var(--primary-shadow);
}

.btn.primary:hover:not(:disabled) {
  filter: brightness(1.06);
}

.btn.ghost {
  background: transparent;
  border-color: var(--border);
}

.btn.ghost:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: var(--surface);
}

.btn.sm {
  min-height: 40px;
  padding: 0.4rem 0.75rem;
  border-radius: 9px;
  font-size: 0.9rem;
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ── Home ── */
.hero {
  position: relative;
  margin-top: 1.5rem;
  padding: 1.75rem 1.25rem 1.5rem;
  background: linear-gradient(180deg, var(--hero-wash), transparent 42%), var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  overflow: hidden;
  text-align: center;
}

.hero-glow {
  position: absolute;
  inset: -35% auto auto 50%;
  width: 70%;
  height: 70%;
  transform: translateX(-50%);
  background: radial-gradient(circle, var(--primary-soft), transparent 68%);
  pointer-events: none;
}

.eyebrow {
  position: relative;
  margin: 0 0 0.5rem;
  color: var(--primary);
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hero h1 {
  position: relative;
  margin: 0 0 0.45rem;
  font-size: clamp(1.65rem, 5vw, 2.05rem);
  line-height: 1.15;
  letter-spacing: -0.03em;
}

.sub {
  position: relative;
  margin: 0 auto 1.25rem;
  color: var(--muted);
  max-width: 28rem;
  font-size: 0.96rem;
}

.search-row {
  position: relative;
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
  text-align: left;
}

.search-field {
  flex: 1 1 220px;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0.9rem;
  min-height: 48px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}

.search-field:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.search-icon {
  color: var(--muted-2);
  flex-shrink: 0;
}

.search-field input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  outline: none;
  padding: 0.8rem 0;
}

.home-hint {
  position: relative;
  margin: 1rem 0 0;
  color: var(--muted-2);
  font-size: 0.86rem;
}

.error {
  color: var(--danger);
  margin: 0.8rem 0 0;
  font-size: 0.92rem;
  text-align: left;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.88rem;
}

/* ── Album ── */
.album-hero {
  margin-bottom: 0.85rem;
}

.album-meta h1 {
  margin: 0.2rem 0 0.35rem;
  font-size: clamp(1.3rem, 4vw, 1.7rem);
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.75rem 0 0.6rem;
}

.stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.28rem 0.6rem;
  border-radius: var(--radius-pill);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.8rem;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.45rem 0 0.65rem;
}

.tag {
  font-size: 0.76rem;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-pill);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--muted);
}

.desc {
  color: var(--muted);
  white-space: pre-wrap;
  max-height: 8rem;
  overflow: auto;
  margin: 0.35rem 0 0;
  font-size: 0.93rem;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 1rem 0 0.55rem;
}

.section-title h2 {
  margin: 0;
  font-size: 1.02rem;
  letter-spacing: -0.01em;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 1.55rem;
  padding: 0.12rem 0.55rem;
  border-radius: var(--radius-pill);
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 600;
}

.chapter-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.4rem;
}

@media (min-width: 768px) {
  .chapter-list {
    grid-template-columns: 1fr 1fr;
  }
}

.chapter-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-align: left;
  min-height: var(--touch);
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  cursor: pointer;
  transition: border-color 0.18s var(--ease), background 0.18s var(--ease), transform 0.12s var(--ease);
}

.chapter-item:hover {
  border-color: color-mix(in srgb, var(--primary) 45%, var(--border));
  background: color-mix(in srgb, var(--bg-elevated) 90%, var(--primary) 10%);
}

.chapter-item:active {
  transform: scale(0.99);
}

.chapter-item .sort {
  flex-shrink: 0;
  min-width: 2.25rem;
  font-size: 0.78rem;
  color: var(--muted-2);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.chapter-item .title {
  flex: 1;
  min-width: 0;
  font-size: 0.92rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Reader ── */
.reader-chrome {
  position: sticky;
  /* Sit under the always-visible topbar (safe-area already in topbar padding) */
  top: calc(var(--topbar-h) + var(--safe-top));
  z-index: var(--z-reader-chrome);
  padding-top: 0;
  background: linear-gradient(180deg, var(--reader-chrome-from), var(--reader-chrome-mid) 70%, transparent);
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
}

body.reader-active:not(.chrome-visible) .reader-chrome {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
}

.reader-toolbar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem max(0.65rem, var(--safe-right)) 0.7rem max(0.65rem, var(--safe-left));
  max-width: 960px;
  margin: 0 auto;
}

.reader-title-wrap {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.reader-title {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reader-progress {
  margin-top: 0.1rem;
}

.reader-nav {
  display: flex;
  gap: 0.35rem;
}

.reader-pages {
  display: flex;
  flex-direction: column;
  gap: 0;
  max-width: 960px;
  margin: 0 auto;
  background: var(--reader-page-bg);
}

.page-wrap {
  position: relative;
  background: var(--reader-page-bg);
  overflow: hidden;
  line-height: 0;
  min-height: 100px;
}

.page-wrap canvas,
.page-wrap img {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
  margin: 0;
  padding: 0;
  vertical-align: top;
}

.page-label {
  position: absolute;
  left: 0.5rem;
  top: 0.5rem;
  z-index: 2;
  font-size: 0.7rem;
  line-height: 1.2;
  padding: 0.2rem 0.45rem;
  border-radius: 8px;
  background: var(--page-label-bg);
  color: var(--page-label-fg);
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.page-placeholder {
  display: grid;
  place-items: center;
  min-height: 180px;
  padding: 2rem 1rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
  background: linear-gradient(
    90deg,
    var(--reader-placeholder-a) 25%,
    var(--reader-placeholder-b) 37%,
    var(--reader-placeholder-a) 63%
  );
  background-size: 400% 100%;
  animation: shimmer 1.2s ease infinite;
}

.page-error {
  display: grid;
  place-items: center;
  min-height: 140px;
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--danger);
  font-size: 0.9rem;
  line-height: 1.45;
  background: var(--reader-error-bg);
}

@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

.reader-footer {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  align-items: stretch;
  margin: 1rem auto 0;
  padding: 0 max(0.85rem, var(--safe-right)) max(0.35rem, var(--safe-bottom)) max(0.85rem, var(--safe-left));
  max-width: 960px;
}

.reader-footer .btn {
  flex: 1 1 0;
  min-width: 0;
  max-width: 12rem;
}

/* ── Overlay / Dialog ── */
.overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  display: grid;
  place-items: center;
  padding: max(0.75rem, var(--safe-top)) max(0.75rem, var(--safe-right)) max(0.75rem, var(--safe-bottom)) max(0.75rem, var(--safe-left));
  background: var(--overlay-scrim);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.overlay[hidden],
.overlay[aria-hidden='true'][hidden] {
  display: none !important;
}

/* Ensure settings sits above age-gate / chrome when open */
#settings-modal:not([hidden]) {
  display: grid;
  z-index: calc(var(--z-overlay) + 5);
}

.dialog {
  width: min(440px, 100%);
  max-height: min(90dvh, 720px);
  overflow: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem;
  box-shadow: var(--shadow);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.3rem;
}

.dialog-icon {
  display: inline-grid;
  place-items: center;
  width: 2.65rem;
  height: 2.65rem;
  margin-bottom: 0.7rem;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary);
}

.dialog h1,
.dialog h2 {
  margin: 0 0 0.5rem;
  font-size: 1.12rem;
  letter-spacing: -0.02em;
}

.dialog p {
  margin: 0.35rem 0;
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.05rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0.8rem 0 0.4rem;
}

.field-label {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text);
}

.field input[type="url"],
.field input[type="text"] {
  min-height: 46px;
  padding: 0.7rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  outline: none;
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}

.field input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.hint {
  font-size: 0.84rem;
  color: var(--muted);
  margin: 0 0 0.75rem;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.92rem;
  color: var(--muted);
  cursor: pointer;
  margin: 0.55rem 0;
}

.check input {
  width: 1.1rem;
  height: 1.1rem;
  margin-top: 0.15rem;
  accent-color: var(--primary);
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 0.3rem;
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
}

.segmented label {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0.35rem 0.4rem;
  border-radius: 8px;
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented label:has(input:checked) {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  border: 1px solid var(--border);
}

.segmented label:has(input:focus-visible) {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.settings-divider {
  height: 1px;
  margin: 0.9rem 0 0.35rem;
  background: var(--border);
  border: 0;
}

/* ── Loading / Toast ── */
.loading {
  position: fixed;
  inset: 0;
  z-index: var(--z-loading);
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 0.75rem;
  background: var(--loading-scrim);
  color: var(--text);
}

.loading[hidden] {
  display: none !important;
}

.spinner {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 3px solid var(--border-strong);
  border-top-color: var(--primary);
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.15rem + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: var(--z-toast);
  max-width: min(92vw, 420px);
  padding: 0.7rem 1rem;
  border-radius: var(--radius-pill);
  background: var(--bg-soft);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  font-size: 0.92rem;
  text-align: center;
}

.toast[hidden] {
  display: none !important;
}

/* ── Responsive ── */
@media (max-width: 720px) {
  :root {
    --page-pad-x: 0.85rem;
    --topbar-h: 3.25rem;
  }

  .reader-nav .btn {
    padding-inline: 0.5rem;
  }

  .search-row {
    flex-direction: column;
    align-items: stretch;
  }

  .search-field {
    flex: 1 1 auto;
    width: 100%;
  }

  #btn-search {
    width: 100%;
  }

  .dialog-actions {
    flex-wrap: wrap;
  }

  .dialog-actions .btn {
    flex: 1 1 auto;
    min-width: 7rem;
  }
}

@media (max-width: 480px) {
  :root {
    --page-pad-x: 0.75rem;
    --topbar-h: 3.15rem;
  }

  /* Prev/next live in footer on narrow phones */
  .reader-nav {
    display: none;
  }

  .topbar {
    gap: 0.3rem;
    padding-left: max(0.5rem, var(--safe-left));
    padding-right: max(0.5rem, var(--safe-right));
  }

  .brand-text {
    font-size: 0.9rem;
  }

  .icon-btn {
    width: 42px;
    height: 42px;
    min-width: 42px;
    min-height: 42px;
  }

  .hero {
    margin-top: 0.75rem;
    padding: 1.2rem 0.95rem 1.1rem;
    border-radius: var(--radius);
  }

  .hero h1 {
    font-size: clamp(1.4rem, 7vw, 1.75rem);
  }

  .sub {
    font-size: 0.92rem;
    margin-bottom: 1rem;
  }

  .search-field {
    min-height: 48px;
  }

  /* iOS: keep ≥16px to avoid focus zoom */
  .search-field input,
  .field input[type="url"],
  .field input[type="text"] {
    font-size: 16px;
  }

  .home-hint {
    font-size: 0.82rem;
  }

  .album-meta h1 {
    font-size: clamp(1.2rem, 6vw, 1.45rem);
  }

  .chapter-item {
    min-height: 48px;
    padding: 0.65rem 0.8rem;
  }

  .reader-title {
    font-size: 0.88rem;
  }

  .reader-progress {
    font-size: 0.78rem;
  }

  .reader-footer {
    gap: 0.4rem;
    margin-top: 0.85rem;
  }

  .reader-footer .btn {
    max-width: none;
    padding-inline: 0.55rem;
    font-size: 0.9rem;
  }

  .segmented {
    grid-auto-flow: row;
    grid-auto-columns: unset;
  }

  .segmented label {
    min-height: 44px;
  }

  .dialog {
    width: 100%;
    max-height: min(88dvh, 720px);
    border-radius: 14px;
    padding: 1rem 0.95rem;
  }

  .dialog-actions {
    position: sticky;
    bottom: 0;
    margin-top: 0.9rem;
    padding-top: 0.55rem;
    background: linear-gradient(180deg, transparent, var(--bg-elevated) 28%);
  }

  .toast {
    left: max(0.75rem, var(--safe-left));
    right: max(0.75rem, var(--safe-right));
    width: auto;
    max-width: none;
    transform: none;
    bottom: calc(0.9rem + var(--safe-bottom));
  }
}

/* Very small / narrow phones */
@media (max-width: 360px) {
  .brand-text {
    max-width: 7.5rem;
  }

  .reader-footer .btn {
    font-size: 0.84rem;
    padding-inline: 0.4rem;
  }
}

/* Landscape phones: tighter vertical chrome */
@media (max-height: 480px) and (orientation: landscape) {
  .hero {
    margin-top: 0.4rem;
    padding: 0.9rem 1rem;
  }

  .reader-chrome {
    top: calc(2.75rem + var(--safe-top));
  }

  .dialog {
    max-height: 92dvh;
  }
}

/* Prefer denser touch feedback without hover dependency */
@media (hover: none) {
  .chapter-item:hover {
    border-color: var(--border);
    background: var(--bg-elevated);
  }

  .chapter-item:active {
    border-color: color-mix(in srgb, var(--primary) 45%, var(--border));
    background: color-mix(in srgb, var(--bg-elevated) 90%, var(--primary) 10%);
  }

  .btn.primary:hover:not(:disabled) {
    filter: none;
  }

  .btn.primary:active:not(:disabled) {
    filter: brightness(1.05);
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
