:root {
  color-scheme: dark;
  --bg: #111314;
  --panel: #181a1b;
  --panel-soft: #232526;
  --text: #ece7dc;
  --muted: #777c80;
  --faint: #34383c;
  --accent: #e6b35a;
  --accent-soft: rgba(230, 179, 90, 0.12);
  --bad: #e06c75;
  --good: #8fc986;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: min(1120px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 30px 0 44px;
}

.topbar,
.control-strip,
.metrics,
.trainer,
.history {
  width: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 38px;
  transition: opacity 180ms ease, visibility 180ms ease;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #15120a;
  font-weight: 900;
}

.mode-tabs,
.segmented,
.control-strip,
.metrics {
  display: flex;
  align-items: center;
}

.mode-tabs,
.segmented {
  gap: 4px;
  padding: 2px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.026);
}

.tab,
.chip,
.text-button,
.select-control select {
  min-height: 34px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  transition: background 140ms ease, color 140ms ease;
}

.tab {
  padding: 0 15px;
}

.chip {
  min-width: 44px;
  padding: 0 12px;
}

.tab:hover,
.chip:hover,
.text-button:hover,
.tab.is-active,
.chip.is-active {
  background: rgba(255, 255, 255, 0.052);
  color: var(--text);
}

.control-strip {
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 56px;
  transition: opacity 180ms ease, visibility 180ms ease;
}

.is-hidden {
  display: none !important;
}

.toggle {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  gap: 9px;
  padding: 0 12px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.026);
  color: var(--muted);
  user-select: none;
}

.select-control {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  gap: 8px;
  padding-left: 12px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.026);
  color: var(--muted);
}

.select-control span {
  font-size: 0.9rem;
}

.select-control select {
  min-width: 92px;
  padding: 0 28px 0 10px;
  border: 0;
  outline: 0;
  color: var(--text);
}

.select-control:hover,
.select-control:focus-within {
  background: rgba(255, 255, 255, 0.052);
}

.toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.toggle:has(input:checked) {
  color: var(--text);
  background: var(--accent-soft);
}

.option-group {
  gap: 0;
}

.option-group .toggle {
  background: transparent;
  min-height: 34px;
  padding: 0 11px;
}

.option-group .toggle:has(input:checked) {
  background: rgba(255, 255, 255, 0.052);
}

.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.icon-button:hover {
  background: rgba(255, 255, 255, 0.052);
  color: var(--text);
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 20px;
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  transition: opacity 180ms ease, visibility 180ms ease;
}

.metrics > div {
  min-height: 62px;
  padding: 0;
}

.metric-label,
.result-grid span,
.result-hero span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.metrics strong {
  font-size: clamp(1.55rem, 2.6vw, 2.1rem);
  line-height: 1;
}

.trainer {
  position: relative;
  min-height: 300px;
  padding: clamp(18px, 3vw, 30px) 0;
}

.text-viewport {
  max-height: 214px;
  overflow: hidden;
  cursor: text;
}

.word-stream {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 10px 16px;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: clamp(1.4rem, 3.1vw, 2.45rem);
  line-height: 1.55;
  letter-spacing: 0;
  transition: transform 180ms ease;
}

.word {
  position: relative;
  display: inline-flex;
}

.letter {
  white-space: pre;
  border-bottom: 2px solid transparent;
}

.letter.is-correct {
  color: var(--text);
}

.letter.is-wrong {
  color: var(--bad);
}

.letter.is-extra {
  color: #191112;
  background: var(--bad);
  border-radius: 3px;
}

.word.is-current .letter.is-current {
  color: var(--muted);
  border-color: var(--accent);
  animation: caret 1s steps(2, start) infinite;
}

.space-caret {
  position: absolute;
  left: calc(100% + 0.08em);
  bottom: 0.2em;
  width: 0.45em;
  border-bottom: 2px solid var(--accent);
  animation: caret 1s steps(2, start) infinite;
  pointer-events: none;
}

.word.is-current.is-mistyped::after {
  position: absolute;
  right: -7px;
  bottom: 0.2em;
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: var(--bad);
  content: "";
}

.typing-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.result-panel {
  display: grid;
  grid-template-columns: 0.85fr 2fr;
  gap: 28px;
  margin-top: 22px;
  padding-top: 22px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  transition: opacity 180ms ease;
}

.result-hero,
.result-grid > div {
  border: 0;
  border-radius: 0;
  background: transparent;
}

.result-hero {
  padding: 0;
}

.result-hero strong {
  color: var(--accent);
  font-size: clamp(3rem, 9vw, 6rem);
  line-height: 0.95;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px 30px;
}

.result-grid > div {
  padding: 0;
}

.result-grid strong {
  font-size: 1.5rem;
}

.history {
  margin-top: 40px;
  padding-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  transition: opacity 180ms ease, visibility 180ms ease;
}

.daily-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 26px;
}

.daily-summary span,
.history-grid h3 {
  display: block;
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.daily-summary strong {
  font-size: 1.55rem;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 30px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.section-heading h2 {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

.text-button {
  padding: 0 12px;
}

.day-list,
.history-list,
.typo-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px 24px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.day-list li,
.history-list li,
.typo-list li {
  min-height: 56px;
  padding: 0;
}

.day-list strong,
.history-list strong,
.typo-list strong {
  display: block;
  margin-bottom: 8px;
  font-size: 1.35rem;
}

.day-list span,
.history-list span,
.typo-list span {
  color: var(--muted);
  font-size: 0.86rem;
}

.is-typing-focus .topbar,
.is-typing-focus .control-strip,
.is-typing-focus .metrics,
.is-typing-focus .history {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

@keyframes caret {
  50% {
    border-color: transparent;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 20px, 1120px);
    padding-top: 16px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .mode-tabs,
  .control-strip .segmented {
    width: 100%;
  }

  .tab,
  .chip {
    flex: 1;
  }

  .metrics,
  .result-panel,
  .daily-summary,
  .history-grid,
  .day-list,
  .history-list,
  .typo-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .trainer {
    min-height: 300px;
    padding: 22px 0;
  }

  .text-viewport {
    max-height: 230px;
  }

  .word-stream {
    gap: 7px 11px;
  }
}

@media (max-width: 480px) {
  .metrics,
  .result-grid,
  .daily-summary,
  .history-grid,
  .day-list,
  .history-list,
  .typo-list {
    grid-template-columns: 1fr;
  }
}
