/* ==========================================================================
   Midadh Libeary — Heritage Wooden Bookshelf & Digital Library Stylesheet
   ========================================================================== */

:root {
  --bg-room: #f5efe4;
  --bg-room-accent: #eadfcd;
  --bg-surface: #fcf8f0;
  --bg-surface-2: #f1e8d8;
  --text-main: #24160e;
  --text-muted: #6c5746;
  --text-on-dark: #faf3e5;

  --wood-darkest: #1c0f08;
  --wood-dark: #2c180e;
  --wood-mid: #4d2c19;
  --wood-warm: #6d3f23;
  --wood-highlight: #8f5835;
  --wood-bevel: #a36a43;

  --brass: #d59a3e;
  --brass-bright: #f2c97d;
  --brass-dark: #93621a;
  --emerald: #1d4b43;
  --emerald-light: #27665b;
  --crimson: #8f2d28;

  --border-soft: rgba(77, 44, 25, 0.16);
  --shadow-card: 0 10px 26px rgba(28, 15, 8, 0.12);
  --shadow-modal: 0 28px 70px rgba(15, 8, 4, 0.45);

  --font-serif: Georgia, "Times New Roman", "Palatino Linotype", "Nirmala UI", "Latha", serif;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Nirmala UI", "Noto Sans Tamil", "Latha", Helvetica, Arial, sans-serif;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --container-max: 1320px;
}

[data-theme="night"] {
  --bg-room: #14100d;
  --bg-room-accent: #1d1612;
  --bg-surface: #211813;
  --bg-surface-2: #2a1f18;
  --text-main: #f4ead9;
  --text-muted: #b9a48d;
  --border-soft: rgba(213, 154, 62, 0.22);
  --shadow-card: 0 12px 30px rgba(0, 0, 0, 0.45);
}

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

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

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--text-main);
  background-color: var(--bg-room);
  background-image:
    radial-gradient(ellipse 90% 45% at 50% 0%, rgba(213, 154, 62, 0.14), transparent 68%),
    linear-gradient(180deg, var(--bg-room) 0%, var(--bg-room-accent) 100%);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
}

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

img {
  max-width: 100%;
  display: block;
}

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

.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;
}

.container {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 20px;
}

