:root {
  --bg: #f6f3ef;
  --surface: #ffffff;
  --surface-2: #efe9e2;
  --ink: #18172b;
  --ink-2: #24224a;
  --muted: #6f6c7d;
  --line: #e6e0d8;
  --brand: #e32b33;
  --brand-dark: #cd2028;
  --lav: #a7a3ff;
  --mint: #87d5bb;
  --gold: #f4c15d;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(24, 23, 43, 0.08);
  --shadow-soft: 0 4px 14px rgba(24, 23, 43, 0.06);
  --player-h: 92px;
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

body { padding-bottom: calc(var(--player-h) + 28px); }
body.sheet-open { overflow: hidden; }

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
img { display: block; max-width: 100%; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 14px 32px;
  background: rgba(246, 243, 239, 0.9);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(230, 224, 216, 0.7);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: var(--brand);
  color: #fff;
  font-size: 19px;
  box-shadow: 0 6px 14px rgba(227, 43, 51, 0.28);
}
.brand-text { font-size: 18px; letter-spacing: -0.4px; }
.brand-text span { color: var(--brand); }

.nav { display: flex; align-items: center; gap: 4px; flex: 1; }
.nav a {
  padding: 9px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  transition: 0.15s;
}
.nav a:hover { color: var(--ink); background: #fff; }
.nav a.active { color: #fff; background: var(--ink); }

.profile-wrap { position: relative; }
.profile-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 12px 6px 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow-soft);
}
.avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--lav);
  color: var(--ink);
  font-weight: 800;
  font-size: 14px;
}
.profile-name { font-size: 13px; font-weight: 700; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chevron { color: var(--muted); font-size: 11px; }

.profile-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 270px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 8px;
  z-index: 60;
}
.profile-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  cursor: pointer;
  text-align: left;
}
.profile-menu button:hover { background: var(--surface-2); }
.profile-menu .pm-name { font-size: 14px; font-weight: 600; }
.profile-menu .pm-sub { font-size: 11px; color: var(--muted); }
.profile-menu .divider { height: 1px; background: var(--line); margin: 6px 4px; }
.profile-menu .pm-action { font-size: 13px; color: var(--brand); font-weight: 700; }

/* ---------- layout ---------- */
.view { max-width: 1240px; margin: 0 auto; padding: 34px 32px 10px; }
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 26px; }
.eyebrow { font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--brand); font-weight: 800; margin: 0 0 8px; }
h1 { font-size: 34px; line-height: 1.1; letter-spacing: -1.1px; margin: 0; }
h2 { letter-spacing: -0.5px; }
.sub { color: var(--muted); font-size: 14px; margin: 8px 0 0; }

/* ---------- covers / cards ---------- */
.cover {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 14px;
  background: var(--surface-2);
  box-shadow: 0 8px 18px rgba(24, 23, 43, 0.12);
}
.cover-wrap { position: relative; }

.shelf { margin-bottom: 40px; }
.shelf-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.shelf-head h2 { margin: 0; font-size: 20px; }
.shelf-head a, .shelf-head span { font-size: 12px; color: var(--muted); font-weight: 600; }

.rail {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 170px;
  gap: 16px;
  overflow-x: auto;
  padding: 2px 2px 12px;
  scrollbar-width: thin;
}
.rail .card { width: 170px; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 22px 18px;
}

