:root {
  color-scheme: dark;
  --bg: #0d0e10;
  --bg-soft: #131518;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-strong: rgba(255, 255, 255, 0.085);
  --line: rgba(239, 231, 214, 0.13);
  --text: #efe7d6;
  --text-soft: rgba(239, 231, 214, 0.68);
  --text-muted: rgba(239, 231, 214, 0.36);
  --correct: #d8d1ad;
  --correct-glow: rgba(216, 209, 173, 0.22);
  --wrong: #dc8e7d;
  --wrong-bg: rgba(220, 142, 125, 0.15);
  --mistake-mark: rgba(220, 142, 125, 0.72);
  --accent: #d7b47a;
  --shadow: 0 26px 70px rgba(0, 0, 0, 0.42);
  --radius: 8px;
  --mono: "SFMono-Regular", "Cascadia Mono", "Liberation Mono", Menlo, Consolas,
    monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia,
    "Noto Serif SC", serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 50% 42%, rgba(215, 180, 122, 0.08), transparent 34rem),
    linear-gradient(160deg, #111316 0%, var(--bg) 48%, #090a0c 100%);
  color: var(--text);
  font-family: var(--sans);
  overflow-x: hidden;
}

button,
textarea,
input {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  min-height: 100vh;
  position: relative;
  isolation: isolate;
}

.screen {
  display: none;
  min-height: 100vh;
  padding: clamp(24px, 5vw, 64px);
}

.screen.is-active {
  display: flex;
}

.setup-screen,
.result-screen {
  align-items: center;
  justify-content: center;
}

.setup-wrap {
  width: min(880px, 100%);
}

.setup-header {
  margin-bottom: 28px;
}

.quiet-label {
  margin: 0 0 10px;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.2;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(3rem, 9vw, 7.25rem);
  line-height: 0.9;
}

h2 {
  font-size: clamp(2.35rem, 6vw, 5rem);
  line-height: 1;
}

.intro {
  max-width: 36rem;
  margin: 22px 0 0;
  color: var(--text-soft);
  font-size: clamp(1rem, 1.7vw, 1.18rem);
  line-height: 1.7;
}

.text-label {
  display: block;
  margin-bottom: 10px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.source-text {
  display: block;
  width: 100%;
  min-height: clamp(240px, 42vh, 440px);
  resize: vertical;
  padding: clamp(18px, 3vw, 28px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  background: rgba(10, 11, 13, 0.58);
  box-shadow: var(--shadow);
  color: var(--text);
  font-family: var(--serif);
  font-size: clamp(1.06rem, 1.45vw, 1.35rem);
  line-height: 1.85;
}

.source-text:focus {
  border-color: rgba(215, 180, 122, 0.42);
  box-shadow:
    var(--shadow),
    0 0 0 1px rgba(215, 180, 122, 0.12);
}

.setup-actions,
.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 18px;
}

.button,
.text-button {
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease,
    color 160ms ease,
    opacity 160ms ease;
}

.button {
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.94rem;
}

.primary-button {
  border-color: rgba(215, 180, 122, 0.5);
  background: rgba(215, 180, 122, 0.13);
  color: #fff3d8;
}

.ghost-button {
  color: var(--text-soft);
}

.button:hover,
.text-button:hover {
  transform: translateY(-1px);
}

.button:active,
.text-button:active {
  transform: translateY(0);
}

.button:focus-visible,
.text-button:focus-visible,
.keyboard-capture:focus-visible {
  outline: 2px solid rgba(215, 180, 122, 0.62);
  outline-offset: 3px;
}

.typing-screen {
  flex-direction: column;
  padding: 0;
}

.typing-topbar {
  display: grid;
  grid-template-columns: minmax(92px, 1fr) auto minmax(92px, 1fr);
  align-items: center;
  gap: 18px;
  min-height: 78px;
  padding: 18px clamp(18px, 4vw, 48px);
  color: var(--text-muted);
}

.text-button {
  justify-self: start;
  padding: 8px 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.stats-bar {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: clamp(12px, 2.3vw, 28px);
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: clamp(0.72rem, 1.1vw, 0.86rem);
  line-height: 1.6;
}

.typing-stage {
  position: relative;
  display: grid;
  place-items: center;
  flex: 1;
  width: 100%;
  padding: clamp(26px, 6vw, 80px) clamp(20px, 3vw, 32px);
  overflow: hidden;
}

.typing-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background: radial-gradient(circle at 50% 48%, rgba(220, 142, 125, 0.13), transparent 34rem);
  opacity: 0;
  pointer-events: none;
}

.typing-stage.has-error::before {
  animation: errorWash 720ms ease both;
}

.typing-line {
  position: relative;
  z-index: 1;
  width: min(1240px, 100%);
  min-height: clamp(112px, 18vh, 210px);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  align-content: center;
  gap: 0.01em;
  color: var(--text-muted);
  font-family: var(--serif);
  font-size: 38px;
  line-height: 1.28;
  letter-spacing: 0;
  text-align: center;
  white-space: normal;
  transition:
    opacity 380ms cubic-bezier(0.4, 0, 0.2, 1),
    transform 380ms cubic-bezier(0.4, 0, 0.2, 1),
    filter 380ms cubic-bezier(0.4, 0, 0.2, 1);
}

.typing-line.line-exit {
  opacity: 0;
  transform: translateY(-16px);
  filter: blur(3px);
}

.typing-line.line-enter {
  opacity: 0;
  transform: translateY(16px);
  filter: blur(3px);
}

.typing-line.line-active {
  opacity: 1;
  transform: translateY(0);
  filter: blur(0);
}

.typing-line.error-shake {
  animation: errorShake 260ms ease;
}

.char {
  position: relative;
  display: inline-block;
  min-width: 0.28em;
  border-radius: 4px;
  color: var(--text-muted);
  white-space: pre;
  transition:
    color 120ms ease,
    background-color 120ms ease,
    text-shadow 120ms ease,
    transform 120ms ease;
}

.char.space {
  min-width: 0.42em;
}

.char.correct {
  color: var(--correct);
  text-shadow: 0 0 22px var(--correct-glow);
}

.char.wrong {
  color: var(--wrong);
  background: rgba(220, 142, 125, 0.2);
  text-shadow: 0 0 18px rgba(220, 142, 125, 0.24);
}

.char.marked-error::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -0.34em;
  width: 0.13em;
  height: 0.13em;
  min-width: 4px;
  min-height: 4px;
  border-radius: 999px;
  background: var(--mistake-mark);
  box-shadow: 0 0 10px rgba(220, 142, 125, 0.34);
  transform: translateX(-50%);
  opacity: 0.86;
  pointer-events: none;
}