/* ---------- Header & Brand Lockup ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: linear-gradient(180deg, #2a170e 0%, #20110a 100%);
  color: var(--text-on-dark);
  border-bottom: 2px solid rgba(213, 154, 62, 0.55);
  box-shadow: 0 6px 24px rgba(15, 7, 3, 0.38);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 74px;
  padding: 10px 0;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  flex-shrink: 1;
  min-width: 0;
}

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-emblem {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.42);
  flex-shrink: 0;
}

.brand-logo--lg .brand-emblem {
  width: 60px;
  height: 60px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}

.brand-title {
  font-family: var(--font-serif);
  font-size: 1.24rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fcf3e1;
}

.brand-title-ta {
  font-size: 0.96rem;
  font-weight: 600;
  color: #f4d28b;
  letter-spacing: 0;
}

.banner-title-ta {
  font-size: 0.85em;
  color: var(--emerald);
  font-weight: 600;
}

[data-theme="night"] .banner-title-ta {
  color: var(--brass-bright);
}

.lang-toggle {
  display: inline-flex;
  align-items: center;
  background: rgba(255, 248, 236, 0.1);
  border: 1px solid rgba(213, 154, 62, 0.42);
  border-radius: 999px;
  padding: 2px;
}

.lang-toggle button {
  background: transparent;
  border: none;
  color: rgba(250, 238, 220, 0.82);
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.18s, color 0.18s;
}

.lang-toggle button.active {
  background: var(--brass);
  color: #1f1209;
}
}

.brand-logo--lg .brand-title {
  font-size: 1.7rem;
}

.brand-subtitle {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--brass-bright);
  opacity: 0.9;
  margin-top: 2px;
}

.header-search-wrap {
  flex: 1 1 260px;
  max-width: 460px;
  min-width: 0;
  position: relative;
}

.header-search-input {
  width: 100%;
  background: rgba(255, 248, 236, 0.1);
  border: 1px solid rgba(213, 154, 62, 0.35);
  border-radius: 999px;
  padding: 9px 38px 9px 40px;
  color: #fff8eb;
  font-size: 0.94rem;
  outline: none;
  transition: border-color 0.2s, background-color 0.2s, box-shadow 0.2s;
}

.header-search-input::placeholder {
  color: rgba(250, 240, 224, 0.58);
}

.header-search-input:focus {
  background: rgba(255, 248, 236, 0.16);
  border-color: var(--brass-bright);
  box-shadow: 0 0 0 3px rgba(213, 154, 62, 0.2);
}

.header-search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 17px;
  height: 17px;
  color: var(--brass-bright);
  pointer-events: none;
}

.header-search-clear {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: rgba(255, 248, 236, 0.7);
  cursor: pointer;
  padding: 4px 6px;
  font-size: 1rem;
  line-height: 1;
  display: none;
}

.header-search-clear.visible {
  display: inline-flex;
}

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

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.15s ease, background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  white-space: nowrap;
}

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

.btn-sm {
  padding: 6px 11px;
  font-size: 0.82rem;
}

.btn-brass {
  background: linear-gradient(180deg, #e5b35c 0%, #c88c31 100%);
  color: #1f1209;
  border-color: #f3d28e;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.22);
}

.btn-brass:hover {
  background: linear-gradient(180deg, #eec06d 0%, #d29639 100%);
}

.btn-emerald {
  background: linear-gradient(180deg, var(--emerald-light) 0%, var(--emerald) 100%);
  color: #fff8ed;
  border-color: rgba(242, 201, 125, 0.35);
}

.btn-emerald:hover {
  background: linear-gradient(180deg, #2d7669 0%, #1f554b 100%);
}

.btn-outline-light {
  background: rgba(255, 248, 236, 0.08);
  color: #faeedc;
  border-color: rgba(213, 154, 62, 0.42);
}

.btn-outline-light:hover {
  background: rgba(255, 248, 236, 0.16);
  border-color: var(--brass-bright);
}

.btn-outline-dark {
  background: var(--bg-surface);
  color: var(--text-main);
  border-color: var(--border-soft);
}

.btn-outline-dark:hover {
  background: var(--bg-surface-2);
  border-color: var(--brass);
}

.btn-danger {
  background: #a4302b;
  color: #fff;
}

.btn-danger:hover {
  background: #892521;
}

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

/* ---------- Library Intro Banner & Stats ---------- */

.library-banner {
  padding: 22px 0 12px;
}

.banner-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 18px 24px;
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
}

.banner-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  background: linear-gradient(180deg, var(--brass-bright), var(--emerald), var(--brass-dark));
}

.banner-identity {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
  flex: 1 1 240px;
}

.banner-logo-card {
  width: 112px;
  height: auto;
  border-radius: 14px;
  padding: 6px;
  background: #f5f1e8;
  border: 1px solid rgba(196, 154, 72, 0.55);
  box-shadow: 0 6px 16px rgba(28, 15, 8, 0.14);
  flex-shrink: 0;
}

.auth-logo-card {
  width: 172px;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  border-radius: 16px;
  padding: 8px;
  background: #f5f1e8;
  border: 1px solid rgba(196, 154, 72, 0.55);
  box-shadow: 0 8px 20px rgba(28, 15, 8, 0.14);
}

.banner-copy {
  min-width: 0;
}

.banner-copy h1 {
  margin: 0 0 4px;
  font-family: var(--font-serif);
  font-size: clamp(1.25rem, 2.2vw, 1.82rem);
  color: var(--text-main);
}

.banner-copy p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.banner-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.stat-chip {
  background: var(--bg-surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  min-width: 96px;
  text-align: center;
}

.stat-chip__val {
  display: block;
  font-family: var(--font-serif);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-main);
}

.stat-chip__label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

/* ---------- Filter & View Toolbar ---------- */

