:root {
  --bg: #050812;
  --panel: rgba(12, 18, 33, 0.94);
  --panel-2: rgba(18, 27, 48, 0.94);

  --text: #eaf0ff;
  --muted: #9caac8;
  --muted-2: #7281a1;

  --blue: #6d8fd8;
  --blue-2: #9bb8f7;

  --silver: #c9d3e8;
  --silver-2: #edf3ff;

  --paper: #e1e6ef;
  --paper-2: #b7c1d1;
  --ink: #101827;

  --danger: #db6d7b;
  --success: #86d2a4;

  --border: rgba(190, 210, 245, 0.18);
  --border-strong: rgba(190, 210, 245, 0.5);

  --reader-font: Georgia, "Times New Roman", serif;
  --reader-size: 22px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  background:
    radial-gradient(circle at 14% 0%, rgba(109, 143, 216, 0.22), transparent 34%),
    radial-gradient(circle at 88% 12%, rgba(155, 184, 247, 0.13), transparent 30%),
    radial-gradient(circle at 50% 85%, rgba(42, 68, 119, 0.2), transparent 42%),
    linear-gradient(135deg, #050812, #10192e 50%, #040713);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at center, transparent 0 46%, rgba(0,0,0,0.44) 100%),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.018) 0 1px, transparent 1px 44px);
}

button,
select,
input {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.reading-progress {
  position: fixed;
  z-index: 100;
  top: 0;
  left: 0;
  height: 4px;
  width: 0%;
  background: linear-gradient(90deg, var(--blue), var(--silver-2));
  box-shadow: 0 0 18px rgba(155, 184, 247, 0.7);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 80;
  min-height: 64px;
  padding: 12px 22px;
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(5, 8, 18, 0.84);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
}

.app {
  position: relative;
  z-index: 1;
  width: min(1220px, calc(100% - 34px));
  margin: 0 auto;
  padding: 42px 0 80px;
}

.brand,
.top-button,
.primary-button,
.secondary-button,
.ghost-button,
.small-button {
  border: 1px solid var(--border);
  color: var(--text);
  background: rgba(18, 27, 48, 0.78);
  border-radius: 999px;
  padding: 10px 15px;
  transition:
    transform 0.16s ease,
    border-color 0.16s ease,
    background 0.16s ease,
    box-shadow 0.16s ease;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: bold;
  letter-spacing: 0.04em;
}

.brand-mark {
  color: var(--blue-2);
}

.brand:hover,
.top-button:hover,
.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.small-button:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
  background: rgba(35, 50, 82, 0.9);
  box-shadow: 0 16px 34px rgba(0,0,0,0.3);
}

.primary-button {
  background: linear-gradient(135deg, #395d9e, #172844);
}

.secondary-button {
  background: rgba(20, 31, 54, 0.92);
}

.ghost-button {
  background: rgba(0, 0, 0, 0.22);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none !important;
}

.breadcrumb {
  min-width: 0;
  color: var(--muted);
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.readonly-badge {
  margin-left: auto;
  border: 1px solid rgba(155, 184, 247, 0.28);
  border-radius: 999px;
  padding: 7px 10px;
  color: var(--blue-2);
  background: rgba(155, 184, 247, 0.08);
  font-size: 0.86rem;
  white-space: nowrap;
}

.hero {
  text-align: center;
  margin-bottom: 36px;
}

.kicker {
  margin: 0 0 10px;
  color: var(--blue-2);
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 0.76rem;
  font-weight: bold;
}

.title {
  margin: 0;
  font-size: clamp(2.4rem, 6vw, 5.2rem);
  line-height: 1;
  text-shadow: 0 18px 40px rgba(0,0,0,0.45);
}

.subtitle {
  max-width: 820px;
  margin: 18px auto 0;
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.65;
}

.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.actions.center {
  justify-content: center;
}

.center-page,
.error-page,
.empty-page {
  min-height: 450px;
  display: grid;
  place-items: center;
  text-align: center;
}

.message-card {
  width: min(820px, 100%);
  padding: clamp(28px, 5vw, 52px);
  border-radius: 34px;
  border: 1px solid var(--border);
  background:
    radial-gradient(circle at 20% 0%, rgba(155,184,247,0.15), transparent 35%),
    linear-gradient(135deg, rgba(21, 33, 58, 0.88), rgba(5, 8, 18, 0.97));
  box-shadow: 0 34px 90px rgba(0,0,0,0.58);
}

.message-card h1 {
  margin: 0 0 16px;
  font-size: clamp(2.2rem, 6vw, 4.4rem);
}

.message-card p {
  color: var(--muted);
  line-height: 1.7;
}

.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 295px));
  justify-content: center;
  gap: 28px;
}

