:root {
  --ink: #171a18;
  --muted: #667069;
  --paper: #f4f0e8;
  --panel: #fffdf8;
  --line: #d8d0c2;
  --line-strong: #b9ad9a;
  --green: #1f725f;
  --green-deep: #164d44;
  --blue: #254c64;
  --rust: #a45532;
  --gold: #c6913d;
  --danger: #9a3b36;
  --shadow: 0 14px 38px rgba(28, 28, 24, 0.12);
  --shadow-soft: 0 7px 20px rgba(28, 28, 24, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-padding-top: 24px;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(31, 114, 95, 0.08) 1px, transparent 1px),
    linear-gradient(180deg, rgba(37, 76, 100, 0.08), transparent 310px),
    var(--paper);
  background-size: 36px 36px, auto, auto;
  font-family: "Aptos", "Segoe UI", sans-serif;
}

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

button,
.ghost-link,
.download-link {
  min-height: 42px;
  border: 1px solid var(--green-deep);
  border-radius: 7px;
  background: var(--green-deep);
  color: #fff;
  padding: 0 15px;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

button:hover,
.ghost-link:hover,
.download-link:hover {
  filter: brightness(1.04);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button.secondary,
.ghost-link {
  background: #fffdf8;
  color: var(--green-deep);
}

button.compact {
  padding-inline: 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--green-deep);
  font-size: 0.82rem;
  font-weight: 900;
  text-transform: uppercase;
}

select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
}

select {
  min-height: 42px;
  padding: 0 11px;
}

textarea {
  min-height: 360px;
  resize: vertical;
  padding: 15px;
  font-family: "Iowan Old Style", "Sitka Text", Georgia, serif;
  font-size: 1rem;
  line-height: 1.62;
}

textarea:focus,
select:focus,
button:focus-visible,
.ghost-link:focus-visible,
.download-link:focus-visible {
  outline: 3px solid rgba(198, 145, 61, 0.36);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 20;
  width: 1px;
  height: 1px;
  overflow: hidden;
  background: #fff;
  color: var(--green-deep);
  padding: 10px 12px;
  text-decoration: none;
  clip-path: inset(50%);
}

.skip-link:focus-visible {
  width: auto;
  height: auto;
  overflow: visible;
  clip-path: none;
}

.reader-shell {
  width: min(1420px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.reader-topbar,
.panel-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.reader-topbar {
  margin-bottom: 18px;
}

.reader-topbar h1,
.panel-heading h2 {
  margin: 0;
  text-wrap: balance;
}

.reader-topbar h1 {
  font-family: "Iowan Old Style", "Sitka Text", Georgia, serif;
  font-size: clamp(2rem, 5vw, 4.3rem);
  line-height: 0.94;
}

.panel-heading h2 {
  font-size: 1.12rem;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--rust);
  font-size: 0.74rem;
  font-weight: 950;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
}

.status-pill {
  min-height: 38px;
  border: 1px solid rgba(37, 76, 100, 0.28);
  border-radius: 7px;
  background: rgba(255, 253, 248, 0.78);
  color: var(--blue);
  padding: 9px 12px;
  font-size: 0.82rem;
  font-weight: 900;
}

.status-pill.ready {
  border-color: rgba(31, 114, 95, 0.34);
  color: var(--green-deep);
}

.status-pill.warn {
  border-color: rgba(164, 85, 50, 0.38);
  color: var(--rust);
}

.reader-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.82fr) minmax(360px, 1.42fr) minmax(220px, 0.58fr);
  gap: 16px;
  align-items: start;
}

.source-panel,
.player-panel,
.section-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: var(--shadow-soft);
}

.source-panel,
.section-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.player-panel {
  overflow: hidden;
}

.reader-controls {
  display: grid;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  background: #fffdf8;
  padding: 16px;
}

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

.mode-button {
  background: #fff;
  color: var(--blue);
  border-color: var(--line-strong);
}

.mode-button.active {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

.control-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(130px, 1fr)) minmax(150px, 0.8fr);
  gap: 10px;
}

