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

:root {
  --bg: #09090b;
  --surface: #131316;
  --surface-raised: #1c1c21;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #f4f4f5;
  --text-muted: #71717a;
  --accent: #fafafa;
  --accent-fg: #09090b;
  --orp: #f87171;
  --guide: rgba(255, 255, 255, 0.06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
  --radius: 0.75rem;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

html {
  color-scheme: dark;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

body {
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

.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;
}

.view {
  min-height: 100dvh;
}

/* Setup */

.setup {
  max-width: 28rem;
  margin: 0 auto;
  padding: 3rem 1.5rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.setup-header {
  text-align: center;
}

.setup-header h1 {
  margin: 0;
  font-size: 2.25rem;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.tagline {
  margin: 0.5rem 0 0;
  color: var(--text-muted);
  font-size: 1rem;
}

.help-trigger {
  position: relative;
  display: inline-block;
  margin-top: 0.75rem;
}

.help-btn {
  padding: 0;
  border: none;
  background: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.8125rem;
  text-decoration: underline;
  text-decoration-color: var(--border-strong);
  text-underline-offset: 0.2em;
  cursor: pointer;
  transition: color 0.15s var(--ease);
}

.help-btn:hover,
.help-trigger.is-open .help-btn {
  color: var(--text);
}

.help-popover {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 50%;
  z-index: 20;
  width: max-content;
  max-width: min(16rem, calc(100vw - 2rem));
  padding: 0.875rem 1rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-raised);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  opacity: 0;
  visibility: hidden;
  transform: translateX(-50%) translateY(-4px);
  transition:
    opacity 0.15s var(--ease),
    transform 0.15s var(--ease),
    visibility 0.15s;
  pointer-events: none;
  text-align: left;
}

.help-popover ol {
  margin: 0;
  padding-left: 1.125rem;
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.help-popover li + li {
  margin-top: 0.375rem;
}

.help-trigger:hover .help-popover,
.help-trigger:focus-within .help-popover,
.help-trigger.is-open .help-popover {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

@media (hover: none) {
  .help-trigger:hover .help-popover {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }

  .help-trigger.is-open .help-popover {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
  }
}

.source-textarea {
  width: 100%;
  height: 7.5rem;
  max-height: 10rem;
  padding: 0.875rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.6;
  resize: vertical;
  transition: border-color 0.2s var(--ease);
}

.source-textarea::placeholder {
  color: var(--text-muted);
}

.source-textarea:focus {
  outline: none;
  border-color: var(--border-strong);
  background: var(--surface-raised);
}

.sample-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
}

.sample-label {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.sample-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}

.setup-actions {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding-top: 0.25rem;
}

.setup-footer {
  margin-top: 0.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.setup-footer p {
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.6;
  color: var(--text-muted);
}

.setup-footer strong {
  color: var(--text);
  font-weight: 500;
}

.field-label {
  display: block;
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.wpm-control {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.wpm-control input[type="range"],
.wpm-row--reading input[type="range"] {
  flex: 1;
  height: 4px;
  accent-color: var(--text-muted);
  cursor: pointer;
}

.wpm-control output,
.wpm-row--reading output {
  min-width: 2.5rem;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--text-muted);
  text-align: right;
}

.sound-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sound-hint {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

.toggle-label input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  margin: 0;
  accent-color: var(--text-muted);
  cursor: pointer;
}

.toggle-label--reading {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.sound-toggles-reading {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1rem;
}

.volume-row.is-disabled {
  opacity: 0.45;
  pointer-events: none;
}

.volume-row input[type="range"] {
  flex: 1;
  height: 4px;
  accent-color: var(--text-muted);
  cursor: pointer;
}

.btn {
  border: none;
  border-radius: var(--radius);
  padding: 0.75rem 1.25rem;
  font-size: 0.9375rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s var(--ease), background 0.15s var(--ease);
}

.btn:active {
  opacity: 0.85;
}

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

.btn-primary:hover {
  opacity: 0.92;
}

.btn-ghost {
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  border-color: var(--border-strong);
}

.btn-start {
  width: 100%;
  padding: 0.875rem;
  font-size: 1rem;
}

.sample-buttons .btn {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 400;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.sample-buttons .btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.125rem;
  font-family: inherit;
  cursor: pointer;
  transition: color 0.15s var(--ease), border-color 0.15s var(--ease);
}

.btn-icon:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

/* Reading */

#reading-view {
  display: flex;
  flex-direction: column;
  position: relative;
  height: 100dvh;
  overflow: hidden;
}

.reading-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  flex-shrink: 0;
}

.progress-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.progress-bar {
  flex: 1;
  height: 2px;
  background: var(--border);
  border-radius: 1px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--text-muted);
  border-radius: 1px;
  transition: width 0.1s linear;
}

.progress-label {
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
}

.focal-view {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 1rem;
  min-height: 0;
}

.focal-guide {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  background: var(--guide);
  transform: translateX(-50%);
  pointer-events: none;
}

.word-display {
  width: 100%;
  max-width: 32rem;
  font-size: clamp(2.25rem, 10vw, 3.75rem);
  font-weight: 450;
  letter-spacing: -0.01em;
  line-height: 1;
  position: relative;
  z-index: 1;
}

.word-line {
  display: flex;
  width: 100%;
  align-items: baseline;
}

.word-before {
  flex: 1 1 50%;
  min-width: 0;
  text-align: right;
  color: var(--text);
}

.word-orp {
  flex: 0 0 auto;
  color: var(--orp);
  font-weight: 600;
}

.word-after {
  flex: 1 1 50%;
  min-width: 0;
  text-align: left;
  color: var(--text);
}

.reading-footer {
  flex-shrink: 0;
  padding: 1rem 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

.controls-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.btn-play {
  min-width: 6.5rem;
  padding: 0.75rem 1.5rem;
  border-radius: 999px;
}

.wpm-row--reading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  max-width: 16rem;
}

/* Completion */

.completion-banner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  background: rgba(9, 9, 11, 0.88);
  backdrop-filter: blur(8px);
  text-align: center;
  padding: 2rem;
  z-index: 10;
}

.completion-banner p {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 500;
  letter-spacing: -0.02em;
}

.completion-actions {
  display: flex;
  gap: 0.625rem;
  flex-wrap: wrap;
  justify-content: center;
}

@media (max-width: 480px) {
  .setup {
    padding-top: 2rem;
  }

  .setup-header h1 {
    font-size: 1.875rem;
  }

  .reading-header {
    padding-inline: 0.75rem;
  }
}