.shelf-controls {
  padding: 10px 0 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.shelf-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.shelf-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: var(--bg-surface);
  color: var(--text-main);
  font-size: 0.87rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
}

.shelf-tab:hover {
  border-color: var(--brass);
  transform: translateY(-1px);
}

.shelf-tab.active {
  background: linear-gradient(180deg, #3c2214 0%, #26140b 100%);
  color: #fcf1dc;
  border-color: var(--brass);
  box-shadow: 0 4px 12px rgba(32, 17, 10, 0.25);
}

.shelf-tab__dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.shelf-tab__count {
  font-size: 0.76rem;
  opacity: 0.78;
}

.shelf-right-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.control-select {
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 0.88rem;
  cursor: pointer;
}

.view-toggle {
  display: inline-flex;
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.view-toggle button {
  background: transparent;
  border: none;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.view-toggle button.active {
  background: var(--wood-dark);
  color: #faeedc;
}

/* ==========================================================================
   WOODEN BOOKCASE & 3D SHELVES
   ========================================================================== */

.bookcase-section {
  padding-bottom: 48px;
}

.bookcase-frame {
  position: relative;
  border-radius: 14px 14px 10px 10px;
  background: linear-gradient(90deg, #3f2314 0%, #5e361f 8px, #472817 16px, #29150b 24px, #24130a calc(100% - 24px), #472817 calc(100% - 16px), #5e361f calc(100% - 8px), #3f2314 100%);
  padding: 0 18px 20px;
  box-shadow:
    0 24px 55px rgba(20, 10, 4, 0.42),
    inset 0 2px 0 rgba(242, 201, 125, 0.25);
  border: 2px solid #2c170c;
}

/* Carved Crown Cornice */
.bookcase-cornice {
  margin: 0 -18px;
  padding: 14px 24px 12px;
  background:
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.025) 0px,
      rgba(255, 255, 255, 0.025) 2px,
      transparent 2px,
      transparent 11px
    ),
    linear-gradient(180deg, #6d3f23 0%, #4b2a17 58%, #341c0e 100%);
  border-radius: 12px 12px 2px 2px;
  border-bottom: 3px solid #1b0d06;
  box-shadow:
    inset 0 2px 0 rgba(245, 208, 138, 0.28),
    0 8px 18px rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brass-plaque {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 18px;
  border-radius: 6px;
  background: linear-gradient(180deg, #e5b762 0%, #bd8229 100%);
  color: #201108;
  border: 1px solid #f7dc9d;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    0 3px 10px rgba(0, 0, 0, 0.35);
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 0.98rem;
  letter-spacing: 0.03em;
}

.cornice-meta {
  font-size: 0.84rem;
  color: rgba(250, 238, 220, 0.8);
}

/* Interior Oak Cavity */
.bookcase-cavity {
  background:
    radial-gradient(ellipse 80% 180px at 50% 0%, rgba(242, 201, 125, 0.14), transparent 70%),
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.012) 0px,
      rgba(255, 255, 255, 0.012) 48px,
      rgba(0, 0, 0, 0.09) 48px,
      rgba(0, 0, 0, 0.09) 50px
    ),
    linear-gradient(180deg, #27150c 0%, #1c0f08 100%);
  border-left: 1px solid rgba(0, 0, 0, 0.6);
  border-right: 1px solid rgba(0, 0, 0, 0.6);
  padding-top: 22px;
  min-height: 280px;
}

/* Shelf Tier (One row of books + continuous 3D wooden plank underneath) */
.shelf-tier {
  position: relative;
  padding-top: 10px;
}

.shelf-tier + .shelf-tier {
  margin-top: 16px;
}

.shelf-books {
  display: grid;
  grid-template-columns: repeat(var(--shelf-cols, 5), minmax(0, 1fr));
  gap: 20px;
  padding: 0 22px;
  align-items: end;
}

/* 3D Wooden Shelf Plank */
.shelf-plank {
  position: relative;
  height: 26px;
  margin: -2px -4px 0;
  z-index: 2;
}

/* Top light-catching horizontal wood surface */
.shelf-plank::before {
  content: "";
  display: block;
  height: 8px;
  margin: 0 4px;
  background: linear-gradient(180deg, #5d361f 0%, #8f5835 100%);
  border-top: 1px solid rgba(255, 224, 175, 0.22);
  box-shadow: inset 0 4px 6px rgba(18, 9, 4, 0.42);
}

/* Front vertical carved wooden lip + deep shadow cast below */
.shelf-plank::after {
  content: "";
  display: block;
  height: 18px;
  background:
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.03) 0px,
      rgba(255, 255, 255, 0.03) 3px,
      transparent 3px,
      transparent 17px
    ),
    linear-gradient(180deg, #7c492a 0%, #5b331b 55%, #3d2010 100%);
  border-top: 1px solid rgba(245, 211, 148, 0.32);
  border-bottom: 2px solid #1b0d05;
  border-radius: 2px;
  box-shadow:
    0 12px 18px rgba(0, 0, 0, 0.68),
    0 4px 6px rgba(0, 0, 0, 0.45);
}

/* ---------- Individual Book Sitting on Shelf ---------- */

.book-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  padding-bottom: 4px;
  min-width: 0;
}

.book-volume {
  position: relative;
  width: 100%;
  max-width: 174px;
  aspect-ratio: 1 / 1.42;
  cursor: pointer;
  transform-origin: bottom center;
  transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1), filter 0.24s ease;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.65));
}

