:root {
  color-scheme: dark;
  --bg: #303030;
  --bg-2: #282828;
  --panel: #3a3a3a;
  --panel-2: #424242;
  --text: #bdbdbd;
  --text-strong: #d4d4d4;
  --text-dim: #8d8d8d;
  --line-strong: rgba(210, 210, 210, 0.22);
  --green: #5d895f;
  --green-bright: #75a879;
  --olive: #868a38;
  --amber: #a98a38;
  --rose: #8d646f;
  --red: #a95656;
  --blue: #7997d3;
  --key-gap: 3px;
  --lesson-font-size: 44px;
  --font-ui: "Avenir Next", "Gill Sans", "Trebuchet MS", sans-serif;
  --font-mono: "SFMono-Regular", "Cascadia Code", "IBM Plex Mono", Menlo, monospace;
  --radius: 12px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family: var(--font-ui);
  background: var(--bg);
  overflow-x: hidden;
}

button,
select,
textarea,
input {
  font: inherit;
}

button,
a,
.typing-stage {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
  text-decoration: none;
}

body.drawer-open {
  overflow: hidden;
}

.focus-grid {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px);
  background-size: 100% 54px, 100% 100%;
  mask-image: linear-gradient(to bottom, transparent 0, black 9rem, black 86%, transparent 100%);
}

.site-header {
  position: fixed;
  inset: 1.25rem 1.5rem auto;
  z-index: 50;
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 1rem;
  align-items: center;
  pointer-events: none;
}

.brand,
.mode-switch,
.header-actions {
  pointer-events: auto;
}

.brand {
  display: inline-flex;
  gap: 0.65rem;
  align-items: center;
  opacity: 0.62;
  transition: opacity 160ms ease;
}

.brand:hover {
  opacity: 1;
}

.brand-mark {
  display: grid;
  width: 2.35rem;
  height: 2.35rem;
  place-items: center;
  color: #f0f0f0;
  font-family: var(--font-mono);
  font-weight: 900;
  letter-spacing: -0.08em;
  background: #151515;
  border: 1px solid var(--line);
  border-radius: 0.65rem;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  color: var(--text-strong);
  font-weight: 800;
  line-height: 1;
}

.brand small {
  margin-top: 0.15rem;
  color: var(--text-dim);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.mode-switch {
  display: flex;
  gap: 0.25rem;
  padding: 0.25rem;
  background: rgba(22, 22, 22, 0.62);
  border: 1px solid var(--line);
  border-radius: 999px;
  backdrop-filter: blur(16px);
}

.mode-tab {
  min-height: 2.15rem;
  padding: 0.45rem 0.85rem;
  color: var(--text-dim);
  font-weight: 900;
  background: transparent;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  transition: color 140ms ease, background-color 140ms ease;
}

.mode-tab:hover,
.mode-tab.is-active {
  color: var(--text-strong);
  background: rgba(255, 255, 255, 0.11);
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: flex-end;
}

.icon-button,
.ghost-button,
.solid-button,
.danger-button,
.close-button {
  border: 0;
}

.icon-button,
.ghost-button,
.solid-button,
.danger-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 2.2rem;
  padding: 0.48rem 0.72rem;
  color: var(--text-strong);
  font-weight: 900;
  background: rgba(22, 22, 22, 0.62);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(16px);
  transition: transform 120ms var(--ease-out), background-color 120ms ease, opacity 120ms ease;
}

.solid-button {
  color: #202020;
  background: var(--green-bright);
  border-color: transparent;
}

.danger-button {
  color: #f2f2f2;
  background: var(--red);
  border-color: transparent;
}

.ghost-button.small {
  min-height: 1.95rem;
  padding: 0.35rem 0.62rem;
  font-size: 0.78rem;
}

.icon-button:hover,
.ghost-button:hover,
.solid-button:hover,
.danger-button:hover {
  transform: translateY(-1px);
  background-color: rgba(255, 255, 255, 0.13);
}

.solid-button:hover {
  background-color: #8aba8d;
}

.danger-button:hover {
  background-color: #b85f5f;
}

.ghost-button:disabled,
.solid-button:disabled,
.danger-button:disabled {
  cursor: not-allowed;
  opacity: 0.44;
  transform: none;
}

.wide {
  width: 100%;
}

.practice-shell {
  display: grid;
  align-content: start;
  grid-template-rows: auto auto auto;
  width: min(1760px, calc(100vw - 5rem));
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(6.1rem, 10vh, 7.4rem) 0 1.7rem;
}

.status-board {
  display: grid;
  gap: 0.18rem;
  width: min(1240px, 78vw);
  margin: 0 auto;
  font-family: var(--font-mono);
  font-size: clamp(0.96rem, 1.05vw, 1.08rem);
  font-weight: 680;
}

.status-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.18rem 0.86rem;
  align-items: center;
  min-height: 1.52rem;
  line-height: 1.08;
}

.status-label {
  flex: 0 0 7.35rem;
  min-width: 0;
  color: var(--text-strong);
  font-family: var(--font-ui);
  font-weight: 850;
  text-align: right;
}

.status-row strong {
  color: var(--text-strong);
}

.status-row small {
  color: var(--text-dim);
  font-size: 0.82em;
}

.divider {
  width: 1px;
  height: 1.1em;
  background: var(--line-strong);
}

