@import url("https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=Manrope:wght@400;500;600;700&family=Newsreader:opsz,wght@6..72,500;6..72,600&display=swap");

:root {
  --ink: #20211e;
  --muted: #6d6f67;
  --paper: #f5f3ea;
  --panel: #fbfaf5;
  --lavender: #dcd5ff;
  --mint: #cee9db;
  --active: #ff875d;
  --active-soft: #ffd8c8;
  --line: rgba(32, 33, 30, 0.17);
  --shadow: 0 18px 60px rgba(35, 38, 31, 0.12);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  min-width: 320px;
  color: var(--ink);
  background:
    radial-gradient(circle at 14% 4%, rgba(206, 233, 219, 0.9), transparent 31rem),
    radial-gradient(circle at 93% 17%, rgba(220, 213, 255, 0.78), transparent 32rem),
    var(--paper);
  font-family: "Manrope", ui-sans-serif, system-ui, sans-serif;
}
button, select, textarea { color: inherit; font: inherit; }
[hidden] { display: none !important; }
button, select, .file-chip { -webkit-tap-highlight-color: transparent; }
button, .file-chip { cursor: pointer; }
button:focus-visible, select:focus-visible, textarea:focus-visible, .file-chip:focus-within { outline: 3px solid rgba(121, 104, 216, 0.34); outline-offset: 3px; }
.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; }
.app-shell { min-height: 100vh; display: grid; grid-template-rows: auto 1fr auto; }

