:root {
  color-scheme: light dark;
  --bg: #f4f6f8;
  --surface-shell: rgba(255, 255, 255, 0.62);
  --surface: #fbfcfd;
  --surface-strong: #eef2f6;
  --text: #14171a;
  --muted: #5e6874;
  --quiet: #798390;
  --accent: #245e73;
  --accent-strong: #174454;
  --ring: rgba(36, 94, 115, 0.24);
  --line: rgba(20, 23, 26, 0.08);
  --shadow: 0 34px 90px rgba(55, 72, 88, 0.16);
  --inner: inset 0 1px 1px rgba(255, 255, 255, 0.82);
  --radius-outer: 2rem;
  --radius-inner: 1.55rem;
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
}

@media (prefers-color-scheme: light) {
  select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M4 6l4 4 4-4' stroke='%23798390' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #07090b;
    --surface-shell: rgba(255, 255, 255, 0.07);
    --surface: #101418;
    --surface-strong: #171d22;
    --text: #f1f5f7;
    --muted: #aab5be;
    --quiet: #81909c;
    --accent: #7eb7c8;
    --accent-strong: #b5dfeb;
    --ring: rgba(126, 183, 200, 0.28);
    --line: rgba(255, 255, 255, 0.1);
    --shadow: 0 34px 90px rgba(0, 0, 0, 0.34);
    --inner: inset 0 1px 1px rgba(255, 255, 255, 0.08);
  }
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  height: 100%;
  min-height: 100dvh;
  margin: 0;
  background:
    radial-gradient(circle at 18% 10%, rgba(126, 183, 200, 0.22), transparent 34rem),
    linear-gradient(135deg, var(--bg), var(--surface-strong));
  color: var(--text);
  font-family: "Geist", "Plus Jakarta Sans", "Aptos", ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0;
  overflow: hidden;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  content: "";
  opacity: 0.025;
  background-image:
    linear-gradient(45deg, currentColor 25%, transparent 25%),
    linear-gradient(-45deg, currentColor 25%, transparent 25%);
  background-size: 5px 5px;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(20rem, 0.78fr) minmax(0, 1.22fr);
  gap: clamp(1.2rem, 3vw, 2.5rem);
  width: min(1400px, calc(100% - 2rem));
  height: 100dvh;
  min-height: 0;
  margin: 0 auto;
  padding: clamp(1rem, 4vw, 3.5rem) 0;
  align-items: stretch;
  overflow: hidden;
}

.control-shell,
.reader-shell {
  min-width: 0;
  min-height: 0;
  padding: 0.45rem;
  border-radius: var(--radius-outer);
  background: var(--surface-shell);
  box-shadow: var(--shadow);
  outline: 1px solid var(--line);
}

.control-core,
.reader-core {
  height: 100%;
  min-height: 0;
  border-radius: var(--radius-inner);
  background: var(--surface);
  box-shadow: var(--inner);
  outline: 1px solid var(--line);
}

.control-core {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: clamp(1rem, 2.2vw, 2rem);
  overflow: auto;
  overscroll-behavior: contain;
}

.reader-core {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.intro {
  display: grid;
  gap: 0.7rem;
}

.eyebrow {
  width: max-content;
  margin: 0;
  border-radius: 999px;
  padding: 0.45rem 0.72rem;
  background: color-mix(in srgb, var(--accent) 11%, transparent);
  color: var(--accent-strong);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  line-height: 1;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  max-width: 8ch;
  font-size: clamp(3rem, 7vw, 5.8rem);
  line-height: 0.92;
  letter-spacing: 0;
}

h2 {
  font-size: clamp(1.65rem, 3vw, 2.4rem);
  line-height: 1;
  letter-spacing: 0;
}

.lede,
.reader-header p,
.field p,
.drop-copy,
.status-line {
  color: var(--muted);
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.drop-zone {
  display: grid;
  gap: 0.38rem;
  min-height: 9.5rem;
  border-radius: 1.45rem;
  padding: 1.2rem;
  align-content: center;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 8%, transparent), transparent);
  outline: 1px solid var(--line);
  cursor: pointer;
  transition:
    transform 480ms var(--ease),
    outline-color 480ms var(--ease),
    background 480ms var(--ease);
}

.drop-zone:hover,
.drop-zone.is-dragging {
  transform: translateY(-2px);
  outline-color: var(--ring);
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 15%, transparent), transparent);
}

.drop-zone:active {
  transform: translateY(1px) scale(0.99);
}

.drop-zone input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
}

.drop-title {
  font-size: 1.15rem;
  font-weight: 800;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 0.55fr 0.55fr;
  gap: 0.7rem;
  margin: 0;
}

.stats div {
  min-width: 0;
  border-radius: 1.2rem;
  padding: 0.85rem;
  background: var(--surface-strong);
  box-shadow: var(--inner);
}

