:root {
  color-scheme: light dark;
  --bg: #111;
  --fg: #eee;
  --surface: #18181b;
  --border: #2c2c30;
  --secondary-bg: #333;
  --secondary-hover: #444;
  --muted: #888;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-soft: rgba(99, 102, 241, 0.18);
  --accent-fg: #fff;
  --focus-ring: rgba(99, 102, 241, 0.4);
  --shadow-card: 0 1px 0 rgba(255,255,255,0.03) inset, 0 20px 50px -20px rgba(0,0,0,0.5);
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #fafafa;
    --fg: #111;
    --surface: #ffffff;
    --border: #e5e7eb;
    --secondary-bg: #e5e5e5;
    --secondary-hover: #d4d4d4;
    --muted: #6b7280;
    --accent-soft: rgba(99, 102, 241, 0.12);
    --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.04), 0 12px 32px -12px rgba(15, 23, 42, 0.12);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111;
  --fg: #eee;
  --surface: #18181b;
  --border: #2c2c30;
  --secondary-bg: #333;
  --secondary-hover: #444;
  --muted: #888;
  --accent-soft: rgba(99, 102, 241, 0.18);
  --shadow-card: 0 1px 0 rgba(255,255,255,0.03) inset, 0 20px 50px -20px rgba(0,0,0,0.5);
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #fafafa;
  --fg: #111;
  --surface: #ffffff;
  --border: #e5e7eb;
  --secondary-bg: #e5e5e5;
  --secondary-hover: #d4d4d4;
  --muted: #6b7280;
  --accent-soft: rgba(99, 102, 241, 0.12);
  --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.04), 0 12px 32px -12px rgba(15, 23, 42, 0.12);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  background-image:
    radial-gradient(900px circle at 0% -10%, color-mix(in oklab, var(--accent) 14%, transparent), transparent 55%),
    radial-gradient(900px circle at 100% 110%, color-mix(in oklab, var(--accent) 8%, transparent), transparent 55%);
  background-attachment: fixed;
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.panel {
  max-width: 720px;
  margin: 0 auto;
  padding: 4rem 1.25rem 3rem;
}

/* ---------- setup view ---------- */
.hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 2rem;
}
.hero h1 {
  margin: 0;
  font-size: clamp(1.85rem, 4vw, 2.4rem);
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.1;
}
.hero-sub {
  margin: 0.4rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.icon-btn {
  flex-shrink: 0;
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: background 120ms, border-color 120ms, transform 120ms;
}
.icon-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.icon-btn:active { transform: scale(0.95); }
.icon-btn svg { display: block; }

.surface {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow-card);
  transition: border-color 140ms, box-shadow 140ms;
}
.surface:focus-within {
  border-color: var(--accent);
  box-shadow: var(--shadow-card), 0 0 0 4px var(--focus-ring);
}
textarea {
  width: 100%;
  min-height: 220px;
  padding: 0;
  background: transparent;
  color: var(--fg);
  border: none;
  outline: none;
  resize: vertical;
  font: inherit;
  font-size: 1rem;
  line-height: 1.55;
}
textarea::placeholder { color: var(--muted); }

.text-meta {
  margin-top: 0.85rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}
.text-meta .dot { opacity: 0.5; }

.wpm-row,
.mode-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1.75rem;
}
.mode-row { margin-top: 1.25rem; }
.wpm-label,
.mode-label {
  flex-basis: 100%;
  margin-bottom: 0.25rem;
  color: var(--muted);
  font-size: 0.85rem;
  letter-spacing: 0.01em;
}
.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.chip {
  padding: 0.4rem 0.85rem;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 999px;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  transition: background 120ms, border-color 120ms, color 120ms;
}
.chip:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
input[type="number"] {
  width: 5.5rem;
  padding: 0.4rem 0.6rem;
  margin-left: auto;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  transition: border-color 120ms, box-shadow 120ms;
}
input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.cta {
  width: 100%;
  margin-top: 1.75rem;
  padding: 0.95rem 1.25rem;
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  border-radius: 12px;
  font: inherit;
  font-weight: 500;
  font-size: 1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  letter-spacing: 0.005em;
  box-shadow: 0 8px 22px -10px color-mix(in oklab, var(--accent) 70%, transparent);
  transition: background 140ms, transform 80ms, box-shadow 140ms;
}
.cta:hover {
  background: var(--accent-hover);
  box-shadow: 0 10px 26px -8px color-mix(in oklab, var(--accent) 75%, transparent);
}
.cta:active { transform: translateY(1px); }
.cta .arrow { transition: transform 140ms; }
.cta:hover .arrow { transform: translateX(3px); }

/* ---------- reader view ---------- */
#reader {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  flex-direction: column;
  text-align: center;
}
#reader.active { display: flex; }

.reader-top {
  flex-shrink: 0;
  display: flex;
  justify-content: flex-end;
  padding: 1.25rem 1.5rem 0;
}

.reader-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
#word {
  font-size: clamp(2.5rem, 8vw, 6rem);
  font-weight: 500;
  min-height: 1.2em;
  letter-spacing: -0.01em;
}
#word.carousel {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: clamp(0.75rem, 2.5vw, 1.75rem);
  width: 100%;
}
#word.carousel .prev,
#word.carousel .next {
  font-size: 0.5em;
  font-weight: 400;
  color: var(--muted);
  opacity: 0.55;
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#word.carousel .prev { text-align: right; }
#word.carousel .next { text-align: left; }
#word.carousel .current {
  flex: 0 0 auto;
}
#progress {
  margin-top: 2rem;
  font-size: 0.9rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.reader-controls {
  flex-shrink: 0;
  padding: 1.25rem 1.5rem calc(1.25rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
}