.book-slot:hover .book-volume,
.book-slot:focus-within .book-volume {
  transform: translateY(-9px) scale(1.03);
  filter: drop-shadow(0 16px 20px rgba(0, 0, 0, 0.8));
}

/* Paper Page Edges on Right Side */
.book-volume::after {
  content: "";
  position: absolute;
  top: 4px;
  bottom: 3px;
  right: -5px;
  width: 6px;
  border-radius: 0 3px 3px 0;
  background: repeating-linear-gradient(
    90deg,
    #efe5d2 0px,
    #efe5d2 1px,
    #d8cab0 1px,
    #d8cab0 2px
  );
  box-shadow: inset -1px 0 2px rgba(0, 0, 0, 0.28);
}

.book-cover-card {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 3px 6px 6px 3px;
  overflow: hidden;
  background: var(--spine-color, #1d4b43);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    inset -2px 0 4px rgba(0, 0, 0, 0.25);
}

/* Spine Crease Lighting */
.book-cover-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 14px;
  z-index: 3;
  background: linear-gradient(
    90deg,
    rgba(0, 0, 0, 0.45) 0%,
    rgba(255, 255, 255, 0.22) 32%,
    rgba(0, 0, 0, 0.22) 64%,
    transparent 100%
  );
  pointer-events: none;
}

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

