:root {
  --ink: #20251f;
  --paper: #f7f3ea;
  --panel: #fffdf8;
  --green: #2e5b45;
  --green-light: #dce7dc;
  --yellow: #edbd62;
  --line: #d8d2c4;
  --red: #9b3b32;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--paper); color: var(--ink); font-family: Georgia, "Times New Roman", serif; }
button, input, select { font: inherit; }
select { width: 100%; min-height: 46px; border: 1px solid var(--line); border-radius: 6px; background: white; padding: 10px 12px; }
button { cursor: pointer; }
.header-actions { display:flex; align-items:center; gap:8px; }
.header-actions a { display:inline-grid; place-items:center; text-decoration:none; }
.hidden { display: none !important; }

.topbar { height: 68px; padding: 0 4vw; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: rgba(247,243,234,.96); }
.brand { display: flex; gap: 10px; align-items: center; color: var(--ink); text-decoration: none; font-weight: 700; font-size: 18px; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; background: var(--green); color: white; font-size: 14px; }
.quiet-button, .secondary { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 6px; min-height: 42px; padding: 8px 14px; }
.primary, .complete-button { border: 0; background: var(--green); color: white; border-radius: 6px; min-height: 42px; padding: 9px 16px; }
.primary:disabled { opacity: .45; cursor: default; }
.icon-button { display: inline-flex; align-items: center; gap: 8px; }

main { min-height: calc(100vh - 68px); }
.view { max-width: 1120px; margin: 0 auto; padding: 48px 4vw 100px; }
.auth-view { min-height: calc(100vh - 68px); display: grid; align-items: center; max-width: none; background: radial-gradient(circle at 75% 30%, #f0dba7 0, transparent 22%), linear-gradient(135deg, #edf1e6 0, #f7f3ea 55%); }
.auth-panel { width: min(520px, 92vw); margin-left: 8vw; }
.eyebrow { margin: 0 0 8px; color: var(--green); font-family: Arial, sans-serif; font-size: 12px; font-weight: 700; letter-spacing: 0; text-transform: uppercase; }
h1 { margin: 0 0 16px; font-size: clamp(40px, 7vw, 76px); line-height: .95; }
.lede { max-width: 470px; font-size: 20px; line-height: 1.45; }
form label { display: grid; gap: 7px; margin: 16px 0; font-family: Arial, sans-serif; font-size: 13px; font-weight: 700; }
input { width: 100%; min-height: 46px; border: 1px solid var(--line); border-radius: 6px; background: white; padding: 10px 12px; }
.error { min-height: 20px; color: var(--red); }
.optional { font-weight: normal; opacity: 0.7; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; }

.section-heading { display: flex; align-items: end; justify-content: space-between; }
.section-heading h1 { font-size: 52px; }
.book-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.book-card { min-height: 180px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 18px; display: flex; flex-direction: column; justify-content: space-between; }
.book-card h2 { margin: 0 0 8px; font-size: 22px; }
.book-card p { margin: 0; color: #687064; }
.status { align-self: start; margin-top: 16px; padding: 5px 8px; border-radius: 4px; background: var(--green-light); font-family: Arial, sans-serif; font-size: 12px; }

.studio-header { display: grid; grid-template-columns: 80px 1fr; align-items: center; gap: 16px; }
.progress-strip { height: 8px; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 5px; }
.progress-dot { height: 8px; border-radius: 4px; background: var(--line); }
.progress-dot.done { background: var(--green); }
.progress-dot.current { background: var(--yellow); }
.recorder-layout { display: grid; grid-template-columns: 280px 1fr; gap: 48px; align-items: center; min-height: 520px; }
.recorder-layout h1 { font-size: 46px; }
.page-status, .recording-status { font-family: Arial, sans-serif; }
.take-panel { display: grid; justify-items: center; }
.page-preview { width: min(560px, 100%); aspect-ratio: 4 / 3; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); display: grid; place-items: center; box-shadow: 0 16px 40px rgba(48,54,45,.08); }
.page-preview span { width: 90px; height: 90px; display: grid; place-items: center; border: 2px solid var(--green); border-radius: 50%; font-size: 44px; }
.take-panel audio { width: min(560px, 100%); margin: 12px 0; }
.page-preview span.title-page { width: auto; min-width: 90px; padding: 0 22px; border-radius: 45px; font-size: 32px; }
.record-controls { height: 90px; display: flex; gap: 10px; align-items: center; }
.record-button { width: 70px; height: 70px; border: 0; border-radius: 50%; background: var(--green); display: grid; place-items: center; }
.record-button span { width: 32px; height: 32px; border-radius: 50%; background: #fff; }
.record-button.recording span { width: 24px; height: 24px; border-radius: 4px; }
.stop-button { border: 0; border-radius: 6px; background: var(--red); color: white; min-height: 42px; padding: 8px 14px; }
.complete-button { width: 100%; min-height: 52px; }

.bottom-nav { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); display: flex; background: var(--ink); border-radius: 8px; box-shadow: 0 8px 30px rgba(32,37,31,.22); }
.bottom-nav button { min-width: 110px; min-height: 48px; border: 0; background: transparent; color: #d9ddd5; }
.bottom-nav button.active { color: white; text-decoration: underline; text-underline-offset: 6px; }

dialog { width: min(480px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 24px; box-shadow: 0 24px 60px rgba(32,37,31,.22); }
dialog::backdrop { background: rgba(32,37,31,.45); }

.preview-header { display: grid; grid-template-columns: 80px 1fr; align-items: center; gap: 16px; }
.preview-header h1 { font-size: 52px; }
.preview-layout { display: grid; grid-template-columns: 280px 1fr; gap: 48px; align-items: center; min-height: 520px; }
.preview-layout aside { font-family: Arial, sans-serif; }
.preview-player { display: grid; justify-items: center; }
.preview-page { width: min(560px, 100%); aspect-ratio: 4 / 3; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); display: grid; place-items: center; }
.preview-page span { width: 90px; height: 90px; display: grid; place-items: center; border: 2px solid var(--green); border-radius: 50%; font-size: 44px; }
.preview-player audio { width: min(560px, 100%); margin: 12px 0; }

.shelf-heading { margin: 28px 0 12px; font-family: Arial, sans-serif; font-size: 14px; text-transform: uppercase; color: #687064; }
.book-card { cursor: pointer; text-align: left; font: inherit; color: inherit; }
.book-card:focus-visible, .player-button:focus-visible, .mode-option:focus-visible, .reader-choice:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }
.empty-shelf { color: #687064; }

.reader-choices { display: grid; gap: 10px; margin: 16px 0; }
.reader-choice { min-height: 60px; border: 1px solid var(--line); border-radius: 8px; background: white; font-size: 20px; text-align: left; padding: 12px 16px; }
.reader-choice small { display: block; font-family: Arial, sans-serif; font-size: 13px; color: #687064; }

.mode-switch { display: inline-flex; margin: 8px 0 20px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); padding: 4px; }
.mode-option { min-height: 44px; border: 0; border-radius: 999px; background: transparent; padding: 8px 18px; font-family: Arial, sans-serif; font-weight: 700; }
.mode-option[aria-checked="true"] { background: var(--green); color: white; }
.player-stage { display: grid; justify-items: center; gap: 14px; }
.player-page { position: relative; width: min(620px, 100%); aspect-ratio: 4 / 3; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); display: grid; place-content: center; justify-items: center; gap: 8px; box-shadow: 0 16px 40px rgba(48,54,45,.08); transition: background .3s; }
.player-page.turning { background: #fbefd2; }
.player-page-label { font-size: clamp(64px, 14vw, 140px); line-height: 1; }
.player-page-sub { font-family: Arial, sans-serif; font-size: 18px; color: #687064; }
.player-turn { position: absolute; bottom: 18px; padding: 6px 14px; border-radius: 999px; background: var(--yellow); font-family: Arial, sans-serif; font-weight: 700; }
.player-progress { width: min(620px, 100%); height: 8px; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; }
.player-progress span { border-radius: 4px; background: var(--line); }
.player-progress span.done { background: var(--green); }
.player-progress span.current { background: var(--yellow); }
.player-status { min-height: 22px; margin: 0; font-family: Arial, sans-serif; color: #687064; }
.player-controls { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.player-button { min-width: 120px; min-height: 64px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); font-size: 22px; padding: 10px 18px; }
.player-button.play { min-width: 170px; border: 0; background: var(--green); color: white; }
.player-button:disabled { opacity: .4; cursor: default; }

/* Player: cover, settings, resume */
.player-heading { display: flex; align-items: center; gap: 16px; min-width: 0; }
.player-heading .cover { width: 54px; height: 80px; flex: none; }
.player-heading .cover .cover-letter { font-size: 28px; }
.player-page-cover { height: 72%; aspect-ratio: 2 / 3; }
.player-page-cover .cover { width: 100%; height: 100%; }
.player-settings { display: flex; flex-wrap: wrap; gap: 12px 24px; margin: -8px 0 20px; font-family: Arial, sans-serif; font-size: 14px; }
.player-settings label { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.player-settings select { width: auto; min-height: 40px; padding: 6px 10px; }
.player-resume { width: min(620px, 100%); display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-radius: 10px; background: var(--green-light); font-family: Arial, sans-serif; font-size: 17px; font-weight: 700; }

/* Recording warnings (too quiet, distorted, silent): advice, never a block */
.page-warning { margin: 10px 0 0; padding: 10px 12px; border-radius: 8px; background: #fbefd2; border: 1px solid var(--yellow); font-family: Arial, sans-serif; font-size: 14px; line-height: 1.4; }

/* New book: find by ISBN or by typed title */
#isbn-section > label { margin-bottom: 7px; }
.isbn-row { display: flex; gap: 8px; }
.isbn-row input { flex: 1; min-width: 0; }
.isbn-row button { flex: none; }
.hint { margin: -8px 0 0; font-family: Arial, sans-serif; font-size: 13px; color: #687064; }
.isbn-result { display: flex; gap: 14px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: white; }
.isbn-result strong { display: block; font-size: 19px; }
.isbn-result span { font-family: Arial, sans-serif; font-size: 13px; color: #687064; }

/* Covers: the image when there is one, otherwise the title's first letter */
.cover { display: grid; place-items: center; overflow: hidden; border-radius: 4px; background: var(--green-light); color: var(--green); }
.cover img { width: 100%; height: 100%; object-fit: contain; display: block; }
.cover .cover-letter { font-size: 64px; line-height: 1; opacity: .7; }
.cover.small { width: 56px; height: 84px; flex: none; }
.cover.small .cover-letter { font-size: 28px; }
.book-card .cover { height: 190px; margin: -6px -6px 14px; }

.toast { position: fixed; top: 84px; left: 50%; transform: translateX(-50%); z-index: 20; display: flex; align-items: center; gap: 12px; max-width: calc(100vw - 32px); padding: 14px 18px; border-radius: 10px; background: var(--green); color: white; font-family: Arial, sans-serif; font-size: 17px; font-weight: 700; box-shadow: 0 12px 30px rgba(32,37,31,.25); }
.toast-close { border: 0; background: transparent; color: white; font-size: 24px; line-height: 1; cursor: pointer; }
.complete-button:disabled { opacity: .6; cursor: progress; }

@media (max-width: 760px) {
  .view { padding-top: 28px; }
  .auth-panel { margin: 0 auto; }
  .recorder-layout { grid-template-columns: 1fr; gap: 12px; min-height: auto; }
  .recorder-layout aside { text-align: center; }
  .recorder-layout h1 { font-size: 36px; }
  .studio-header { grid-template-columns: 70px 1fr; }
  .section-heading h1 { font-size: 42px; }
  .preview-layout { grid-template-columns: 1fr; gap: 12px; min-height: auto; }
  .preview-header { grid-template-columns: 70px 1fr; }
  .preview-header h1 { font-size: 36px; }
}
