:root {
  --ink: #17130d;
  --muted: #6e675c;
  --paper: #f7f2e8;
  --panel: #fffaf0;
  --line: #d8cdbb;
  --accent: #a6402d;
  --accent-dark: #6f2419;
  --field: #fffdf8;
  --ok: #315f46;
  --danger: #9c2f2f;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(23, 19, 13, 0.035) 1px, transparent 1px) 0 0 / 28px 28px,
    linear-gradient(0deg, rgba(23, 19, 13, 0.025) 1px, transparent 1px) 0 0 / 28px 28px,
    var(--paper);
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  overflow-x: hidden;
}

button,
input,
textarea {
  font: inherit;
}

a {
  color: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(18px, 4vw, 56px);
  border-bottom: 1px solid rgba(23, 19, 13, 0.14);
  background: rgba(247, 242, 232, 0.9);
  backdrop-filter: blur(12px);
}

.brand {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0;
  text-decoration: none;
  text-transform: uppercase;
}

nav {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 0.95rem;
}

nav a,
.back-link {
  color: var(--ink);
  text-decoration-color: rgba(166, 64, 45, 0.5);
  text-underline-offset: 4px;
}

.app-shell,
.admin-shell {
  width: min(1180px, calc(100% - 36px));
  margin: 0 auto;
  padding: clamp(26px, 6vw, 72px) 0;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(340px, 0.95fr);
  align-items: end;
  gap: clamp(24px, 5vw, 72px);
  min-height: 48vh;
  padding-bottom: clamp(28px, 6vw, 64px);
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent-dark);
  font-size: 0.84rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 13ch;
  margin-bottom: 0;
  font-size: clamp(2.8rem, 6vw, 5.2rem);
  line-height: 0.94;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 14px;
  font-size: 1.45rem;
  line-height: 1.05;
}

h3 {
  margin-bottom: 6px;
  font-size: 1.12rem;
  line-height: 1.2;
}

.submit-panel,
.panel,
.paper-card,
.table-row,
.player-shell {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.9);
  box-shadow: 0 18px 48px rgba(45, 31, 17, 0.08);
}

.submit-panel {
  padding: clamp(18px, 3vw, 28px);
}

label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.input-row,
.inline-admin-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

input {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--field);
  outline: none;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(166, 64, 45, 0.14);
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: #fffaf5;
  background: var(--accent);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

button:hover,
.button:hover {
  background: var(--accent-dark);
}

.secondary,
.nav-button {
  color: var(--ink);
  border-color: var(--line);
  background: transparent;
}

.secondary:hover,
.nav-button:hover {
  color: var(--ink);
  background: rgba(166, 64, 45, 0.08);
}

.disabled {
  opacity: 0.62;
}

.disabled-link {
  pointer-events: none;
  opacity: 0.52;
}

.access-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  padding: 28px 0;
}

.panel {
  padding: 22px;
}

.panel p,
.muted {
  color: var(--muted);
  overflow-wrap: anywhere;
}

#waitlist-form,
#login-form {
  display: grid;
  gap: 10px;
}