/* Procedural Hardcover Design when no thumbnail image */
.book-hardcover {
  width: 100%;
  height: 100%;
  padding: 16px 14px 16px 22px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background:
    radial-gradient(circle at 80% 18%, rgba(255, 255, 255, 0.14), transparent 55%),
    linear-gradient(155deg, rgba(255, 255, 255, 0.08) 0%, rgba(0, 0, 0, 0.28) 100%),
    var(--spine-color, #1d4b43);
  color: #fcf3e1;
  position: relative;
}

.book-hardcover::after {
  content: "";
  position: absolute;
  inset: 9px 9px 9px 17px;
  border: 1px solid rgba(242, 201, 125, 0.45);
  border-radius: 2px;
  pointer-events: none;
}

.book-hardcover__shelf {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--brass-bright);
  opacity: 0.92;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-hardcover__title {
  font-family: var(--font-serif);
  font-size: 0.96rem;
  font-weight: 700;
  line-height: 1.26;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
}

.book-hardcover__author {
  font-size: 0.74rem;
  color: rgba(252, 243, 225, 0.85);
  border-top: 1px solid rgba(242, 201, 125, 0.35);
  padding-top: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Featured Ribbon Bookmark */
.book-ribbon {
  position: absolute;
  top: 0;
  right: 12px;
  z-index: 4;
  width: 20px;
  height: 28px;
  background: linear-gradient(180deg, #e7b55a 0%, #ba7c22 100%);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 76%, 0 100%);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.45);
}

/* Quick Hover Overlay on Book Cover */
.book-hover-actions {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: linear-gradient(180deg, rgba(20, 11, 6, 0.15) 0%, rgba(18, 10, 5, 0.88) 100%);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 7px;
  padding: 12px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.book-slot:hover .book-hover-actions,
.book-slot:focus-within .book-hover-actions {
  opacity: 1;
}

/* Title & Direct Touch Action Bar Below Book (Readable on all devices) */
.book-caption {
  width: 100%;
  max-width: 174px;
  min-width: 0;
  overflow: hidden;
  margin-top: 9px;
  background: rgba(253, 246, 232, 0.94);
  color: #24160e;
  border: 1px solid rgba(213, 154, 62, 0.55);
  border-radius: 7px;
  padding: 7px 9px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.36);
}

.book-caption__title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.1em;
}

.book-caption__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-top: 4px;
  font-size: 0.72rem;
  color: #6b5442;
}

.book-caption__author {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-caption__actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  margin-top: 7px;
}

.book-caption__actions .btn {
  padding: 6px 8px;
  font-size: 0.75rem;
  border-radius: 5px;
  min-width: 0;
  white-space: normal;
  line-height: 1.15;
  text-align: center;
  min-height: 34px;
}

@media (hover: none), (pointer: coarse) {
  .book-hover-actions {
    display: none;
  }

  .book-slot:hover .book-volume {
    transform: none;
  }
}

/* ---------- Catalog List View ---------- */

.catalog-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 22px;
}

.catalog-row {
  display: grid;
  grid-template-columns: 68px 1fr auto;
  gap: 16px;
  align-items: center;
  background: rgba(252, 246, 235, 0.96);
  color: #24160e;
  border: 1px solid rgba(213, 154, 62, 0.45);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.25);
}

.catalog-thumb {
  width: 68px;
  height: 94px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--spine-color, #1d4b43);
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
}

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

.catalog-info h3 {
  margin: 0 0 3px;
  font-family: var(--font-serif);
  font-size: 1.05rem;
  cursor: pointer;
}

.catalog-info h3:hover {
  color: var(--emerald);
}

.catalog-meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.8rem;
  color: #6b5442;
  margin-bottom: 5px;
}