.keys-row {
  align-items: start;
}

.letter-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1px;
  flex: 0 1 auto;
  max-width: min(100%, 58rem);
}

.letter-token {
  display: grid;
  min-width: 1.52rem;
  height: 1.52rem;
  place-items: center;
  color: rgba(220, 220, 220, 0.38);
  font-family: var(--font-mono);
  font-size: 0.82em;
  font-weight: 850;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(0, 0, 0, 0.22);
}

.letter-token.is-open {
  color: rgba(235, 235, 235, 0.8);
  background: var(--green);
}

.letter-token.is-focus {
  position: relative;
  z-index: 1;
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

.progress-status {
  align-items: center;
  color: var(--text-dim);
}

.progress-status #lessonTitle {
  flex: 0 1 auto;
  width: max-content;
  min-width: 0;
  max-width: min(24rem, 34vw);
  overflow: hidden;
  color: var(--text-strong);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lesson-text-count {
  color: var(--text-strong);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 900;
  white-space: nowrap;
}

.lesson-progress {
  flex: 1 1 18rem;
  max-width: 42rem;
  height: 0.46rem;
  overflow: hidden;
  background: transparent;
  border: 1px solid var(--line-strong);
}

.lesson-progress span {
  display: block;
  width: var(--lesson-progress, 0%);
  height: 100%;
  background: rgba(117, 168, 121, 0.28);
  transition: width 150ms var(--ease-out);
}

.mode-panel[data-mode-panel="race"],
.race-panel[data-mode-panel="race"],
.game-panel[data-mode-panel="game"] {
  display: none;
}

.practice-shell[data-active-mode="race"] .keys-row,
.practice-shell[data-active-mode="race"] .solo-status,
.practice-shell[data-active-mode="race"] .progress-status {
  display: none;
}

.practice-shell[data-active-mode="race"] .race-panel[data-mode-panel="race"] {
  display: grid;
}

.practice-shell[data-active-mode="game"] .status-board,
.practice-shell[data-active-mode="game"] .typing-area {
  display: none;
}

.practice-shell[data-active-mode="game"] .game-panel[data-mode-panel="game"] {
  display: grid;
}

.practice-shell[data-active-mode="race"][data-race-joined="false"] .status-row,
.practice-shell[data-active-mode="race"][data-race-joined="false"] .race-headline,
.practice-shell[data-active-mode="race"][data-race-joined="false"] .typing-area,
.practice-shell[data-active-mode="race"][data-race-joined="false"] .keyboard-panel {
  display: none;
}

.practice-shell[data-active-mode="race"][data-race-joined="false"] .race-panel {
  padding-top: 0;
  border-top: 0;
}

.practice-shell[data-active-mode="race"][data-race-joined="false"] .race-form {
  margin: 0 auto;
}

.race-panel {
  gap: 0.42rem;
  padding: 0.42rem 0 0 0;
  border-top: 1px solid var(--line);
}

@media (min-width: 981px) {
  .letter-grid {
    flex-wrap: nowrap;
  }
}

.race-headline {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.6rem;
  align-items: center;
}

.race-headline > .status-label {
  width: auto;
  min-width: auto;
  flex: 0 0 auto;
}

.race-actions {
  display: inline-flex;
  flex-wrap: wrap;
  flex: 0 0 auto;
  gap: 0.45rem;
  align-items: center;
  margin-left: auto;
}

.race-actions button {
  white-space: nowrap;
}

.race-status {
  display: inline-flex;
  min-height: 1.9rem;
  padding: 0.28rem 0.55rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-weight: 800;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
}

.race-status.is-live {
  color: #d1e1d2;
  background: rgba(93, 137, 95, 0.42);
}

.race-status.is-warning {
  color: #e2b7b7;
  background: rgba(169, 86, 86, 0.22);
}

.race-current-user {
  display: inline-flex;
  min-height: 1.9rem;
  align-items: center;
  padding: 0.28rem 0.55rem;
  color: var(--text-strong);
  font-family: var(--font-mono);
  font-weight: 850;
  background: rgba(117, 168, 121, 0.13);
  border: 1px solid rgba(117, 168, 121, 0.24);
}

.race-text-picker {
  display: inline-flex;
  flex: 0 1 15rem;
  gap: 0.45rem;
  align-items: center;
  min-width: min(15rem, 100%);
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.race-text-picker select,
.race-text-trigger {
  width: 100%;
  min-height: 2.15rem;
  padding: 0.45rem 0.6rem;
  color: var(--text-strong);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: none;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
  border-radius: 0.35rem;
  outline: none;
}

.race-text-trigger {
  display: block;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.race-text-picker select:focus,
.race-text-trigger:focus {
  border-color: rgba(117, 168, 121, 0.58);
  box-shadow: 0 0 0 3px rgba(117, 168, 121, 0.12);
}

.race-text-picker select:disabled,
.race-text-trigger:disabled {
  color: var(--text-dim);
  cursor: not-allowed;
  opacity: 0.72;
}

.race-text-popover {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: transparent;
}

.race-text-popover-card {
  position: fixed;
  left: min(var(--popover-left, 50vw), calc(100vw - min(34rem, 92vw) - 1rem));
  top: min(var(--popover-top, 7rem), calc(100vh - 26rem));
  width: min(34rem, 92vw);
  max-height: min(24rem, calc(100vh - 2rem));
  overflow: hidden;
  background: rgba(46, 46, 46, 0.96);
  border: 1px solid var(--line-strong);
  border-radius: 0.9rem;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(18px);
}

.race-text-popover-head {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem;
  color: var(--text-strong);
  border-bottom: 1px solid var(--line);
}

.race-text-options {
  display: grid;
  gap: 0.25rem;
  max-height: min(19rem, calc(100vh - 7rem));
  padding: 0.55rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: rgba(189, 189, 189, 0.32) rgba(255, 255, 255, 0.05);
}

.race-text-option {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.55rem;
  align-items: center;
  min-height: 2.35rem;
  padding: 0.42rem 0.55rem;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 0.42rem;
  cursor: pointer;
}

.race-text-option:hover,
.race-text-option:has(input:checked) {
  color: var(--text-strong);
  background: rgba(117, 168, 121, 0.16);
  border-color: rgba(117, 168, 121, 0.3);
}

.race-text-option input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--green-bright);
}

.race-form {
  display: grid;
  grid-template-columns: minmax(8rem, 1fr) minmax(7rem, 0.8fr) auto;
  gap: 0.5rem;
  align-items: end;
  max-width: 36rem;
  margin-left: 8.55rem;
}

.race-form label,
.settings-form label,
.import-form label {
  display: grid;
  gap: 0.28rem;
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0.03em;
}

.race-form input,
.settings-form select,
.import-form input[type="file"],
.import-form textarea {
  width: 100%;
  min-height: 2.35rem;
  padding: 0.55rem 0.68rem;
  color: var(--text-strong);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
  border-radius: 0.35rem;
  outline: none;
}

.race-form input:focus,
.settings-form select:focus,
.import-form input[type="file"]:focus,
.import-form textarea:focus {
  border-color: rgba(117, 168, 121, 0.58);
  box-shadow: 0 0 0 3px rgba(117, 168, 121, 0.12);
}

.race-leaderboard-tools {
  display: flex;
  gap: 0.65rem;
  align-items: center;
  justify-content: space-between;
  max-width: 56rem;
  margin: 0.25rem 0 -0.05rem 8.55rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 850;
}

.race-leaderboard {
  display: grid;
  gap: 0.35rem;
  max-width: 56rem;
  max-height: calc(3 * 3.5rem + 2 * 0.35rem);
  margin: 0.25rem 0 0 8.55rem;
  padding: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: rgba(189, 189, 189, 0.32) rgba(255, 255, 255, 0.05);
  list-style: none;
}

.race-leaderboard.is-expanded {
  max-height: none;
  overflow: visible;
}

.race-player {
  display: grid;
  grid-template-columns: 2rem 1fr auto;
  gap: 0.65rem;
  align-items: center;
  min-height: 3.5rem;
  padding: 0.42rem 0.5rem;
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid rgba(255, 255, 255, 0.075);
}

.race-player > div {
  min-width: 0;
}

.race-rank {
  display: grid;
  width: 1.65rem;
  height: 1.65rem;
  place-items: center;
  color: var(--text-strong);
  background: rgba(0, 0, 0, 0.22);
}

.race-player strong,
.race-player small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.race-player em {
  margin-left: 0.45rem;
  color: var(--green-bright);
  font-size: 0.75em;
  font-style: normal;
  letter-spacing: 0.04em;
}

.race-player small {
  color: var(--text-dim);
}

.race-player.is-me {
  border-color: rgba(117, 168, 121, 0.48);
}

.race-progress {
  height: 0.36rem;
  margin-top: 0.28rem;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
}

.race-progress span {
  display: block;
  width: var(--race-progress, 0%);
  height: 100%;
  background: var(--green-bright);
  transition: width 150ms var(--ease-out);
}

.game-panel {
  gap: 1rem;
  width: min(1180px, 92vw);
  margin: 0 auto 8rem;
  font-family: var(--font-mono);
  --game-primary: #79e7ff;
  --game-secondary: #75a879;
  --game-danger: #e4a34f;
  --game-glow: rgba(121, 231, 255, 0.36);
}

.game-hud {
  display: grid;
  grid-template-columns: minmax(13rem, 1.35fr) repeat(4, minmax(5.5rem, 1fr)) auto;
  gap: 0.65rem;
  align-items: stretch;
}

.game-mode-card,
.game-stat,
.game-actions {
  min-height: 4.1rem;
  padding: 0.72rem 0.85rem;
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid var(--line);
  border-radius: 0.9rem;
}

.game-mode-card {
  display: grid;
  gap: 0.46rem;
}

.game-mode-card > span,
.game-stat span,
.game-message {
  color: var(--text-dim);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.game-mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
}

.game-mode-button {
  min-height: 2rem;
  color: var(--text-dim);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 950;
  letter-spacing: 0.04em;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  cursor: pointer;
  transition: transform 120ms var(--ease-out), border-color 120ms var(--ease-out), background 120ms var(--ease-out), color 120ms var(--ease-out);
}

.game-mode-button:hover {
  color: var(--text-strong);
  transform: translateY(-1px);
}

.game-mode-button.is-active {
  color: #07100f;
  background: linear-gradient(135deg, var(--game-primary), var(--game-secondary));
  border-color: rgba(255, 255, 255, 0.42);
  box-shadow: 0 0 24px var(--game-glow);
}

.game-mode-card small {
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 850;
}

.game-stat strong {
  display: block;
  margin-top: 0.18rem;
  color: var(--text-strong);
  font-size: clamp(1.35rem, 2.2vw, 2.2rem);
  line-height: 1;
}

.game-actions {
  display: inline-flex;
  gap: 0.55rem;
  align-items: center;
}

.game-arena {
  position: relative;
  height: min(60vh, 560px);
  min-height: 420px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 108%, rgba(121, 231, 255, 0.2), transparent 25%),
    radial-gradient(circle at 18% 18%, rgba(117, 168, 121, 0.2), transparent 30%),
    radial-gradient(circle at 82% 34%, rgba(228, 163, 79, 0.12), transparent 24%),
    linear-gradient(180deg, rgba(5, 12, 18, 0.92), rgba(10, 20, 28, 0.78) 48%, rgba(28, 34, 32, 0.82));
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 1.25rem;
  outline: none;
  box-shadow: inset 0 -70px 120px rgba(0, 0, 0, 0.32), 0 26px 80px rgba(0, 0, 0, 0.24);
}

