/* Palette and type lifted from the Uizard "FeedBacker" template:
   warm sage ground, cream panels, olive accents, near-black controls.
   https://app.uizard.io/templates/rgRngJGJBocW9Jl5A8LZ/preview
   Philosopher for headings, Inter for everything else. */

:root {
  --sage: #c9c9b0;
  --sage-soft: #e2e2ce;
  --cream: #f4f4ec;
  --white: #fefefe;
  --khaki: #bcb78f;
  --olive: #6b6645;
  --olive-deep: #39361f;
  --ink: #030303;
  --muted: #7f7f7f;
  --danger: #8c3a2b;
  --danger-soft: #f2e2de;

  --r-card: 12px;
  --r-control: 10px;
  --r-pill: 999px;

  --shadow: 0 1px 2px rgba(57, 54, 31, 0.08), 0 8px 24px rgba(57, 54, 31, 0.06);
  --sidebar-w: 264px;

  color-scheme: light;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--sage);
  color: var(--ink);
  font: 400 14px/1.5 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
p { margin: 0; }

button, input, textarea, select { font: inherit; color: inherit; }

a { color: var(--olive); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ------------------------------------------------------------- shell */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--cream);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.nav { display: flex; flex-direction: column; gap: 4px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border: 0;
  border-radius: var(--r-control);
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  text-decoration: none;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.12s ease;
}

.nav-item:hover { background: var(--sage-soft); }

.nav-item[aria-current="true"] {
  background: var(--sage-soft);
  color: var(--olive-deep);
}

.nav-heading {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 14px;
  margin-bottom: 6px;
}

.book-links { display: flex; flex-direction: column; gap: 2px; }

.book-link {
  display: block;
  padding: 9px 14px;
  border-radius: var(--r-control);
  font-size: 13px;
  color: var(--olive-deep);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-link:hover { background: var(--sage-soft); }
.book-link[aria-current="true"] { background: var(--sage-soft); font-weight: 600; }

.sidebar-foot { margin-top: auto; font-size: 11px; color: var(--muted); }
.sidebar-foot p { margin-top: 12px; }

.btn-link {
  border: 0;
  background: none;
  padding: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--olive);
  cursor: pointer;
  text-decoration: underline;
}
.btn-link:hover { color: var(--olive-deep); }

.main { padding: 28px 32px 64px; min-width: 0; max-width: 1240px; width: 100%; }

.topbar { display: none; }

/* ------------------------------------------------------------- pieces */

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.page-head h1 {
  font-family: Philosopher, Georgia, serif;
  font-size: 23px;
  line-height: 1.2;
}

.page-head .sub { margin-top: 6px; font-size: 13px; color: var(--olive-deep); }

.card {
  background: var(--cream);
  border-radius: var(--r-card);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card + .card,
.card + .panel,
.panel + .card,
.panel + .panel { margin-top: 16px; }

.card h2 {
  font-size: 16px;
  margin-bottom: 4px;
}

.card .hint { font-size: 12px; color: var(--muted); }

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

/* ------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border: 1px solid transparent;
  border-radius: var(--r-pill);
  background: var(--white);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.08s ease, background 0.12s ease, border-color 0.12s ease;
}

.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn:focus-visible { outline: 2px solid var(--olive); outline-offset: 2px; }

.btn-primary { background: var(--ink); color: var(--cream); }
.btn-primary:not(:disabled):hover { background: #232318; }

.btn-secondary { background: var(--white); border-color: var(--khaki); color: var(--olive-deep); }
.btn-secondary:not(:disabled):hover { background: var(--sage-soft); }

.btn-ghost { background: transparent; color: var(--olive); padding: 8px 12px; }
.btn-ghost:not(:disabled):hover { background: var(--sage-soft); }

.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:not(:disabled):hover { background: #ebd2cc; }

.btn-lg { padding: 14px 24px; font-size: 14px; }
.btn-sm { padding: 7px 12px; font-size: 12px; }

.btn-icon {
  padding: 7px;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: transparent;
  color: var(--olive);
}
.btn-icon:not(:disabled):hover { background: var(--sage-soft); }

/* ------------------------------------------------------------- forms */

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12px; font-weight: 600; margin-bottom: 6px; }

.input, .select, .textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--khaki);
  border-radius: var(--r-control);
  background: var(--white);
  font-size: 14px;
}

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--olive);
  box-shadow: 0 0 0 3px rgba(107, 102, 69, 0.15);
}

.textarea { min-height: 200px; resize: vertical; line-height: 1.6; }

/* ------------------------------------------------------------- library */

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.book-card {
  display: block;
  background: var(--cream);
  border-radius: var(--r-card);
  padding: 20px;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  transition: transform 0.1s ease;
}

.book-card:hover { transform: translateY(-2px); }

.book-card h3 {
  font-family: Philosopher, Georgia, serif;
  font-size: 17px;
  margin-bottom: 8px;
  overflow-wrap: anywhere;
}

