/* ==========================================================================
   Dynamic Dexter Home Library — stylesheet
   Brand: ink navy (#0f172a) + Dexter orange (#ff7828) on soft grey.
   ========================================================================== */

/* ---------- Design tokens ---------- */
:root {
  --ink: #0f172a;
  --ink-soft: #1e293b;
  --ink-muted: #334155;
  --accent: #ff7828;
  --accent-strong: #e9641a;
  --accent-text: #b4490c; /* orange that passes contrast on white */
  --accent-soft: #fff1e6;
  --accent-border: #ffd6b8;

  --bg: #f2f3f4;
  --surface: #ffffff;
  --surface-muted: #f6f7f9;
  --border: #e3e7eb;
  --border-strong: #cfd5dc;

  --text: #111318;
  --muted: #5a6472;
  --subtle: #8b95a3;

  --danger: #c0392b;
  --danger-soft: #fdecea;
  --success: #15803d;
  --success-soft: #e8f6ee;
  --warning: #9a4a07;
  --warning-soft: #fff6e5;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;

  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05), 0 4px 12px -4px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 2px 6px -1px rgba(15, 23, 42, 0.08), 0 14px 30px -10px rgba(15, 23, 42, 0.2);
  --shadow-lg: 0 30px 60px -18px rgba(15, 23, 42, 0.45);
  --ring: 0 0 0 3px rgba(255, 120, 40, 0.3);

  --font-sans: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --font-display: "Bebas Neue", "Oswald", Impact, "Arial Narrow Bold", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --app-bar-h: 64px;
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: calc(var(--app-bar-h) + 20px);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* Soft brand glow behind everything */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(55% 45% at 0% 0%, rgba(255, 120, 40, 0.1), transparent 70%),
    radial-gradient(45% 40% at 100% 8%, rgba(15, 23, 42, 0.07), transparent 70%),
    radial-gradient(50% 40% at 70% 100%, rgba(255, 120, 40, 0.06), transparent 70%);
}

body.side-menu-open {
  overflow: hidden;
}

body.is-reordering-books {
  user-select: none;
  cursor: grabbing;
}

img {
  max-width: 100%;
}

a {
  color: var(--ink);
  text-decoration-color: rgba(255, 120, 40, 0.7);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

a:hover {
  color: var(--accent-text);
}

h1,
h2,
h3 {
  line-height: 1.2;
  color: var(--ink);
}

p {
  margin: 0 0 0.75em;
}

:focus-visible {
  outline: 3px solid rgba(255, 120, 40, 0.6);
  outline-offset: 2px;
}

::selection {
  background: rgba(255, 120, 40, 0.25);
}

[hidden] {
  display: none !important;
}

/* ---------- Utilities ---------- */
.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;
}

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.mono { font-family: var(--font-mono); }
.nowrap { white-space: nowrap; }
.break { word-break: break-all; }
.center { text-align: center; }
.align-right { text-align: right; }

.skip-link {
  position: absolute;
  left: 12px;
  top: -80px;
  z-index: 2000;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  transition: top 0.15s;
}

.skip-link:focus {
  top: 12px;
  color: #fff;
}

/* ---------- Icons ---------- */
.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 1.25em;
  height: 1.25em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.22em;
}

/* ---------- Layout ---------- */
.page {
  flex: 1 0 auto;
  width: 100%;
}

.container {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 20px 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.container--narrow { max-width: 760px; }
.container--form { max-width: 820px; }

.page-header {
  display: flex;
  flex-direction: column;
}

.page-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(2.4rem, 6vw, 3.2rem);
  line-height: 0.95;
  letter-spacing: 0.02em;
  color: var(--ink);
}

.page-subtitle {
  margin: 8px 0 0;
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-text);
}

/* Grunge title artwork (1920x420 PNGs with transparent padding) — crop to the lettering */
.page-title-img {
  margin: 0 auto;
  width: 100%;
  line-height: 0;
  text-align: center;
}

.page-title-img img {
  display: block;
  margin: 0 auto;
  width: 100%;
  max-width: 520px;
  aspect-ratio: 1920 / 250;
  object-fit: cover;
  object-position: center;
}

.page-title-img--tall img { aspect-ratio: 1920 / 300; }
.page-title-img--sm img { max-width: 400px; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.section-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 2rem;
  letter-spacing: 0.02em;
  line-height: 1;
}

.section-head__actions,
.button-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.back-link {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: -6px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted);
  text-decoration: none;
}

.back-link:hover {
  color: var(--ink);
}

/* ---------- App bar ---------- */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 900;
  padding-top: env(safe-area-inset-top);
  background: rgba(255, 255, 255, 0.85);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--border);
}