.cover-card {
  position: relative;
  overflow: hidden;
  width: 100%;
  min-height: 300px;
  padding: 26px;
  border-radius: 18px 30px 30px 18px;
  border: 1px solid rgba(190, 210, 245, 0.26);
  color: var(--text);
  text-align: left;
  background:
    linear-gradient(90deg, rgba(0,0,0,0.36) 0 18px, transparent 18px),
    radial-gradient(circle at 72% 18%, rgba(155,184,247,0.14), transparent 34%),
    linear-gradient(145deg, #15213a, #070b16 72%);
  box-shadow:
    16px 24px 58px rgba(0,0,0,0.5),
    inset 0 0 0 1px rgba(255,255,255,0.04);
}

.cover-card::before {
  content: "";
  position: absolute;
  left: 31px;
  top: 28px;
  bottom: 28px;
  width: 5px;
  border-radius: 999px;
  background: linear-gradient(var(--silver-2), var(--blue));
  opacity: 0.85;
}

.cover-card::after {
  content: "";
  position: absolute;
  inset: 16px;
  border: 1px solid rgba(190,210,245,0.17);
  border-radius: 14px 24px 24px 14px;
  pointer-events: none;
}

.cover-card:hover {
  transform: translateY(-7px) rotate(-1deg);
  border-color: rgba(190, 210, 245, 0.65);
}

.cover-content {
  position: relative;
  z-index: 1;
  min-height: 240px;
  padding-left: 24px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.cover-title {
  margin: 0;
  font-size: clamp(1.8rem, 3vw, 2.6rem);
  line-height: 1.04;
  overflow-wrap: anywhere;
}

.cover-meta {
  margin: 18px 0 0;
  color: var(--muted);
}

.saga-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 24px;
  align-items: start;
}

.book-list-stage {
  width: min(980px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 42px;
}

.book-section {
  display: grid;
  gap: 12px;
}

.book-section-title {
  margin: 0 0 4px;
  color: var(--blue-2);
  letter-spacing: 0.13em;
  text-transform: uppercase;
  font-size: 0.8rem;
}

.book-row {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 15px 18px;
  color: var(--text);
  background:
    radial-gradient(circle at 8% 0%, rgba(155,184,247,0.12), transparent 34%),
    linear-gradient(135deg, rgba(20,31,54,0.92), rgba(5,8,18,0.96));
  box-shadow: 0 18px 42px rgba(0,0,0,0.32);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
  text-align: left;
}

.book-row:hover {
  transform: translateX(6px);
  border-color: var(--border-strong);
  background:
    radial-gradient(circle at 8% 0%, rgba(155,184,247,0.18), transparent 34%),
    linear-gradient(135deg, rgba(35,50,82,0.96), rgba(7,11,22,0.98));
}

.book-row-title {
  display: block;
  font-size: 1.15rem;
  font-weight: bold;
  line-height: 1.25;
}

.book-row-subtitle {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.9rem;
}

.book-row-index {
  color: var(--muted);
  font-size: 0.86rem;
}

.author-panel,
.side-panel {
  position: sticky;
  top: 84px;
  border: 1px solid var(--border);
  border-radius: 26px;
  padding: 18px;
  background:
    radial-gradient(circle at 50% 0%, rgba(155,184,247,0.12), transparent 40%),
    rgba(5, 8, 18, 0.94);
  box-shadow: 0 28px 80px rgba(0,0,0,0.48);
}

.author-panel h3,
.side-panel h3 {
  margin: 0 0 12px;
}

.author-text {
  min-height: 120px;
  color: var(--muted);
  line-height: 1.65;
  white-space: pre-wrap;
}

.codex {
  width: min(980px, 100%);
  margin: 0 auto;
  border-radius: 34px;
  padding: clamp(24px, 5vw, 52px);
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 0%, rgba(255,255,255,0.38), transparent 40%),
    linear-gradient(90deg, rgba(41, 56, 87, 0.18), transparent 10%, transparent 90%, rgba(41,56,87,0.18)),
    linear-gradient(135deg, #dfe4ee, #b6c0d1);
  box-shadow: 0 30px 100px rgba(0,0,0,0.62);
}

.codex .kicker {
  color: rgba(17, 24, 39, 0.62);
}

.codex-title {
  margin: 0;
  color: var(--ink);
  font-size: clamp(2rem, 5vw, 4.1rem);
  line-height: 1;
}

.codex-subtitle {
  margin: 10px 0 0;
  color: rgba(17, 24, 39, 0.64);
}

.chapter-list {
  margin-top: 28px;
  display: grid;
  gap: 9px;
}

.chapter-row {
  width: 100%;
  border: 1px solid rgba(17, 24, 39, 0.16);
  border-radius: 14px;
  padding: 9px 12px;
  color: var(--ink);
  background: rgba(255,255,255,0.28);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  text-align: left;
}

.chapter-row:hover {
  background: rgba(255,255,255,0.55);
  transform: translateX(5px);
}

.chapter-open {
  border: none;
  background: transparent;
  color: var(--ink);
  padding: 6px;
  text-align: left;
  border-radius: 10px;
}

.chapter-open:hover {
  background: rgba(255,255,255,0.28);
}

.chapter-name {
  display: block;
  font-size: 1rem;
  font-weight: bold;
}

.chapter-index {
  color: rgba(17, 24, 39, 0.55);
  font-size: 0.9rem;
}

.reader-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 24px;
  align-items: start;
}

.reader-main {
  min-height: 92vh;
  color: var(--ink);
  border-radius: 34px;
  padding: clamp(26px, 5vw, 64px);
  background:
    radial-gradient(circle at 50% 0%, rgba(255,255,255,0.46), transparent 38%),
    linear-gradient(90deg, rgba(41,56,87,0.14), transparent 8%, transparent 92%, rgba(41,56,87,0.14)),
    linear-gradient(135deg, #e1e6ef, #b7c1d1);
  box-shadow: 0 30px 100px rgba(0,0,0,0.64);
}

.reader-heading {
  margin: 0 0 28px;
  color: var(--ink);
  font-size: clamp(2.1rem, 5vw, 4.2rem);
  line-height: 1;
}

.reader-text {
  font-family: var(--reader-font);
  font-size: var(--reader-size);
  line-height: 1.9;
}

.reader-text p {
  margin: 0 0 1.35em;
}

.tool-group {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.tool-group label {
  color: var(--muted);
  font-size: 0.92rem;
}

.tool-group select,
.tool-group input {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--border);
  color: var(--text);
  background: rgba(0,0,0,0.3);
  padding: 10px 12px;
}

.entities-page {
  display: grid;
  gap: 18px;
}

.entities-card {
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: 22px;
  background:
    radial-gradient(circle at 10% 0%, rgba(155,184,247,0.12), transparent 35%),
    rgba(5, 8, 18, 0.88);
  box-shadow: 0 24px 70px rgba(0,0,0,0.42);
}

.entity-table {
  display: grid;
  gap: 12px;
  margin-top: 22px;
}

.entity-row {
  display: grid;
  grid-template-columns: 150px minmax(160px, 1fr) 120px 120px;
  gap: 12px;
  align-items: start;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(255,255,255,0.045);
}

.entity-type {
  width: fit-content;
  border: 1px solid rgba(155,184,247,0.25);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--blue-2);
  background: rgba(155,184,247,0.08);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  font-weight: bold;
}

.entity-name {
  margin: 0;
  font-size: 1.25rem;
}

.entity-info {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.55;
  white-space: pre-wrap;
}

.entity-count {
  color: var(--silver-2);
  font-size: 1.8rem;
  font-weight: bold;
}

.entity-count-label {
  color: var(--muted);
  font-size: 0.82rem;
}

.empty-entity {
  color: var(--muted);
  line-height: 1.6;
}

@media (max-width: 980px) {
  .saga-layout,
  .reader-shell {
    grid-template-columns: 1fr;
  }

  .author-panel,
  .side-panel {
    position: static;
  }

  .entity-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .app {
    width: min(100%, calc(100% - 24px));
    padding: 28px 0 58px;
  }

  .topbar {
    padding: 10px 12px;
    gap: 8px;
  }

  .breadcrumb,
  .readonly-badge {
    display: none;
  }

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

  .cover-card {
    min-height: 230px;
  }

  .cover-content {
    min-height: 180px;
  }

  .reader-main {
    padding: 26px 20px;
  }

  .chapter-row,
  .book-row {
    grid-template-columns: 1fr;
  }
}
