/* Fable booklet presentation, integrated with the production portal. */

:root {
  --paper: #FBF8F2;
  --surface: #FFFFFF;
  --ink: #1F1D1A;
  --ink-soft: #5A554D;
  --line: #E3DCD0;
  --line-strong: #8A8172;
  --accent: #1F5F4A;
  --accent-soft: #E4EFE9;
  --on-accent: #FFFFFF;
  --caution: #8A4B00;
  --caution-soft: #F7EBDD;
  --trouble: #9B2C2C;
  --trouble-soft: #F8E6E6;
  --record: #B3261E;
  --focus: #1F5F4A;

  --serif: "Iowan Old Style", "Charter", "Palatino", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;

  --body: 1.125rem;      /* 18px at 16px root */
  --body-lh: 1.6;
  --ui: 1rem;            /* 16px */
  --small: 0.9375rem;    /* 15px, never smaller */
  --h1: 1.5rem;
  --h2: 1.1875rem;

  --gutter: 20px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 32px; --s7: 48px;
  --tap: 48px;
  --radius: 10px;
  --measure: 34em;
  --nav-h: 60px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #15140F;
    --surface: #1E1C16;
    --ink: #ECE6DA;
    --ink-soft: #B5AC9C;
    --line: #2E2B24;
    --line-strong: #7A7264;
    --accent: #7FC8A9;
    --accent-soft: #1C3028;
    --on-accent: #0F2A20;
    --caution: #E0A85C;
    --caution-soft: #2E2416;
    --trouble: #E88F8F;
    --trouble-soft: #311A1A;
    --record: #E06A62;
    --focus: #7FC8A9;
  }
}

/* Follow the iPhone text-size setting where Safari supports it. Not verified on a device in this review. */
@supports (font: -apple-system-body) {
  html { font: -apple-system-body; }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
html { background: var(--paper); color: var(--ink); -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--sans);
  font-size: var(--ui);
  line-height: 1.45;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-wrap: anywhere;
}

.app { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }

/* Header: a quiet strip with a back control and a kicker. */
.top {
  display: flex; align-items: center; gap: var(--s2);
  min-height: 52px; padding: 0 var(--s3);
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  position: sticky; top: 0; z-index: 5;
}
.top .kicker { font-size: var(--small); color: var(--ink-soft); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }


main.page {
  flex: 1;
  padding: var(--s5) var(--gutter) calc(var(--nav-h) + var(--s6) + env(safe-area-inset-bottom));
  max-width: calc(var(--measure) + 2 * var(--gutter));
  width: 100%;
  margin: 0 auto;
}
main.page:focus { outline: none; }

/* Bottom tabs */
nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs a {
  min-height: var(--nav-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--ink-soft); font-size: var(--small);
  position: relative;
}
nav.tabs a[aria-current="page"] { color: var(--accent); font-weight: 600; }
nav.tabs a[aria-current="page"]::before { content: ""; position: absolute; top: 0; left: 20%; right: 20%; height: 3px; background: var(--accent); border-radius: 0 0 3px 3px; }
nav.tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
nav.tabs .dot { position: absolute; top: 10px; right: calc(50% - 18px); width: 8px; height: 8px; border-radius: 50%; background: var(--caution); }

/* Type */
h1 { font-family: var(--serif); font-size: var(--h1); line-height: 1.25; font-weight: 600; margin: 0 0 var(--s3); letter-spacing: -0.005em; }
h1:focus { outline: none; }
h2 { font-family: var(--serif); font-size: var(--h2); line-height: 1.3; font-weight: 600; margin: var(--s6) 0 var(--s3); }
h3 { font-family: var(--sans); font-size: var(--ui); margin: var(--s5) 0 var(--s2); color: var(--ink-soft); font-weight: 600; text-transform: none; }
p { margin: 0 0 var(--s4); }
.prose p, .prose li { font-family: var(--serif); font-size: var(--body); line-height: var(--body-lh); }
.prose ul { padding-left: 1.2em; margin: 0 0 var(--s4); }
.prose li { margin-bottom: var(--s2); }
.prose em { font-style: italic; }
.muted { color: var(--ink-soft); }
.small { font-size: var(--small); }
.lede { font-family: var(--serif); font-size: var(--body); line-height: var(--body-lh); color: var(--ink-soft); }