.app-bar__inner {
  max-width: 1280px;
  height: var(--app-bar-h);
  margin: 0 auto;
  padding: 0 16px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
}

.app-bar__start { justify-self: start; }
.app-bar__end { justify-self: end; }

.app-bar__brand {
  display: block;
  line-height: 0;
  border-radius: var(--radius-sm);
}

.app-logo {
  display: block;
  height: 48px;
  width: auto;
}

/* ---------- Buttons ---------- */
.btn {
  --btn-bg: var(--ink);
  --btn-fg: #fff;
  --btn-border: transparent;
  --btn-hover-bg: var(--ink-soft);
  --btn-hover-border: var(--btn-border);

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  min-height: 42px;
  padding: 0.6em 1.1em;
  border: 1px solid var(--btn-border);
  border-radius: 10px;
  background: var(--btn-bg);
  color: var(--btn-fg);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s, transform 0.1s;
}

.btn:hover {
  background: var(--btn-hover-bg);
  border-color: var(--btn-hover-border);
  color: var(--btn-fg);
}

.btn:active { transform: translateY(1px); }

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  background: var(--btn-bg);
}

.btn .icon { width: 1.15em; height: 1.15em; }

.btn--primary { /* default look; kept for readability in templates */ }

.btn--accent {
  --btn-bg: var(--accent);
  --btn-fg: var(--ink);
  --btn-hover-bg: var(--accent-strong);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 6px 16px -8px rgba(255, 120, 40, 0.9);
}

.btn--ghost {
  --btn-bg: var(--surface);
  --btn-fg: var(--ink);
  --btn-border: var(--border-strong);
  --btn-hover-bg: var(--surface-muted);
  --btn-hover-border: #b3bcc7;
}

.btn--danger-ghost {
  --btn-bg: var(--surface);
  --btn-fg: var(--danger);
  --btn-border: rgba(192, 57, 43, 0.35);
  --btn-hover-bg: var(--danger-soft);
  --btn-hover-border: var(--danger);
}

.btn--danger-text {
  --btn-bg: transparent;
  --btn-fg: var(--danger);
  --btn-hover-bg: var(--danger-soft);
}

.btn--sm {
  min-height: 34px;
  padding: 0.45em 0.85em;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.btn--lg {
  min-height: 50px;
  padding: 0.8em 1.4em;
  border-radius: var(--radius);
  font-size: 1rem;
}

.btn--block { width: 100%; }

.btn.is-copied {
  --btn-bg: var(--success);
  --btn-hover-bg: var(--success);
  --btn-fg: #fff;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.icon-btn:hover { background: var(--ink-soft); }

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

.icon-btn--ghost:hover { background: var(--surface-muted); }

.icon-btn--sm {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
}

.icon-btn--sm .icon { width: 16px; height: 16px; }

.icon-btn.is-copied { color: var(--success); }

.menu-btn:hover {
  background: var(--accent);
  color: var(--ink);
}

/* ---------- Side menu ---------- */
.menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 1250;
  background: rgba(15, 23, 42, 0.45);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.22s ease;
}

.menu-overlay.open { opacity: 1; }

.menu-panel {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 1300;
  width: min(300px, calc(100vw - 48px));
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-radius: 0 22px 22px 0;
  box-shadow: var(--shadow-lg);
  transform: translateX(-105%);
  transition: transform 0.26s var(--ease);
}

.menu-panel.open { transform: translateX(0); }

.menu-panel__head {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
}

.menu-panel__head .icon-btn {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
}

.menu-title-img {
  display: block;
  width: 130px;
  height: 46px;
  object-fit: cover;
}

.menu-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 14px;
  background: var(--ink);
  color: #fff;
}

.menu-user__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.menu-user__text strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-user__label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.65);
}

.menu-items {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.menu-section {
  margin: 12px 12px 4px;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--subtle);
}

.menu-section:first-child { margin-top: 4px; }

.menu-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: var(--radius);
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
  transition: background-color 0.15s, color 0.15s;
}

.menu-item .icon {
  color: var(--subtle);
  transition: color 0.15s;
}

.menu-item:hover {
  background: var(--surface-muted);
  color: var(--ink);
}

.menu-item:hover .icon { color: var(--ink); }

.menu-item[aria-current="page"] {
  background: var(--accent-soft);
  font-weight: 700;
}

.menu-item[aria-current="page"] .icon { color: var(--accent-strong); }

.menu-item[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}

.menu-logout {
  margin: 0;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 1.45rem;
  line-height: 1;
  padding-top: 2px;
}

.avatar--sm {
  width: 34px;
  height: 34px;
  font-size: 1.2rem;
}