.catalog-desc {
  margin: 0;
  font-size: 0.86rem;
  color: #49382c;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.catalog-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- Empty State ---------- */

.empty-shelf {
  text-align: center;
  padding: 54px 24px;
  color: #f4e6cf;
}

.empty-shelf h3 {
  font-family: var(--font-serif);
  font-size: 1.4rem;
  margin: 0 0 8px;
}

.empty-shelf p {
  margin: 0 0 18px;
  color: rgba(244, 230, 207, 0.78);
}

/* ---------- Modals ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(15, 9, 5, 0.72);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-dialog {
  width: 100%;
  max-width: 720px;
  max-height: 92vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid rgba(213, 154, 62, 0.5);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  position: relative;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border-soft);
  background: var(--bg-surface-2);
  color: var(--text-main);
  cursor: pointer;
  font-size: 1.2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.book-modal-body {
  display: grid;
  grid-template-columns: 210px 1fr;
  gap: 24px;
  padding: 26px;
}

.book-modal-cover {
  aspect-ratio: 1 / 1.42;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 14px 32px rgba(20, 10, 4, 0.35);
}

.book-modal-title {
  margin: 0 0 6px;
  font-family: var(--font-serif);
  font-size: 1.48rem;
  line-height: 1.24;
  padding-right: 36px;
}

.book-modal-author {
  margin: 0 0 14px;
  color: var(--text-muted);
  font-size: 0.98rem;
}

.book-modal-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.meta-pill {
  font-size: 0.78rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-soft);
  color: var(--text-main);
}

.book-modal-desc {
  margin: 0 0 20px;
  font-size: 0.94rem;
  color: var(--text-main);
  white-space: pre-line;
}

.book-modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* ==========================================================================
   PDF READER PAGE (reader.php)
   ========================================================================== */

body.reader-body {
  background: #221a15;
  color: #f5ebd9;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

body.reader-body[data-reader-theme="paper"] {
  background: #e5dfd3;
  color: #24160e;
}

body.reader-body[data-reader-theme="sepia"] {
  background: #dfcfb3;
  color: #2f2114;
}

body.reader-body[data-reader-theme="night"] {
  background: #14110f;
  color: #efe4d2;
}

.reader-toolbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: linear-gradient(180deg, #2a180f 0%, #1e1009 100%);
  color: #faf0df;
  border-bottom: 2px solid rgba(213, 154, 62, 0.5);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}

.reader-title-group {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1 1 240px;
}

.reader-book-meta {
  min-width: 0;
}

.reader-book-meta h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.05rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reader-book-meta span {
  display: block;
  font-size: 0.76rem;
  color: rgba(250, 240, 223, 0.72);
}

.reader-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.reader-page-box {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 248, 236, 0.1);
  border: 1px solid rgba(213, 154, 62, 0.38);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 0.85rem;
}

.reader-page-input {
  width: 48px;
  text-align: center;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(213, 154, 62, 0.35);
  border-radius: 5px;
  padding: 3px 4px;
  color: #fff;
}

.reader-stage {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 14px 86px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.reader-resume-banner {
  background: rgba(31, 75, 67, 0.94);
  color: #fff9ee;
  border: 1px solid var(--brass);
  border-radius: 10px;
  padding: 10px 16px;
  display: none;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  max-width: 720px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

.reader-resume-banner.visible {
  display: flex;
}

.pdf-page-slot {
  position: relative;
  background: #ffffff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6c5746;
}

body.reader-body[data-reader-theme="sepia"] .pdf-page-slot canvas {
  filter: sepia(0.24) brightness(0.96);
}

body.reader-body[data-reader-theme="night"] .pdf-page-slot canvas {
  filter: invert(0.88) hue-rotate(180deg) contrast(0.95);
}

.pdf-page-badge {
  position: absolute;
  bottom: 8px;
  right: 10px;
  background: rgba(24, 14, 8, 0.72);
  color: #faf0df;
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  pointer-events: none;
}

.reader-loading {
  text-align: center;
  padding: 60px 20px;
  font-size: 1rem;
}

.reader-mobile-bar {
  display: none;
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 55;
  background: rgba(34, 19, 11, 0.95);
  border: 1px solid rgba(213, 154, 62, 0.55);
  border-radius: 999px;
  padding: 6px 12px;
  gap: 10px;
  align-items: center;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.55);
}

/* ==========================================================================
   ADMIN PORTAL & STUDIO (admin.php)
   ========================================================================== */

.admin-auth-wrap {
  min-height: calc(100vh - 140px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}

.admin-auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  border-top: 5px solid var(--brass);
  border-radius: var(--radius-lg);
  padding: 30px 28px;
  box-shadow: var(--shadow-card);
}

.admin-auth-head {
  text-align: center;
  margin-bottom: 22px;
}

.admin-auth-head h1 {
  font-family: var(--font-serif);
  font-size: 1.48rem;
  margin: 12px 0 4px;
}

.admin-auth-head p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.form-group {
  margin-bottom: 15px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  background: var(--bg-room);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.94rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
  border-color: var(--brass);
  box-shadow: 0 0 0 3px rgba(213, 154, 62, 0.18);
}

.password-wrap {
  position: relative;
}

.password-toggle {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.alert {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  margin-bottom: 14px;
  display: none;
}

.alert.visible {
  display: block;
}

.alert-error {
  background: rgba(164, 48, 43, 0.14);
  border: 1px solid rgba(164, 48, 43, 0.45);
  color: #8b201b;
}

[data-theme="night"] .alert-error {
  color: #ffb8b3;
}

.alert-success {
  background: rgba(29, 75, 67, 0.15);
  border: 1px solid rgba(29, 75, 67, 0.45);
  color: #16443b;
}

[data-theme="night"] .alert-success {
  color: #9ce6d5;
}

/* Admin Dashboard Layout */
.admin-shell {
  padding: 24px 0 54px;
}

.admin-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.admin-stat-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  box-shadow: var(--shadow-card);
}

.admin-stat-box__val {
  font-family: var(--font-serif);
  font-size: 1.55rem;
  font-weight: 700;
}

.admin-stat-box__lbl {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.admin-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
  border-bottom: 2px solid var(--border-soft);
  padding-bottom: 10px;
}

.admin-tab-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}

.admin-tab-btn.active {
  background: var(--wood-dark);
  color: #fcf1dc;
  border-color: var(--brass);
}

.admin-panel {
  display: none;
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-card);
}