.speed-field {
  align-content: end;
}

.speed-field span {
  color: var(--ink);
  font-weight: 800;
  text-transform: none;
}

input[type="range"] {
  accent-color: var(--rust);
  width: 100%;
}

.transport-row,
.source-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.transport-row button {
  flex: 1 1 96px;
}

#playButton {
  flex-basis: 130px;
}

#downloadButton {
  border-color: var(--rust);
  color: var(--rust);
}

audio {
  width: 100%;
  min-height: 42px;
}

.download-link[hidden],
.hidden {
  display: none;
}

.reader-message {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  font-weight: 750;
}

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

.reader-message.success {
  color: var(--green);
}

.file-picker {
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: rgba(31, 114, 95, 0.06);
  padding: 14px;
}

.file-picker span {
  color: var(--green-deep);
}

.file-picker input {
  width: 100%;
  color: var(--ink);
}

.source-actions button {
  flex: 1 1 120px;
}

.stats-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.stats-strip span {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--blue);
  padding: 9px;
  font-size: 0.86rem;
  font-weight: 900;
  display: grid;
  place-items: center;
  text-align: center;
}

.progress-block {
  border-bottom: 1px solid var(--line);
  background: rgba(37, 76, 100, 0.05);
  padding: 12px 16px;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--blue);
  font-size: 0.84rem;
  font-weight: 900;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(37, 76, 100, 0.16);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--gold), var(--rust));
  transition: width 180ms ease;
}

.reading-surface {
  min-height: 580px;
  max-height: calc(100vh - 260px);
  overflow: auto;
  background: #fffdf8;
  padding: clamp(20px, 4vw, 46px);
  font-family: "Iowan Old Style", "Sitka Text", Georgia, serif;
}

.empty-state {
  display: grid;
  min-height: 400px;
  place-items: center;
  border: 1px dashed var(--line-strong);
  color: var(--muted);
  font-family: "Aptos", "Segoe UI", sans-serif;
  font-weight: 850;
  text-align: center;
}

.reader-section {
  border-left: 4px solid transparent;
  margin: 0 0 22px;
  padding: 0 0 0 18px;
}

.reader-section.active {
  border-color: var(--rust);
}

.reader-section h3 {
  margin: 0 0 8px;
  color: var(--green-deep);
  font-family: "Aptos", "Segoe UI", sans-serif;
  font-size: 0.92rem;
  text-transform: uppercase;
}

.reader-section p {
  margin: 0;
  font-size: clamp(1.05rem, 1.5vw, 1.32rem);
  line-height: 1.72;
}

.section-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 190px);
  overflow: auto;
}

.section-item {
  width: 100%;
  min-height: 66px;
  justify-content: start;
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
  padding: 10px;
  text-align: left;
}

.section-item.active {
  border-color: var(--rust);
  background: rgba(164, 85, 50, 0.09);
}

.section-item strong,
.section-item span {
  display: block;
  overflow-wrap: anywhere;
}

.section-item strong {
  margin-bottom: 4px;
  color: var(--green-deep);
  font-size: 0.85rem;
}

.section-item span {
  color: var(--muted);
  font-size: 0.79rem;
}

@media (max-width: 1120px) {
  .reader-grid {
    grid-template-columns: minmax(270px, 0.8fr) minmax(360px, 1.2fr);
  }

  .section-panel {
    grid-column: 1 / -1;
  }

  .section-list {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    max-height: none;
  }
}

@media (max-width: 760px) {
  .reader-shell {
    width: min(100vw - 20px, 680px);
    padding: 18px 0;
  }

  .reader-topbar,
  .panel-heading {
    align-items: start;
    flex-direction: column;
  }

  .topbar-actions,
  .transport-row,
  .source-actions {
    width: 100%;
  }

  .ghost-link,
  .status-pill,
  .transport-row button,
  .source-actions button {
    width: 100%;
  }

  .reader-grid,
  .control-row {
    grid-template-columns: 1fr;
  }

  .reading-surface {
    min-height: 420px;
    max-height: none;
  }

  textarea {
    min-height: 280px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