.game-panel.is-kid {
  --game-primary: #8af2ff;
  --game-secondary: #ffd66d;
  --game-danger: #ff8fb5;
  --game-glow: rgba(255, 214, 109, 0.35);
}

.game-panel.is-kid .game-arena {
  background:
    radial-gradient(circle at 50% 106%, rgba(255, 214, 109, 0.28), transparent 25%),
    radial-gradient(circle at 20% 20%, rgba(138, 242, 255, 0.2), transparent 30%),
    radial-gradient(circle at 78% 28%, rgba(255, 143, 181, 0.18), transparent 25%),
    linear-gradient(180deg, rgba(8, 23, 37, 0.92), rgba(13, 36, 49, 0.78) 55%, rgba(36, 40, 34, 0.78));
}

.game-arena::after {
  position: absolute;
  right: 0;
  bottom: 5rem;
  left: 0;
  height: 1px;
  content: "";
  background: linear-gradient(90deg, transparent, rgba(121, 231, 255, 0.28), transparent);
  box-shadow: 0 0 22px var(--game-glow);
  opacity: 0.72;
}

.game-arena:focus {
  border-color: rgba(117, 168, 121, 0.48);
}

.game-stars {
  position: absolute;
  inset: 0;
  opacity: 0.38;
  background-image:
    radial-gradient(circle, rgba(255, 255, 255, 0.72) 0 1px, transparent 1.5px),
    radial-gradient(circle, var(--game-primary) 0 1px, transparent 1.5px);
  background-position: 0 0, 38px 24px;
  background-size: 72px 72px, 118px 118px;
  mask-image: linear-gradient(to bottom, black, transparent 92%);
  animation: game-star-drift 18s linear infinite;
}