/* "Something you could say" card */
.say {
  margin: var(--s4) 0 var(--s5);
  padding: var(--s4) var(--s4);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
}
.say .say-label { font-family: var(--sans); font-size: var(--small); color: var(--ink-soft); margin: 0 0 var(--s2); }
.say p { font-family: var(--serif); font-size: var(--body); line-height: 1.7; margin: 0; white-space: pre-wrap; }

/* Links and buttons */
a { color: var(--accent); }
/* Inline text links: padding grows the tap area to 44px+ while negative margins keep the text rhythm. */
p a:not(.btn), .note a, .privacy-line a, .lede a { display: inline-block; padding: 13px 0; margin: -13px 0; }
a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid var(--focus); outline-offset: 2px;
}
button { font: inherit; color: inherit; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--tap); padding: 0 var(--s5);
  border-radius: var(--radius); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink);
  font-size: var(--ui); font-weight: 600; cursor: pointer; text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn.quiet { background: transparent; border-color: transparent; color: var(--accent); padding: 0 var(--s3); }
.btn.danger { color: var(--trouble); }
.btn.block { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--s3); margin: var(--s4) 0; }
.btn-row > .btn { flex: 1 1 auto; }
.back {
  min-width: var(--tap); min-height: var(--tap); display: inline-flex; align-items: center; gap: 4px;
  border: 0; background: transparent; color: var(--accent); font-weight: 600; padding: 0 var(--s2) 0 0; cursor: pointer; font-size: var(--ui);
}
.back svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* Lists of chapters / questions */
.list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.list li { border-bottom: 1px solid var(--line); }
.list a, .list button.rowbtn {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: var(--s3);
  width: 100%; min-height: 56px; padding: var(--s3) 0; text-align: left;
  background: transparent; border: 0; color: var(--ink); text-decoration: none; cursor: pointer; font-size: var(--ui);
}
.list .row-title { font-family: var(--serif); font-size: var(--body); line-height: 1.35; }
.list .row-meta { display: block; font-size: var(--small); color: var(--ink-soft); margin-top: 2px; font-family: var(--sans); }
.list .chev { width: 18px; height: 18px; stroke: var(--ink-soft); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.list .num { display: inline-block; min-width: 1.6em; color: var(--ink-soft); font-family: var(--sans); font-size: var(--small); }

.status {
  display: inline-block; font-size: var(--small); color: var(--ink-soft); font-family: var(--sans);
}
.status.saved { color: var(--accent); }
.status.draft { color: var(--caution); }
.status.trouble { color: var(--trouble); }

/* Resume line and notes */
.note {
  border-radius: var(--radius); padding: var(--s3) var(--s4); margin: 0 0 var(--s5);
  background: var(--surface); border: 1px solid var(--line);
  font-size: var(--small); color: var(--ink-soft);
}
.note.accent { background: var(--accent-soft); border-color: transparent; color: var(--ink); }
.note.caution { background: var(--caution-soft); border-color: transparent; color: var(--ink); }
.note.trouble { background: var(--trouble-soft); border-color: transparent; color: var(--ink); }
.note p:last-child { margin-bottom: 0; }

/* Reading progress bar */
.readbar { position: fixed; top: calc(52px + env(safe-area-inset-top)); left: 0; height: 3px; background: var(--accent); width: 0; z-index: 5; transition: width 150ms linear; }
@media (prefers-reduced-motion: reduce) { .readbar { transition: none; } }

/* Section footer: Explore this more */
.explore {
  display: inline-flex; align-items: center; gap: var(--s2);
  min-height: var(--tap); padding: 0 var(--s3) 0 var(--s2);
  border: 1px solid var(--line); border-radius: 999px; background: transparent;
  color: var(--ink-soft); font-size: var(--small); cursor: pointer; margin: 0 0 var(--s4);
}
.explore svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.explore[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.explore .label-off, .explore[aria-pressed="true"] .label-on { display: inline; }
.explore .label-on, .explore[aria-pressed="true"] .label-off { display: none; }

.chapter-foot { margin-top: var(--s6); padding-top: var(--s5); border-top: 1px solid var(--line); }

/* Question page */
.q-text { font-family: var(--serif); font-size: 1.3125rem; line-height: 1.4; font-weight: 600; margin: 0 0 var(--s3); }
.q-purpose { color: var(--ink-soft); font-size: var(--small); margin-bottom: var(--s4); }
details.hint { margin: 0 0 var(--s5); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
details.hint summary { min-height: var(--tap); display: flex; align-items: center; padding: 0 var(--s4); cursor: pointer; font-weight: 600; list-style: none; }
details.hint summary::-webkit-details-marker { display: none; }
details.hint summary::after { content: "+"; margin-left: auto; color: var(--ink-soft); font-size: 1.3em; }
details.hint[open] summary::after { content: "–"; }
details.hint .body { padding: 0 var(--s4) var(--s4); font-family: var(--serif); font-size: var(--body); line-height: var(--body-lh); }

.voice-stage { text-align: center; padding: var(--s5) 0 var(--s4); }
.record-btn {
  width: 88px; height: 88px; border-radius: 50%; border: 0;
  background: var(--record); color: #fff; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 0 rgba(0,0,0,0.12);
}
.record-btn svg { width: 36px; height: 36px; fill: currentColor; }
.record-btn.stop { background: var(--ink); border-radius: 18px; }
.record-btn.stop svg { width: 30px; height: 30px; }
.record-label { display: block; margin-top: var(--s3); font-weight: 600; }
.record-sub { display: block; margin-top: var(--s1); color: var(--ink-soft); font-size: var(--small); }
.timer { font-variant-numeric: tabular-nums; font-size: 1.75rem; font-family: var(--sans); font-weight: 600; margin: var(--s3) 0 var(--s1); }
.level { display: flex; gap: 3px; justify-content: center; align-items: flex-end; height: 28px; margin: var(--s2) auto var(--s3); }
.level span { width: 5px; height: 6px; background: var(--record); border-radius: 2px; }
@media (prefers-reduced-motion: no-preference) {
  .level.live span { animation: lv 900ms ease-in-out infinite alternate; }
  .level.live span:nth-child(2n) { animation-duration: 700ms; }
  .level.live span:nth-child(3n) { animation-duration: 1100ms; }
  @keyframes lv { from { height: 6px; } to { height: 28px; } }
}
@media (prefers-reduced-motion: reduce) { .level.live span { height: 16px; } }

.or { display: block; text-align: center; margin: var(--s4) 0; }
.or button { background: none; border: 0; color: var(--accent); font-size: var(--ui); font-weight: 600; min-height: var(--tap); padding: 0 var(--s3); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

textarea {
  width: 100%; min-height: 10em; padding: var(--s3) var(--s4);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
  font-family: var(--serif); font-size: var(--body); line-height: 1.55; resize: vertical;
}
label.field { display: block; font-weight: 600; margin: 0 0 var(--s2); }
.count { text-align: right; font-size: var(--small); color: var(--ink-soft); min-height: 1.4em; }
.count.near { color: var(--caution); }
.count.over { color: var(--trouble); font-weight: 600; }
input[type="text"], input[type="password"] {
  width: 100%; min-height: var(--tap); padding: 0 var(--s4);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); font: inherit; font-size: var(--body);
}

audio { width: 100%; margin: var(--s3) 0; }
.preview { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: var(--s4); margin: var(--s4) 0; }
.privacy-line { font-size: var(--small); color: var(--ink-soft); margin: var(--s3) 0 0; }
.privacy-line a { color: var(--accent); }
/* Inline text links: padding grows the tap area to 44px+ while negative margins keep the text rhythm. */
p a:not(.btn), .note a, .privacy-line a, .lede a { display: inline-block; padding: 13px 0; margin: -13px 0; }

/* Saved and error */
.result { text-align: center; padding: var(--s6) 0 var(--s4); }
.result .mark { width: 56px; height: 56px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; margin-bottom: var(--s3); }
.result .mark svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.result .mark.ok { background: var(--accent-soft); color: var(--accent); }
.result .mark.bad { background: var(--trouble-soft); color: var(--trouble); }
.result .mark.wait { background: var(--surface); color: var(--ink-soft); border: 1px solid var(--line); }
details.receipt { margin: var(--s4) 0; }
details.receipt summary { min-height: var(--tap); display: inline-flex; align-items: center; cursor: pointer; color: var(--accent); font-weight: 600; }
details.receipt code { font-size: var(--small); word-break: break-all; display: block; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: var(--s2) var(--s3); margin-top: var(--s2); }

/* Sent list */
.answer { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: var(--s4); margin: 0 0 var(--s4); }
.answer .a-q { font-family: var(--serif); font-weight: 600; font-size: var(--body); line-height: 1.35; margin: 0 0 var(--s1); }
.answer .a-meta { font-size: var(--small); color: var(--ink-soft); margin: 0 0 var(--s3); }
.answer .a-body { font-family: var(--serif); font-size: var(--body); line-height: 1.55; white-space: pre-wrap; margin: 0 0 var(--s3); }
.answer .correction { border-left: 3px solid var(--accent); padding-left: var(--s3); margin: var(--s3) 0; }
.answer .correction .c-meta { font-size: var(--small); color: var(--ink-soft); margin: 0 0 var(--s1); }
.answer .a-actions { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s3); }
.answer .a-actions .btn { flex: 1 1 auto; min-width: 0; }
.answer.hidden-item { opacity: 0.75; }
details.hidden-group summary { min-height: var(--tap); display: inline-flex; align-items: center; cursor: pointer; font-weight: 600; color: var(--ink-soft); }

/* Session-expiry sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 560px; background: var(--paper); border-radius: 16px 16px 0 0;
  padding: var(--s5) var(--gutter) calc(var(--s6) + env(safe-area-inset-bottom));
  max-height: 90vh; max-height: 90dvh; overflow: auto;
}
.sheet h2 { margin-top: 0; }

.access { padding-top: var(--s6); }
.access .brand { font-family: var(--serif); font-size: 1.25rem; font-weight: 600; margin-bottom: var(--s5); }

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

hr.soft { border: 0; border-top: 1px solid var(--line); margin: var(--s6) 0; }

.marks-list .m-sec { font-family: var(--serif); font-size: var(--body); }
.marks-list .m-ch { font-size: var(--small); color: var(--ink-soft); display: block; }

@media (max-width: 380px) {
  :root { --gutter: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
.record-btn{width:100%;min-height:88px;border:1px solid var(--line-strong);border-radius:var(--radius);background:var(--surface);color:var(--record);display:flex;align-items:center;justify-content:center;gap:16px;font:inherit;font-weight:600;font-size:1.125rem;cursor:pointer}.record-btn>span:first-child{font-size:2rem}.record-btn:disabled{opacity:.6}.voice-stage{text-align:center;margin:24px 0}.voice-stage .small{margin-top:16px}.voice-stage audio{display:block}.hint{margin:20px 0}.hint summary,details>summary{min-height:48px;cursor:pointer;padding:12px 0}.marked-row{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:12px 0}.chapter-foot{margin-top:32px}.chapter-foot>.btn{margin-bottom:12px}.correction{margin-top:20px!important}.answer h2{margin-top:0}.brand{font-family:var(--serif)}#globalStatus{overflow-wrap:anywhere}#draftState{margin-top:16px}.btn-row .btn{min-width:0}.prose pre{white-space:pre-wrap}.prose ol{font-family:var(--serif);font-size:var(--body);line-height:var(--body-lh)}.page section>h1{overflow-wrap:anywhere}.a-body{white-space:pre-wrap}.tabs a>span[aria-hidden]{font-size:1.4rem;line-height:1}.say .say-label{font-size:var(--small)}.say p+ p{margin-top:12px}#readingGuidance{margin-top:24px}#readingGuidance>p>a{margin-right:8px}.prose table{display:block;overflow-x:auto}.prose th,.prose td{padding:8px;border:1px solid var(--line)}.prose blockquote{border-left:3px solid var(--accent);margin-left:0;padding-left:16px}#questionText{margin-top:8px}@media print{.top,.tabs,#readingGuidance,.explore,.chapter-foot{display:none!important}.page{max-width:none;padding:0}}
.prose .source-excerpt{background:var(--accent-soft);border:1px solid var(--line-strong);border-left:3px solid var(--accent);padding:16px;margin:20px 0;border-radius:var(--radius)}.prose .source-excerpt .source-label{font-family:var(--sans);font-size:var(--small);font-weight:600;color:var(--ink-soft)}

.record-btn{width:88px;height:88px;min-height:88px;border:0;border-radius:50%;background:var(--record);color:var(--paper);display:inline-flex;padding:0}.record-btn svg{width:36px;height:36px;fill:none;stroke:currentColor;stroke-width:2}.record-btn.stop{background:var(--ink);color:var(--paper);border-radius:18px}.hint>p{padding:0 16px}#questionText{font-size:1.3125rem;line-height:1.4}

.prose .source-excerpt, .prose .source-excerpt p, .prose .source-excerpt li { font-family: var(--sans); }