.or-divider {
  margin: 12px 0 10px;
  text-align: center;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.upload-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.upload-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.upload-row input[type="file"] {
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 0.9rem;
}

.transcript-section-heading {
  margin: 18px 0 6px;
  font-size: 1.15rem;
  font-weight: 800;
}

.form-message {
  min-height: 22px;
  margin: 10px 0 0;
  color: var(--accent-dark);
}

.feed-line {
  min-height: 24px;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.text-button {
  min-height: 0;
  margin-left: 8px;
  padding: 0;
  border: 0;
  color: var(--accent-dark);
  background: transparent;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.text-button:hover {
  color: var(--accent);
  background: transparent;
}

.library,
.admin-grid {
  padding-top: 24px;
}

.section-title,
.admin-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.section-title h2,
.admin-header h1 {
  margin-bottom: 0;
}

.admin-header h1 {
  max-width: none;
  font-size: clamp(2.7rem, 8vw, 5.6rem);
}

.paper-list,
.table-list {
  display: grid;
  gap: 10px;
}

.paper-card,
.table-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 16px;
}

.paper-actions,
.row-actions,
.actions {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.paper-actions .text-button,
.row-actions .text-button,
.actions .text-button {
  margin-left: 0;
  padding-right: 4px;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid rgba(49, 95, 70, 0.28);
  border-radius: 999px;
  color: var(--ok);
  background: rgba(49, 95, 70, 0.08);
  font-size: 0.88rem;
  line-height: 1;
}

/* .table-row span (admin rows) sets display: block, which defeats the pill's
   inline-flex vertical centering — the label ends up hugging the pill's top.
   Higher specificity restores the flex pill inside table rows. */
.table-row .status {
  display: inline-flex;
}

.paper-tags {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.tag-list {
  display: flex;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
  flex-wrap: wrap;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 3px 9px;
  border: 1px solid rgba(64, 76, 85, 0.24);
  border-radius: 999px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.52);
  font-size: 0.82rem;
}

.tag-chip-hidden {
  border-style: dashed;
  color: var(--muted);
}

.tag-remove,
.tag-add {
  display: inline-grid;
  width: 26px;
  height: 26px;
  min-height: 26px;
  padding: 0;
  border-radius: 50%;
  place-items: center;
  font-size: 1rem;
  line-height: 1;
}

.tag-remove {
  width: 20px;
  height: 20px;
  min-height: 20px;
  margin: 0 -5px 0 2px;
  border: 0;
  color: var(--muted);
  background: transparent;
}

.tag-editor {
  position: relative;
  width: min(240px, 100%);
}

.tag-input {
  width: 100%;
  min-height: 34px;
  padding: 7px 10px;
  font-size: 0.88rem;
}

.tag-options {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  left: 0;
  width: 100%;
  max-height: 220px;
  margin: 0;
  padding: 4px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
  box-shadow: 0 10px 24px rgba(32, 25, 18, 0.14);
  list-style: none;
}

.tag-options [role="option"] {
  padding: 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.88rem;
}

.tag-options [role="option"]:hover,
.tag-options [aria-selected="true"] {
  color: white;
  background: var(--accent);
}

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

.pipeline-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.progress-track {
  width: 140px;
  height: 8px;
  border-radius: 999px;
  border: 1px solid rgba(49, 95, 70, 0.28);
  background: rgba(49, 95, 70, 0.08);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--ok);
  transition: width 0.4s ease;
}

.progress-track.indeterminate .progress-fill {
  width: 35%;
  animation: progress-slide 1.4s ease-in-out infinite;
}

@keyframes progress-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(300%); }
}

.stopped-note {
  font-size: 0.85rem;
}

.error {
  color: var(--danger);
}

/* Failure triage on admin reading rows: one-line reason, collapsible raw log
   and fix suggestions. */
.failure-help details {
  margin-top: 4px;
}

.failure-help summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--muted);
}

.error-log {
  margin: 8px 0;
  padding: 8px 10px;
  max-height: 160px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--danger);
  background: rgba(146, 60, 42, 0.06);
  border: 1px solid rgba(146, 60, 42, 0.18);
  border-radius: 8px;
}

.fix-steps {
  margin: 0 0 6px;
  padding-left: 18px;
  font-size: 0.88rem;
}

.fix-steps li {
  margin-bottom: 4px;
}

.fix-steps code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
}

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

.table-row strong,
.table-row span {
  display: block;
}

.table-row strong {
  overflow-wrap: anywhere;
}

.table-row span {
  color: var(--muted);
  font-size: 0.92rem;
}

.player-body {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.player-shell {
  width: min(920px, 100%);
  padding: clamp(22px, 5vw, 44px);
}

.player-shell h1 {
  max-width: 16ch;
  margin: 22px 0 12px;
  font-size: clamp(2.4rem, 7vw, 5rem);
}

audio {
  width: 100%;
  margin: 22px 0;
}

.transcript {
  margin-top: 34px;
  padding-top: 26px;
  border-top: 1px solid var(--line);
}

.transcript-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  list-style: none;
  padding: 4px 0;
}

.transcript-summary::-webkit-details-marker { display: none; }

.chapters {
  margin-top: 30px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.chapters-heading {
  margin-bottom: 12px;
  font-size: 0.86rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-dark);
}

.chapter-list {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: chapter;
}

.chapter-link {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: baseline;
  gap: 14px;
  width: 100%;
  min-height: 0;
  padding: 9px 10px;
  border: 0;
  border-radius: 6px;
  color: var(--ink);
  background: transparent;
  text-align: left;
  white-space: normal;
  cursor: pointer;
}

.chapter-link:hover {
  background: rgba(166, 64, 45, 0.08);
}

/* Subchapters nest under their parent section with a progressive indent and a
   slightly quieter title, mirroring the paper's heading hierarchy. */
.chapter-item.chapter-level-2 .chapter-link {
  padding-left: 26px;
}

