/* Book One reader. Look A from the design canvas: a quiet reading column, a sheet that slides up from the bottom
   when a sentence is tapped. Colours and sizes are the canvas values (artboards A1 light and A2 dark). */

:root {
  --bg: #FFFFFF; --ink: #1B1D22; --muted: #5E6470; --rule: #ECEDF0;
  --sheet: #FFFFFF; --sheet-line: #E3E4E8; --btn-line: #DADDE3; --grab: #D0D3D9; --field: #FFFFFF;
  --accent: #5B3FA0; --accent-press: #432C7A; --on-accent: #FFFFFF; --sel: #ECE6FA;
  --shadow: 0 -10px 30px rgba(16, 24, 40, 0.10); --pop-shadow: 0 16px 40px rgba(16, 24, 40, 0.16);
  --rec: #D92D20; --bar-off: #D0D3D9;
  --r-cut: #D92D20; --r-confusing: #DC6803; --r-voice: #7F56D9; --r-slow: #2E90FA; --r-adds-up: #0E9384; --r-love: #17B26A;
  --text: "Literata", Georgia, "Times New Roman", serif;
  --ui: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --fs: 19px; --hd: 60px; --sheet-h: 0px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121318; --ink: #E7E5E0; --muted: #9AA0AA; --rule: #262830;
    --sheet: #1A1C22; --sheet-line: #2C2F38; --btn-line: #3A3E48; --grab: #3A3E48; --field: #121318;
    --accent: #B9A4F2; --accent-press: #D3C5F7; --on-accent: #17121F; --sel: #2B2344;
    --shadow: 0 -10px 30px rgba(0, 0, 0, 0.45); --pop-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
    --rec: #F04438; --bar-off: #5C5F6A;
    --r-cut: #F97066; --r-confusing: #FDB022; --r-voice: #B692F6; --r-slow: #53B1FD; --r-adds-up: #2ED3B7; --r-love: #47CD89;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121318; --ink: #E7E5E0; --muted: #9AA0AA; --rule: #262830;
  --sheet: #1A1C22; --sheet-line: #2C2F38; --btn-line: #3A3E48; --grab: #3A3E48; --field: #121318;
  --accent: #B9A4F2; --accent-press: #D3C5F7; --on-accent: #17121F; --sel: #2B2344;
  --shadow: 0 -10px 30px rgba(0, 0, 0, 0.45); --pop-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  --rec: #F04438; --bar-off: #5C5F6A;
  --r-cut: #F97066; --r-confusing: #FDB022; --r-voice: #B692F6; --r-slow: #53B1FD; --r-adds-up: #2ED3B7; --r-love: #47CD89;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--ui);
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- buttons ---- */
.btn { min-height: 44px; border: 0; background: transparent; font-size: 15px; font-weight: 500; padding: 0 8px; }
.btn.primary {
  width: 100%; min-height: 52px; border-radius: 10px; background: var(--accent); color: var(--on-accent);
  font-size: 16px; font-weight: 600;
}
.btn.primary:active { background: var(--accent-press); }
.btn.primary:disabled { opacity: 0.55; cursor: default; }
.btn.link { color: var(--accent); }
.btn.link.small { min-height: 44px; }
.btn.link.danger { color: var(--r-cut); }
.btn.quiet { color: var(--ink); border: 1px solid var(--btn-line); border-radius: 8px; padding: 0 14px; }
.icon {
  width: 44px; height: 44px; border: 0; background: transparent; position: relative;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon .aa { font-size: 17px; font-weight: 600; }
.icon[aria-expanded="true"] { background: var(--sel); border-radius: 8px; }

/* ---- sign in and messages ---- */
.screen {
  min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.card { width: 100%; max-width: 22rem; display: flex; flex-direction: column; gap: 14px; }
.card form { display: flex; flex-direction: column; gap: 14px; }
.brand { margin: 0; font-size: 13px; font-weight: 600; color: var(--accent); }
.brand-t { margin: -8px 0 4px; font-family: var(--text); font-size: 34px; font-weight: 600; line-height: 1.15; }
.lead { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.5; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 500; }
.field input {
  height: 48px; padding: 0 12px; font: inherit; font-size: 17px; font-weight: 400; color: var(--ink);
  background: var(--field); border: 1px solid var(--btn-line); border-radius: 8px;
}
.err { margin: 0; color: var(--r-cut); font-size: 15px; line-height: 1.45; }

/* ---- header ---- */
.hd {
  position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--rule);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  height: calc(var(--hd) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
}
.hd-where {
  min-width: 0; flex: 1; height: 52px; border: 0; background: transparent; text-align: left; padding: 0 8px;
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
}
.hd-ch { font-size: 12px; color: var(--muted); }
.hd-title { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hd-tools { display: flex; gap: 4px; flex: none; }
.badge {
  position: absolute; top: 6px; right: 2px; min-width: 16px; height: 16px; padding: 0 3px;
  background: var(--accent); color: var(--on-accent); font-size: 11px; font-weight: 600; line-height: 16px; text-align: center;
  border-radius: 3px;
}
.dot { position: absolute; bottom: 9px; right: 7px; width: 8px; height: 8px; border-radius: 4px; background: var(--r-confusing); border: 2px solid var(--bg); }

.hint {
  max-width: 40rem; margin: 16px auto 0; padding: 4px 8px 4px 16px; display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--btn-line); border-radius: 10px; font-size: 15px; color: var(--muted);
  margin-left: max(16px, calc((100% - 40rem) / 2)); margin-right: max(16px, calc((100% - 40rem) / 2));
}
.hint p { margin: 0; flex: 1; line-height: 1.45; }

/* ---- the reading column ---- */
.text {
  max-width: 40rem; margin: 0 auto; font-family: var(--text); font-size: var(--fs); line-height: 1.7;
  padding: 28px max(24px, env(safe-area-inset-right)) calc(var(--sheet-h) + 48px) max(24px, env(safe-area-inset-left));
}
.text p { margin: 0 0 0.95em; }
.text .part { text-align: center; margin: 1.6em 0 2.2em; }
.text .part-k { margin: 0; font-family: var(--ui); font-size: 13px; font-weight: 600; color: var(--accent); }
.text .part-t { margin: 0.2em 0 0; font-size: 1.5em; font-weight: 600; line-height: 1.2; }
.text .ch-n { margin: 0; font-family: var(--ui); font-size: 13px; color: var(--muted); }
.text h1 { margin: 0.15em 0 1.2em; font-size: 1.55em; font-weight: 600; line-height: 1.2; text-wrap: balance; }
.text .brk { text-align: center; color: var(--muted); letter-spacing: 0.5em; margin: 1.4em 0; }

.s {
  cursor: pointer; border-radius: 2px; scroll-margin-top: calc(var(--hd) + env(safe-area-inset-top) + 20px);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-box-decoration-break: clone; box-decoration-break: clone;
}
.s.mk {
  text-decoration-line: underline; text-decoration-color: var(--mk, var(--accent));
  text-decoration-thickness: 2px; text-underline-offset: 6px; text-decoration-skip-ink: none;
}
.s.sel { background: var(--sel); box-shadow: 0 0 0 3px var(--sel); border-bottom: 2px solid var(--accent); }
.s.flash { animation: flash 1.6s ease-out 1; }
@keyframes flash { 0%, 40% { background: var(--sel); box-shadow: 0 0 0 3px var(--sel); } 100% { background: transparent; box-shadow: none; } }

.ch-end { margin: 3em 0 1em; padding-top: 1.6em; border-top: 1px solid var(--rule); font-family: var(--ui); display: flex; flex-direction: column; gap: 10px; }
.ch-end p { margin: 0 0 4px; color: var(--muted); font-size: 14px; }
.ch-next {
  width: 100%; min-height: 56px; padding: 10px 16px; border: 0; border-radius: 10px; background: var(--accent); color: var(--on-accent);
  font-size: 16px; font-weight: 600; text-align: left; line-height: 1.35;
}
.ch-next span { display: block; font-size: 13px; font-weight: 500; opacity: 0.85; }
.ch-prev { align-self: flex-start; }

/* ---- the sheet ---- */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; max-width: 40rem; margin: 0 auto;
  background: var(--sheet); border-top: 1px solid var(--sheet-line); border-radius: 14px 14px 0 0; box-shadow: var(--shadow);
  padding: 10px max(16px, env(safe-area-inset-right)) calc(14px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: 10px;
  transform: translateY(0); transition: transform 0.22s ease-out;
}
.sheet.away { transform: translateY(110%); }
@media (min-width: 40rem) { .sheet { border-left: 1px solid var(--sheet-line); border-right: 1px solid var(--sheet-line); } }
.grab { width: 36px; height: 4px; border-radius: 2px; background: var(--grab); align-self: center; }
.sheet-row { display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.sheet-what { font-size: 14px; color: var(--muted); }
.pane { display: flex; flex-direction: column; gap: 10px; }
.reasons { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.reason {
  height: 52px; display: flex; align-items: center; gap: 10px; padding: 0 12px; border: 1px solid var(--btn-line);
  border-radius: 8px; background: transparent; font-size: 15px; font-weight: 500; text-align: left; line-height: 1.2;
}
.reason .sw { width: 10px; height: 10px; flex: none; background: var(--rc); }
.reason .tick { margin-left: auto; width: 16px; height: 16px; flex: none; color: var(--rc); visibility: hidden; }
.reason[aria-pressed="true"] { border-color: var(--rc); box-shadow: inset 0 0 0 1px var(--rc); background: var(--sel); }
@supports (background: color-mix(in srgb, red 10%, white)) {
  .reason[aria-pressed="true"] { background: color-mix(in srgb, var(--rc) 12%, var(--sheet)); }
}
.reason[aria-pressed="true"] .tick { visibility: visible; }

.have { display: flex; flex-direction: column; gap: 8px; }
.have-voice { display: flex; align-items: center; gap: 10px; }
.have-body {
  border: 1px solid var(--btn-line); border-radius: 8px; background: transparent; padding: 10px 12px; text-align: left;
  font-size: 15px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
#note-text {
  width: 100%; min-height: 120px; resize: vertical; padding: 12px; font: inherit; font-size: 17px; line-height: 1.45;
  color: var(--ink); background: var(--field); border: 1px solid var(--btn-line); border-radius: 8px;
}

.talk {
  height: 56px; margin-top: 2px; display: flex; align-items: center; justify-content: center; gap: 10px;
  border: 0; border-radius: 10px; background: var(--accent); color: var(--on-accent); font-size: 16px; font-weight: 600;
  touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.talk:active { background: var(--accent-press); }
.talk.rec { height: 64px; background: var(--rec); color: #FFFFFF; font-size: 17px; }
.talk.save { background: var(--rec); color: #FFFFFF; }
.sheet-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

.rec-row { display: flex; align-items: center; gap: 14px; min-height: 44px; }
.rec-dot { width: 12px; height: 12px; border-radius: 6px; background: var(--rec); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
.rec-time { font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 3.4ch; }
.bars { flex: 1; height: 40px; display: flex; align-items: center; gap: 3px; overflow: hidden; }
.bars i { width: 4px; height: 36px; flex: none; background: var(--accent); transform: scaleY(0.2); transform-origin: center; }
.bars i.off { background: var(--bar-off); }
.rec-hint { margin: 0; font-size: 15px; color: var(--muted); }
.rec-hint.warn { color: var(--rec); font-weight: 500; }

/* ---- the voice clip player ---- */
.play {
  height: 40px; display: inline-flex; align-items: center; gap: 8px; padding: 0 12px 0 10px; border: 1px solid var(--btn-line);
  border-radius: 20px; background: transparent; font-size: 14px; font-weight: 500; font-variant-numeric: tabular-nums;
}
.play svg { width: 16px; height: 16px; }
.play:disabled { opacity: 0.5; cursor: default; }

/* ---- the text size and theme popover ---- */
.pop {
  position: fixed; z-index: 30; top: calc(var(--hd) + env(safe-area-inset-top) - 4px); right: max(10px, env(safe-area-inset-right));
  width: min(300px, calc(100vw - 20px)); padding: 16px; background: var(--sheet); border: 1px solid var(--sheet-line);
  border-radius: 12px; box-shadow: var(--pop-shadow); display: flex; flex-direction: column; gap: 12px;
}
.pop-k { font-size: 14px; font-weight: 600; color: var(--muted); }
.size { display: flex; align-items: center; gap: 8px; }
.size-btn { width: 44px; height: 44px; border: 1px solid var(--btn-line); border-radius: 6px; background: transparent; font-family: var(--text); }
.size-btn.small-a { font-size: 15px; }
.size-btn.big-a { font-size: 23px; }
.size-steps { flex: 1; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
.size-steps i { height: 8px; background: var(--btn-line); }
.size-steps i.on { background: var(--ink); }
.seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border: 1px solid var(--btn-line); border-radius: 6px; overflow: hidden; }
.seg button { height: 44px; border: 0; background: transparent; font-size: 15px; font-weight: 500; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); font-weight: 600; }

/* ---- full-screen panels: contents and notes ---- */
.panel { position: fixed; inset: 0; z-index: 40; background: var(--bg); overflow-y: auto; overscroll-behavior: contain; }
.panel-hd {
  position: sticky; top: 0; z-index: 1; background: var(--bg); border-bottom: 1px solid var(--rule);
  display: flex; align-items: center; justify-content: space-between;
  height: calc(var(--hd) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) 0 max(20px, env(safe-area-inset-left));
}
.panel-hd h2 { margin: 0; font-size: 17px; font-weight: 600; }
.panel-body { max-width: 40rem; margin: 0 auto; padding: 8px max(16px, env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }

.toc { list-style: none; margin: 0; padding: 0; }
.toc .toc-part { margin: 22px 0 6px; padding: 0 4px; font-size: 13px; font-weight: 600; color: var(--accent); }
.toc button {
  width: 100%; min-height: 48px; display: flex; align-items: center; gap: 12px; padding: 8px 4px; border: 0; border-bottom: 1px solid var(--rule);
  background: transparent; text-align: left; font-size: 16px;
}
.toc .n { width: 2ch; flex: none; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.toc .t { flex: 1; min-width: 0; font-family: var(--text); }
.toc .c { flex: none; font-size: 13px; color: var(--muted); }
.toc button[aria-current="true"] .t { font-weight: 600; }
.toc button[aria-current="true"] .n { color: var(--accent); font-weight: 600; }
.about { margin-top: 28px; display: flex; flex-direction: column; align-items: flex-start; gap: 10px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.about p { margin: 0; }

.sendstate { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; font-size: 15px; color: var(--muted); }
.notelist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.note { padding: 16px 0; border-top: 1px solid var(--rule); display: flex; flex-direction: column; gap: 8px; }
.note-top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); }
.note-q {
  border: 0; background: transparent; padding: 0; text-align: left; font-family: var(--text); font-size: 17px; line-height: 1.55;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border: 1px solid var(--btn-line); border-radius: 6px; font-size: 13px; font-weight: 500; }
.chip .sw { width: 8px; height: 8px; background: var(--rc); }
.note-body { margin: 0; font-size: 15px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.note .play { align-self: flex-start; }
.empty { color: var(--muted); font-size: 15px; line-height: 1.5; padding: 24px 0; }

/* ---- toast ---- */
.toast {
  position: fixed; z-index: 50; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--sheet-h) + 16px + env(safe-area-inset-bottom));
  max-width: min(26rem, calc(100vw - 32px)); padding: 10px 14px; border-radius: 8px; background: var(--ink); color: var(--bg);
  font-size: 14px; line-height: 1.4; box-shadow: var(--pop-shadow);
}

/* ---- the opening animation (boot/boot.js): over everything, then gone ---- */
.boot { position: fixed; inset: 0; z-index: 100; width: 100%; height: 100%; display: block; transition: opacity 0.25s linear; }
.boot.gone { opacity: 0; }

@media (prefers-reduced-motion: reduce) {
  .sheet { transition: none; }
  .s.flash, .rec-dot { animation: none; }
}