.admin-panel.active {
  display: block;
}

/* Dropzone & Unlimited Chunked Uploader */
.upload-dropzone {
  border: 2px dashed rgba(213, 154, 62, 0.72);
  border-radius: var(--radius-lg);
  background: var(--bg-surface-2);
  padding: 34px 20px;
  text-align: center;
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s, transform 0.15s;
}

.upload-dropzone.dragover {
  background: rgba(213, 154, 62, 0.18);
  border-color: var(--emerald);
  transform: scale(1.005);
}

.upload-dropzone__badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--emerald);
  color: #fff8ea;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}

.upload-queue {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 20px;
}

.upload-item {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  background: var(--bg-room);
  padding: 16px;
}

.upload-item-grid {
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 18px;
}

.upload-cover-preview {
  width: 112px;
  aspect-ratio: 1 / 1.42;
  border-radius: 6px;
  border: 1px solid var(--border-soft);
  background: var(--emerald);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #faf0df;
  font-size: 0.75rem;
  text-align: center;
  padding: 6px;
}

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

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

.upload-subgrid-3 {
  display: grid;
  grid-template-columns: 1fr 90px 70px;
  gap: 8px;
  margin-bottom: 8px;
}

.progress-track {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: rgba(77, 44, 25, 0.16);
  overflow: hidden;
  margin: 10px 0 6px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--emerald) 0%, var(--brass) 100%);
  transition: width 0.15s linear;
}

.admin-table-wrap {
  overflow-x: auto;
}

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

.admin-table th,
.admin-table td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--border-soft);
  text-align: left;
  vertical-align: middle;
}

.admin-table th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.table-book-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.table-book-thumb {
  width: 38px;
  height: 52px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--emerald);
}

/* ---------- Footer ---------- */