/* ---------- Footer & back-to-top ---------- */
.app-footer {
  margin-top: 56px;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  background: var(--ink);
  color: rgba(255, 255, 255, 0.75);
  text-align: center;
  font-size: 0.875rem;
}

.app-footer p { margin: 0; }

.app-footer__accent {
  color: var(--accent);
  font-weight: 700;
}

.scroll-top-btn {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 950;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease, background-color 0.15s ease;
}

.scroll-top-btn.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.scroll-top-btn:hover {
  background: var(--accent);
  color: var(--ink);
}

/* ---------- Forms ---------- */
input[type="text"],
input[type="search"],
input[type="number"],
input[type="password"],
input[type="email"],
input[type="url"],
input[type="date"],
select,
textarea {
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 0.6em 0.85em;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background-color: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input::placeholder,
textarea::placeholder {
  color: var(--subtle);
}

input:hover,
select:hover,
textarea:hover {
  border-color: #b3bcc7;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}

select {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 2.5em;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235a6472' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.8em center;
  background-size: 16px;
  text-overflow: ellipsis;
}

input[type="search"]::-webkit-search-cancel-button {
  cursor: pointer;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field > label,
.merge-form > label {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--ink);
}

.label-optional {
  font-weight: 500;
  color: var(--subtle);
}

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

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.field--full { grid-column: 1 / -1; }

.form-sections {
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.form-section {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.form-section > legend {
  float: left;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 14px;
  padding: 0;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-text);
}

.form-section > legend::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.form-section > legend + * { clear: both; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.input-icon {
  position: relative;
  min-width: 0;
}

.input-icon > .icon {
  position: absolute;
  left: 13px;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  color: var(--subtle);
  pointer-events: none;
}

.input-icon > input,
.input-icon > select {
  padding-left: 40px;
}

.input-icon--lg > .icon {
  left: 16px;
  width: 20px;
  height: 20px;
}

.input-icon--lg > input {
  min-height: 54px;
  padding-left: 48px;
  border-radius: 14px;
  font-size: 1.05rem;
  box-shadow: var(--shadow-sm);
}

.input-icon--lg > input:focus {
  box-shadow: var(--ring), var(--shadow-sm);
}

input[type="file"].file-input {
  width: 100%;
  padding: 10px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-muted);
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

input[type="file"].file-input:hover { border-color: var(--accent); }

.file-input::file-selector-button {
  margin-right: 12px;
  padding: 0.55em 1em;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.password-wrap { position: relative; }

.password-wrap input { padding-right: 52px; }

.password-toggle {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.password-toggle:hover { color: var(--ink); background: var(--surface-muted); }
.password-toggle .icon { width: 20px; height: 20px; }
.password-icon--hide { display: none; }
.password-toggle.is-revealed .password-icon--show { display: none; }
.password-toggle.is-revealed .password-icon--hide { display: block; }

.inline-form {
  display: inline-flex;
  margin: 0;
}

/* ---------- Cards, alerts, tags ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card--pad { padding: 24px; }

.form-card {
  padding: 28px 32px 32px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 16px;
  font-size: 1.05rem;
  font-weight: 800;
}

.card-title .icon {
  width: 20px;
  height: 20px;
  color: var(--accent-strong);
}

.subhead {
  margin: 18px 0 4px;
  font-size: 0.95rem;
  font-weight: 800;
}

.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0;
  padding: 12px 14px;
  border: 1px solid;
  border-radius: var(--radius);
  font-size: 0.92rem;
  line-height: 1.45;
}

.alert .icon {
  width: 18px;
  height: 18px;
  margin-top: 1px;
}

.alert--error { background: var(--danger-soft); border-color: rgba(192, 57, 43, 0.25); color: #8a2a1f; }
.alert--success { background: var(--success-soft); border-color: rgba(21, 128, 61, 0.25); color: #14532d; }
.alert--info { background: #eef2f8; border-color: rgba(15, 23, 42, 0.12); color: var(--ink); }
.alert--warning { background: var(--warning-soft); border-color: rgba(154, 74, 7, 0.25); color: #6b3305; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.5;
  text-decoration: none;
  white-space: nowrap;
}

a.tag:hover { background: var(--accent); color: var(--ink); }

.tag--soft {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  color: var(--ink-muted);
  font-family: var(--font-sans);
  text-transform: capitalize;
}

.tag--success {
  background: var(--success-soft);
  color: var(--success);
  font-family: var(--font-sans);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.chip {
  padding: 2px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--ink-muted);
  font-size: 0.74rem;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
}

.chip--accent {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: #8f3a07;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  font-size: 0.8rem;
  white-space: nowrap;
}

.status-badge {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.status-badge .icon { width: 15px; height: 15px; }

.status-badge--read {
  background: var(--success-soft);
  border-color: rgba(21, 128, 61, 0.2);
  color: var(--success);
}

.empty-state {
  padding: 40px 20px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.7);
  color: var(--muted);
  text-align: center;
}

.empty-state p { margin: 0; }

.empty-state__icon {
  width: 40px;
  height: 40px;
  margin-bottom: 8px;
  color: var(--accent);
}

.empty-state__title {
  margin: 0 0 4px !important;
  color: var(--ink);
  font-size: 1.1rem;
  font-weight: 800;
}

/* ---------- Dashboard ---------- */
.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.hero__name-img {
  display: block;
  height: 84px;
  width: auto;
  margin-top: -2px;
}

.hero__name-text {
  margin: 0;
  font-family: var(--font-display);
  font-size: 4rem;
  line-height: 1;
  color: var(--accent);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.stat-card {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.stat-card__icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.stat-card__icon .icon { width: 22px; height: 22px; }

.stat-card__body {
  flex: 1;
  min-width: 0;
}

.stat-card__label {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

.stat-card__value {
  margin: 4px 0 0;
  font-family: var(--font-display);
  font-size: 3.2rem;
  line-height: 0.9;
  letter-spacing: 0.01em;
  color: var(--ink);
}

.stat-card__note {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.stat-card--feature {
  background: linear-gradient(140deg, #0f172a 0%, #1b2741 100%);
  border-color: var(--ink);
  color: #fff;
}

.stat-card--feature::after {
  content: "";
  position: absolute;
  right: -60px;
  top: -60px;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 120, 40, 0.35), transparent 70%);
  pointer-events: none;
}

.stat-card--feature .stat-card__icon {
  background: rgba(255, 120, 40, 0.16);
  color: var(--accent);
}

.stat-card--feature .stat-card__label,
.stat-card--feature .stat-card__note {
  color: rgba(255, 255, 255, 0.72);
}

.stat-card--feature .stat-card__value { color: #fff; }

.progress {
  height: 8px;
  margin-top: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
}

.progress__bar {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #ffa462);
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.quick-action {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  box-shadow: var(--shadow-xs);
  transition: transform 0.18s var(--ease), box-shadow 0.18s, border-color 0.18s;
}

.quick-action:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  color: var(--ink);
}

.quick-action__icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
}

.quick-action--primary .quick-action__icon {
  background: var(--accent);
  color: var(--ink);
}

.quick-action__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.3;
}

.quick-action__text strong { font-size: 0.95rem; }

.quick-action__text span {
  font-size: 0.8rem;
  color: var(--muted);
}

.chart-card {
  padding: 22px 24px 24px;
}

.chart-card .page-title-img { margin-bottom: 14px; }

.chart-card__canvas {
  position: relative;
  height: 340px;
}

/* ---------- Library page ---------- */
.library { gap: 14px; }

.library-top {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin-bottom: 4px;
}

.toolbar {
  width: 100%;
  max-width: 780px;
  display: flex;
  align-items: stretch;
  gap: 10px;
  margin: 0;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.toolbar > .input-icon {
  flex: 1 1 0;
}

.toolbar > .btn { flex: none; }

.search-wrap {
  width: 100%;
  max-width: 780px;
}

.search-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-results:not(:empty) { margin-top: 10px; }

.search-result {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
}

.search-result__thumb {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 58px;
  overflow: hidden;
  border-radius: 3px 5px 5px 3px;
  background: linear-gradient(135deg, var(--ink-soft), var(--ink));
  color: #fff;
  font-family: var(--font-display);
  font-size: 1.4rem;
}

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

.search-result__text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.35;
}

.search-result__title {
  overflow: hidden;
  font-weight: 700;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result__title:hover { text-decoration: underline; }

.search-result__author {
  font-size: 0.85rem;
  color: var(--muted);
}

.search-result__loc {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent-text);
}

.search-results__empty {
  margin: 0;
  padding: 12px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  text-align: center;
}

.search-results__empty.is-error { color: var(--danger); }

.library-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.library-controls__buttons {
  display: flex;
  gap: 8px;
}

.read-key {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.read-key__swatch {
  position: relative;
  width: 22px;
  height: 22px;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
}

.read-key__swatch .read-corner {
  width: 22px;
  height: 22px;
  filter: none;
  border-radius: 0;
}

/* Rooms and shelves (collapsible) */
.collapsible-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px 12px 18px;
  border-radius: 14px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s, box-shadow 0.15s;
}

.collapsible-header .title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.collapsible-right {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
}

.collapsible-header .collapsible-meta {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.toggle-btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.toggle-btn .icon {
  width: 16px;
  height: 16px;
  transition: transform 0.22s var(--ease);
}

.toggle-btn[aria-expanded="true"] .icon { transform: rotate(90deg); }

/* Room = solid ink bar */
.location-group > .collapsible-header {
  background: linear-gradient(135deg, #0f172a 0%, #1b2741 100%);
  color: #fff;
  font-size: 1.05rem;
  box-shadow: var(--shadow-sm);
}

.location-group > .collapsible-header:hover {
  background: linear-gradient(135deg, #16213a 0%, #24324f 100%);
}

.location-group > .collapsible-header .title .icon { color: var(--accent); }
.location-group > .collapsible-header .collapsible-meta { background: rgba(255, 255, 255, 0.1); }

.location-group > .collapsible-header .toggle-btn {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.16);
}

/* Shelf = white card with a light header */
.shelf-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 0 4px 14px;
  margin-left: 14px;
  border-left: 2px solid var(--border);
}

.shelf-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}

.shelf-group > .collapsible-header {
  padding: 10px 12px 10px 16px;
  color: var(--ink);
  font-size: 0.95rem;
  border-radius: var(--radius-lg);
}

.shelf-group > .collapsible-header:hover { background: var(--surface-muted); }
.shelf-group > .collapsible-header .title { font-family: var(--font-mono); }
.shelf-group > .collapsible-header .title .icon { color: var(--subtle); }

.shelf-group > .collapsible-header .collapsible-meta {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  color: var(--muted);
}

.shelf-group > .collapsible-header .toggle-btn {
  background: var(--surface-muted);
  border-color: var(--border);
}

.shelf-group:has(> .collapsible-content:not(.collapsed)) > .collapsible-header {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.collapsible-content.collapsed { display: none; }

.collapsible-content:not(.collapsed) {
  animation: reveal 0.22s var(--ease);
}

@keyframes reveal {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Book grid & cards ---------- */
.book-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr));
  gap: 14px;
}

.shelf-group > .book-list { padding: 6px 12px 14px; }

.book-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-xs);
  scroll-margin-top: calc(var(--app-bar-h) + 24px);
  transition: transform 0.18s var(--ease), box-shadow 0.18s, border-color 0.18s, opacity 0.18s;
}

.book-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

[data-reorder-list] > .book-card { cursor: grab; }
[data-reorder-list] > .book-card:active { cursor: grabbing; }

.book-list.is-reorder-active .book-card {
  transition: transform 0.08s ease, box-shadow 0.18s, border-color 0.18s;
}

.book-card.is-dragging {
  opacity: 0.85;
  border-color: var(--accent);
  box-shadow: var(--shadow-lg);
  transform: scale(0.98) rotate(-1deg);
}

.book-list.is-saving-order .book-card {
  opacity: 0.5;
  pointer-events: none;
}

/* Cover "stage" + book */
.cover {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 210px;
  padding: 14px;
  border-radius: var(--radius);
  background: radial-gradient(120% 90% at 50% 100%, #e6e9ee 0%, #f5f6f8 65%);
}

.cover__book {
  position: relative;
  max-width: 100%;
  line-height: 0;
}

.cover__img {
  display: block;
  max-width: 100%;
  max-height: 182px;
  width: auto;
  height: auto;
  border-radius: 2px 5px 5px 2px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.15), 0 12px 22px -10px rgba(15, 23, 42, 0.55);
}

.cover__placeholder {
  position: relative;
  display: grid;
  place-items: center;
  width: 122px;
  height: 182px;
  overflow: hidden;
  border-radius: 2px 6px 6px 2px;
  background: linear-gradient(145deg, #1e293b 0%, #0f172a 70%);
  color: #fff;
  font-family: var(--font-display);
  font-size: 3.4rem;
  line-height: 1;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.2), 0 12px 22px -10px rgba(15, 23, 42, 0.6);
}

.cover__placeholder::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 8px;
  width: 2px;
  background: rgba(255, 255, 255, 0.12);
}

.cover__placeholder::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 26px;
  height: 6px;
  background: var(--accent);
}

.cover__img + .cover__placeholder { display: none; }
.cover.is-broken .cover__img { display: none; }
.cover.is-broken .cover__placeholder { display: grid; }

.cover--lg {
  height: 380px;
  padding: 24px;
}

.cover--lg .cover__img { max-height: 332px; }

.cover--lg .cover__placeholder {
  width: 220px;
  height: 332px;
  font-size: 6rem;
}

/* Read ribbon (folded corner) — colour per reader */
.read-corner {
  position: absolute;
  top: 0;
  right: 0;
  width: 38px;
  height: 38px;
  pointer-events: none;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.45) 0%, rgba(255, 255, 255, 0) 45%),
    var(--corner-color);
  clip-path: polygon(100% 0, 0 0, 100% 100%);
  border-top-right-radius: 5px;
}

.read-corner--jack { --corner-color: #2563eb; }
.read-corner--thom { --corner-color: #dc2626; }

.book-card__body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  padding: 0 2px;
}

.book-card__title {
  margin: 0;
  overflow: hidden;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-card__title a {
  color: inherit;
  text-decoration: none;
}

.book-card__title a:hover { color: var(--accent-text); }

.book-card__author {
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-card__body .chip {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-card__series {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 2px 0 0;
  color: var(--ink-muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.book-card__series .icon {
  width: 15px;
  height: 15px;
  color: var(--accent-strong);
  flex-shrink: 0;
}

.book-card__series span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-card__next,
.book-card__isbn {
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.8rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-card__isbn { font-size: 0.75rem; color: var(--subtle); }

/* Track-reading toggle */
.book-card__tracking {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-track {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
  background: transparent;
  color: var(--ink-muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.btn-track::before {
  content: "";
  width: 14px;
  height: 14px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z'/%3E%3C/svg%3E") center / contain no-repeat;
}

.btn-track:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--ink);
}

.btn-track.active {
  border-style: solid;
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

.btn-track.active::before {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z'/%3E%3C/svg%3E");
  color: var(--accent);
}

.btn-track.active::before { background: var(--accent); }

/* Reading dates */
.reading-dates__display {
  display: flex;
  flex-wrap: wrap;
  gap: 28px;
  margin-bottom: 16px;
}

.reading-dates__item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 110px;
}

.reading-dates__label,
.reading-dates__field label {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.reading-dates__value {
  color: var(--ink);
  font-weight: 700;
}

.reading-dates__form {
  margin: 0;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.reading-dates__fields {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  align-items: end;
  gap: 12px;
}

.reading-dates__field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.reading-dates__field input[type="date"] {
  min-height: 40px;
  padding: 0.4em 0.6em;
  font-size: 0.9rem;
}

.reading-dates--card {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.reading-dates--card .reading-dates__form {
  padding-top: 0;
  border-top: 0;
}

.reading-dates--card .reading-dates__fields {
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 8px;
}

.reading-dates--card .reading-dates__fields .btn { grid-column: 1 / -1; }

.reading-dates--card input[type="date"] {
  min-height: 36px;
  font-size: 0.8rem;
}

/* Card action bar */
.book-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.book-actions--single { display: block; }

.book-actions__group {
  display: flex;
  align-items: center;
}

.book-actions__group--right {
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 2px;
  margin-left: auto;
}

.book-actions__group--two { grid-template-columns: repeat(2, auto); }

.reorder-form,
.delete-form {
  display: contents;
}

.btn-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}

.btn-icon .icon { width: 15px; height: 15px; }

.btn-icon--first { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }

.btn-icon--last {
  margin-left: -1px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.btn-icon:hover:not(:disabled) {
  z-index: 1;
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

.btn-icon:disabled,
.btn-icon[aria-disabled="true"] {
  color: var(--subtle);
  background: var(--surface-muted);
  cursor: not-allowed;
}

.btn-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.btn-action:hover {
  border-color: var(--border);
  background: var(--surface-muted);
  color: var(--ink);
}

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

.btn-action--danger:hover {
  border-color: rgba(192, 57, 43, 0.25);
  background: var(--danger-soft);
  color: var(--danger);
}

/* ---------- Move dialog ---------- */
.modal {
  width: min(480px, calc(100vw - 32px));
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

.modal::backdrop {
  background: rgba(15, 23, 42, 0.5);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.modal[open] { animation: modal-in 0.22s var(--ease); }

@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.modal__inner {
  display: flex;
  flex-direction: column;
  margin: 0;
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 14px 20px;
  border-bottom: 1px solid var(--border);
}

.modal__title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 1.1rem;
  font-weight: 800;
}

.modal__title .icon { color: var(--accent-strong); }

.modal__body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px 20px 20px;
}

.modal__subject {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.modal__subject-label {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface-muted);
}

/* ---------- Book detail ---------- */
.book-hero {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  align-items: start;
  gap: 32px;
  padding: 24px;
}

.book-hero__info {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  padding-top: 4px;
}

.book-hero__title {
  margin: 0;
  font-size: clamp(1.6rem, 3.4vw, 2.4rem);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.book-hero__author {
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.meta-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 24px;
  margin: 6px 0 4px;
  padding: 16px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.meta-list dt {
  margin-bottom: 3px;
  color: var(--subtle);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.meta-list dd {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--ink);
  font-weight: 600;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.table-wrap {
  position: relative; /* contains .sr-only headers so they can't widen the page */
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table th {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

.table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #fafbfc; }

/* ---------- Scan page ---------- */
.scanner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
}

.scanner__frame {
  position: relative;
  width: 100%;
  max-width: 440px;
  min-height: 220px;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: linear-gradient(145deg, #1e293b, #0f172a);
  box-shadow: var(--shadow-md);
}

#reader {
  width: 100%;
  border: 0 !important;
}

#reader video {
  display: block;
  width: 100% !important;
}

#reader:empty {
  display: grid;
  place-items: center;
  min-height: 220px;
}

#reader:empty::before {
  content: "Camera preview";
  color: rgba(255, 255, 255, 0.45);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.scanner__hint {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.status-pill {
  margin: 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--success-soft);
  color: var(--success);
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
}

.status-pill:empty { display: none; }

.status-pill.is-error {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ---------- Locations page ---------- */
.label-img {
  display: block;
  line-height: 0;
}

.label-img img {
  display: block;
  width: 100%;
  max-width: 230px;
  margin: 0 auto;
  aspect-ratio: 1920 / 240;
  object-fit: cover;
}

.location-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.location-list details.book-card {
  display: block;
  padding: 0;
  cursor: default;
  scroll-margin-top: 0;
}

.location-list details.book-card:hover {
  transform: none;
  box-shadow: var(--shadow-xs);
}

details.collapsible > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  list-style: none;
  cursor: pointer;
}

details.collapsible > summary::-webkit-details-marker { display: none; }

details.collapsible .collapsible-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-weight: 800;
}

details.collapsible > summary .collapsible-meta {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  white-space: nowrap;
}

.collapsible-chevron {
  width: 18px;
  height: 18px;
  margin-left: 4px;
  transition: transform 0.22s var(--ease);
}

details[open] > summary .collapsible-chevron { transform: rotate(90deg); }

details.room-group {
  overflow: hidden;
  border-radius: var(--radius-lg);
}

details.room-group > summary {
  padding: 14px 16px 14px 18px;
  background: linear-gradient(135deg, #0f172a 0%, #1b2741 100%);
  color: #fff;
  transition: background 0.15s;
}

details.room-group > summary:hover {
  background: linear-gradient(135deg, #16213a 0%, #24324f 100%);
}

details.room-group > summary .collapsible-title .icon { color: var(--accent); }

.prefix-pattern {
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.8);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
}

details.room-group > .collapsible-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: var(--surface-muted);
}

details.shelf-item {
  border-radius: var(--radius);
}

details.shelf-item > summary {
  padding: 12px 14px;
  border-radius: var(--radius);
  color: var(--ink);
  transition: background 0.15s;
}

details.shelf-item > summary:hover { background: var(--surface-muted); }

details.shelf-item > summary .collapsible-title {
  font-family: var(--font-mono);
  font-size: 0.95rem;
}

details.shelf-item > summary .collapsible-meta { color: var(--muted); }

.shelf-item__name {
  overflow: hidden;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shelf-item__body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px;
  border-top: 1px solid var(--border);
}

.merge-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
}

.merge-form > label {
  color: var(--muted);
  font-size: 0.8rem;
}

.merge-form__row {
  display: flex;
  gap: 8px;
}

.merge-form__row select {
  flex: 1;
  min-width: 0;
  min-height: 38px;
  font-size: 0.9rem;
}

/* ---------- Shelf / room header ---------- */
.place-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px;
}

.place-header__text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.place-header__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 6vw, 3.4rem);
  font-weight: 400;
  line-height: 0.95;
  letter-spacing: 0.02em;
}

.place-header__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 8px 0 0;
  color: var(--muted);
}

.place-header .button-row { margin-top: 12px; }

.barcode-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}

.barcode-box img {
  display: block;
  max-width: 260px;
  height: auto;
}

/* ---------- Settings ---------- */
.settings-card p.muted { margin-bottom: 12px; }

.settings-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

.settings-card__head .card-title { margin: 0; }

.copy-field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 6px 6px 6px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.copy-field__value {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-card .inline-form + * { margin-top: 16px; }

.member-list {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  list-style: none;
}

.member {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.member:last-child { border-bottom: 0; }

.member__text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.member__text .muted { font-size: 0.85rem; }

.invite-cell {
  display: flex;
  align-items: center;
  gap: 6px;
}

.invite-cell a { font-size: 0.82rem; }

.join-card p { margin: 0; }
.join-card .page-title { margin-bottom: 12px; }
.join-card .alert { margin: 16px 0; }

/* ---------- Auth pages (login / register) ---------- */
.auth-shell {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(28px + env(safe-area-inset-top)) 16px 0;
}

.auth-brand { padding: 4px 0 24px; }

.auth-logo {
  display: block;
  width: min(380px, 80vw);
  height: auto;
}

.auth-main {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  width: 100%;
}

.auth-card {
  position: relative;
  overflow: hidden;
  width: 100%;
  max-width: 440px;
  padding: 34px 32px 30px;
  border-radius: 22px;
  box-shadow: var(--shadow-md);
}

.auth-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--accent), #ffa462 55%, var(--ink));
}

.auth-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 3.2rem;
  font-weight: 400;
  line-height: 0.95;
  letter-spacing: 0.02em;
}

.auth-subtitle {
  margin: 6px 0 20px;
  color: var(--muted);
}

.auth-card .alert { margin-bottom: 16px; }

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: 0;
}

.auth-form > .btn { margin-top: 6px; }

.auth-switch {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.auth-footer {
  padding: 28px 16px calc(20px + env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-card--feature { grid-column: 1 / -1; }
  .quick-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .book-hero {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .cover--lg { height: 320px; }
  .cover--lg .cover__img { max-height: 280px; }
  .cover--lg .cover__placeholder { width: 186px; height: 280px; }
  .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  :root { --app-bar-h: 58px; }

  .container {
    padding: 20px 14px 0;
    gap: 16px;
  }

  .app-bar__inner { padding: 0 12px; }
  .app-logo { height: 40px; }
  .app-bar__cta-label { display: none; }

  .app-bar__cta {
    width: 40px;
    min-height: 40px;
    padding: 0;
  }

  .card--pad { padding: 18px; }
  .form-card { padding: 22px 18px 24px; gap: 18px; }
  .form-grid { grid-template-columns: 1fr; }

  .form-actions {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .form-actions .btn { width: 100%; }

  .toolbar {
    flex-direction: column;
    padding: 12px;
  }

  .library-controls { justify-content: center; }

  .shelf-list {
    padding-left: 8px;
    margin-left: 6px;
  }

  .shelf-group > .book-list { padding: 4px 8px 10px; }

  .collapsible-header { padding: 10px 10px 10px 14px; }
  .location-group > .collapsible-header { font-size: 1rem; }
  .collapsible-header .collapsible-meta { font-size: 0.75rem; padding: 2px 8px; }

  .meta-list { grid-template-columns: 1fr; }

  .reading-dates__fields { grid-template-columns: 1fr 1fr; }
  .reading-dates__fields .btn { grid-column: 1 / -1; }

  .chart-card { padding: 18px 14px; }
  .chart-card__canvas { height: 260px; }

  .stat-card { padding: 16px; }
  .stat-card__value { font-size: 2.8rem; }

  .place-header { padding: 18px; }
  .barcode-box { width: 100%; }

  .prefix-pattern { display: none; }

  .merge-form__row { flex-direction: column; }

  .auth-card { padding: 28px 20px 24px; }
}

@media (max-width: 520px) {
  .stat-grid { grid-template-columns: 1fr; }
  .quick-actions { gap: 10px; }
  .quick-action { flex-direction: column; align-items: flex-start; gap: 10px; padding: 14px; }
  .hero__name-img { height: 64px; }

  details.room-group > summary { padding: 12px 12px 12px 14px; }

  details.room-group > summary .collapsible-meta .pill:first-child { display: none; }
}

/* Phones: compact horizontal book cards (cover left, details right) */
@media (max-width: 560px) {
  .book-list {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .book-card {
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr);
    align-items: start;
    gap: 10px 12px;
  }

  .book-card > .cover {
    grid-column: 1;
    grid-row: 1;
    height: 134px;
    padding: 8px;
  }

  .book-card > .cover .cover__img { max-height: 118px; }

  .book-card > .cover .cover__placeholder {
    width: 78px;
    height: 118px;
    font-size: 2.2rem;
  }

  .book-card > .cover .cover__placeholder::after { bottom: 16px; height: 4px; }

  .book-card > .cover .read-corner { width: 28px; height: 28px; }

  .book-card > .book-card__body {
    grid-column: 2;
    grid-row: 1;
    align-self: center;
  }

  .book-card > .book-card__tracking,
  .book-card > .book-actions {
    grid-column: 1 / -1;
  }

}

@media (hover: none) {
  .book-card:hover,
  .quick-action:hover {
    transform: none;
    box-shadow: var(--shadow-xs);
  }
}

@media (pointer: coarse) {
  /* 16px stops iOS zooming into focused fields */
  .reading-dates__field input[type="date"],
  .merge-form__row select {
    font-size: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  body::before,
  .app-bar,
  .menu-panel,
  .menu-overlay,
  .app-footer,
  .scroll-top-btn,
  .back-link,
  .btn,
  .book-actions,
  .book-card__tracking {
    display: none !important;
  }

  body { background: #fff; }

  .card,
  .book-card {
    box-shadow: none;
    break-inside: avoid;
  }
}
