/* Read Aloud — warm paper reading room */

:root {
  --bg: #f3ead8;
  --bg-raised: #fffaf0;
  --ink: #1f1a14;
  --muted: #6b6358;
  --rule: #e0d4be;
  --accent: #8b3e2f;
  --accent-hover: #6f2f24;
  --accent-on: #fffaf0;
  --forest: #2c5e4a;
  --word-hl: #ffe07a;
  --sent-hl: #ffe39a;
  --shadow: 0 1px 2px rgba(40, 30, 10, 0.06), 0 10px 28px rgba(40, 30, 10, 0.08);
  --radius: 16px;
  --header-h: 4.25rem;
  --player-h: 4.5rem;
  --prose-size: 1.35rem;
  --font-ui: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  --font-prose: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #16130f;
  --bg-raised: #221e18;
  --ink: #f3ead8;
  --muted: #b5ab9a;
  --rule: #3c362c;
  --accent: #e8a089;
  --accent-hover: #f3b9a6;
  --accent-on: #1f1a14;
  --forest: #8fcebb;
  --word-hl: #d4a017;
  --sent-hl: #5c4514;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 28px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16130f;
    --bg-raised: #221e18;
    --ink: #f3ead8;
    --muted: #b5ab9a;
    --rule: #3c362c;
    --accent: #e8a089;
    --accent-hover: #f3b9a6;
    --accent-on: #1f1a14;
    --forest: #8fcebb;
    --word-hl: #d4a017;
    --sent-hl: #5c4514;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 28px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

img { max-width: 100%; }

button, input, select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

/* Author display rules must not override the hidden attribute. */
[hidden] {
  display: none !important;
}



:focus { outline: none; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: -3rem;
  z-index: 20;
  background: var(--bg-raised);
  color: var(--ink);
  padding: 0.5rem 0.8rem;
  border-radius: 8px;
}
.skip-link:focus {
  top: 0.75rem;
}


/* Sticky chrome: header + player stay together on desktop.
   On mobile, display:contents lets the player stick to the bottom. */
.chrome {
  position: sticky;
  top: 0;
  z-index: 8;
  background: var(--bg);
}

@media (max-width: 720px) {
  .chrome { display: contents; }
}

/* Header */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1.25rem;
  padding-top: max(0.7rem, env(safe-area-inset-top));
  border-bottom: 1px solid var(--rule);
  background: var(--bg);
}

.chrome .site-header {
  position: relative;
  z-index: 8;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}

.logo {
  display: block;
  border-radius: 7px;
  flex-shrink: 0;
}

.brand-text h1 {
  margin: 0;
  font-family: var(--font-prose);
  font-size: 1.28rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

.tagline {
  margin: 0.1rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  border: 0;
  border-radius: 999px;
  padding: 0.55rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1;
  min-height: 2.6rem;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-on);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.6rem;
  height: 2.6rem;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: var(--bg-raised);
  color: var(--ink);
  padding: 0;
}

.icon-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.play-btn {
  background: var(--forest);
  color: #fffaf0;
  border-color: transparent;
}

.play-btn:hover:not(:disabled) {
  color: #fffaf0;
  filter: brightness(1.08);
}

[data-theme="dark"] .play-btn,
:root:not([data-theme="light"]) .play-btn {
  color: #1f1a14;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .play-btn {
    color: #fffaf0;
  }
}

/* Theme icon swap */
.theme-icon { display: none; }
html:not([data-theme="dark"]) .theme-icon-dark { display: inline-flex; }
html[data-theme="dark"] .theme-icon-light { display: inline-flex; }

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .theme-icon-dark { display: none; }
  html:not([data-theme="light"]) .theme-icon-light { display: inline-flex; }
}

/* Player */

.player {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.85rem 1.25rem;
  padding: 0.7rem 1.25rem;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--rule);
  box-shadow: 0 4px 16px rgba(40, 30, 10, 0.04);
}

.player-transport {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}

.player-status {
  margin: 0 0 0 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
}

.control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.control-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  flex-shrink: 0;
}

.speed-control input[type="range"] {
  width: 8rem;
  accent-color: var(--accent);
}

.speed-value {
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
  min-width: 2.6rem;
}

.voice-control select {
  max-width: min(18rem, 46vw);
  border: 1px solid var(--rule);
  background: var(--bg);
  border-radius: 8px;
  padding: 0.35rem 0.5rem;
  min-height: 2.2rem;
}

.font-control {
  margin-left: auto;
}

.text-size-btn {
  border: 1px solid var(--rule);
  background: var(--bg);
  border-radius: 8px;
  min-width: 2.2rem;
  min-height: 2.2rem;
  padding: 0 0.4rem;
}

.text-size-btn:hover {
  border-color: var(--accent);
}