.site-footer {
  text-align: center;
  padding: 20px 16px 34px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ==========================================================================
   RESPONSIVE BREAKPOINTS
   ========================================================================== */

@media (max-width: 960px) {
  .admin-stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .banner-card {
    padding: 16px 18px;
  }

  .banner-stats {
    width: 100%;
  }

  .stat-chip {
    flex: 1 1 0;
  }
}

@media (max-width: 780px) {
  .header-inner {
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 0 12px;
  }

  .header-search-wrap {
    order: 3;
    flex: 1 1 100%;
    max-width: none;
  }

  .bookcase-frame {
    padding: 0 10px 14px;
  }

  .bookcase-cornice {
    margin: 0 -10px;
    padding: 12px 14px 10px;
  }

  .shelf-books {
    gap: 14px;
    padding: 0 12px;
  }

  .book-modal-body {
    grid-template-columns: 1fr;
    padding: 20px;
  }

  .book-modal-cover {
    max-width: 180px;
    margin: 0 auto;
  }

  .upload-item-grid {
    grid-template-columns: 1fr;
  }

  .upload-cover-preview {
    margin: 0 auto;
  }

  .form-grid-2 {
    grid-template-columns: 1fr;
  }

  .catalog-row {
    grid-template-columns: 58px 1fr;
  }

  .catalog-actions {
    grid-column: 1 / -1;
  }

  .reader-mobile-bar {
    display: inline-flex;
    max-width: calc(100vw - 20px);
    bottom: max(12px, env(safe-area-inset-bottom));
  }

  .reader-toolbar {
    padding: 8px 12px;
  }

  .reader-toolbar .reader-hide-sm {
    display: none;
  }
}

@media (max-width: 680px) {
  .admin-table thead {
    display: none;
  }

  .admin-table,
  .admin-table tbody,
  .admin-table tr,
  .admin-table td {
    display: block;
    width: 100%;
  }

  .admin-table tr {
    background: var(--bg-room);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    margin-bottom: 12px;
  }

  .admin-table td {
    border-bottom: 1px solid rgba(77, 44, 25, 0.08);
    padding: 8px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  .admin-table td:last-child {
    border-bottom: none;
    padding-bottom: 2px;
  }

  .admin-table td::before {
    content: attr(data-label);
    font-size: 0.74rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    flex-shrink: 0;
  }

  .admin-table td[data-label="Volume"] {
    flex-direction: column;
    align-items: flex-start;
  }

  .admin-table td[data-label="Volume"]::before {
    display: none;
  }

  .admin-table td[data-label="Shelf Name"] {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 640px) {
  .banner-identity {
    flex-direction: column;
    text-align: center;
    gap: 12px;
  }

  .banner-logo-card {
    width: 104px;
  }

  .shelf-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .shelf-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 6px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .shelf-tab {
    flex-shrink: 0;
  }

  .shelf-right-controls {
    justify-content: space-between;
  }

  .shelf-right-controls .control-select {
    flex: 1 1 auto;
    min-width: 0;
  }

  .admin-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .admin-tab-btn {
    flex-shrink: 0;
  }
}

@media (max-width: 520px) {
  .container {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  .header-inner {
    row-gap: 8px;
  }

  .brand-link {
    flex: 1 1 auto;
  }

  .header-actions {
    flex: 0 1 auto;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
  }

  .brand-title {
    font-size: 1rem;
  }

  .brand-title-ta {
    display: none;
  }

  .brand-subtitle {
    font-size: 0.64rem;
    letter-spacing: 0.08em;
  }

  .brand-emblem {
    width: 38px;
    height: 38px;
  }

  .lang-toggle button {
    padding: 4px 8px;
    font-size: 0.72rem;
  }

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

  .btn {
    padding: 7px 11px;
    font-size: 0.8rem;
  }

  .banner-card {
    padding: 14px 14px;
  }

  .stat-chip {
    flex: 1 1 calc(50% - 8px);
    min-width: 0;
    padding: 7px 10px;
  }

  .bookcase-frame {
    padding: 0 7px 12px;
  }

  .bookcase-cornice {
    margin: 0 -7px;
    padding: 10px 12px;
  }

  .brass-plaque {
    padding: 5px 12px;
    font-size: 0.86rem;
  }

  .shelf-books {
    gap: 10px;
    padding: 0 8px;
  }

  .book-volume::after {
    right: -4px;
    width: 4px;
  }

  .book-caption {
    padding: 6px 7px;
  }

  .book-caption__title {
    font-size: 0.77rem;
  }

  .book-caption__actions {
    gap: 4px;
  }

  .book-caption__actions .btn {
    min-height: 32px;
    padding: 5px 5px;
    font-size: 0.7rem;
  }

  .upload-subgrid-3 {
    grid-template-columns: 1fr 1fr;
  }

  .admin-auth-card {
    padding: 22px 16px;
  }

  .admin-panel {
    padding: 14px;
  }

  .modal-backdrop {
    padding: 10px;
  }
}

@media (max-width: 380px) {
  .header-inner {
    gap: 8px;
  }

  .brand-subtitle {
    display: none;
  }

  .brand-emblem {
    width: 34px;
    height: 34px;
  }

  .brand-title {
    font-size: 0.92rem;
  }

  .header-actions .btn {
    padding: 6px 9px;
    font-size: 0.74rem;
  }

  .book-caption__actions {
    grid-template-columns: minmax(0, 1fr) 30px;
  }

  .admin-stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
}