.game-targets,
.game-effects {
  position: absolute;
  inset: 0;
}

.game-effects {
  pointer-events: none;
}

.game-word {
  position: absolute;
  left: var(--x);
  top: var(--y);
  display: inline-flex;
  gap: 0.42rem;
  align-items: center;
  padding: 0;
  color: #dfdfdf;
  font-size: clamp(1rem, 1.6vw, 1.45rem);
  font-weight: 900;
  letter-spacing: 0.04em;
  text-shadow: 0 0 18px var(--game-glow);
  transform: translate3d(0, 0, 0);
  animation: enemy-float 1.8s ease-in-out infinite;
}

.game-word::before {
  position: absolute;
  left: 1rem;
  bottom: -1.15rem;
  width: 1px;
  height: 1.35rem;
  content: "";
  background: linear-gradient(to bottom, var(--game-primary), transparent);
  filter: drop-shadow(0 0 8px var(--game-primary));
}

.enemy-icon {
  position: relative;
  width: 2.2rem;
  height: 1.36rem;
  background: linear-gradient(135deg, rgba(121, 231, 255, 0.94), rgba(117, 168, 121, 0.72));
  clip-path: polygon(50% 0, 94% 78%, 67% 68%, 50% 100%, 33% 68%, 6% 78%);
  filter: drop-shadow(0 0 12px var(--game-glow));
}

.enemy-icon::after {
  position: absolute;
  inset: 38% 34% auto;
  height: 0.18rem;
  content: "";
  background: rgba(255, 255, 255, 0.8);
  border-radius: 999px;
}

.game-word-text {
  min-width: 1.8rem;
  padding: 0.25rem 0.56rem 0.28rem;
  color: #e9f8ff;
  background: rgba(5, 10, 14, 0.66);
  border: 1px solid rgba(121, 231, 255, 0.28);
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04), 0 0 18px rgba(0, 0, 0, 0.22);
}

.game-word.is-letter .game-word-text {
  min-width: 2.35rem;
  text-align: center;
  text-transform: uppercase;
}

.game-word.is-active {
  color: #f4f4f4;
  animation-duration: 0.9s;
}

