:root {
  --ink: #2b1a12;
  --muted: #755b4b;
  --line: #ead6b4;
  --panel: #ffffff;
  --wash: #fff8ec;
  --brand: #b8170f;
  --brand-strong: #871008;
  --gold: #f2b933;
  --gold-soft: #fff0c8;
  --flame: #ef6b1f;
  --warn: #8a4b00;
  --bad: #b8170f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 240, 200, 0.72), rgba(255, 248, 236, 0.96) 260px),
    var(--wash);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  background: linear-gradient(180deg, #d51d12, var(--brand));
  color: #fff;
  padding: 10px 14px;
  border-radius: 6px;
  cursor: pointer;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 10px 14px;
  border-radius: 6px;
  background: linear-gradient(180deg, #d51d12, var(--brand));
  color: #fff;
  text-decoration: none;
}

button.secondary {
  background: #fff0c8;
  color: var(--ink);
  border: 1px solid #e7bd62;
}

button.danger {
  background: var(--bad);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: #fff;
}

input:focus,
select:focus {
  outline: 2px solid rgba(242, 185, 51, 0.46);
  border-color: var(--gold);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
}

.inline-check input {
  width: auto;
}

.shell {
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: rgba(255, 250, 241, 0.96);
  border-bottom: 1px solid #e2b95f;
  box-shadow: 0 4px 18px rgba(135, 16, 8, 0.08);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  color: var(--brand-strong);
}

.brand span {
  font-size: 18px;
  line-height: 1.15;
  max-width: min(54vw, 520px);
}

.brand img {
  width: 42px;
  height: 42px;
  object-fit: cover;
  border-radius: 50%;
  border: 2px solid var(--gold);
  background: #fff;
}

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

.nav a {
  color: var(--ink);
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 6px;
}

.nav a.active,
.nav a:hover {
  background: #fff0c8;
  color: var(--brand-strong);
}

.nav a.upload-live-link {
  background: var(--brand);
  color: #fff;
  font-weight: 700;
}

.nav a.upload-live-link.done {
  background: #fff0c8;
  color: var(--brand-strong);
}

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 24px;
}

.login-page {
  position: relative;
  overflow: hidden;
  min-height: 100vh;
  display: grid;
  justify-items: end;
  align-items: center;
  padding: 32px max(32px, 8vw) 32px 32px;
  background: #1c0d09;
}

.login-page::before,
.login-page::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.login-page::before {
  background: url("/assets/gothic-library-bg.svg?v=2") center / cover no-repeat;
  transform: scale(1.02);
}

.login-page::after {
  background:
    linear-gradient(90deg, rgba(18, 8, 5, 0.18), rgba(18, 8, 5, 0.08) 48%, rgba(18, 8, 5, 0.58)),
    radial-gradient(circle at 41% 45%, rgba(255, 215, 117, 0.24), transparent 430px);
}

.login-card,
.panel,
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.login-card {
  position: relative;
  z-index: 1;
  width: min(440px, 100%);
  padding: 26px;
  border: 1px solid rgba(255, 220, 140, 0.46);
  border-top: 5px solid rgba(242, 185, 51, 0.9);
  background: rgba(35, 15, 10, 0.48);
  color: #fff8ec;
  box-shadow: 0 30px 90px rgba(20, 8, 5, 0.58);
  backdrop-filter: blur(10px);
}

.login-card .subtle,
.login-card label {
  color: #fff0c8;
}

.login-card input {
  background: rgba(255, 250, 241, 0.94);
  color: var(--ink);
  border-color: rgba(242, 185, 51, 0.62);
}

.login-card button.secondary {
  background: rgba(255, 240, 200, 0.92);
}

.login-brand {
  display: grid;
  justify-items: center;
  gap: 12px;
  text-align: center;
}

.login-brand img {
  width: 118px;
  height: 118px;
  object-fit: cover;
  border-radius: 50%;
  border: 3px solid var(--gold);
  background: #fff;
  box-shadow: 0 10px 26px rgba(135, 16, 8, 0.16);
}

.login-brand h1 {
  font-size: clamp(30px, 4.2vw, 42px);
  line-height: 1.05;
}

.login-card h1,
.page h1 {
  margin: 0 0 8px;
}

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

.form {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

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

.admin-panels {
  display: grid;
  grid-template-columns: minmax(320px, 1.25fr) minmax(260px, 0.75fr);
  gap: 14px;
  align-items: start;
  margin: 18px 0 26px;
}

.admin-panels .panel:first-child {
  grid-row: span 2;
}

.admin-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 16px 0 20px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf1;
}

.admin-tabs a {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--brand-strong);
  text-decoration: none;
  font-weight: 700;
}

