:root {
  --bg: #f7f4ee;
  --surface: #fffdf9;
  --text: #24211c;
  --muted: #6d665b;
  --line: #e2dccf;
  --accent: #2f5d50;
  --accent-text: #ffffff;
  --hl: #f3e2a9;
  --hl-text: #24211c;
  --hover: #ece6d8;
  --ok: #3f8a5a;
  --warn: #b7791f;
  --err: #b4483a;
  --serif: "Iowan Old Style", "Charter", "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17191a;
    --surface: #1f2223;
    --text: #e6e1d6;
    --muted: #9b958a;
    --line: #33383a;
    --accent: #7fb8a4;
    --accent-text: #10201b;
    --hl: #4a4128;
    --hl-text: #f6efd9;
    --hover: #2a2e2f;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #17191a;
  --surface: #1f2223;
  --text: #e6e1d6;
  --muted: #9b958a;
  --line: #33383a;
  --accent: #7fb8a4;
  --accent-text: #10201b;
  --hl: #4a4128;
  --hl-text: #f6efd9;
  --hover: #2a2e2f;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

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

/* Header */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner, .controls-inner, main {
  max-width: 46rem; margin: 0 auto; padding-left: 16px; padding-right: 16px;
}
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-top: 12px; padding-bottom: 12px; flex-wrap: wrap;
}
.brand { font-family: var(--serif); font-size: 1.25rem; font-weight: 600; margin: 0; letter-spacing: 0.01em; }
.engine { display: inline-flex; align-items: center; gap: 8px; font-size: 0.8125rem; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); flex: none; }
.dot.ok { background: var(--ok); }
.dot.err { background: var(--err); }

.loadbar { max-width: 46rem; margin: 0 auto; padding: 0 16px 12px; }
.loadbar-label { font-size: 0.8125rem; color: var(--muted); margin-bottom: 6px; font-variant-numeric: tabular-nums; }
.loadbar-track { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.loadbar-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.2s ease; }

/* Controls */
.controls {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.controls-inner { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding-top: 10px; padding-bottom: 10px; }
.voice { flex: 1 1 12rem; min-width: 0; }
select, .btn {
  font: inherit; font-size: 0.9375rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  height: 40px;
}
select { width: 100%; padding: 0 10px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 0 14px;
  cursor: pointer; white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; fill: currentColor; }
.btn:hover:not(:disabled) { background: var(--hover); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn:disabled, select:disabled { opacity: 0.5; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Views */
main { padding-top: 20px; padding-bottom: 48px; }
textarea {
  display: block; width: 100%; min-height: 65vh; resize: vertical;
  padding: 16px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text);
  font-family: var(--serif); font-size: 1.0625rem; line-height: 1.6;
}
.hint { color: var(--muted); font-size: 0.8125rem; margin: 10px 2px 0; }

.reader {
  font-family: var(--serif); font-size: 1.1875rem; line-height: 1.75;
  max-width: 38rem; margin: 0 auto; overflow-wrap: break-word;
}
.reader p { margin: 0 0 1.1em; }
.reader p.break { text-align: center; color: var(--muted); letter-spacing: 0.5em; }
.reader .s { cursor: pointer; border-radius: 3px; transition: background-color 0.15s ease; }
.reader .s:hover { background: var(--hover); }
.reader .s.on { background: var(--hl); color: var(--hl-text); box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.reader:empty::before { content: "Nothing to read yet. Go back and paste some text."; color: var(--muted); font-family: var(--sans); font-size: 1rem; }

.notice {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%);
  max-width: calc(100% - 32px); width: max-content;
  background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px;
  font-size: 0.875rem; box-shadow: 0 4px 16px rgb(0 0 0 / 0.2);
}

@media (max-width: 480px) {
  .reader { font-size: 1.0625rem; }
  .btn { padding: 0 11px; }
  .voice { flex-basis: 100%; }
}