.game-word.is-aiming .enemy-icon,
.game-word.is-active .enemy-icon {
  background: linear-gradient(135deg, #fff4b5, var(--game-danger));
}

.game-word.is-aiming .game-word-text {
  border-color: rgba(255, 214, 109, 0.7);
  box-shadow: 0 0 0 3px rgba(255, 214, 109, 0.13), 0 0 26px rgba(255, 214, 109, 0.2);
}

.game-word.is-active .game-word-text {
  border-color: rgba(121, 231, 255, 0.82);
  box-shadow: 0 0 0 3px rgba(121, 231, 255, 0.14), 0 0 28px var(--game-glow);
}

.typed-part {
  color: var(--game-secondary);
}

.game-ship {
  position: absolute;
  left: 50%;
  bottom: 1.55rem;
  z-index: 2;
  width: 6rem;
  height: 4.9rem;
  filter: drop-shadow(0 0 26px var(--game-glow));
  transform: translateX(-50%) rotate(var(--game-aim-angle, 0deg));
  transform-origin: 50% 82%;
  transition: transform 120ms var(--ease-out), filter 160ms ease;
}

.game-ship::before {
  position: absolute;
  top: 0.08rem;
  left: 50%;
  width: 0.9rem;
  height: 3.42rem;
  content: "";
  background: linear-gradient(180deg, #f4fdff 0%, var(--game-primary) 46%, #53736f 100%);
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 0.5rem 0.5rem 0.26rem 0.26rem;
  box-shadow: inset 0 0.35rem 0 rgba(255, 255, 255, 0.24), 0 0 22px var(--game-glow);
  transform: translateX(-50%);
}

.game-ship::after {
  position: absolute;
  bottom: 0.2rem;
  left: 50%;
  width: 4.65rem;
  height: 1.55rem;
  content: "";
  background:
    radial-gradient(circle at 24% 78%, #263330 0 0.42rem, var(--game-primary) 0.46rem 0.58rem, transparent 0.62rem),
    radial-gradient(circle at 76% 78%, #263330 0 0.42rem, var(--game-primary) 0.46rem 0.58rem, transparent 0.62rem),
    linear-gradient(135deg, var(--game-secondary), var(--game-danger));
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 1rem 1rem 0.7rem 0.7rem;
  box-shadow: inset 0 0.38rem 0 rgba(255, 255, 255, 0.17), 0 0 20px var(--game-glow);
  transform: translateX(-50%);
}

.game-ship.is-aiming {
  filter: drop-shadow(0 0 34px var(--game-glow));
}

.game-typed {
  position: absolute;
  left: 50%;
  bottom: 6.35rem;
  z-index: 2;
  min-width: 14rem;
  padding: 0.35rem 0.72rem;
  color: var(--text-strong);
  font-weight: 900;
  text-align: center;
  background: rgba(0, 0, 0, 0.42);
  border: 1px solid var(--line);
  border-radius: 999px;
  transform: translateX(-50%);
}

.aim-hint {
  color: var(--text-dim);
}

.game-message {
  position: absolute;
  top: 1rem;
  left: 1rem;
  right: 1rem;
  z-index: 2;
  text-align: center;
}

.game-shot {
  position: absolute;
  left: 0;
  top: 0;
  width: 1.7rem;
  height: 0.52rem;
  background:
    radial-gradient(circle at 86% 50%, #fff 0 0.16rem, var(--game-secondary) 0.18rem 0.28rem, transparent 0.31rem),
    linear-gradient(90deg, rgba(121, 231, 255, 0), var(--game-primary) 24%, #fff 72%, var(--game-danger));
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 999px 70% 70% 999px;
  box-shadow: 0 0 10px #fff, 0 0 24px var(--game-primary), 0 0 46px var(--game-primary);
  transform-origin: 50% 50%;
  animation: shot-flight 260ms linear forwards;
}

.game-burst {
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  width: 3rem;
  height: 3rem;
  place-items: center;
  color: rgba(255, 255, 255, 0.86);
  font-size: 0.78rem;
  font-weight: 950;
  text-transform: uppercase;
  border: 1px solid var(--game-secondary);
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(121, 231, 255, 0.42), inset 0 0 18px var(--game-glow);
  animation: burst-pop 700ms ease-out forwards;
}

@keyframes game-star-drift {
  to {
    background-position: 0 72px, 38px 142px;
  }
}

@keyframes enemy-float {
  50% {
    transform: translate3d(0, 5px, 0);
  }
}

@keyframes engine-pulse {
  from {
    opacity: 0.45;
    transform: scaleY(0.7);
  }

  to {
    opacity: 0.95;
    transform: scaleY(1.12);
  }
}

@keyframes shot-flight {
  from {
    opacity: 0.25;
    transform: translate3d(var(--sx), var(--sy), 0) rotate(var(--shot-angle, 0deg)) scale(0.7);
  }

  80% {
    opacity: 1;
  }

  to {
    opacity: 0;
    transform: translate3d(var(--tx), var(--ty), 0) rotate(var(--shot-angle, 0deg)) scale(1.45);
  }
}

@keyframes burst-pop {
  from {
    opacity: 0.95;
    transform: translate3d(calc(var(--bx) - 1.5rem), calc(var(--by) - 1.5rem), 0) scale(0.45);
  }

  to {
    opacity: 0;
    transform: translate3d(calc(var(--bx) - 1.5rem), calc(var(--by) - 1.5rem), 0) scale(1.8);
    box-shadow: 0 0 0 2.4rem rgba(121, 231, 255, 0), inset 0 0 28px transparent;
  }
}

.typing-area {
  position: relative;
  display: grid;
  align-content: center;
  gap: 0.62rem;
  margin: clamp(0.75rem, 2vh, 1.35rem) 0 clamp(1.2rem, 2.3vh, 1.8rem);
  transition: box-shadow 140ms ease, background-color 140ms ease, border-color 140ms ease;
}

.typing-area[hidden] {
  display: none;
}

.typing-area.is-floating {
  position: fixed;
  z-index: 62;
  max-width: calc(100vw - 1.5rem);
  max-height: calc(100vh - 1.5rem);
  margin: 0;
  padding: 1.25rem 1rem 1rem;
  overflow: auto;
  overscroll-behavior: contain;
  background: rgba(31, 31, 31, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 1.15rem;
  box-shadow: 0 22px 80px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(16px);
}

.typing-area.is-dragging {
  cursor: grabbing;
  user-select: none;
  box-shadow: 0 28px 96px rgba(0, 0, 0, 0.34);
}

.typing-area.has-translate {
  align-content: start;
}

.typing-area-drag-handle {
  position: absolute;
  top: 0.35rem;
  right: 0.45rem;
  z-index: 2;
  display: grid;
  width: 2rem;
  height: 2rem;
  padding: 0;
  place-items: center;
  color: rgba(232, 232, 232, 0.78);
  background: rgba(255, 255, 255, 0.055);
  border: 0;
  border-radius: 0.7rem;
  opacity: 0.66;
  cursor: grab;
  transition: opacity 120ms ease, color 120ms ease, background-color 120ms ease, transform 120ms var(--ease-out);
}

.typing-area-drag-handle:hover,
.typing-area-drag-handle:focus-visible {
  opacity: 0.9;
  color: var(--text-strong);
  background-color: rgba(255, 255, 255, 0.09);
  outline: none;
  transform: translateY(-1px);
}

.typing-area.is-dragging .typing-area-drag-handle {
  cursor: grabbing;
  opacity: 1;
}

.drag-move-icon {
  width: 1.12rem;
  height: 1.12rem;
  overflow: visible;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.typing-stage {
  position: relative;
  width: min(92vw, 1760px);
  min-height: 8.6rem;
  margin: 0 auto;
  padding: 0 0.5rem;
  cursor: text;
  outline: none;
}

.typing-area.is-floating .typing-stage {
  width: min(100%, 1760px);
}

.lesson-translate {
  width: min(92vw, 1320px);
  margin: 0 auto;
  padding: 0.85rem 2rem;
  color: rgba(232, 232, 232, 0.84);
  font-family: var(--font-ui);
  font-size: clamp(1rem, 1.45vw, 1.35rem);
  font-weight: 760;
  line-height: 1.45;
  text-align: center;
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid var(--line);
  border-radius: 1rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.035), 0 18px 60px rgba(0, 0, 0, 0.18);
  cursor: grab;
  touch-action: none;
}

.lesson-translate[hidden] {
  display: none;
}

.typing-area.is-floating .lesson-translate {
  width: min(100%, 1320px);
}

.typing-area.is-dragging .lesson-translate {
  cursor: grabbing;
}

.typing-stage:focus-within .lesson-copy,
.typing-stage.is-focused .lesson-copy {
  color: var(--text-strong);
}

.lesson-copy {
  font-family: var(--font-mono);
  font-size: clamp(1.55rem, var(--lesson-font-size), 4.25rem);
  font-weight: 760;
  line-height: 1.36;
  letter-spacing: -0.025em;
  color: #a8a8a8;
  text-wrap: pretty;
  word-break: break-word;
  user-select: none;
}

.char {
  position: relative;
  display: inline-block;
  min-width: 0.34ch;
  color: rgba(205, 205, 205, 0.52);
  border-radius: 0.12em;
  transition: color 70ms ease, background-color 70ms ease, transform 70ms ease;
}

.char.is-space {
  min-width: 0.72ch;
  color: rgba(205, 205, 205, 0.34);
  text-align: center;
}

.char.is-space::before {
  content: none;
}

.char.is-correct {
  color: #dadada;
}

.char.is-error {
  color: #f1dede;
  background: rgba(169, 86, 86, 0.72);
  animation: errorKick 140ms var(--ease-out);
}

.char.is-current {
  color: #f1f1f1;
  background: rgba(169, 138, 56, 0.34);
}

.char.is-current::after {
  position: absolute;
  inset: auto 0 -0.08em;
  height: 0.1em;
  content: "";
  background: var(--amber);
  border-radius: 999px;
  animation: cursorPulse 950ms ease-in-out infinite;
}

#typingInput {
  position: absolute;
  inset: 0 auto auto 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.keyboard-panel {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  z-index: 64;
  width: min(980px, calc(100vw - 2rem));
  margin: 0;
  padding: 1rem;
  background: rgba(64, 64, 64, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 1rem;
  box-shadow: 0 18px 70px rgba(0, 0, 0, 0.22);
  transform: translateX(-50%);
  backdrop-filter: blur(16px);
  touch-action: none;
  transition: opacity 140ms ease, box-shadow 140ms ease;
}

.keyboard-panel.is-dragging {
  cursor: grabbing;
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.34);
  user-select: none;
}

.keyboard-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 2rem;
  margin-bottom: 0.7rem;
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: grab;
}

.keyboard-drag-handle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 1.95rem;
}

.keyboard-drag-handle .drag-move-icon {
  width: 1rem;
  height: 1rem;
  color: rgba(232, 232, 232, 0.7);
  transition: color 120ms ease, transform 120ms var(--ease-out);
}

.keyboard-toolbar:hover .keyboard-drag-handle .drag-move-icon {
  color: var(--text-strong);
  transform: translateY(-1px);
}

.keyboard-actions {
  display: inline-flex;
  gap: 0.45rem;
  align-items: center;
}

.keyboard-actions button {
  cursor: pointer;
}

.keyboard-show-button {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 64;
  min-height: 2.35rem;
  padding: 0.55rem 0.82rem;
  color: var(--text-strong);
  font-weight: 900;
  background: rgba(22, 22, 22, 0.72);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.28);
  cursor: pointer;
  backdrop-filter: blur(16px);
  transition: transform 120ms var(--ease-out), background-color 120ms ease;
}

.keyboard-show-button:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.13);
}

.keyboard {
  display: grid;
  gap: var(--key-gap);
  transition: opacity 150ms ease, max-height 180ms ease;
}

.keyboard.is-hidden {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
}

.keyboard-row {
  display: flex;
  gap: var(--key-gap);
}

.key {
  position: relative;
  display: grid;
  flex: 1 1 0;
  min-width: 0;
  min-height: clamp(2.55rem, 3.8vw, 3.45rem);
  place-items: center;
  color: rgba(230, 230, 230, 0.64);
  font-family: var(--font-mono);
  font-size: clamp(0.98rem, 1.45vw, 1.35rem);
  font-weight: 760;
  line-height: 1.05;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(0, 0, 0, 0.04)),
    var(--key-color, var(--green));
  border: 1px solid rgba(0, 0, 0, 0.33);
  border-radius: 0;
  cursor: pointer;
  transition: transform 80ms ease, outline-color 100ms ease, filter 100ms ease;
}

.key.is-next {
  z-index: 1;
  outline: 0.36rem solid rgba(121, 151, 211, 0.82);
  outline-offset: -0.18rem;
  filter: brightness(1.16);
}

.key.is-pressed {
  transform: translateY(2px) scale(0.992);
  filter: brightness(1.22);
}

.key.is-locked {
  opacity: 0.48;
}

.key.space {
  flex: 6 1 0;
  background: var(--red);
}

.key.tab,
.key.ctrl {
  flex: 1.5 1 0;
}

.key.caps,
.key.enter,
.key.backspace {
  flex: 2 1 0;
}

.key.shift {
  flex: 2.25 1 0;
}

.keyboard-row:last-child .key:not(.space) {
  background: var(--green);
}

.settings-scrim {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(8px);
}

.race-start-overlay {
  position: fixed;
  inset: 0;
  z-index: 65;
  display: grid;
  place-items: center;
  pointer-events: none;
  color: var(--text-strong);
  background: rgba(12, 12, 12, 0.72);
  backdrop-filter: blur(12px);
}

.race-start-overlay[hidden],
.settings-scrim[hidden] {
  display: none !important;
}

.race-start-card {
  display: grid;
  gap: 0.5rem;
  place-items: center;
  width: min(34rem, calc(100vw - 2rem));
  padding: clamp(2rem, 5vw, 3.5rem);
  text-align: center;
  background: rgba(48, 48, 48, 0.92);
  border: 1px solid var(--line-strong);
  border-radius: 1.2rem;
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.38);
}

