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

:root {
  --bg: #e9e1d6;
  --surface: rgba(255, 252, 247, 0.64);
  --surface-strong: rgba(255, 251, 245, 0.86);
  --line: rgba(55, 40, 26, 0.2);
  --text: #1b1611;
  --muted: #36281e;
  --accent: #c25a21;
  --gold: #b8943e;
  --punk-cyan: #2fc9c2;
  --shadow: 0 24px 60px rgba(35, 25, 16, 0.16);
  --radius-lg: 24px;
  --radius-md: 16px;
  --font: Georgia, "Times New Roman", "Songti SC", serif;
  --font-mono: "SF Mono", "Fira Code", "Courier New", monospace;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  color: var(--text);
  background:
    linear-gradient(rgba(245, 238, 229, 0.72), rgba(232, 223, 212, 0.76)),
    linear-gradient(180deg, #f4ede4 0%, #e6ddcf 100%);
  font-family: var(--font);
  line-height: 1.65;
  font-weight: 500;
  overflow-x: hidden;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.86' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 220px 220px;
  z-index: 2;
}

button,
input {
  font: inherit;
}

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

.page-border {
  position: fixed;
  inset: 8px;
  border: 1px solid var(--line);
  pointer-events: none;
  z-index: 4;
}

.page-border::before {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(55, 40, 26, 0.12);
}

.bookshelf-page {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  padding: 14px;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 320px;
  grid-template-rows: 58px minmax(0, 1fr);
  gap: 12px;
}

.glass {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px) saturate(140%);
}

.glass::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: calc(var(--radius-lg) - 6px);
  pointer-events: none;
  opacity: .48;
  z-index: 1;
}

.top-strip {
  grid-column: 1 / 4;
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 10px;
}

.kicker {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
}

.top-strip h1 {
  margin: 0;
  font-size: clamp(25px, 2.2vw, 36px);
  line-height: 1;
}