.char.marked-error.current::before {
  background: rgba(231, 164, 140, 0.86);
  box-shadow: 0 0 12px rgba(231, 164, 140, 0.38);
}

.char.rewinding {
  color: rgba(239, 231, 214, 0.24);
  background: transparent;
  text-shadow: none;
  transform: translateY(-1px);
}

.char.current {
  color: var(--text);
  animation: currentBreath 1.25s ease-in-out infinite;
}

.char.current::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -0.16em;
  width: 70%;
  height: 2px;
  border-radius: 999px;
  background: var(--accent);
  transform: translateX(-50%);
  opacity: 1;
  box-shadow: 0 0 18px rgba(215, 180, 122, 0.42);
  animation: cursorBreathe 1.2s ease-in-out infinite;
}

.char.bump {
  animation: wrongBump 190ms ease;
}

.hint {
  position: absolute;
  z-index: 1;
  left: 50%;
  bottom: clamp(28px, 5vw, 58px);
  width: min(90vw, 34rem);
  margin: 0;
  transform: translateX(-50%);
  color: rgba(239, 231, 214, 0.24);
  font-size: 0.82rem;
  line-height: 1.5;
  text-align: center;
}

.line-transition-hint {
  position: absolute;
  z-index: 1;
  left: 50%;
  bottom: clamp(64px, 8vw, 100px);
  margin: 0;
  transform: translate(-50%, 6px);
  color: rgba(239, 231, 214, 0.22);
  font-family: var(--mono);
  font-size: 0.76rem;
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 220ms cubic-bezier(0.4, 0, 0.2, 1),
    transform 220ms cubic-bezier(0.4, 0, 0.2, 1);
}

.line-transition-hint.visible {
  opacity: 0.46;
  transform: translate(-50%, 0);
}

.mistake-toast {
  position: absolute;
  z-index: 1;
  left: 50%;
  bottom: clamp(88px, 10vw, 126px);
  margin: 0;
  transform: translate(-50%, 6px);
  color: rgba(220, 142, 125, 0.76);
  font-family: var(--mono);
  font-size: 0.76rem;
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.mistake-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.keyboard-capture {
  position: fixed;
  left: 50%;
  bottom: 14px;
  width: 1px;
  height: 1px;
  opacity: 0.01;
  pointer-events: none;
}

.result-panel {
  width: min(680px, 100%);
  padding: clamp(28px, 5vw, 52px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(10, 11, 13, 0.62);
  box-shadow: var(--shadow);
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  margin: 34px 0 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--line);
}

.result-grid div {
  min-width: 0;
  padding: 18px 14px;
  background: rgba(13, 14, 16, 0.94);
}

.result-grid dt {
  margin: 0 0 9px;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.result-grid dd {
  margin: 0;
  color: var(--text);
  font-family: var(--mono);
  font-size: clamp(1.05rem, 2vw, 1.35rem);
}

.mistake-summary {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: var(--text-muted);
}

.mistake-summary h3 {
  margin: 0 0 9px;
  color: var(--text-soft);
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 500;
}

.mistake-summary div {
  display: grid;
  gap: 7px;
  color: rgba(239, 231, 214, 0.42);
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.65;
}

.mistake-summary p {
  margin: 0;
}

@keyframes currentBreath {
  0%,
  100% {
    text-shadow: 0 0 0 rgba(215, 180, 122, 0);
  }
  50% {
    text-shadow: 0 0 24px rgba(215, 180, 122, 0.38);
  }
}

@keyframes cursorBreathe {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.28;
  }
}

@keyframes wrongBump {
  0%,
  100% {
    transform: translateX(0);
  }
  30% {
    transform: translateX(-0.08em);
  }
  65% {
    transform: translateX(0.08em);
  }
}

@keyframes errorShake {
  0%,
  100% {
    transform: translateX(0);
  }
  22% {
    transform: translateX(-5px);
  }
  45% {
    transform: translateX(4px);
  }
  68% {
    transform: translateX(-2px);
  }
}

@keyframes errorWash {
  0%,
  100% {
    opacity: 0;
  }
  28% {
    opacity: 1;
  }
}

@media (max-width: 760px) {
  .screen {
    padding: 22px;
  }

  .typing-topbar {
    grid-template-columns: 1fr;
    justify-items: center;
    min-height: auto;
    padding: 18px;
  }

  .text-button {
    justify-self: center;
  }

  .typing-stage {
    padding-inline: 18px;
  }

  .typing-line {
    font-size: 28px;
  }

  .line-transition-hint {
    bottom: 78px;
  }

  .mistake-toast {
    bottom: 104px;
  }

  .result-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .setup-actions,
  .result-actions {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (max-width: 420px) {
  .typing-line {
    font-size: 24px;
  }
}

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