:root {
  color-scheme: dark;
  --bg: #171511;
  --bg-soft: #211e19;
  --panel: rgba(49, 44, 36, 0.72);
  --panel-solid: #2a261f;
  --line: rgba(255, 255, 255, 0.1);
  --text: #f8f2e8;
  --muted: #afa79a;
  --accent: #e79a52;
  --accent-strong: #ffad61;
  --accent-dark: #4d2d18;
  --danger: #f27878;
  --success: #84c99a;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 82% 0%, rgba(150, 85, 38, 0.23), transparent 28rem),
    radial-gradient(circle at 8% 22%, rgba(93, 56, 35, 0.18), transparent 24rem),
    var(--bg);
}
button, input, select, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, .book-card:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 3px;
}
.hidden { display: none !important; }

.app { min-height: 100vh; padding-bottom: 118px; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  min-height: 76px;
  padding: 0 5vw;
  border-bottom: 1px solid var(--line);
  background: rgba(23, 21, 17, 0.83);
  backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 0.8rem; }
.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(231, 154, 82, 0.42);
  border-radius: 50%;
  color: var(--accent);
  background: rgba(231, 154, 82, 0.08);
  font-size: 0.86rem;
  padding-left: 2px;
}
.brand strong, .brand span { display: block; }
.brand strong { font-family: Georgia, serif; font-size: 1.1rem; }
.brand div > span { margin-top: 0.12rem; color: var(--muted); font-size: 0.76rem; }
.brand-large { margin-bottom: 2rem; }
.brand-large .brand-mark { width: 54px; height: 54px; }
.brand-large strong { font-size: 1.4rem; }
.top-actions { display: flex; align-items: center; gap: 0.65rem; }

.content { width: min(1440px, 92vw); margin: 0 auto; }
.hero {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 300px;
  padding: 3.2rem clamp(0rem, 3vw, 3rem);
  overflow: hidden;
}
.hero::after {
  content: "";
  position: absolute;
  right: 3%;
  width: 340px;
  height: 340px;
  border: 1px solid rgba(231, 154, 82, 0.15);
  border-radius: 50%;
  box-shadow: inset 0 0 0 38px rgba(231, 154, 82, 0.018), inset 0 0 0 80px rgba(231, 154, 82, 0.018);
}
.eyebrow {
  margin: 0 0 0.65rem;
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.19em;
}
h1, h2, h3, p { margin-top: 0; }
h1 {
  position: relative;
  z-index: 1;
  margin-bottom: 1rem;
  max-width: 820px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.5rem, 5vw, 5.2rem);
  font-weight: 500;
  line-height: 0.98;
  letter-spacing: -0.045em;
}
.hero p:last-child { color: var(--muted); font-size: 1rem; }
.hero-orbit {
  position: relative;
  z-index: 2;
  display: grid;
  width: 118px;
  height: 118px;
  place-content: center;
  border: 1px solid rgba(231, 154, 82, 0.35);
  border-radius: 50%;
  text-align: center;
  background: rgba(23, 21, 17, 0.7);
  box-shadow: 0 0 60px rgba(231, 154, 82, 0.08);
}
.hero-orbit span { color: var(--accent); font-family: Georgia, serif; font-size: 2.2rem; }
.hero-orbit small { color: var(--muted); text-transform: uppercase; letter-spacing: 0.12em; }