.race-start-card strong {
  color: var(--amber);
  font-family: var(--font-mono);
  font-size: clamp(6rem, 18vw, 13rem);
  font-weight: 950;
  line-height: 0.82;
  letter-spacing: -0.08em;
  animation: countdownPop 260ms var(--ease-out);
}

.race-start-card span {
  color: var(--text);
  font-family: var(--font-mono);
  font-size: clamp(1rem, 2vw, 1.35rem);
  font-weight: 800;
}

.settings-drawer {
  position: fixed;
  inset: 0 0 0 auto;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: min(34rem, 100vw);
  height: 100vh;
  padding: 1rem;
  overflow-y: auto;
  color: var(--text);
  background: #262626;
  border-left: 1px solid var(--line-strong);
  box-shadow: -30px 0 80px rgba(0, 0, 0, 0.28);
  transform: translateX(110%);
  transition: transform 240ms var(--ease-out);
}

.settings-close-button {
  position: sticky;
  top: 0;
  z-index: 2;
  align-self: flex-end;
  flex: 0 0 auto;
  margin-bottom: -0.35rem;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(14px);
}

body.drawer-open .settings-drawer {
  transform: translateX(0);
}

.settings-section,
.result-card {
  padding: 1rem;
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.panel-heading {
  display: flex;
  gap: 0.8rem;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 0.85rem;
}

.panel-heading strong {
  display: block;
  color: var(--text-strong);
  font-size: 1.05rem;
}

.import-form,
.settings-form {
  display: grid;
  gap: 0.72rem;
}

.import-form textarea {
  min-height: 9rem;
  resize: vertical;
  line-height: 1.45;
}

.font-size-stepper {
  display: grid;
  grid-template-columns: auto minmax(5rem, 1fr) auto;
  gap: 0.5rem;
  align-items: center;
}

.font-size-stepper output {
  display: grid;
  min-height: 2.2rem;
  place-items: center;
  color: var(--text-strong);
  font-family: var(--font-mono);
  font-weight: 900;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.checkbox-row {
  display: flex !important;
  flex-direction: row;
  gap: 0.55rem !important;
  align-items: center;
}

.settings-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.muted {
  color: var(--text-dim);
}

.settings-section canvas {
  width: 100%;
  height: auto;
  margin-top: 0.35rem;
  background: rgba(0, 0, 0, 0.13);
  border: 1px solid var(--line);
}

.weak-list {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.75rem;
}

.weak-item {
  display: grid;
  grid-template-columns: 2rem 1fr auto;
  gap: 0.6rem;
  align-items: center;
  padding: 0.5rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.07);
}

.weak-letter {
  display: grid;
  width: 1.8rem;
  height: 1.8rem;
  place-items: center;
  color: var(--text-strong);
  font-family: var(--font-mono);
  font-weight: 900;
  background: var(--green);
}

.weak-bar {
  height: 0.38rem;
  margin-top: 0.24rem;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
}

.weak-bar span {
  display: block;
  width: var(--bar, 0%);
  height: 100%;
  background: linear-gradient(90deg, var(--red), var(--amber), var(--green-bright));
}

.close-button {
  display: grid;
  width: 2.2rem;
  height: 2.2rem;
  place-items: center;
  color: var(--text-dim);
  font-size: 1.55rem;
  line-height: 1;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
}

.result-dialog {
  width: min(30rem, calc(100vw - 2rem));
  padding: 0;
  color: var(--text);
  background: transparent;
  border: 0;
}

.result-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(12px);
}