.admin-tabs a.active,
.admin-tabs a:hover {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.admin-action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin: 12px 0 26px;
}

.admin-action-card {
  display: block;
  color: inherit;
  text-decoration: none;
}

.admin-action-card h2 {
  margin-top: 0;
}

.panel {
  padding: 18px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin: 12px 0 24px;
}

.stat-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 58px;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stat-card span {
  color: var(--muted);
  font-size: 13px;
}

.stat-card strong {
  color: var(--brand-strong);
  font-size: 24px;
}

.stat-total {
  border-color: #e7bd62;
  background: #fff0c8;
}

.storage-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf0;
}

.storage-panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.storage-panel h3 {
  margin: 0 0 4px;
  color: var(--brand-strong);
}

.storage-meter {
  height: 12px;
  overflow: hidden;
  background: #f2dfbd;
  border-radius: 999px;
  margin: 0;
}

.storage-meter span {
  display: block;
  height: 100%;
  min-width: 2px;
  background: linear-gradient(90deg, var(--brand), var(--flame), var(--gold));
}

.storage-meter-label {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: end;
  margin: 18px 0;
}

.toolbar.compact {
  margin: 0;
}

.toolbar .sub-category-button {
  margin-left: 10px;
  border-color: #f0cf84;
  background: #fff7e6;
}

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

.section-heading {
  justify-content: space-between;
}

.section-heading {
  margin-top: 22px;
}

.section-heading h2 {
  margin: 0;
}

.searchbar {
  align-items: end;
  background: #fffaf1;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.library-page {
  max-width: 1260px;
}

.library-hero {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(320px, 430px);
  gap: 20px;
  align-items: stretch;
  padding: 24px;
  margin-bottom: 18px;
  border: 1px solid #e7bd62;
  border-radius: 8px;
  background:
    linear-gradient(120deg, rgba(43, 26, 18, 0.86), rgba(135, 16, 8, 0.7)),
    url("/assets/gothic-library-bg.svg?v=2") center / cover no-repeat;
  color: #fff8ec;
  box-shadow: 0 16px 42px rgba(135, 16, 8, 0.18);
}

.library-hero-copy {
  display: grid;
  align-content: center;
  gap: 12px;
  min-height: 250px;
}

.library-hero h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 58px);
  line-height: 1;
}

.library-hero p {
  max-width: 640px;
  margin: 0;
  color: #fff0c8;
  font-size: 17px;
}

.library-kicker {
  color: var(--gold);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.library-metrics {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.library-metrics span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 240, 200, 0.42);
  border-radius: 8px;
  background: rgba(255, 248, 236, 0.12);
  color: #fff8ec;
}

.library-metrics strong {
  color: var(--gold);
}

.library-search-panel {
  display: grid;
  gap: 14px;
  align-content: center;
  padding: 18px;
  border: 1px solid rgba(255, 240, 200, 0.42);
  border-radius: 8px;
  background: rgba(255, 248, 236, 0.9);
  box-shadow: 0 16px 36px rgba(20, 8, 5, 0.26);
}

.library-search-panel label {
  color: var(--brand-strong);
  font-weight: 700;
}

.category-ribbon {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  overflow: visible;
  padding: 8px 2px 14px;
  margin-bottom: 8px;
}

.category-ribbon a {
  flex: 1 1 190px;
  text-align: center;
  padding: 9px 12px;
  border: 1px solid #e7bd62;
  border-radius: 8px;
  background: #fffaf1;
  color: var(--brand-strong);
  text-decoration: none;
  font-weight: 700;
}