.topbar {
  min-height: 76px;
  padding: 15px clamp(18px, 3vw, 44px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(245, 243, 234, 0.72);
  backdrop-filter: blur(18px);
}
.brand { color: var(--ink); font: 600 clamp(1.45rem, 2.5vw, 2rem)/1 "DM Mono", monospace; letter-spacing: -0.09em; text-decoration: none; }
.brand span { color: var(--active); }
.topbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.text-button, .rate-button, .voice-control select, .chip { border: 1px solid var(--line); border-radius: 999px; background: rgba(251, 250, 245, 0.86); box-shadow: 0 5px 18px rgba(35, 38, 31, 0.05); }
.text-button, .rate-button, .chip { padding: 10px 15px; font-weight: 600; }
.text-button { border-color: transparent; background: transparent; box-shadow: none; }
.rate-button { min-width: 62px; }
.voice-control select { max-width: min(34vw, 260px); padding: 10px 34px 10px 15px; }

.reader-shell { width: min(1120px, calc(100% - 36px)); margin: clamp(28px, 5vh, 72px) auto 118px; }
.reader-card { min-height: min(680px, calc(100vh - 240px)); overflow: hidden; border: 1px solid var(--line); border-radius: 30px; background: rgba(251, 250, 245, 0.92); box-shadow: var(--shadow); }
.reader-heading { padding: clamp(24px, 4vw, 50px); display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 10px; color: var(--muted); font: 500 0.72rem/1.3 "DM Mono", monospace; letter-spacing: 0.1em; text-transform: uppercase; }
h1, h2 { margin: 0; font-family: "Newsreader", Georgia, serif; font-weight: 600; letter-spacing: -0.045em; }
h1 { max-width: 660px; font-size: clamp(3rem, 7vw, 6.5rem); line-height: 0.83; }
h2 { font-size: 2.25rem; }
.word-meter { display: grid; min-width: 90px; padding: 14px; text-align: right; border-radius: 18px; background: var(--mint); }
.word-meter strong { font: 500 clamp(1.35rem, 2.7vw, 2.2rem)/1 "DM Mono", monospace; }
.word-meter span { color: var(--muted); font-size: 0.75rem; }
.text-stage { position: relative; min-height: 330px; }
textarea, .read-along {
  width: 100%;
  min-height: clamp(330px, 43vh, 520px);
  padding: clamp(24px, 4vw, 50px);
  border: 0;
  background: transparent;
  color: var(--ink);
  font: 500 clamp(1.45rem, 2.55vw, 2.25rem)/1.62 "Newsreader", Georgia, serif;
  letter-spacing: -0.012em;
  white-space: pre-wrap;
}
textarea { display: block; resize: vertical; }
textarea:focus { outline: 0; background: rgba(255,255,255,0.38); }
textarea::placeholder { color: #a3a49d; }
.read-along { overflow: auto; }
.echo-word { border-radius: 0.19em; transition: color 90ms linear, background-color 90ms linear, box-shadow 90ms linear; }
.echo-word.is-spoken { color: #85877e; }
.echo-word.is-active { color: #171713; background: var(--active-soft); box-shadow: 0 0 0 0.13em var(--active-soft); text-decoration: underline; text-decoration-color: var(--active); text-decoration-thickness: 0.12em; text-underline-offset: 0.16em; }
.reader-actions { padding: 16px clamp(24px, 4vw, 50px) 24px; display: flex; flex-wrap: wrap; gap: 9px; border-top: 1px solid var(--line); }
.chip { display: inline-flex; align-items: center; font-size: 0.84rem; }
.chip:hover, .round-button:hover, .rate-button:hover { transform: translateY(-1px); }
.file-chip input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.transport {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  width: min(780px, calc(100% - 30px));
  min-height: 76px;
  padding: 12px 13px 12px 20px;
  display: grid;
  grid-template-columns: minmax(160px, auto) 1fr auto;
  align-items: center;
  gap: 18px;
  border: 1px solid rgba(32, 33, 30, 0.22);
  border-radius: 25px;
  background: rgba(32, 33, 30, 0.94);
  box-shadow: 0 20px 50px rgba(20, 21, 18, 0.25);
  color: #f8f7f0;
  backdrop-filter: blur(18px);
}
.transport-copy { min-width: 0; display: flex; align-items: center; gap: 9px; font-size: 0.76rem; }
.transport-copy span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 0 4px rgba(206, 233, 219, 0.13); }
.transport-progress { height: 4px; overflow: hidden; border-radius: 99px; background: rgba(255,255,255,0.15); }
.transport-progress span { display: block; width: 0%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--mint), var(--lavender)); transition: width 100ms linear; }
.transport-buttons { display: flex; gap: 8px; }
.round-button { width: 46px; height: 46px; display: inline-grid; place-items: center; padding: 0; border: 1px solid rgba(255,255,255,0.2); border-radius: 50%; background: rgba(255,255,255,0.09); color: #fff; transition: transform 140ms ease, background 140ms ease; }
.round-button svg { width: 21px; height: 21px; fill: currentColor; }
.play-button { background: var(--lavender); color: var(--ink); }
.icon-pause { display: none; }
body.is-speaking .icon-play { display: none; }
body.is-speaking .icon-pause { display: block; }

.draft-dialog { width: min(620px, calc(100% - 30px)); max-height: 80vh; padding: 0; border: 1px solid var(--line); border-radius: 27px; background: var(--panel); box-shadow: var(--shadow); }
.draft-dialog::backdrop { background: rgba(25, 26, 23, 0.45); backdrop-filter: blur(4px); }
.dialog-card { padding: 26px; }
.dialog-heading { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; }
.dialog-heading .round-button { color: var(--ink); border-color: var(--line); background: var(--paper); font-size: 1.45rem; }
.dialog-heading .small { width: 38px; height: 38px; }
.draft-list { display: grid; gap: 10px; max-height: 54vh; overflow: auto; }
.draft-item { width: 100%; padding: 16px; text-align: left; border: 1px solid var(--line); border-radius: 16px; background: #fff; }
.draft-item strong, .draft-item span { display: block; }
.draft-item span { margin-top: 5px; color: var(--muted); font-size: 0.78rem; }
.empty-drafts { color: var(--muted); }

@media (max-width: 700px) {
  .topbar { align-items: flex-start; }
  .topbar-actions { gap: 5px; }
  .text-button { display: none; }
  .voice-control select { max-width: 47vw; font-size: 0.78rem; }
  .rate-button { min-width: 54px; padding-inline: 10px; font-size: 0.78rem; }
  .reader-shell { width: min(100% - 20px, 1120px); margin-top: 12px; }
  .reader-card { border-radius: 22px; }
  .reader-heading { padding: 24px 20px; }
  h1 { font-size: clamp(2.8rem, 16vw, 4.7rem); }
  .word-meter { min-width: 72px; padding: 10px; }
  textarea, .read-along { padding: 28px 20px; font-size: 1.45rem; }
  .reader-actions { padding: 14px 20px 20px; }
  .transport { grid-template-columns: 1fr auto; gap: 9px; padding-left: 15px; }
  .transport-progress { grid-column: 1 / -1; grid-row: 2; }
  .transport-buttons { grid-column: 2; grid-row: 1; }
}

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