.chapter-item.chapter-level-3 .chapter-link {
  padding-left: 42px;
}

.chapter-item.chapter-level-2 .chapter-title,
.chapter-item.chapter-level-3 .chapter-title {
  font-size: 0.94em;
  color: color-mix(in srgb, var(--ink) 78%, transparent);
}

.chapter-active {
  background: rgba(166, 64, 45, 0.12);
}

.chapter-active .chapter-title {
  font-weight: 800;
}

.chapter-time {
  font-variant-numeric: tabular-nums;
  color: var(--accent-dark);
  font-size: 0.9rem;
}

.chapter-title {
  overflow-wrap: anywhere;
}

.transcript-heading {
  display: grid;
  gap: 2px;
}

.transcript-title {
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.2;
}

.transcript-toggle {
  flex: none;
  width: 12px;
  height: 12px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.2s ease;
  opacity: 0.55;
}

.transcript[open] .transcript-toggle {
  transform: rotate(-135deg);
}

.transcript-body {
  display: grid;
  gap: 14px;
  margin-top: 20px;
}

.transcript-body > p {
  margin-bottom: 0;
  color: #282016;
  line-height: 1.62;
}

.transcript-visual {
  padding: 16px;
  border: 1px solid rgba(49, 95, 70, 0.28);
  border-radius: 8px;
  background: rgba(49, 95, 70, 0.07);
}

.transcript-visual h2 {
  margin-bottom: 8px;
  font-size: 1.12rem;
  line-height: 1.22;
}

.transcript-visual p {
  margin-bottom: 0;
  line-height: 1.45;
}

.visual-kind {
  color: var(--ok);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.transcript-visual pre {
  max-width: 100%;
  overflow-x: auto;
  margin: 12px 0 0;
  padding: 12px;
  border-radius: 6px;
  background: rgba(255, 250, 240, 0.8);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.84rem;
  white-space: pre-wrap;
}

@media (max-width: 820px) {
  .hero,
  .access-grid,
  .admin-grid,
  .paper-card,
  .table-row,
  .admin-header {
    grid-template-columns: 1fr;
  }

  .section-title,
  .admin-header {
    align-items: start;
  }

  .hero {
    min-height: auto;
  }

  h1 {
    max-width: 10ch;
  }

  .input-row,
  .inline-admin-form {
    grid-template-columns: 1fr;
  }

  .input-row button,
  .inline-admin-form button,
  #waitlist-form button {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  nav {
    flex-wrap: wrap;
  }

  .app-shell,
  .admin-shell {
    width: min(100% - 24px, 1180px);
  }
}

.example-blurb {
  margin: 0.5rem 0 0;
  color: #555;
  font-size: 0.92rem;
  line-height: 1.45;
  max-width: 60ch;
}

/* --- Readings search/filter controls ---------------------------------- */

.list-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.list-search,
.list-filter {
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--field);
  font: inherit;
  outline: none;
}

.list-search:focus,
.list-filter:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(166, 64, 45, 0.14);
}

.list-search {
  width: min(260px, 100%);
}

/* --- Sign-in method modal ---------------------------------------------- */

.signin-modal {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0;
  width: min(420px, calc(100vw - 32px));
  background: var(--panel);
  color: var(--ink);
}

.signin-modal::backdrop {
  background: rgba(23, 19, 13, 0.5);
}

.signin-modal-body {
  padding: 22px;
  display: grid;
  gap: 10px;
}

.signin-modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.signin-method-title {
  margin: 4px 0 0;
  font-size: 1rem;
}

.signin-modal form {
  display: grid;
  gap: 10px;
}

/* --- Alternate sign-in actions (magic link / forgot password) ---------- */

.auth-alt-actions {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  flex-wrap: wrap;
}

/* display:grid on modal forms would defeat the hidden attribute (UA display:none
   loses to any authored display); keep [hidden] authoritative. */
.signin-modal form[hidden] {
  display: none;
}

/* Reading versions: collapsed list of superseded generations on a paper card,
   and the player-page notice shown when listening to an archived generation. */
.older-versions {
  margin-top: 10px;
  font-size: 0.9rem;
}

.older-versions summary {
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  width: fit-content;
}

.older-versions-list {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
}

.older-version {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 2px;
}

.older-version-label {
  color: var(--muted);
}

.version-banner {
  margin: 18px 0 0;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 244, 214, 0.9);
  color: var(--muted);
  font-size: 0.95rem;
}

.version-banner a {
  color: var(--accent-dark);
  text-decoration: underline;
  text-underline-offset: 3px;
}