.category-ribbon a.active,
.category-ribbon a:hover {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.subcategory-ribbon {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px;
  margin: -4px 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.82);
}

.subcategory-ribbon a {
  padding: 7px 10px;
  margin-left: calc(var(--level, 0) * 12px);
  border-radius: 8px;
  background: #fff0c8;
  color: var(--brand-strong);
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
}

.subcategory-ribbon a:hover {
  background: var(--brand);
  color: #fff;
}

.continue-reading {
  margin: 0 0 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf1;
}

.continue-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.continue-card {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) auto auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid #efd49a;
  border-radius: 8px;
  background: #fff;
}

.continue-card h3,
.continue-card p {
  margin: 0;
}

.continue-card h3 {
  color: var(--brand-strong);
  font-size: 15px;
  line-height: 1.25;
}

.continue-card p {
  font-size: 13px;
}

.continue-card button {
  white-space: nowrap;
}

.category-tree {
  display: grid;
  gap: 12px;
  margin: 12px 0 24px;
}

.category-tree-group {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.78);
}

.category-tree-row {
  margin-left: calc(var(--level, 0) * 18px);
}

.category-tree-row a {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid #efd49a;
  border-radius: 8px;
  background: #fff;
  color: var(--brand-strong);
  text-decoration: none;
}

.category-tree-row a:hover {
  border-color: var(--brand);
  background: #fff0c8;
}

.category-tree-row span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.category-tree-row strong {
  color: var(--brand);
  white-space: nowrap;
}