.book-card .meta { font-size: 12px; color: var(--olive-deep); }

.bar {
  height: 6px;
  border-radius: var(--r-pill);
  background: var(--sage-soft);
  overflow: hidden;
  margin-top: 12px;
}

.bar > i { display: block; height: 100%; background: var(--khaki); border-radius: inherit; }

/* ------------------------------------------------------------- pages */

.page-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}

.page-card {
  background: var(--cream);
  border-radius: var(--r-card);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.page-card .shot {
  position: relative;
  aspect-ratio: 3 / 4;
  background: var(--sage-soft);
  cursor: zoom-in;
  border: 0;
  padding: 0;
  display: block;
  width: 100%;
}

.page-card .shot img { width: 100%; height: 100%; object-fit: cover; display: block; }

.page-card .no { position: absolute; top: 8px; left: 8px; }

.page-card .body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 10px; flex: 1; }

.page-card .chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip.printed {
  background: transparent;
  border: 1px solid var(--khaki);
  color: var(--olive);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 600;
}

.page-card .preview {
  font-size: 12px;
  line-height: 1.55;
  color: var(--olive-deep);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.4em;
}

.page-card .preview.empty { color: var(--muted); font-style: italic; }
.page-card .row { display: flex; align-items: center; gap: 4px; margin-top: auto; }
.page-card .row .spacer { flex: 1; }

.chip {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--r-pill);
  background: var(--sage-soft);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--olive-deep);
}

.chip.done { background: var(--khaki); color: #2c2a15; }
.chip.working { background: var(--ink); color: var(--cream); }
.chip.error { background: var(--danger-soft); color: var(--danger); }
.chip.solid { background: var(--white); }

.chip .dot {
  width: 6px; height: 6px; border-radius: 50%; background: currentColor;
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

@media (prefers-reduced-motion: reduce) {
  .chip .dot { animation: none; }
  .book-card:hover { transform: none; }
}

.page-error { font-size: 12px; color: var(--danger); }

/* ------------------------------------------------------------- reader */

.reader {
  background: var(--white);
  border-radius: var(--r-card);
  padding: 28px 30px;
  box-shadow: var(--shadow);
  max-width: 74ch;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 15px;
  line-height: 1.7;
  color: var(--olive-deep);
}

.reader .page-rule {
  margin: 26px 0 18px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  border-top: 1px solid var(--sage-soft);
  padding-top: 12px;
}

.reader .page-rule:first-child { margin-top: 0; border-top: 0; padding-top: 0; }

/* ------------------------------------------------------------- empty */

.empty {
  background: var(--cream);
  border-radius: var(--r-card);
  padding: 48px 28px;
  text-align: center;
  box-shadow: var(--shadow);
}

.empty h2 { font-family: Philosopher, Georgia, serif; font-size: 20px; margin-bottom: 8px; }
.empty p { color: var(--olive-deep); max-width: 46ch; margin: 0 auto 20px; }

/* ------------------------------------------------------------- overlays */

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(57, 54, 31, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal {
  background: var(--cream);
  border-radius: 16px;
  padding: 26px;
  width: min(440px, 100%);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
}

.modal h2 { font-family: Philosopher, Georgia, serif; font-size: 19px; margin-bottom: 10px; }
.modal p { font-size: 13px; color: var(--olive-deep); margin-bottom: 18px; }
.modal .actions { justify-content: flex-end; }

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(3, 3, 3, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 60;
  cursor: zoom-out;
}

.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

.toast-tray {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 70;
  pointer-events: none;
  width: min(420px, calc(100vw - 32px));
}

.toast {
  background: var(--ink);
  color: var(--cream);
  padding: 12px 18px;
  border-radius: var(--r-pill);
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.toast.bad { background: var(--danger); }

/* ------------------------------------------------------------- mobile */

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }

  .sidebar { display: none; }

  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--cream);
    padding: 14px 16px;
    position: sticky;
    top: 0;
    z-index: 20;
  }

  .topbar .nav { flex-direction: row; gap: 2px; }
  .topbar .nav-item { padding: 8px 12px; font-size: 13px; }

  .main { padding: 18px 16px 56px; }

  .page-head h1 { font-size: 21px; }
  .page-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .book-grid { grid-template-columns: 1fr; }
  .reader { padding: 20px 18px; }

  .actions .btn { flex: 1 1 auto; }
}

/* ------------------------------------------------------------- sign in */

.gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.gate-card {
  background: var(--cream);
  border-radius: 16px;
  padding: 34px 32px;
  width: min(400px, 100%);
  box-shadow: var(--shadow);
}

.gate-card h1 {
  font-family: Philosopher, Georgia, serif;
  font-size: 24px;
  margin-bottom: 8px;
}

.gate-card > p {
  font-size: 13px;
  color: var(--olive-deep);
  margin-bottom: 22px;
}

.gate-card .btn { width: 100%; }