.result-card {
  position: relative;
  background: #303030;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.32);
}

.result-card .close-button {
  position: absolute;
  inset: 0.8rem 0.8rem auto auto;
}

.result-card h2 {
  margin: 0.2rem 0 1rem;
  color: var(--text-strong);
  font-size: 2.1rem;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.result-grid div {
  padding: 0.75rem;
  text-align: center;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
}

.result-grid span,
.result-grid small {
  display: block;
}

.result-grid span {
  color: var(--text-strong);
  font-family: var(--font-mono);
  font-size: 1.9rem;
  font-weight: 900;
}

.result-grid small {
  color: var(--text-dim);
  font-size: 0.68rem;
  font-weight: 950;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

@keyframes cursorPulse {
  0%, 100% { opacity: 0.25; }
  45% { opacity: 1; }
}

@keyframes errorKick {
  0% { transform: translateX(0); }
  35% { transform: translateX(-0.08em); }
  70% { transform: translateX(0.08em); }
  100% { transform: translateX(0); }
}

@keyframes countdownPop {
  from {
    opacity: 0;
    transform: scale(0.88);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@media (max-width: 980px) {
  .site-header {
    position: sticky;
    inset: 0;
    grid-template-columns: 1fr;
    padding: 0.75rem;
    background: rgba(48, 48, 48, 0.9);
    backdrop-filter: blur(16px);
  }

  .mode-switch,
  .header-actions {
    justify-self: stretch;
    justify-content: center;
  }

  .practice-shell {
    width: min(100vw - 1rem, 1760px);
    padding-top: 1rem;
  }

  .status-board {
    width: 100%;
  }

  .status-row {
    flex-wrap: wrap;
  }

  .status-label {
    flex: 1 1 100%;
    min-width: 0;
    width: 100%;
    text-align: left;
  }

  .race-headline .status-label {
    width: auto;
    min-width: 0;
  }

  .race-headline {
    flex-wrap: wrap;
  }

  .race-actions {
    margin-left: 0;
  }

  .race-form,
  .race-leaderboard-tools,
  .race-leaderboard {
    margin-left: 0;
  }

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

  .game-actions {
    grid-column: 1 / -1;
  }

  .race-form {
    grid-template-columns: 1fr 1fr;
  }

  .race-text-picker {
    flex: 1 1 100%;
  }

  .race-text-picker select {
    width: 100%;
  }

  .typing-area {
    margin: 2rem 0;
  }

  .keyboard-panel {
    width: min(980px, calc(100vw - 1rem));
    padding: 0.75rem;
  }
}

@media (max-width: 700px) {
  .typing-area-drag-handle {
    display: none;
  }

  .lesson-translate {
    cursor: default;
    touch-action: auto;
  }
}

@media (max-width: 560px) {
  .header-actions {
    justify-content: flex-start;
  }

  .status-board {
    font-size: 0.95rem;
  }

  .letter-token {
    min-width: 1.46rem;
    height: 1.46rem;
  }

  .lesson-copy {
    font-size: clamp(1.35rem, var(--lesson-font-size), 4.25rem);
  }

  .race-form,
  .settings-actions,
  .result-grid,
  .game-hud {
    grid-template-columns: 1fr;
  }

  .game-arena {
    min-height: 390px;
  }

  .game-word {
    font-size: 0.95rem;
  }

  .race-text-picker {
    width: 100%;
  }

  .key {
    min-height: 2.4rem;
    font-size: 0.72rem;
  }
}

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