#font-down { font-size: 0.85rem; }
#font-up { font-size: 1.05rem; font-weight: 700; }

/* Main */

.main {
  flex: 1;
  width: 100%;
  max-width: 46rem;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 4rem;
}

/* Empty state */

.empty {
  display: flex;
  justify-content: center;
  padding: 2rem 0 3rem;
}

.empty-card {
  width: 100%;
  text-align: center;
  background: var(--bg-raised);
  border: 2px dashed var(--rule);
  border-radius: calc(var(--radius) + 4px);
  padding: 2.6rem 1.75rem;
  box-shadow: var(--shadow);
}

.empty-card.is-dragover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--bg-raised));
}

.empty-icon {
  color: var(--forest);
  margin-bottom: 0.6rem;
}

.empty h2 {
  font-family: var(--font-prose);
  font-size: 1.7rem;
  font-weight: 650;
  margin: 0 0 0.7rem;
}

.empty p {
  margin: 0 0 0.7rem;
  color: var(--ink);
  line-height: 1.55;
  font-size: 1.05rem;
}

.empty-note {
  color: var(--muted) !important;
  font-size: 0.95rem !important;
}

.empty-formats {
  color: var(--muted) !important;
  font-size: 0.88rem !important;
  margin-bottom: 0 !important;
}

.empty code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: var(--bg);
  padding: 0.1em 0.4em;
  border-radius: 4px;
}

/* Notice / errors */

.notice {
  background: var(--bg-raised);
  border: 1px solid var(--rule);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 1rem 1.1rem;
  margin: 0 0 1.25rem;
  line-height: 1.5;
}

.notice.is-error {
  border-left-color: #b33;
}

/* Document */

.doc-header {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--rule);
}

.doc-title {
  font-family: var(--font-prose);
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0 0 0.25rem;
  word-break: break-word;
}

.doc-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.prose {
  font-family: var(--font-prose);
  font-size: var(--prose-size);
  line-height: 1.75;
  letter-spacing: 0.01em;
}

.prose p {
  margin: 0 0 1.15em;
}

.sentence {
  border-radius: 0.2em;
  transition: background-color 0.15s ease;
}

.sentence.is-active {
  background: var(--sent-hl);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.word {
  cursor: pointer;
  border-radius: 0.12em;
  padding: 0;
}

.word:hover {
  background: color-mix(in srgb, var(--word-hl) 45%, transparent);
}

.word.is-current {
  background: var(--word-hl);
  box-shadow: 0 0 0 0.14em var(--word-hl);
  border-radius: 0.12em;
  color: #1a1408;
}

.page-break {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 2rem 0 1.25rem;
}

.page-break::before,
.page-break::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--rule);
}

/* Drag overlay */

.drag-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.drag-overlay p {
  background: var(--bg-raised);
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  padding: 2rem 2.4rem;
  font-family: var(--font-prose);
  font-size: 1.4rem;
  box-shadow: var(--shadow);
}

/* Loading state on empty card */
.is-loading .empty-icon {
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  50% { opacity: 0.45; }
}

@media (prefers-reduced-motion: reduce) {
  .sentence, .is-loading .empty-icon { transition: none; animation: none; }
}

/* Mobile */

@media (max-width: 720px) {
  .tagline { display: none; }
  .brand-text h1 { font-size: 1.12rem; }
  .site-header { padding: 0.6rem 0.9rem; padding-top: max(0.6rem, env(safe-area-inset-top)); }
  .btn { padding: 0.55rem 0.85rem; }

  .player {
    order: 3;
    border-bottom: 0;
    border-top: 1px solid var(--rule);
    padding: 0.65rem 0.9rem calc(0.75rem + env(safe-area-inset-bottom));
    box-shadow: 0 -6px 18px rgba(40, 30, 10, 0.06);
  }

  .font-control { margin-left: 0; }
  .voice-control { flex: 1 1 100%; }
  .voice-control select { max-width: none; flex: 1; }
  .speed-control { flex: 1; }
  .speed-control input[type="range"] { flex: 1; width: auto; }

  .player {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    z-index: 8;
  }

  .main {
    padding: 1.25rem 1rem 2rem;
  }

  body:has(#player:not([hidden])) .main {
    padding-bottom: 13.5rem;
  }

  .word, .sentence {
    scroll-margin-top: 5rem;
    scroll-margin-bottom: 13.5rem;
  }

  .prose {
    font-size: max(1.15rem, calc(var(--prose-size) - 0.1rem));
  }

  .empty { padding-top: 1rem; }
  .empty-card { padding: 1.8rem 1.15rem; }
  .empty h2 { font-size: 1.4rem; }
  .player-status { max-width: 9rem; overflow: hidden; text-overflow: ellipsis; }
}

