:root {
  color-scheme: dark;
  --bg: #0d1118;
  --panel: #171d27;
  --panel-2: #222a38;
  --text: #f7fbff;
  --muted: #98a8bb;
  --line: rgba(255, 255, 255, 0.13);
  --blue: #43c9ff;
  --green: #73f0a6;
  --red: #ff5a7d;
  --yellow: #ffd166;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(circle at 16% 8%, rgba(67, 201, 255, 0.16), transparent 27rem),
    radial-gradient(circle at 90% 14%, rgba(255, 90, 125, 0.14), transparent 25rem),
    linear-gradient(135deg, #0d1118, #171a26 54%, #211723);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  background: #293548;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
  min-height: 42px;
  padding: 0 18px;
}

button:hover,
button:focus-visible,
.typing-input:focus {
  border-color: rgba(67, 201, 255, 0.75);
  outline: none;
}

.game-shell {
  display: grid;
  gap: 8px;
  grid-template-rows: auto minmax(210px, 0.95fr) auto auto;
  height: 100vh;
  margin: 0 auto;
  max-width: 1220px;
  overflow: hidden;
  padding: 8px;
}

.hud,
.typing-panel,
.training-grid {
  background: rgba(23, 29, 39, 0.93);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  padding: 8px;
}

.hud {
  align-items: stretch;
  grid-template-columns: repeat(9, minmax(0, 1fr)) auto;
}

.hud > div,
.sentence-card,
.progress-card,
.keyboard-card,
.hands-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}

.level-jump input,
.difficulty-select select {
  background: #0f1520;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  font-weight: 900;
  height: 28px;
  padding: 0 8px;
  width: 100%;
}

.label {
  color: var(--muted);
  display: block;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
  text-transform: uppercase;
}

strong {
  font-size: 1.08rem;
}

.stage-wrap {
  background: #070a10;
  border: 1px solid var(--line);
  border-radius: 8px;
  height: 100%;
  min-height: 210px;
  overflow: hidden;
  position: relative;
}

canvas {
  display: block;
  height: 100%;
  width: 100%;
}

.overlay {
  align-items: center;
  background: rgba(7, 10, 16, 0.82);
  display: grid;
  inset: 0;
  justify-items: center;
  padding: 20px;
  place-content: center;
  position: absolute;
  text-align: center;
}

.overlay.hidden {
  display: none;
}

.overlay h1 {
  font-size: clamp(2.2rem, 6vw, 5rem);
  line-height: 0.95;
  margin: 0 0 12px;
}

.overlay p {
  color: var(--muted);
  font-size: 1.08rem;
  margin: 0 0 24px;
  max-width: 38rem;
}

.typing-panel {
  grid-template-columns: minmax(0, 1.55fr) minmax(240px, 0.45fr);
}

.sentence-display {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: clamp(1.1rem, 2.2vw, 1.8rem);
  font-weight: 900;
  line-height: 1.25;
  min-height: 52px;
  overflow-wrap: anywhere;
  padding: 9px 11px;
}

.sentence-display span {
  border-radius: 5px;
  padding: 0 1px;
}

.sentence-display .correct {
  color: var(--green);
}

.sentence-display .current {
  color: var(--blue);
}

.sentence-display .wrong-char {
  color: var(--red);
}

.typing-input {
  background: #0f1520;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 1.2rem;
  font-weight: 800;
  margin-top: 7px;
  min-height: 38px;
  padding: 0 14px;
  width: 100%;
}

.bar {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  height: 14px;
  overflow: hidden;
}

.bar span {
  background: linear-gradient(90deg, var(--green), var(--blue));
  display: block;
  height: 100%;
  transition: width 180ms ease;
  width: 0%;
}

#levelInfo {
  color: var(--muted);
  line-height: 1.35;
  font-size: 0.88rem;
  margin: 7px 0 0;
}

.training-grid {
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.6fr);
}

.keyboard-card {
  overflow: hidden;
}

.keyboard-trainer {
  min-height: 124px;
  position: relative;
}

.keyboard {
  display: grid;
  gap: 5px;
  position: relative;
  z-index: 1;
}

.key-row {
  display: flex;
  gap: 5px;
  justify-content: center;
}

.key {
  align-items: center;
  background: #101722;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 7px;
  color: #dbe7f6;
  display: flex;
  font-size: clamp(0.78rem, 1.8vw, 1rem);
  font-weight: 900;
  height: 30px;
  justify-content: center;
  min-width: 30px;
  padding: 0 8px;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}

.key.locked {
  color: rgba(219, 231, 246, 0.28);
}

.key.next {
  background: rgba(67, 201, 255, 0.28);
  border-color: var(--blue);
  transform: translateY(-2px);
}

.key.delete {
  background: rgba(255, 90, 125, 0.28);
  border-color: var(--red);
}

.key.wrong-press {
  animation: wrongKeyFlash 700ms ease;
  background: rgba(255, 90, 125, 0.48);
  border-color: var(--red);
  color: #fff;
}

@keyframes wrongKeyFlash {
  0%,
  100% {
    transform: translateY(0);
  }

  35% {
    box-shadow: 0 0 18px rgba(255, 90, 125, 0.8);
    transform: translateY(-2px) scale(1.08);
  }
}

.key.finger-left-pinky,
.key.finger-right-pinky {
  border-color: rgba(255, 90, 125, 0.36);
}

.key.finger-left-ring,
.key.finger-right-ring {
  border-color: rgba(255, 209, 102, 0.36);
}

.key.finger-left-middle,
.key.finger-right-middle {
  border-color: rgba(115, 240, 166, 0.36);
}

.key.finger-left-index,
.key.finger-right-index {
  border-color: rgba(67, 201, 255, 0.36);
}

.key.finger-thumbs {
  border-color: rgba(179, 136, 255, 0.42);
}

.key.space {
  min-width: 200px;
}

.key.shift {
  min-width: 74px;
}

.hands {
  display: grid;
  gap: 0;
  grid-template-columns: 1fr 1fr;
}

.hand {
  max-height: 128px;
  min-width: 0;
  transform-origin: center;
  width: 100%;
}

.left-hand {
  transform: scaleX(-1) rotate(-5deg);
}

.right-hand {
  transform: scaleX(-1) rotate(5deg);
}

.finger,
.palm {
  fill: #2b3445;
  stroke: rgba(255, 255, 255, 0.14);
  stroke-width: 4;
  transition: fill 120ms ease, filter 120ms ease;
}

.finger.active {
  fill: var(--blue);
  filter: drop-shadow(0 0 10px rgba(67, 201, 255, 0.75));
}

.finger.error {
  fill: var(--red);
  filter: drop-shadow(0 0 10px rgba(255, 90, 125, 0.75));
}

.wrong {
  animation: shake 160ms linear;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-8px); }
  70% { transform: translateX(8px); }
}

@media (max-width: 850px) {
  body {
    overflow: auto;
  }

  .game-shell {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .hud,
  .typing-panel,
  .training-grid {
    grid-template-columns: 1fr;
  }

  .stage-wrap {
    height: 280px;
    min-height: 240px;
  }

  .key {
    min-width: 27px;
    padding: 0 7px;
  }

  .key.space {
    min-width: 150px;
  }
}

@media print {
  @page {
    margin: 0.25in;
    size: landscape;
  }

  body {
    background: #0d1118;
    overflow: hidden;
  }

  .game-shell {
    height: calc(100vh - 0.5in);
    overflow: hidden;
    page-break-after: avoid;
    page-break-inside: avoid;
  }
}
