@font-face {
  font-family: "EB Garamond";
  src: url("fonts/eb-garamond-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "EB Garamond";
  src: url("fonts/eb-garamond-400-italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "EB Garamond";
  src: url("fonts/eb-garamond-500.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "EB Garamond";
  src: url("fonts/eb-garamond-600.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Source Sans 3";
  src: url("fonts/source-sans-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Source Sans 3";
  src: url("fonts/source-sans-600.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #f4efe6;
  --bg-2: #ebe4d6;
  --paper: #fbfaf6;
  --ink: #1c1915;
  --muted: #5c564c;
  --line: #d7cfc0;
  --accent: #6b4f2a;
  --accent-soft: #efe4d0;
  --forest: #3d5a4c;
  --danger: #8a3a2a;
  --shadow: 0 10px 30px rgba(28, 25, 21, 0.08);
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --tab-h: calc(64px + env(safe-area-inset-bottom, 0px));
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #161412;
  --bg-2: #1e1b18;
  --paper: #221f1b;
  --ink: #f3eee6;
  --muted: #b4ada2;
  --line: #3a342c;
  --accent: #d4b07a;
  --accent-soft: #2b261f;
  --forest: #8fbfa6;
  --danger: #e08a7a;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.5;
  min-height: 100%;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
a { color: var(--accent); text-decoration: none; }
img, svg { display: block; max-width: 100%; }

#app {
  max-width: 430px;
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--bg);
  position: relative;
  box-shadow: 0 0 0 1px var(--line);
}

.screen {
  min-height: 100dvh;
  padding: calc(20px + var(--safe-top)) 20px calc(24px + var(--tab-h));
}
.screen.no-tab { padding-bottom: calc(28px + var(--safe-bot)); }

h1, h2, h3 {
  font-family: "EB Garamond", Georgia, serif;
  font-weight: 500;
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1.2;
}
.kicker {
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* Lock */
.lock {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 28px calc(32px + var(--safe-bot));
  text-align: center;
  background:
    radial-gradient(1200px 500px at 50% -10%, var(--accent-soft), transparent 60%),
    var(--bg);
}
.lock-mark {
  width: 72px;
  height: 72px;
  border-radius: 20px;
  margin-bottom: 22px;
  box-shadow: var(--shadow);
}
.lock h1 { font-size: 48px; font-style: italic; margin-bottom: 6px; }
.lock .tag { color: var(--muted); margin-bottom: 36px; font-size: 16px; }
.lock-status { min-height: 24px; margin-bottom: 18px; color: var(--muted); font-size: 15px; }
.lock-status.error { color: var(--danger); }
.dots { display: flex; gap: 14px; justify-content: center; margin-bottom: 28px; }
.dots span {
  width: 12px; height: 12px; border-radius: 50%;
  border: 1.5px solid var(--accent);
  background: transparent;
  transition: background 0.15s;
}
.dots span.on { background: var(--accent); }
.pad {
  display: grid;
  grid-template-columns: repeat(3, 74px);
  gap: 12px 18px;
  justify-content: center;
}
.pad button {
  width: 74px; height: 74px;
  border-radius: 50%;
  background: var(--paper);
  border: 1px solid var(--line);
  font-size: 26px;
  font-family: "EB Garamond", Georgia, serif;
}
.pad button:active { background: var(--accent-soft); }
.pad .ghost { background: transparent; border-color: transparent; font-size: 13px; letter-spacing: 0.08em; color: var(--muted); }
.lock-forgot { margin-top: 28px; color: var(--muted); font-size: 13px; }

/* Top bar */
.top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}
.top h1, .top h2 { flex: 1; font-size: 28px; font-style: italic; }
.icon-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  display: grid; place-items: center;
  color: var(--ink);
  border: 1px solid transparent;
}
.icon-btn:active { background: var(--bg-2); }

/* Library */
.continue {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 14px;
  padding: 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 22px;
  text-align: left;
  width: 100%;
}
.continue img, .continue .cover-mini { width: 72px; height: 108px; border-radius: 8px; object-fit: cover; background: var(--bg-2); }
.continue .meta { display: flex; flex-direction: column; justify-content: center; align-items: flex-start; }
.continue .play-label { color: var(--accent); font-weight: 600; font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; margin-bottom: 4px; }

.book-card {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 16px;
  padding: 0 0 22px;
  text-align: left;
  width: 100%;
  color: inherit;
}
.book-card .cover, .cover-mini, .cover-lg {
  background: var(--bg-2);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.book-card .cover { width: 92px; height: 138px; }
.book-card .cover img { width: 100%; height: 100%; object-fit: cover; }
.book-card h3 { font-size: 22px; margin: 2px 0 4px; }
.book-stats { font-size: 13px; color: var(--muted); }

.section-title {
  margin: 10px 0 14px;
  font-size: 22px;
  font-style: italic;
}

/* Book page */
.book-hero { display: flex; flex-direction: column; align-items: center; text-align: center; margin-bottom: 22px; }
.cover-lg { width: 180px; height: 270px; margin: 8px auto 18px; }
.cover-lg img { width: 100%; height: 100%; object-fit: cover; }
.book-hero h2 { font-size: 32px; font-style: italic; margin-bottom: 4px; }
.dl-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  align-items: center;
  margin: 16px 0 8px;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 16px;
  border-radius: 999px;
  background: var(--accent);
  color: #fbfaf6;
  font-weight: 600;
  font-size: 15px;
}
:root[data-theme="dark"] .btn { color: #1c1915; }
.btn.secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn:disabled { opacity: 0.55; }
.credit { font-size: 13px; color: var(--muted); max-width: 34em; margin: 8px auto 0; }

.chapter {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 14px 0;
  border-top: 1px solid var(--line);
  text-align: left;
  color: inherit;
}
.chapter .num {
  font-family: "EB Garamond", Georgia, serif;
  font-style: italic;
  color: var(--muted);
  width: 1.6em;
}
.chapter .done { color: var(--forest); font-size: 13px; }
.chapter .dur { color: var(--muted); font-size: 13px; }

/* Player */
.player-screen { padding-bottom: calc(28px + var(--safe-bot)); }
.player-cover { width: 240px; height: 360px; margin: 8px auto 22px; border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.player-cover img { width: 100%; height: 100%; object-fit: cover; }
.player-titles { text-align: center; margin-bottom: 22px; }
.player-titles h2 { font-size: 26px; font-style: italic; }
.scrub { margin: 8px 0 4px; }
input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  height: 4px;
}
.times { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
  margin: 18px 0 8px;
}
.controls .play {
  width: 74px; height: 74px;
  border-radius: 50%;
  background: var(--accent);
  color: #fbfaf6;
  display: grid; place-items: center;
}
:root[data-theme="dark"] .controls .play { color: #1c1915; }
.controls .skip {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}
.tools {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 8px 0 24px;
  flex-wrap: wrap;
}
.chip {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper);
  font-size: 14px;
  font-weight: 600;
}
.chip.active { border-color: var(--accent); color: var(--accent); }
.takeaways, .worksheet, .panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin: 12px 0;
}
.takeaways h3, .worksheet h3, .panel h3 { font-size: 22px; font-style: italic; margin-bottom: 8px; }
.takeaways li, .worksheet li { margin: 0 0 8px; }
.worksheet label {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  font-size: 16px;
}
.worksheet input[type="checkbox"] { margin-top: 4px; accent-color: var(--forest); width: 18px; height: 18px; }

/* Libby */
.libby-note {
  background: var(--accent-soft);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 18px;
  font-size: 15px;
}
.libby-item {
  padding: 16px 0;
  border-top: 1px solid var(--line);
}
.libby-item h3 { font-size: 22px; font-style: italic; }
.libby-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* Tabs */
.tabs {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 430px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--paper);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bot);
  z-index: 20;
}
.tabs a, .tabs button {
  min-height: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
  background: none;
  width: 100%;
}
.tabs .on { color: var(--ink); }

.mini-bar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: var(--tab-h);
  width: calc(100% - 24px);
  max-width: 406px;
  background: var(--ink);
  color: var(--bg);
  border-radius: 14px 14px 0 0;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 12px;
  z-index: 19;
  text-align: left;
}
:root[data-theme="dark"] .mini-bar { background: #0e0c0a; }
.mini-bar .t { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-bar .s { font-size: 12px; opacity: 0.75; }
.mini-bar .go { color: inherit; width: 42px; height: 42px; }

.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(28, 25, 21, 0.4);
  z-index: 30;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  width: 100%;
  max-width: 430px;
  background: var(--paper);
  border-radius: 22px 22px 0 0;
  padding: 18px 18px calc(22px + var(--safe-bot));
}
.sheet h3 { margin-bottom: 12px; font-style: italic; }
.sheet button.row {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px 4px;
  border-top: 1px solid var(--line);
  font-size: 17px;
}

.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.hidden { display: none !important; }
.has-mini .screen { padding-bottom: calc(24px + var(--tab-h) + 58px); }