.card { display: block; cursor: pointer; border: 0; background: transparent; padding: 0; text-align: left; }
.card .cover { transition: transform 0.18s ease, box-shadow 0.18s ease; }
.card:hover .cover { transform: translateY(-4px); box-shadow: 0 16px 26px rgba(24, 23, 43, 0.18); }
.card-title {
  margin-top: 10px;
  font-size: 13.5px;
  font-weight: 700;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-sub { margin-top: 3px; font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  position: absolute;
  left: 8px;
  top: 8px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(24, 23, 43, 0.82);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  backdrop-filter: blur(4px);
}
.badge.premium { background: rgba(227, 43, 51, 0.92); }
.progress-strip {
  margin-top: 8px;
  height: 4px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.progress-strip i { display: block; height: 100%; background: var(--brand); border-radius: 999px; }

/* ---------- book page ---------- */
.book-hero {
  display: grid;
  grid-template-columns: 230px 1fr;
  gap: 34px;
  padding: 28px;
  border-radius: 26px;
  background: linear-gradient(135deg, #ffffff, #f1ece5);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
  margin-bottom: 32px;
}
.book-hero .cover { aspect-ratio: 1; }
.book-meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 18px; }
.pill { padding: 6px 11px; border-radius: 999px; background: #fff; border: 1px solid var(--line); font-size: 12px; font-weight: 600; color: var(--muted); }
.book-hero h1 { font-size: 32px; }
.book-desc { color: var(--muted); font-size: 14px; line-height: 1.65; max-height: 9.8em; overflow: hidden; position: relative; white-space: pre-line; }
.book-desc.expanded { max-height: none; }
.desc-toggle { border: 0; background: transparent; color: var(--brand); font-weight: 700; font-size: 13px; padding: 6px 0 0; cursor: pointer; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: 0.15s;
  background: #fff;
  color: var(--ink);
}
.btn:hover { transform: translateY(-1px); }
.btn.primary { background: var(--brand); color: #fff; box-shadow: 0 8px 18px rgba(227, 43, 51, 0.26); }
.btn.primary:hover { background: var(--brand-dark); }
.btn.ghost { background: #fff; border-color: var(--line); }
.btn.dark { background: var(--ink); color: #fff; }
.btn.small { padding: 8px 13px; font-size: 12.5px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.chapters { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.chapter {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 13px 10px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
  border-radius: 10px;
}
.chapter:hover { background: #fff; }
.chapter.active { background: #fff; box-shadow: inset 3px 0 0 var(--brand); }
.ch-num { width: 26px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; text-align: right; }
.ch-title { flex: 1; font-size: 13.5px; font-weight: 600; }
.ch-time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ch-play { color: var(--brand); font-size: 13px; width: 18px; }

/* ---------- library / stats ---------- */
.tabs { display: flex; gap: 8px; margin-bottom: 22px; flex-wrap: wrap; }
.tab { padding: 9px 15px; border-radius: 999px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 13px; font-weight: 700; color: var(--muted); }
.tab.active { background: var(--ink); border-color: var(--ink); color: #fff; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 30px; }
.stat-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-soft); }
.stat-card .label { font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; }
.stat-card .value { font-size: 30px; font-weight: 800; letter-spacing: -1px; margin-top: 8px; }
.stat-card .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

.panel { background: #fff; border: 1px solid var(--line); border-radius: 22px; padding: 24px; box-shadow: var(--shadow-soft); margin-bottom: 22px; }
.panel h2 { margin: 0 0 4px; font-size: 19px; }
.panel .panel-sub { color: var(--muted); font-size: 13px; margin: 0 0 20px; }

.bars { display: flex; align-items: flex-end; gap: 5px; height: 150px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 6px; }
.bar { width: 100%; min-height: 3px; background: var(--lav); border-radius: 5px 5px 2px 2px; transition: 0.2s; }
.bar-col:hover .bar { background: var(--brand); }
.bar-label { font-size: 9px; color: var(--muted); writing-mode: vertical-rl; transform: rotate(180deg); max-height: 50px; }

.book-row { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.book-row:last-child { border-bottom: 0; }
.book-row img { width: 46px; height: 46px; border-radius: 9px; object-fit: cover; background: var(--surface-2); }
.book-row .br-title { font-size: 13.5px; font-weight: 700; }
.book-row .br-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.book-row .br-pct { margin-left: auto; font-size: 12px; font-weight: 800; color: var(--brand); }

/* ---------- settings ---------- */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; align-items: start; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12px; font-weight: 700; color: var(--muted); }
.field input, .field select {
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  outline: none;
}
.field input:focus { border-color: var(--lav); box-shadow: 0 0 0 3px rgba(167, 163, 255, 0.25); }

.row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .name { font-size: 14px; font-weight: 700; }
.row .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex: none; }
.dot.on { background: #2fbf82; box-shadow: 0 0 0 4px rgba(47, 191, 130, 0.16); }
.dot.off { background: var(--brand); box-shadow: 0 0 0 4px rgba(227, 43, 51, 0.14); }

.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty h2 { color: var(--ink); margin-bottom: 8px; }

/* ---------- player ---------- */
.audio-el { position: fixed; width: 1px; height: 1px; opacity: 0; pointer-events: none; left: -10px; bottom: 0; }

.playerbar {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: 14px;
  z-index: 50;
  display: grid;
  grid-template-columns: 52px minmax(130px, 1fr) auto minmax(190px, 1.2fr) auto;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-radius: 20px;
  background: rgba(24, 23, 43, 0.96);
  color: #fff;
  box-shadow: 0 18px 40px rgba(24, 23, 43, 0.28);
  backdrop-filter: blur(16px);
}
.playerbar[hidden] { display: none; }
.player-cover img { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; background: #2c2a4a; }
.player-title { font-size: 13.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-sub { font-size: 11.5px; color: rgba(255, 255, 255, 0.6); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.player-controls { display: flex; align-items: center; gap: 4px; }
.icon-btn {
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 18px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.12); }
.icon-btn.skip { font-size: 11px; font-weight: 800; }
.play-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: var(--brand);
  color: #fff;
  font-size: 17px;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 16px rgba(227, 43, 51, 0.4);
}
.play-btn:hover { background: var(--brand-dark); }

.player-seek { display: flex; align-items: center; gap: 8px; }
.player-seek span { font-size: 10.5px; color: rgba(255, 255, 255, 0.6); width: 34px; text-align: center; font-variant-numeric: tabular-nums; }
input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 18px; background: transparent; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 9px; background: rgba(255, 255, 255, 0.22); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: #fff; margin-top: -5px; box-shadow: 0 0 0 3px rgba(227, 43, 51, 0.35); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 9px; background: rgba(255, 255, 255, 0.22); }
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%; background: #fff; }
.player-extra { display: flex; align-items: center; gap: 4px; }
.player-extra select { background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.14); color: #fff; border-radius: 9px; padding: 5px 7px; font-size: 12px; }
.player-extra select option { color: var(--ink); }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(24, 23, 43, 0.55);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 20px;
}
.sheet[hidden] { display: none; }
.sheet-card {
  width: min(520px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--ink);
  color: #fff;
  border-radius: 26px;
  padding: 22px 24px 26px;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.4);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: rgba(255, 255, 255, 0.55); }
.np-cover { width: min(260px, 60vw); aspect-ratio: 1; object-fit: cover; border-radius: 18px; margin: 22px auto 18px; box-shadow: 0 22px 40px rgba(0, 0, 0, 0.45); }
.sheet-card h2 { text-align: center; font-size: 22px; margin: 0 0 4px; }
.np-meta { text-align: center; color: rgba(255, 255, 255, 0.6); font-size: 13px; margin: 0 0 16px; }
.np-times { display: flex; justify-content: space-between; font-size: 11px; color: rgba(255, 255, 255, 0.55); font-variant-numeric: tabular-nums; }
.np-controls { justify-content: center; margin: 10px 0 18px; }
.sheet-card h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.1em; color: rgba(255, 255, 255, 0.5); margin: 0 0 8px; }
.np-chapters { max-height: 210px; overflow-y: auto; }
.np-chapters .chapter { color: #fff; border-bottom-color: rgba(255, 255, 255, 0.08); }
.np-chapters .chapter:hover { background: rgba(255, 255, 255, 0.08); }
.np-chapters .chapter.active { background: rgba(255, 255, 255, 0.1); box-shadow: inset 3px 0 0 var(--brand); }
.np-chapters .ch-num, .np-chapters .ch-time { color: rgba(255, 255, 255, 0.5); }

/* ---------- onboarding ---------- */
.onboard { max-width: 460px; margin: 9vh auto; background: #fff; border: 1px solid var(--line); border-radius: 28px; padding: 38px; box-shadow: var(--shadow); text-align: center; }
.onboard .brand-mark { width: 54px; height: 54px; border-radius: 17px; font-size: 28px; margin: 0 auto 18px; }
.onboard h1 { font-size: 28px; }
.onboard p { color: var(--muted); font-size: 14px; line-height: 1.6; }
.onboard .field { text-align: left; margin-top: 22px; }
.onboard .btn { width: 100%; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--player-h) + 34px);
  transform: translateX(-50%);
  z-index: 100;
  background: var(--ink);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  max-width: min(90vw, 520px);
  text-align: center;
}
.toast[hidden] { display: none; }
.toast.error { background: var(--brand); }

.hint-box { background: #fbf3e4; border: 1px solid #f0dfbd; border-radius: 14px; padding: 14px 16px; font-size: 12.5px; color: #7a5b1c; line-height: 1.55; }
.hint-box strong { color: #5c430f; }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .topbar { gap: 14px; padding: 12px 16px; flex-wrap: wrap; }
  .nav { order: 3; flex: 0 0 100%; width: 100%; overflow-x: auto; padding-bottom: 2px; }
  .nav a { white-space: nowrap; padding: 8px 11px; font-size: 13px; }
  .profile-wrap { margin-left: auto; }
  .view { padding: 24px 16px 6px; }
  .book-hero { grid-template-columns: 150px 1fr; gap: 20px; padding: 20px; }
  .settings-grid { grid-template-columns: 1fr; }
  .playerbar {
    grid-template-columns: 46px 1fr auto;
    grid-template-areas: 'cover info controls' 'seek seek seek';
    row-gap: 8px;
    left: 8px; right: 8px; bottom: 8px;
    padding: 10px 12px;
  }
  .player-cover { grid-area: cover; }
  .player-info { grid-area: info; }
  .player-controls { grid-area: controls; }
  .player-seek { grid-area: seek; }
  .player-extra { display: none; }
  .playerbar .icon-btn:not(.skip) { display: none; }
  .player-cover img { width: 46px; height: 46px; }
}

@media (max-width: 620px) {
  h1 { font-size: 27px; }
  .book-hero { grid-template-columns: 1fr; }
  .book-hero .cover { width: 170px; margin: 0 auto; }
  .book-hero h1 { font-size: 25px; }
  .rail { grid-auto-columns: 138px; }
  .rail .card { width: 138px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 18px 14px; }
  .sheet-card { border-radius: 22px; padding: 18px; }
  .onboard { margin: 4vh auto; padding: 28px 22px; }
  .page-head { flex-direction: column; align-items: flex-start; }
}
