:root {
  color-scheme: light;
  --background: #fff;
  --surface: #fff;
  --text: #111;
  --muted: #666;
  --line: #d6d6d6;
  --highlight: #ffe17d;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--background);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--background);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input {
  font: inherit;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  width: min(960px, calc(100% - 32px));
  margin: 0 auto;
  padding: 56px 0 72px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

h1,
p {
  margin-top: 0;
}

h1 {
  max-width: 700px;
  margin-bottom: 0;
  font-size: clamp(1.75rem, 5vw, 2.6rem);
  line-height: 1;
  letter-spacing: -0.045em;
  text-align: right;
}

.setup-toggle {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  background: #fff;
  font-weight: 700;
  cursor: pointer;
}

.setup-toggle:hover {
  background: #f1f1f1;
}

.setup-toggle:focus-visible {
  outline: 3px solid rgb(0 0 0 / 18%);
  outline-offset: 2px;
}

.setup-toggle-icon {
  width: 9px;
  height: 9px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translate(-1px, -1px);
  transition: transform 220ms ease;
}

.setup-toggle-icon.is-collapsed {
  transform: rotate(-45deg) translate(-1px, -1px);
}

#setup-controls {
  overflow: hidden;
  opacity: 1;
  transition: max-height 260ms ease, opacity 180ms ease;
}

#setup-controls.is-collapsed {
  opacity: 0;
}

.panel {
  margin-top: 18px;
  padding: clamp(20px, 4vw, 28px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.character-count {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.text-input {
  min-height: 96px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 4px;
  outline: none;
  background: #fff;
  font-family: inherit;
  font-size: clamp(1.05rem, 2.5vw, 1.2rem);
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.text-input:empty::before {
  color: #90968f;
  content: attr(data-placeholder);
  pointer-events: none;
}

.text-input:focus {
  border-color: var(--text);
  box-shadow: 0 0 0 2px rgb(0 0 0 / 8%);
}

.text-input[contenteditable="false"] {
  background: #f7f7f7;
  cursor: default;
}

.active-word {
  padding: 0.08em 0.12em;
  border-radius: 0.22em;
  background: var(--highlight);
  box-shadow: 0 0 0 2px var(--highlight);
}

.active-word.focus-word {
  background: #bfdbfe;
  box-shadow: 0 0 0 2px #bfdbfe;
}

.wpm-output {
  position: absolute;
  top: 0;
  left: clamp(18px, var(--slider-progress, 22.22%), calc(100% - 18px));
  min-width: 42px;
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 800;
  text-align: center;
  font-variant-numeric: tabular-nums;
  transform: translateX(-50%);
}

.slider-wrap {
  padding: 8px 2px 0;
}

.wpm-control {
  position: relative;
  padding-top: 28px;
}

input[type="range"] {
  width: 100%;
  height: 8px;
  margin: 0;
  border-radius: 999px;
  outline: none;
  appearance: none;
  background: linear-gradient(
    to right,
    var(--slider-color, #16a34a) 0%,
    var(--slider-color, #16a34a) var(--slider-progress, 22.22%),
    #deded4 var(--slider-progress, 22.22%),
    #deded4 100%
  );
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  width: 26px;
  height: 26px;
  border: 4px solid var(--surface);
  border-radius: 50%;
  appearance: none;
  background: var(--slider-color, #16a34a);
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: 4px solid var(--surface);
  border-radius: 50%;
  background: var(--slider-color, #16a34a);
}

input[type="range"]:focus-visible {
  box-shadow: 0 0 0 3px rgb(0 0 0 / 12%);
}

.pace-status {
  display: flex;
  align-items: baseline;
  margin-top: 10px;
}

.pace-label {
  color: var(--slider-color, #16a34a);
  font-weight: 700;
}

.chunk-controls {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.chunk-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  font-size: 0.9rem;
}

.chunk-heading label {
  font-weight: 700;
}

.chunk-heading output {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.chunk-slider {
  --slider-color: #111;
  --slider-progress: 0%;
}

.reader-panel {
  min-height: 350px;
}

.reader-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.word-display {
  display: grid;
  min-height: 155px;
  margin-bottom: 0;
  padding: 24px;
  place-items: center;
  border: 1px solid var(--text);
  border-radius: 4px;
  background: var(--text);
  color: #fff;
  text-align: center;
}

#display-word {
  max-width: 100%;
  font-size: var(--display-font-size, clamp(2.4rem, 10vw, 6.4rem));
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.055em;
  overflow-wrap: anywhere;
  transition: font-size 160ms ease;
}

.play-button {
  display: flex;
  width: 42px;
  height: 42px;
  min-height: 0;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--text);
  border-radius: 4px;
  color: var(--text);
  background: #fff;
  font-weight: 800;
  cursor: pointer;
  transition: background 160ms ease, transform 160ms ease;
}

.play-button:hover:not(:disabled) {
  background: #f1f1f1;
}

.play-button:active:not(:disabled) {
  transform: translateY(1px);
}

.play-button:focus-visible {
  outline: 3px solid rgb(0 0 0 / 18%);
  outline-offset: 3px;
}

.play-button:disabled {
  color: #7f8781;
  background: #d9dcd8;
  border-color: #d9dcd8;
  cursor: not-allowed;
}

#button-icon {
  font-size: 0.85em;
}

@media (max-width: 600px) {
  .app-shell {
    width: min(100% - 20px, 960px);
    padding: 32px 0 44px;
  }

  .panel {
    border-radius: 8px;
  }

  .text-input {
    min-height: 88px;
    padding: 16px;
  }

  .reader-panel {
    min-height: 310px;
  }

  .word-display {
    min-height: 130px;
  }
}

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