/* ── Design Tokens ──────────────────────────────────────────────── */
:root {
  --bg:           #0d0d0f;
  --bg-surface:   #16161a;
  --bg-border:    #2a2a35;
  --text-primary: #e8e6e3;
  --text-dim:     #6a6a7a;
  --text-context: #6a6a7a;
  --accent:       #6c63ff;
  --accent-hover: #8b84ff;
  --font:         'Inter', system-ui, sans-serif;
  --radius:       8px;
  --ease:         0.2s ease;
}

/* ── Links ──────────────────────────────────────────────────────── */
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }

/* ── Reset ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

/* ── Screen management ──────────────────────────────────────────── */
.screen {
  display: none;
  min-height: 100vh;
  width: 100%;
}
.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ── Setup Screen ───────────────────────────────────────────────── */
.setup-header {
  text-align: center;
  margin-bottom: 2.5rem;
}

.logo {
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -0.04em;
  color: var(--text-primary);
}

.tagline {
  margin-top: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}

.setup-main {
  width: 100%;
  max-width: 560px;
  padding: 0 1.5rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Textarea */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.input-group label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-dim);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

#text-input {
  width: 100%;
  min-height: 180px;
  resize: vertical;
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.9rem;
  line-height: 1.65;
  padding: 0.85rem 1rem;
  outline: none;
  transition: border-color var(--ease);
}

#text-input:focus {
  border-color: var(--accent);
}

#text-input::placeholder {
  color: var(--text-dim);
  opacity: 0.5;
}

/* Controls row */
.controls-row {
  display: flex;
  align-items: flex-end;
  gap: 2rem;
  flex-wrap: wrap;
}

/* WPM slider */
.wpm-control {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
  min-width: 180px;
}

.wpm-control label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-dim);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 1rem;
}

#wpm-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(
    to right,
    var(--accent) var(--fill-pct, 22%),
    var(--bg-border) var(--fill-pct, 22%)
  );
  outline: none;
  cursor: pointer;
}

#wpm-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-primary);
  cursor: pointer;
  transition: background var(--ease), transform var(--ease);
}

#wpm-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-primary);
  border: none;
  cursor: pointer;
}

#wpm-slider:hover::-webkit-slider-thumb,
#wpm-slider:focus::-webkit-slider-thumb {
  background: var(--accent-hover);
  transform: scale(1.15);
}

.wpm-value-row {
  display: flex;
  align-items: baseline;
  gap: 0.25rem;
  min-width: 4.5rem;
}

#wpm-display {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.unit {
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* Toggle */
.toggle-control {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toggle-control label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-dim);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.toggle-btn {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 0.85rem;
  transition: color var(--ease);
}

.toggle-btn[aria-checked="true"] {
  color: var(--text-primary);
}

.toggle-track {
  position: relative;
  width: 36px;
  height: 20px;
  border-radius: 10px;
  background: var(--bg-border);
  transition: background var(--ease);
  flex-shrink: 0;
}

.toggle-btn[aria-checked="true"] .toggle-track {
  background: var(--accent);
}

.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-primary);
  transition: transform var(--ease);
}

.toggle-btn[aria-checked="true"] .toggle-thumb {
  transform: translateX(16px);
}

/* Start button */
.primary-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  width: 100%;
  padding: 14px 32px;
  background: var(--accent);
  color: #fff;
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--ease), opacity var(--ease);
  letter-spacing: 0.01em;
}

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

.primary-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ── Reader Screen ───────────────────────────────────────────────── */
#reader-screen {
  position: relative;
  overflow: hidden;
}

/* Focal word — padding-bottom lifts the flex centre above the controls bar */
.word-display {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100vh;
  padding-bottom: 80px;
  position: relative;
  z-index: 2;
}

/* ORP grid: 1fr | ORP char | 1fr  →  ORP char sits at the horizontal center */
#focal-word {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: baseline;
  width: 100%;
  user-select: none;
  transition: opacity 0.06s ease;
}

.orp-before,
.orp-char,
.orp-after {
  font-size: clamp(3rem, 10vw, 7rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  white-space: nowrap;
  line-height: 1;
}

.orp-before {
  color: var(--text-primary);
  text-align: right;
}

/* ORP character: subtle accent color, small underline dot as marker */
.orp-char {
  color: var(--accent);
  position: relative;
}

.orp-after {
  color: var(--text-primary);
  text-align: left;
}

/* Pause context — sentence below the focal word, matching the lift offset */
.context-display {
  position: fixed;
  top: calc(50% - 40px);
  left: 0;
  right: 0;
  padding-top: clamp(3rem, 8vw, 5.5rem);
  display: flex;
  justify-content: center;
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.context-display.hidden  { display: none; }
.context-display.visible { opacity: 1; }

.context-sentence {
  max-width: min(640px, 86vw);
  margin: 0;
  font-size: clamp(0.78rem, 1.5vw, 0.96rem);
  font-weight: 400;
  line-height: 2;
  text-align: center;
  letter-spacing: 0.02em;
}

/* All sentence words: dim by default */
.ctx-word {
  color: var(--text-primary);
  opacity: 0.3;
}

/* Current word: fully visible, accent underline as the marker */
.ctx-current {
  opacity: 1;
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

/* First and last words of the sentence: fade further */
.ctx-fade {
  opacity: 0.1;
}

/* Progress bar */
.progress-track {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: var(--bg-border);
  z-index: 10;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.1s linear;
}

/* Controls bar */
.reader-controls {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 2rem;
  z-index: 10;
  padding: 14px 32px;
  border-radius: 40px;
  background: rgba(22, 22, 26, 0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--bg-border);
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  opacity: 0.4;
  padding: 4px;
  border-radius: 6px;
  transition: opacity var(--ease);
}

.icon-btn:hover {
  opacity: 1;
}

.pause-btn {
  opacity: 0.7;
}

.pause-btn:hover {
  opacity: 1;
}

.live-wpm {
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  min-width: 6rem;
  text-align: center;
  letter-spacing: 0.02em;
}

/* ── Reduced motion ─────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  #focal-word         { transition: none; }
  .context-display    { transition: none; }
  .toggle-thumb       { transition: none; }
  .toggle-track       { transition: none; }
}