.gate-error {
  font-size: 13px;
  color: var(--danger);
  background: var(--danger-soft);
  padding: 10px 14px;
  border-radius: var(--r-control);
  margin-bottom: 14px;
}

/* ------------------------------------------------------------- listening */

.player-card {
  background: var(--cream);
  border: 1px solid var(--khaki);
}

.player-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.player-top h2 { font-size: 16px; }
.player-top .hint { margin-top: 4px; }

/* The one control that matters, sized so it is obvious and easy to hit. */
.play {
  flex: none;
  width: 62px;
  height: 62px;
  border: 0;
  border-radius: 50%;
  background: var(--ink);
  color: var(--cream);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease;
}

.play svg { width: 26px; height: 26px; }
.play:hover { background: #232318; }
.play:active { transform: scale(0.94); }
.play:focus-visible { outline: 3px solid var(--olive); outline-offset: 3px; }
.play.playing { background: var(--olive); }

.track {
  height: 8px;
  border-radius: var(--r-pill);
  background: var(--sage-soft);
  overflow: hidden;
  margin: 18px 0 14px;
}

.track > i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--khaki);
  transition: width 0.35s ease;
}

/* The passage being spoken, so it can be followed on the page. */
.player-line {
  font-size: 15px;
  line-height: 1.65;
  color: var(--olive-deep);
  min-height: 3.3em;
  margin-bottom: 16px;
  overflow-wrap: anywhere;
}

.player-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.speeds {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--sage-soft);
  border-radius: var(--r-pill);
}

.speed {
  border: 0;
  background: transparent;
  border-radius: var(--r-pill);
  padding: 6px 11px;
  font-size: 12px;
  font-weight: 600;
  color: var(--olive-deep);
  cursor: pointer;
  white-space: nowrap;
}

.speed:hover { background: rgba(254, 254, 254, 0.6); }
.speed.on { background: var(--ink); color: var(--cream); }
.speed:focus-visible { outline: 2px solid var(--olive); outline-offset: 1px; }

.resume {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 16px;
  padding: 11px 14px;
  border-radius: var(--r-control);
  background: var(--white);
  font-size: 13px;
  color: var(--olive-deep);
}

/* ------------------------------------------------------------- disclosures */

.panel {
  background: var(--cream);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 700;
  list-style: none;
  user-select: none;
}

.panel > summary::-webkit-details-marker { display: none; }
.panel > summary:hover { background: var(--sage-soft); }
.panel > summary:focus-visible { outline: 2px solid var(--olive); outline-offset: -2px; }

.panel > summary > span:first-child {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.panel > summary .count {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

/* A chevron that turns as the panel opens. */
.panel > summary::after {
  content: '';
  width: 8px;
  height: 8px;
  margin-left: 4px;
  border-right: 2px solid var(--olive);
  border-bottom: 2px solid var(--olive);
  transform: rotate(45deg);
  transition: transform 0.15s ease;
  flex: none;
}

.panel[open] > summary::after { transform: rotate(-135deg); }

.panel-body { padding: 4px 20px 20px; }

@media (prefers-reduced-motion: reduce) {
  .track > i, .panel > summary::after, .play { transition: none; }
}

@media (max-width: 820px) {
  .play { width: 66px; height: 66px; }
  .player-controls { justify-content: center; }
  .speeds { width: 100%; justify-content: space-between; }
  .speed { flex: 1; padding: 8px 6px; text-align: center; }
  .panel > summary { padding: 14px 16px; }
  .panel-body { padding: 4px 16px 18px; }
}

.book-card .listening {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 4px 10px;
  border-radius: var(--r-pill);
  background: var(--sage-soft);
  font-size: 11px;
  font-weight: 600;
  color: var(--olive-deep);
}

.book-card .listening svg { width: 12px; height: 12px; }

/* ------------------------------------------------------------- devices */

.gate-or {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  color: var(--muted);
  font-size: 12px;
}

.gate-or::before, .gate-or::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--sage-soft);
}

.devices { list-style: none; margin: 0; padding: 0; }

.devices li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--r-control);
  background: var(--white);
  font-size: 13px;
}

.devices li + li { margin-top: 8px; }
.devices li > span:first-child { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
.devices .when { flex: 1; color: var(--muted); font-size: 12px; }

/* ------------------------------------------------------------- speakers */

.speaker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 8px;
}

.speaker-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.speaker-row .initials {
  flex: none;
  min-width: 74px;
  font-size: 13px;
  font-weight: 700;
  color: var(--olive-deep);
  font-variant-numeric: tabular-nums;
}

.speaker-row .input { padding: 8px 12px; font-size: 13px; }

.speaker-row .times {
  flex: none;
  min-width: 30px;
  text-align: right;
  font-size: 11px;
  color: var(--muted);
}

.voice-note {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  padding: 4px 10px;
  border-radius: var(--r-pill);
  border: 1px solid var(--sage-soft);
  white-space: nowrap;
}

.voice-note:hover { background: var(--sage-soft); color: var(--olive-deep); }