.panel {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.14);
  backdrop-filter: blur(12px);
}
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.72rem;
}
.search-box {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 0.7rem;
  min-width: 240px;
  padding: 0 0.8rem;
  color: var(--muted);
}
.search-box input {
  width: 100%;
  padding: 0.75rem 0;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
}
.search-box input::placeholder { color: #817a70; }
.segmented { display: flex; gap: 0.25rem; padding: 0.2rem; border-radius: 12px; background: rgba(0, 0, 0, 0.16); }
.segmented button {
  padding: 0.62rem 0.8rem;
  border: 0;
  border-radius: 9px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  white-space: nowrap;
}
.segmented button.active { color: var(--text); background: rgba(255, 255, 255, 0.08); }

button { border: 0; cursor: pointer; }
.primary, .ghost, .icon-button, .play-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 11px;
  transition: transform 150ms ease, background 150ms ease, opacity 150ms ease;
}
.primary {
  min-height: 42px;
  padding: 0.65rem 1rem;
  color: #24170d;
  font-weight: 800;
  background: var(--accent);
}
.primary:hover { background: var(--accent-strong); transform: translateY(-1px); }
.primary:disabled { cursor: wait; opacity: 0.55; transform: none; }
.ghost {
  min-height: 40px;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.035);
}
.ghost:hover, .icon-button:hover { background: rgba(255, 255, 255, 0.08); }
.ghost.compact { min-height: 36px; padding: 0.45rem 0.7rem; font-size: 0.82rem; }
.icon-button { width: 40px; height: 40px; background: transparent; color: var(--muted); }
.wide { width: 100%; }

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin: 3rem 0 1.2rem;
}
.section-heading h2 { margin-bottom: 0; font-family: Georgia, serif; font-size: 2rem; font-weight: 500; }
.count-badge { padding: 0.35rem 0.65rem; border: 1px solid var(--line); border-radius: 99px; color: var(--muted); font-size: 0.76rem; }

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: clamp(1.2rem, 2vw, 2rem);
}
.book-card { min-width: 0; cursor: pointer; }
.cover-wrap {
  position: relative;
  aspect-ratio: 0.68;
  overflow: hidden;
  border-radius: 10px 16px 16px 10px;
  background: #3b342a;
  box-shadow: 12px 20px 36px rgba(0, 0, 0, 0.26);
  transition: transform 180ms ease, box-shadow 180ms ease;
}
.cover-wrap::before {
  content: "";
  position: absolute;
  z-index: 2;
  top: 0;
  bottom: 0;
  left: 5%;
  width: 1px;
  background: rgba(255, 255, 255, 0.16);
  box-shadow: 2px 0 rgba(0, 0, 0, 0.2);
}
.book-card:hover .cover-wrap { transform: translateY(-5px); box-shadow: 16px 28px 48px rgba(0, 0, 0, 0.34); }
.book-cover { width: 100%; height: 100%; background: linear-gradient(145deg, #62472f, #26211b); }
.book-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-placeholder { display: grid; width: 100%; height: 100%; place-items: center; color: rgba(255, 255, 255, 0.22); font-family: Georgia, serif; font-size: 4rem; }
.status-pill {
  position: absolute;
  z-index: 3;
  top: 0.7rem;
  right: 0.7rem;
  padding: 0.3rem 0.5rem;
  border-radius: 99px;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 800;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(8px);
}
.card-play {
  position: absolute;
  z-index: 4;
  right: 0.8rem;
  bottom: 0.8rem;
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  padding-left: 3px;
  border-radius: 50%;
  color: #28190d;
  background: var(--accent);
  box-shadow: 0 9px 26px rgba(0, 0, 0, 0.36);
  opacity: 0;
  transform: translateY(8px);
  transition: 180ms ease;
}
.book-card:hover .card-play, .card-play:focus-visible { opacity: 1; transform: translateY(0); }
.book-card-body { padding: 1rem 0.15rem 0; }
.book-series { min-height: 1em; margin-bottom: 0.35rem; color: var(--accent); font-size: 0.65rem; font-weight: 800; letter-spacing: 0.11em; text-transform: uppercase; }
.book-title { overflow: hidden; margin-bottom: 0.35rem; font-family: Georgia, serif; font-size: 1.25rem; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.book-author { overflow: hidden; margin-bottom: 0.65rem; color: var(--muted); font-size: 0.84rem; text-overflow: ellipsis; white-space: nowrap; }
.book-meta { display: flex; gap: 0.75rem; color: #817a70; font-size: 0.72rem; }
.progress-track { height: 3px; margin-top: 0.85rem; overflow: hidden; border-radius: 99px; background: rgba(255, 255, 255, 0.08); }
.progress-track span { display: block; width: 0; height: 100%; background: var(--accent); }
.progress-label { margin: 0.38rem 0 0; color: #817a70; font-size: 0.68rem; }

.empty-state { display: grid; min-height: 260px; place-items: center; align-content: center; padding: 2rem; text-align: center; }
.empty-state h2 { margin: 0.8rem 0 0.4rem; }
.empty-state p { color: var(--muted); }
.empty-icon { display: grid; width: 60px; height: 60px; place-items: center; border: 1px solid var(--line); border-radius: 50%; color: var(--accent); font-size: 1.5rem; }
.spinner { width: 30px; height: 30px; border: 3px solid rgba(255, 255, 255, 0.1); border-top-color: var(--accent); border-radius: 50%; animation: spin 800ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.player {
  position: fixed;
  z-index: 40;
  right: 1.3rem;
  bottom: 1.3rem;
  left: 1.3rem;
  display: grid;
  grid-template-columns: minmax(200px, 1fr) minmax(300px, 2fr) minmax(180px, 1fr);
  align-items: center;
  gap: 1.2rem;
  min-height: 86px;
  padding: 0.85rem 1rem;
  border: 1px solid rgba(231, 154, 82, 0.18);
  border-radius: 18px;
  background: rgba(31, 28, 23, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}
.player-book { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.mini-cover { flex: 0 0 auto; width: 52px; height: 62px; overflow: hidden; border-radius: 5px 8px 8px 5px; background: #3a3128; }
.mini-cover img { width: 100%; height: 100%; object-fit: cover; }
.mini-cover span { display: grid; width: 100%; height: 100%; place-items: center; color: var(--accent); }
.player-text { min-width: 0; }
.player-text strong, .player-text span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-text strong { font-family: Georgia, serif; font-size: 1rem; }
.player-text span { margin-top: 0.26rem; color: var(--muted); font-size: 0.76rem; }
.player-main { min-width: 0; }
.player-controls { display: flex; align-items: center; justify-content: center; gap: 0.2rem; }
.player-controls .icon-button { width: 36px; height: 34px; font-size: 0.73rem; }
.play-button { width: 42px; height: 42px; margin: 0 0.25rem; padding-left: 3px; border-radius: 50%; color: #26170c; background: var(--accent); }
.timeline-row { display: grid; grid-template-columns: 40px 1fr 40px; align-items: center; gap: 0.55rem; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.68rem; }
.timeline-row span:last-child { text-align: right; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.player-options { display: flex; align-items: center; justify-content: flex-end; gap: 0.7rem; }
.rate-control { color: var(--muted); font-size: 0.68rem; }
.rate-control select { display: block; margin-top: 0.2rem; padding: 0.25rem 0.4rem; border: 1px solid var(--line); border-radius: 7px; color: var(--text); background: #26221c; }

.centered-view { display: grid; min-height: 100vh; place-items: center; padding: 1rem; }
.login-panel { width: min(430px, 100%); padding: 2rem; }
label { display: block; color: var(--muted); font-size: 0.8rem; }
label input, label textarea {
  width: 100%;
  margin-top: 0.42rem;
  padding: 0.78rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  outline: 0;
  background: rgba(0, 0, 0, 0.18);
}
label + label { margin-top: 1rem; }
.login-panel .primary { margin-top: 1.3rem; }
.form-message { min-height: 1.2em; margin: 0.7rem 0 0; color: var(--muted); font-size: 0.78rem; }
.form-message.error, .error { color: var(--danger); }
.form-message.success { color: var(--success); }

.modal {
  width: min(760px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 20px;
  color: var(--text);
  background: #242019;
  box-shadow: var(--shadow);
}
.modal::backdrop { background: rgba(4, 3, 2, 0.72); backdrop-filter: blur(5px); }
.modal-card { padding: clamp(1.2rem, 3vw, 2rem); }
.modal-header { display: flex; align-items: start; justify-content: space-between; gap: 1rem; margin-bottom: 1.4rem; }
.modal-header h2 { margin-bottom: 0; font-family: Georgia, serif; font-size: 2rem; font-weight: 500; }
.drop-zone { display: grid; place-items: center; padding: 1.7rem; border: 1px dashed rgba(231, 154, 82, 0.35); border-radius: 14px; text-align: center; background: rgba(231, 154, 82, 0.035); }
.drop-zone strong { margin-top: 0.8rem; }
.drop-zone > span, .drop-zone p { color: var(--muted); font-size: 0.76rem; }
.file-picker { position: relative; margin-top: 1rem; overflow: hidden; }
.file-picker input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1.3rem; }
.form-grid label + label { margin-top: 0; }
.span-2 { grid-column: 1 / -1; }
.optional { color: #7e766b; font-size: 0.7rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.7rem; margin-top: 1.3rem; }
.book-modal { width: min(980px, calc(100vw - 2rem)); }
.book-sheet { position: relative; padding: 0; overflow: hidden; }
.floating-close { position: absolute; z-index: 3; top: 1rem; right: 1rem; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.4); }
.book-detail-hero { display: grid; grid-template-columns: 190px 1fr; gap: 2rem; padding: 2rem; background: linear-gradient(145deg, rgba(231, 154, 82, 0.11), transparent 45%); }
.detail-cover { width: 190px; aspect-ratio: 0.68; overflow: hidden; border-radius: 8px 13px 13px 8px; background: #3c3329; box-shadow: 15px 22px 40px rgba(0, 0, 0, 0.3); }
.detail-cover img { width: 100%; height: 100%; object-fit: cover; }
.detail-cover span { display: grid; width: 100%; height: 100%; place-items: center; color: var(--accent); font-size: 3rem; }
.detail-copy { align-self: center; min-width: 0; }
.detail-copy h2 { margin-bottom: 0.55rem; font-family: Georgia, serif; font-size: clamp(2rem, 5vw, 3.7rem); font-weight: 500; line-height: 1; }
.detail-copy .byline { color: var(--muted); }
.detail-tags { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 1rem 0; }
.detail-tags span { padding: 0.32rem 0.55rem; border: 1px solid var(--line); border-radius: 99px; color: var(--muted); font-size: 0.68rem; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 1.2rem; }
.book-detail-body { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(260px, 0.7fr); gap: 1.5rem; padding: 1.5rem 2rem 2rem; }
.chapter-list { max-height: 420px; overflow: auto; border-top: 1px solid var(--line); }
.chapter-row { display: grid; grid-template-columns: 38px 1fr auto; align-items: center; gap: 0.65rem; width: 100%; padding: 0.82rem 0.3rem; border-bottom: 1px solid var(--line); text-align: left; background: transparent; }
.chapter-row:hover, .chapter-row.active { background: rgba(255, 255, 255, 0.035); }
.chapter-number { color: #777066; font-variant-numeric: tabular-nums; font-size: 0.72rem; }
.chapter-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chapter-duration { color: var(--muted); font-size: 0.72rem; }
.metadata-form { padding: 1rem; border: 1px solid var(--line); border-radius: 14px; background: rgba(0, 0, 0, 0.13); }
.metadata-form h3 { font-family: Georgia, serif; font-weight: 500; }
.metadata-form label + label { margin-top: 0.75rem; }
.metadata-form textarea { min-height: 80px; resize: vertical; }
.metadata-form .primary { width: 100%; margin-top: 1rem; }
.danger-button { width: 100%; margin-top: 0.65rem; padding: 0.65rem; border: 1px solid rgba(242, 120, 120, 0.28); border-radius: 10px; color: var(--danger); background: transparent; }

@media (max-width: 880px) {
  .toolbar { align-items: stretch; flex-direction: column; }
  .segmented { overflow-x: auto; }
  .player { grid-template-columns: 1fr auto; }
  .player-main { grid-column: 1 / -1; grid-row: 2; }
  .player-options { grid-column: 2; grid-row: 1; }
  .book-detail-body { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .app { padding-bottom: 164px; }
  .topbar { min-height: 66px; padding: 0 1rem; }
  .brand div > span, #install-button { display: none; }
  .top-actions .primary { padding: 0.55rem 0.7rem; font-size: 0.8rem; }
  .content { width: min(100% - 2rem, 1440px); }
  .hero { min-height: 235px; padding: 2.3rem 0; }
  .hero-orbit { display: none; }
  .hero::after { right: -190px; }
  h1 { font-size: 2.65rem; }
  .book-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.3rem 0.9rem; }
  .book-card-body { padding-top: 0.7rem; }
  .book-title { font-size: 1rem; }
  .book-meta { display: none; }
  .section-heading { margin-top: 2rem; }
  .section-heading h2 { font-size: 1.55rem; }
  .player { right: 0.55rem; bottom: 0.55rem; left: 0.55rem; grid-template-columns: 1fr auto; gap: 0.45rem; padding: 0.65rem; border-radius: 15px; }
  .player-options { display: none; }
  .player-main { grid-column: 1 / -1; }
  .mini-cover { width: 42px; height: 50px; }
  .player-controls { justify-content: flex-end; }
  .timeline-row { grid-template-columns: 34px 1fr 34px; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .book-detail-hero { grid-template-columns: 105px 1fr; gap: 1rem; padding: 1.2rem; }
  .detail-cover { width: 105px; }
  .detail-copy h2 { font-size: 1.8rem; }
  .detail-copy .eyebrow, .detail-copy .byline, .detail-tags { margin-bottom: 0.4rem; }
  .book-detail-body { padding: 1.2rem; }
}
