@font-face {
  font-family: "Inconsolata";
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: local("Inconsolata");
}

:root {
  font-family: "Inconsolata", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #212121;
  background: #fff;
  font-optical-sizing: auto;
  font-size: 16px;
  font-weight: 400;
  --page: #fff;
  --ink: #212121;
  --muted: #898989;
  --line: #dedede;
  --error: #df4242;
  --panel: #fff;
}

* { box-sizing: border-box; }
*[hidden] { display: none !important; }

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background: var(--page);
  color: var(--ink);
}

button { color: inherit; font: inherit; }

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: clamp(18px, 3.2vw, 42px) clamp(18px, 4vw, 64px) 20px;
  background: var(--page);
  color: var(--ink);
  transition: background-color 160ms ease, color 160ms ease;
}

.app-shell[data-theme="dark"] {
  color-scheme: dark;
  --page: #212121;
  --ink: #f5f5f5;
  --muted: #a4a4a4;
  --line: #555;
  --error: #ff6b6b;
  --panel: #212121;
}

.topbar, .topbar-left, .topbar-actions, .mode-switch, .theme-button, .practice-head, .practice-foot, .footer, .result-actions {
  display: flex;
  align-items: center;
}

.topbar { position: relative; justify-content: space-between; gap: 20px; }
.topbar-left { gap: clamp(18px, 3vw, 36px); }
.topbar-actions { gap: 16px; }
.mode-switch { gap: 5px; }

.mode-button, .theme-button, .settings-button, .text-button {
  border: 0;
  background: transparent;
  cursor: pointer;
}

.mode-button {
  padding: 8px 11px;
  color: var(--muted);
  font-size: .9rem;
  transition: color 140ms ease;
}

.mode-button:hover, .mode-button:focus-visible, .mode-button.is-active { color: var(--ink); }
.mode-button.is-active { text-decoration: underline; text-underline-offset: 5px; }

.theme-button, .settings-button { padding: 8px 0; color: var(--muted); font-size: .86rem; }
.settings-button:hover, .settings-button:focus-visible, .theme-button:hover, .theme-button:focus-visible { color: var(--ink); }

.settings-panel {
  position: absolute;
  z-index: 10;
  top: calc(100% + 8px);
  right: 0;
  display: grid;
  gap: 11px;
  width: min(230px, calc(100vw - 32px));
  padding: 14px;
  border: 1px solid var(--ink);
  background: var(--panel);
  color: var(--ink);
}
.settings-panel[hidden] { display: none; }
.settings-title { margin: 0 0 1px; color: var(--muted); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; }
.settings-panel label { display: flex; align-items: center; gap: 9px; font-size: .85rem; cursor: pointer; }
.settings-panel input { margin: 0; accent-color: var(--ink); }
.settings-panel .duration-setting { justify-content: space-between; }
.settings-panel select { border: 1px solid var(--line); padding: 4px 6px; background: var(--page); color: var(--ink); font: inherit; font-size: .8rem; }

.practice {
  width: min(680px, 100%);
  align-self: center;
  justify-self: center;
  position: relative;
  --typing-width: min(400px, 100%);
}

.practice-head, .practice-foot {
  width: var(--typing-width);
  margin-inline: auto;
  justify-content: space-between;
  color: var(--muted);
  font-size: .8rem;
}
.practice-head { min-height: 34px; padding: 0 2px 10px; }
.timer { color: var(--ink); font-size: .9rem; font-variant-numeric: tabular-nums; }
.practice-head .timer, .practice-head .chill-label { margin-left: auto; }
.chill-label { color: var(--muted); }

.typing-box {
  position: relative;
  display: flex;
  align-items: center;
  width: var(--typing-width);
  min-height: 160px;
  margin-inline: auto;
  padding: clamp(16px, 2.4vw, 24px);
  overflow: hidden;
  border: 1px solid var(--ink);
  background: var(--panel);
  cursor: text;
  outline: none;
  transition: border-color 140ms ease, background-color 160ms ease;
}

.typing-box:focus-visible { box-shadow: 0 0 0 2px var(--page), 0 0 0 3px var(--ink); }
.words { width: 100%; color: var(--muted); font-size: clamp(.9rem, 1.3vw, 1.05rem); line-height: 1.8; letter-spacing: .015em; overflow-wrap: anywhere; user-select: none; }
.word { white-space: nowrap; }
.letter.correct { color: var(--ink); }
.letter.incorrect { color: var(--error); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.letter.current { position: relative; }
.letter.current::before { content: ""; position: absolute; top: .18em; bottom: .1em; left: -.045em; width: 1px; background: var(--ink); animation: blink 1s steps(2, start) infinite; }
.app-shell[data-highlight-mistakes="false"] .letter.incorrect { color: var(--muted); text-decoration: none; }
.word.current-word { border-bottom: 1px solid var(--line); }
.practice-foot { padding: 12px 2px 0; gap: 16px; }
kbd { border: 1px solid var(--line); padding: 1px 5px; color: var(--ink); font: inherit; }
.keyboard-capture { position: fixed; width: 1px; height: 1px; left: -10px; bottom: -10px; opacity: 0; resize: none; }

.footer { justify-content: flex-end; min-height: 28px; color: var(--muted); font-size: .76rem; }
.coffee-link { color: var(--muted); font-size: .72rem; text-decoration: none; transition: color 140ms ease; }
.coffee-link:hover, .coffee-link:focus-visible { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }

.result-panel {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: var(--typing-width);
  min-height: 160px;
  padding: 16px;
  transform: translate(-50%, -50%);
  border: 1px solid var(--ink);
  background: var(--panel);
  text-align: center;
}
.result-panel[hidden] { display: none; }
.result-eyebrow { margin: 0 0 4px; color: var(--muted); font-size: .72rem; }
.stats { display: flex; justify-content: center; gap: clamp(22px, 7vw, 58px); margin: 18px 0; }
.stat { display: grid; gap: 4px; }
.stat strong { font-size: 1.1rem; font-weight: 500; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .72rem; }
.result-actions { justify-content: center; gap: 18px; }
.text-button { padding: 10px 4px; color: var(--muted); }
.text-button:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 4px; }

@keyframes blink { to { visibility: hidden; } }

@media (max-width: 560px) {
  .app-shell { padding: 16px 16px 14px; }
  .mode-button { padding: 8px 7px; font-size: .82rem; }
  .typing-box { min-height: 140px; padding: 16px; }
  .words { font-size: clamp(.82rem, 3.4vw, .92rem); line-height: 1.8; }
  .result-panel { min-height: 140px; padding: 14px; }
  .stats { gap: 20px; margin: 16px 0; }
  .stat strong { font-size: 1.15rem; }
}

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