.library-results {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.cover-cell {
  width: 76px;
}

.book-cover-thumb {
  width: 56px;
  min-width: 56px;
  height: 78px;
  overflow: hidden;
  display: grid;
  place-items: center;
  border: 1px solid #e7bd62;
  border-radius: 4px;
  background: linear-gradient(160deg, #fff8ec, #f2b933 58%, #b8170f);
  box-shadow: 0 2px 8px rgba(135, 16, 8, 0.14);
  color: #fff;
}

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

.book-cover-thumb span {
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
}

.book-cover-thumb small {
  max-width: 48px;
  padding: 0 4px 5px;
  color: #5a1b12;
  font-size: 9px;
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
}

.book-cover-thumb.cover-fallback {
  align-content: center;
  gap: 4px;
  background: #fff7e6;
  color: var(--brand-strong);
}

.upload-log {
  max-height: 180px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf1;
  color: var(--muted);
  font-size: 13px;
}

.folder-drop {
  display: grid;
  gap: 4px;
  padding: 16px;
  border: 2px dashed #e7bd62;
  border-radius: 8px;
  background: #fff7e6;
  color: var(--brand-strong);
  cursor: pointer;
}

.folder-drop span {
  color: var(--muted);
  font-size: 13px;
}

.folder-drop.active {
  border-color: var(--brand);
  background: #fff0c8;
}

.upload-progress {
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf1;
}

.upload-progress[hidden] {
  display: none;
}

.upload-progress progress {
  width: 100%;
  height: 14px;
  accent-color: var(--brand);
}

.upload-progress span {
  color: var(--brand-strong);
  font-size: 13px;
  font-weight: 700;
}

.upload-log:empty {
  display: none;
}

.upload-log div {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}

.upload-log div:last-child {
  border-bottom: 0;
}

.upload-skipped-details {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid #e7bd62;
  border-radius: 8px;
  background: #fff7e6;
}

.upload-skipped-details p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.upload-skipped-details ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.upload-skipped-details li {
  display: grid;
  gap: 2px;
  overflow-wrap: anywhere;
}

.upload-skipped-details em {
  color: var(--brand-strong);
  font-style: normal;
  font-size: 12px;
}

.temp-password {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid #e7bd62;
  border-radius: 8px;
  background: #fff0c8;
}

.temp-password span {
  color: var(--muted);
  font-size: 13px;
}

.temp-password strong {
  color: var(--brand-strong);
  font-size: 20px;
  letter-spacing: 1px;
}

.card {
  padding: 16px;
  display: grid;
  gap: 10px;
}

.card h3 {
  margin: 0;
}

.badge {
  display: inline-flex;
  width: fit-content;
  border-radius: 999px;
  padding: 4px 9px;
  background: #fff0c8;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.badge.pending {
  background: #fff2d6;
  color: var(--warn);
}

.badge.published {
  background: #fff0c8;
  color: var(--brand-strong);
}

.table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

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

.table td:last-child {
  min-width: 260px;
}

.table td:last-child button {
  margin: 2px;
}

.library-table td:last-child {
  min-width: 80px;
}

.library-admin-edit {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-width: 320px;
}

.library-admin-edit select {
  min-width: 0;
}

.hidden-file {
  display: none;
}

.reader {
  height: calc(100vh - 64px);
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.reader-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 10px;
  background: #fffaf1;
  border-bottom: 1px solid var(--line);
}

.reader-bar-pdf {
  flex-wrap: wrap;
}

.reader-title {
  min-width: 180px;
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.reader-title strong {
  max-width: 340px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-title .subtle {
  font-size: 12px;
}

.reader iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.epub-reader {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  background: #fffaf1;
}

.epub-stage {
  grid-row: 2;
  position: relative;
  min-height: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #fffdf8;
}

.epub-stage iframe {
  background: #fffdf8;
}

.epub-opening-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.epub-opening-preview {
  z-index: 2;
}

.pdf-viewer {
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr;
  background: #f5e8d4;
}

.pdf-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex-wrap: wrap;
  flex: 1 1 380px;
}

.pdf-controls button {
  padding: 6px 9px;
}

.pdf-controls button.active {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
}

.pdf-controls span {
  color: var(--muted);
  min-width: 110px;
  text-align: center;
  font-size: 13px;
}

.pdf-page-jump {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 150px;
}

.pdf-page-jump label {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.pdf-page-jump input {
  width: 68px;
  min-height: 32px;
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
}

.pdf-stage {
  min-height: 0;
  overflow: auto;
  display: grid;
  justify-items: center;
  align-items: start;
  padding: 8px;
}

.pdf-stage canvas,
.pdf-scroll-page canvas {
  max-width: 100%;
  height: auto;
  background: #fff;
  box-shadow: 0 2px 16px rgba(135, 16, 8, 0.18);
}

.pdf-scroll-stage {
  min-height: 0;
  overflow: auto;
  display: grid;
  gap: 12px;
  justify-items: center;
  align-content: start;
  padding: 8px;
}

.pdf-scroll-stage[hidden] {
  display: none;
}

.pdf-scroll-page {
  display: grid;
  justify-items: center;
  width: 100%;
}

.notice {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
}

.error {
  color: var(--bad);
}

@media (max-width: 680px) {
  .login-page {
    justify-items: center;
    padding: 22px;
  }

  .login-page::after {
    background:
      linear-gradient(180deg, rgba(18, 8, 5, 0.34), rgba(18, 8, 5, 0.66)),
      radial-gradient(circle at 50% 28%, rgba(255, 215, 117, 0.22), transparent 310px);
  }

  .library-hero {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .library-hero-copy {
    min-height: 180px;
  }

  .library-search-panel,
  .library-results {
    padding: 14px;
  }

  .continue-card {
    grid-template-columns: 56px minmax(0, 1fr);
  }

  .continue-card button {
    width: 100%;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .brand span {
    max-width: 100%;
  }

  .admin-panels {
    grid-template-columns: 1fr;
  }

  .page {
    padding: 20px 14px;
  }

  .reader-title {
    min-width: 100%;
  }

  .reader-title strong {
    max-width: 100%;
  }

  .pdf-controls {
    justify-content: flex-start;
    gap: 4px;
  }

  .pdf-controls button {
    padding: 6px 8px;
    font-size: 13px;
  }

  .pdf-controls span {
    min-width: 92px;
  }

  .pdf-page-jump {
    min-width: 130px;
  }

  .pdf-page-jump input {
    width: 58px;
  }

  .reader-bar {
    padding: 5px 8px;
  }

  .pdf-stage,
  .pdf-scroll-stage {
    padding: 4px;
    gap: 8px;
  }

  .library-admin-edit {
    grid-template-columns: 1fr;
    min-width: 220px;
  }
}