dt {
  color: var(--quiet);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

dd {
  overflow: hidden;
  margin: 0.3rem 0 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 750;
}

.field {
  display: grid;
  gap: 0.45rem;
}

.field label {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 760;
}

.field p {
  font-size: 0.84rem;
}

select,
input[type="range"],
input[type="url"],
input[type="text"] {
  min-width: 0;
  width: 100%;
}

select,
input[type="url"],
input[type="text"] {
  min-height: 3rem;
  border: 0;
  border-radius: 999px;
  padding: 0 1rem;
  background: var(--surface-strong);
  color: var(--text);
  outline: 1px solid var(--line);
  box-shadow: var(--inner);
}

select {
  appearance: none;
  padding-right: 2.75rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M4 6l4 4 4-4' stroke='%2381909c' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  cursor: pointer;
}

input[type="url"],
input[type="text"] {
  font-family: "Geist Mono", "SF Mono", "Cascadia Code", ui-monospace, monospace;
  font-size: 0.86rem;
}

input[type="range"] {
  accent-color: var(--accent);
}

select:focus-visible,
input[type="url"]:focus-visible,
input[type="text"]:focus-visible,
button:focus-visible,
.drop-zone:focus-within {
  outline: 3px solid var(--ring);
  outline-offset: 3px;
}

.range-grid,
.transport {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.local-settings {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
}

.local-settings[hidden] {
  display: none;
}

.transport {
  display: flex;
  gap: 0.85rem;
}

.transport button {
  flex: 1;
}

.transport button[hidden] {
  display: none;
}

button {
  min-height: 3.15rem;
  border: 0;
  border-radius: 999px;
  padding: 0 1.1rem;
  background: var(--surface-strong);
  color: var(--text);
  box-shadow: var(--inner);
  cursor: pointer;
  transition:
    transform 420ms var(--ease),
    background 420ms var(--ease),
    color 420ms var(--ease),
    opacity 420ms var(--ease);
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
}

button:active:not(:disabled) {
  transform: translateY(1px) scale(0.98);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.primary-action {
  background: var(--accent-strong);
  color: var(--bg);
}

/* Pause/Resume buttons share the primary style while active */
#pause,
#resume {
  background: var(--accent-strong);
  color: var(--bg);
}

.status-line {
  display: grid;
  gap: 0.65rem;
  margin-top: auto;
  font-size: 0.92rem;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.status-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--quiet);
  flex-shrink: 0;
  transition: background 300ms ease;
}

.status-dot.is-playing {
  background: var(--accent);
  animation: pulse-dot 1.6s ease-in-out infinite;
}

.status-dot.is-paused {
  background: var(--accent);
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

@media (prefers-reduced-motion: reduce) {
  .status-dot.is-playing {
    animation: none;
  }
}

progress {
  width: 100%;
  height: 0.55rem;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  background: var(--surface-strong);
}

progress::-webkit-progress-bar {
  background: var(--surface-strong);
}

progress::-webkit-progress-value,
progress::-moz-progress-bar {
  background: var(--accent);
}

.reader-header {
  display: flex;
  justify-content: space-between;
  gap: 2rem;
  padding: clamp(1rem, 2.2vw, 2rem);
  align-items: end;
}

.reader-header p {
  max-width: 28ch;
  font-size: 0.95rem;
}

.text-output {
  flex: 1;
  min-height: 0;
  margin: 0;
  border-top: 1px solid var(--line);
  padding: clamp(1rem, 2.2vw, 2rem);
  overflow: auto;
  overscroll-behavior: contain;
  color: var(--text);
  font-family: "Geist Mono", "SF Mono", "Cascadia Code", ui-monospace, monospace;
  font-size: clamp(0.95rem, 1.6vw, 1.08rem);
  line-height: 1.75;
  white-space: pre-wrap;
}

.speech-chunk {
  border-radius: 0.4rem;
  padding: 0.08rem 0.22rem;
  cursor: pointer;
  transition:
    background 220ms ease,
    box-shadow 220ms ease;
}

.speech-chunk:hover {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.speech-chunk.is-active {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  box-shadow:
    inset 0 0 0 1px color-mix(in srgb, var(--accent) 30%, transparent),
    0 2px 8px color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent-strong);
}

.sentence-focus {
  position: relative;
  display: inline;
  border-radius: 0.55rem;
  padding: 0.08rem 0.25rem;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--accent) 20%, transparent),
    0 12px 34px color-mix(in srgb, var(--accent) 16%, transparent);
}

.sentence-focus::after {
  position: absolute;
  right: -1.05rem;
  bottom: -0.55rem;
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 999px;
  background:
    radial-gradient(circle at 45% 42%, transparent 34%, var(--accent) 38%, var(--accent) 52%, transparent 56%),
    linear-gradient(45deg, transparent 58%, var(--accent) 60%, var(--accent) 72%, transparent 74%);
  content: "";
  filter: drop-shadow(0 8px 16px color-mix(in srgb, var(--accent) 26%, transparent));
  pointer-events: none;
  transform: translate3d(0, 0, 0);
}

.reveal {
  animation: enter 820ms var(--ease) both;
}

.reader-shell {
  animation-delay: 90ms;
}

@keyframes enter {
  from {
    opacity: 0;
    transform: translateY(22px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    width: min(100% - 1rem, 48rem);
    padding: 0.5rem 0 1rem;
  }

  h1 {
    max-width: 8ch;
    font-size: clamp(2.65rem, 15vw, 4rem);
    line-height: 0.96;
  }

  .reader-header {
    display: grid;
    align-items: start;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 0.7rem, 48rem);
  }

  .control-core,
  .reader-core {
    padding-inline: 0.95rem;
  }

  .stats,
  .range-grid,
  .transport {
    grid-template-columns: 1fr;
  }

  .control-shell,
  .reader-shell {
    border-radius: 1.55rem;
    padding: 0.35rem;
  }

  .control-core,
  .reader-core {
    border-radius: 1.25rem;
  }

  .control-core {
    gap: 1rem;
  }

  .drop-zone {
    min-height: 8rem;
    padding: 1rem;
  }
}