.nav-pills {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.pill {
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(55, 40, 26, 0.17);
  border-radius: 999px;
  background: rgba(255, 252, 247, 0.72);
  box-shadow: 0 10px 24px rgba(35, 25, 16, 0.08);
  padding: 0 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

.pill.primary {
  border-color: rgba(194, 90, 33, .46);
  background: rgba(194, 90, 33, .14);
  color: #7b3111;
}

.pill.danger {
  border-color: rgba(214, 58, 58, .34);
  background: rgba(214, 58, 58, .1);
  color: #8f2525;
}

.filter-panel {
  grid-column: 1;
  grid-row: 2;
  padding: 18px;
}

.filter-block {
  position: relative;
  z-index: 2;
  display: grid;
  gap: 8px;
  margin-bottom: 22px;
}

.filter-block h2 {
  margin: 0 0 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
}

.filter {
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid rgba(55, 40, 26, 0.13);
  border-radius: 13px;
  background: rgba(255, 252, 247, 0.68);
  color: var(--text);
  padding: 0 12px;
  text-align: left;
}

.filter.active {
  border-color: rgba(47, 201, 194, .45);
  background: rgba(47, 201, 194, .13);
}

.library-panel {
  grid-column: 2;
  grid-row: 2;
  padding: 16px;
}

.toolbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.search {
  flex: 1;
  display: grid;
  gap: 5px;
  font-family: var(--font-mono);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.search input {
  height: 38px;
  width: 100%;
  border: 1px solid rgba(55, 40, 26, 0.14);
  border-radius: 13px;
  background: rgba(255, 252, 247, 0.84);
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

.sort-chip {
  height: 38px;
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(55, 40, 26, 0.14);
  border-radius: 13px;
  background: rgba(255, 252, 247, 0.76);
  padding: 0 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.book-grid {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
}

.book-card {
  min-height: 184px;
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 12px;
  border: 1px solid rgba(55, 40, 26, 0.13);
  border-radius: var(--radius-md);
  background: rgba(255, 252, 247, 0.82);
  box-shadow: 0 12px 28px rgba(35, 25, 16, 0.09);
  padding: 12px;
  cursor: pointer;
}

.book-card.selected {
  border-color: rgba(194, 90, 33, .42);
  background: rgba(255, 248, 238, 0.9);
}

.book-card:focus {
  outline: 2px solid rgba(47, 201, 194, .55);
  outline-offset: 2px;
}

.cover,
.detail-cover {
  display: grid;
  place-items: center;
  border: 1px solid rgba(55, 40, 26, 0.16);
  border-radius: 14px;
  background: linear-gradient(155deg, rgba(194, 90, 33, .18), rgba(255, 252, 247, .82));
  color: #7b3111;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 800;
}

.cover.cyan {
  background: linear-gradient(155deg, rgba(47, 201, 194, .2), rgba(255, 252, 247, .82));
  color: #0e7772;
}

.cover.gold {
  background: linear-gradient(155deg, rgba(184, 148, 62, .24), rgba(255, 252, 247, .82));
  color: #705213;
}

.book-info {
  min-width: 0;
  display: grid;
  align-content: space-between;
}

.book-info h2 {
  margin: 0;
  font-size: 19px;
  line-height: 1.25;
}

.book-info p {
  margin: 8px 0;
  color: var(--muted);
}

.book-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.book-tag {
  border: 1px solid rgba(55, 40, 26, 0.12);
  border-radius: 999px;
  background: rgba(255, 252, 247, 0.72);
  color: var(--muted);
  padding: 2px 7px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
}

.progress {
  height: 8px;
  border-radius: 999px;
  background: rgba(55, 40, 26, 0.11);
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--punk-cyan));
}

.empty-state {
  position: relative;
  z-index: 2;
  display: none;
  margin-top: 16px;
  border: 1px solid rgba(55, 40, 26, 0.12);
  border-radius: var(--radius-md);
  background: rgba(255, 252, 247, 0.78);
  padding: 18px;
  color: var(--muted);
}

.detail-panel {
  grid-column: 3;
  grid-row: 2;
  padding: 18px;
  display: grid;
  grid-template-rows: 230px auto auto auto;
  gap: 14px;
}

.detail-panel > * {
  position: relative;
  z-index: 2;
}

.detail-cover {
  min-height: 0;
  font-size: 18px;
}

.detail-copy h2 {
  margin: 4px 0 8px;
  font-size: 26px;
  line-height: 1.18;
}

.detail-copy p {
  margin: 0;
  color: var(--muted);
}

.detail-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.detail-stats div {
  display: grid;
  gap: 3px;
  padding: 10px;
  border: 1px solid rgba(55, 40, 26, 0.12);
  border-radius: 13px;
  background: rgba(255, 252, 247, 0.78);
}

.detail-stats strong {
  color: var(--accent);
  font-size: 19px;
  line-height: 1;
}

.detail-stats span {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
}

.detail-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.main-action,
.ghost-action {
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.main-action {
  border: 1px solid rgba(194, 90, 33, .46);
  background: rgba(194, 90, 33, .14);
  color: #7b3111;
}

.ghost-action {
  border: 1px solid rgba(47, 201, 194, .42);
  background: rgba(47, 201, 194, .12);
  color: #0e7772;
}

.ghost-action.danger {
  border-color: rgba(214, 58, 58, .34);
  background: rgba(214, 58, 58, .1);
  color: #8f2525;
}

.ghost-action:disabled,
.pill:disabled {
  cursor: not-allowed;
  opacity: .45;
}

.upload-status {
  min-height: 20px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
}

@media (max-width: 1000px) {
  .bookshelf-page {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }

  .top-strip,
  .filter-panel,
  .library-panel,
  .detail-panel {
    grid-column: 1;
    grid-row: auto;
  }

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

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

  .filter-block {
    margin-bottom: 0;
  }

  .detail-panel {
    grid-template-rows: auto;
  }

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

@media (max-width: 560px) {
  .bookshelf-page {
    padding: 10px;
  }

  .page-border {
    display: none;
  }

  .nav-pills {
    width: 100%;
    overflow-x: auto;
    justify-content: flex-start;
  }

  .filter-panel {
    grid-template-columns: 1fr;
  }

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

  .detail-stats,
  .detail-actions {
    grid-template-columns: 1fr;
  }
}
