:root {
  color-scheme: light;
  --bg: #241035;
  --ink: #160f1f;
  --muted: #6c6077;
  --panel: #ffffff;
  --line: rgba(255, 255, 255, 0.34);
  --green: #1f9d73;
  --red: #e45572;
  --yellow: #ffd166;
  --blue: #50b7f5;
  --accent: #8f5cff;
  --accent-two: #ff7ad9;
  --accent-three: #50d6ff;
  --accent-soft: #efe7ff;
  --accent-glass: rgba(239, 231, 255, 0.5);
  --shadow: 0 28px 80px rgba(14, 6, 25, 0.34);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  position: relative;
  min-height: 100vh;
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(ellipse at 12% 16%, rgba(255, 122, 217, 0.42), transparent 34%),
    radial-gradient(ellipse at 88% 10%, rgba(80, 214, 255, 0.36), transparent 32%),
    radial-gradient(ellipse at 50% 92%, rgba(143, 92, 255, 0.54), transparent 40%),
    linear-gradient(135deg, #170d2a 0%, #35124f 42%, #5d1e74 70%, #231548 100%),
    var(--bg);
  background-size: 130% 130%, 130% 130%, 150% 150%, 200% 200%;
  animation: purpleFlow 18s ease-in-out infinite;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, transparent 0 12%, rgba(255, 255, 255, 0.08) 12% 12.2%, transparent 12.2% 100%),
    linear-gradient(0deg, transparent 0 16%, rgba(255, 255, 255, 0.07) 16% 16.2%, transparent 16.2% 100%);
  background-size: 108px 108px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.9), transparent 80%);
}

body[data-language="russian"] {
  --accent: #7f7cff;
  --accent-two: #ffffff;
  --accent-three: #ff5c8a;
  --accent-soft: #ecebff;
  --accent-glass: rgba(236, 235, 255, 0.5);
}

body[data-language="ukrainian"] {
  --accent: #50d6ff;
  --accent-two: #ffd166;
  --accent-three: #a06cff;
  --accent-soft: #e9f7ff;
  --accent-glass: rgba(233, 247, 255, 0.5);
}

body[data-language="belarusian"] {
  --accent: #58d68d;
  --accent-two: #ffffff;
  --accent-three: #ff5c8a;
  --accent-soft: #e9fff0;
  --accent-glass: rgba(233, 255, 240, 0.5);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
}

.background-motion {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.motion-line {
  position: absolute;
  left: -20%;
  width: 140%;
  height: 5px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), var(--accent), var(--accent-two), var(--accent-three), transparent);
  filter: blur(1px);
  opacity: 0.54;
  transform: rotate(-12deg);
  animation: slideLine 12s linear infinite;
}

.line-one {
  top: 16%;
}

.line-two {
  top: 46%;
  animation-duration: 16s;
  animation-direction: reverse;
}

.line-three {
  top: 76%;
  animation-duration: 20s;
}

.glyph-stream {
  position: absolute;
  left: -20%;
  color: rgba(255, 255, 255, 0.14);
  font-size: clamp(2.6rem, 9vw, 7rem);
  font-weight: 800;
  letter-spacing: 0;
  white-space: nowrap;
  animation: driftGlyphs 28s linear infinite;
}

.stream-one {
  top: 4%;
}

.stream-two {
  top: 56%;
  animation-duration: 34s;
  animation-direction: reverse;
}

.stream-three {
  top: 82%;
  animation-duration: 31s;
}

.app-shell {
  position: relative;
  width: min(1220px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: clamp(18px, 3vw, 38px);
  align-items: center;
  padding: clamp(18px, 4vw, 48px) 0;
}

.trainer,
.reference-panel {
  position: relative;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.24);
  border: 1px solid rgba(255, 255, 255, 0.38);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px) saturate(1.35);
}

.trainer::before,
.reference-panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 7px;
  background: linear-gradient(90deg, var(--accent), var(--accent-two), var(--accent-three));
  background-size: 180% 100%;
  animation: accentFlow 9s ease-in-out infinite;
}

.trainer {
  padding: clamp(22px, 4vw, 42px);
}

.reference-panel {
  align-self: stretch;
  padding: clamp(20px, 3vw, 32px);
}

.topbar,
.reference-header,
.stats-row,
.mode-row,
.language-grid {
  display: flex;
  gap: 12px;
}

.topbar,
.reference-header {
  justify-content: space-between;
  align-items: flex-start;
}

.eyebrow {
  margin: 0 0 6px;
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 7vw, 4.8rem);
  line-height: 0.94;
  letter-spacing: 0;
  max-width: 720px;
  color: #ffffff;
  text-shadow: 0 12px 34px rgba(20, 7, 39, 0.25);
}

h2 {
  margin-bottom: 0;
  font-size: 1.25rem;
  color: #ffffff;
}

.timer-block {
  min-width: 112px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 8px;
  text-align: center;
  background: rgba(255, 255, 255, 0.24);
  box-shadow: inset 0 -4px 0 rgba(21, 27, 31, 0.06);
}

.timer-block.warning {
  border-color: rgba(199, 67, 61, 0.5);
  background: #fff0ef;
}

.timer-label {
  display: block;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.78rem;
  font-weight: 700;
}

#timer {
  display: block;
  margin-top: 4px;
  font-size: 1.55rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #ffffff;
}

.language-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 32px;
}

.language-button,
.mode-button,
.reset-button {
  min-height: 46px;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.language-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  background: rgba(255, 255, 255, 0.22);
  color: #ffffff;
  font-weight: 800;
}

.language-button img {
  width: 34px;
  height: 24px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.36);
}

.language-button.active {
  border-color: var(--accent);
  background: var(--accent-glass);
  box-shadow: inset 0 -4px 0 rgba(21, 27, 31, 0.07);
}

.language-button[data-language="russian"].active {
  color: #ffffff;
}

.language-button[data-language="ukrainian"].active {
  color: #ffffff;
}

.language-button[data-language="belarusian"].active {
  color: #ffffff;
}

.mode-row {
  flex-wrap: wrap;
  margin-top: 14px;
}

.mode-button,
.reset-button {
  padding: 0 16px;
  background: rgba(255, 255, 255, 0.22);
  color: #ffffff;
  font-weight: 800;
}

.mode-button.active,
.mode-button.accent {
  background: rgba(255, 255, 255, 0.94);
  color: #241035;
}

.mode-button.active {
  box-shadow: inset 0 -4px 0 rgba(143, 92, 255, 0.28);
}

.mode-button.accent {
  background: linear-gradient(135deg, var(--accent), var(--accent-two), var(--accent-three));
  color: #ffffff;
}

.mode-button:hover,
.language-button:hover,
.reset-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(21, 27, 31, 0.1);
}

.practice-stage {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 16px;
  margin-top: 32px;
  padding: 34px 20px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.07) 0 1px, transparent 1px 36px),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.055) 0 1px, transparent 1px 36px),
    rgba(255, 255, 255, 0.18);
  background-position: 0 0, 0 0, 0 0;
  animation: keyGrid 18s linear infinite;
}

.practice-stage::before,
.practice-stage::after {
  content: "";
  position: absolute;
  top: 118px;
  width: min(19%, 150px);
  height: 8px;
  border-radius: 8px;
  background: var(--accent);
  animation: pulseBridge 2.8s ease-in-out infinite;
}

.practice-stage::before {
  left: 18px;
}

.practice-stage::after {
  right: 18px;
  background: var(--accent-three);
  animation-delay: 500ms;
}

#instructionText {
  margin-bottom: 0;
  color: rgba(255, 255, 255, 0.78);
  font-weight: 700;
  text-align: center;
}

.target-character {
  position: relative;
  z-index: 1;
  width: min(100%, 360px);
  min-height: 190px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.42), transparent 32%),
    linear-gradient(145deg, var(--accent-two), var(--accent), var(--accent-three));
  color: #ffffff;
  font-size: clamp(5rem, 24vw, 10rem);
  line-height: 1;
  font-weight: 800;
  box-shadow: inset 0 -8px 0 rgba(23, 32, 27, 0.12), 0 22px 54px rgba(31, 9, 58, 0.24);
  transition: transform 180ms ease, background 180ms ease;
  animation: characterFloat 4s ease-in-out infinite;
}

.target-character.correct {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.44), transparent 34%),
    #67d49f;
}

.target-character.wrong {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.44), transparent 34%),
    #f08a7f;
}

.answer-input {
  position: relative;
  z-index: 1;
  width: min(100%, 360px);
  height: 58px;
  border: 2px solid rgba(255, 255, 255, 0.42);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  text-align: center;
  font-size: 1.6rem;
  font-weight: 800;
  outline: none;
}

.answer-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(31, 120, 168, 0.12);
}

.answer-input.correct {
  border-color: var(--green);
  background: #e7f4ee;
  animation: bump 220ms ease;
}

.answer-input.wrong {
  border-color: var(--red);
  background: #fff0ef;
  animation: shake 180ms ease;
}

.feedback {
  min-height: 24px;
  margin-bottom: 0;
  font-weight: 800;
  text-align: center;
}

.feedback.neutral {
  color: rgba(255, 255, 255, 0.78);
}

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

.feedback.wrong {
  color: var(--red);
}

.solution-panel {
  width: min(100%, 520px);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 10px;
  border: 1px solid rgba(199, 67, 61, 0.25);
  border-radius: 8px;
  background: rgba(255, 246, 244, 0.74);
}

.solution-panel[hidden] {
  display: none;
}

.solution-panel span {
  min-height: 42px;
  display: grid;
  align-content: center;
  justify-items: center;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.58);
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.solution-panel strong {
  color: var(--ink);
  font-size: 1.35rem;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 16px;
}

.stat {
  min-height: 86px;
  display: grid;
  align-content: center;
  justify-items: center;
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.22);
  transition: transform 160ms ease, border-color 160ms ease;
}

.stat:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
}

.stat span {
  font-size: 1.8rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.stat p {
  margin: 4px 0 0;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.84rem;
  font-weight: 700;
}

.keyboard-image {
  width: 100%;
  height: auto;
  margin-top: 20px;
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.42);
  box-shadow: inset 0 0 0 6px rgba(255, 255, 255, 0.28);
}

.hint-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.hint-list p {
  margin: 0;
  color: rgba(255, 255, 255, 0.78);
  line-height: 1.5;
}

#directionHint {
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 8px;
  background: var(--accent-glass);
  color: #ffffff;
}

.result-dialog {
  width: min(420px, calc(100% - 32px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
  background: rgba(255, 255, 255, 0.76);
  backdrop-filter: blur(20px);
}

.result-dialog::backdrop {
  background: rgba(23, 32, 27, 0.45);
}

.result-dialog form {
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.42);
}

.result-stats {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 16px;
}

.result-stats span {
  padding: 10px 12px;
  border-radius: 8px;
  background: #f3f7fa;
  font-weight: 800;
}

@keyframes purpleFlow {
  0% {
    background-position: 0% 40%, 100% 20%, 50% 100%, 0% 50%;
  }

  50% {
    background-position: 22% 48%, 78% 34%, 44% 82%, 100% 50%;
  }

  100% {
    background-position: 0% 40%, 100% 20%, 50% 100%, 0% 50%;
  }
}

.result-dialog button {
  margin-top: 12px;
}

@keyframes bump {
  50% {
    transform: scale(1.03);
  }
}

@keyframes accentFlow {
  50% {
    background-position: 100% 0;
  }
}

@keyframes slideLine {
  from {
    transform: translateX(-10%) rotate(-12deg);
  }

  to {
    transform: translateX(10%) rotate(-12deg);
  }
}

@keyframes driftGlyphs {
  from {
    transform: translateX(-8%);
  }

  to {
    transform: translateX(28%);
  }
}

@keyframes keyGrid {
  to {
    background-position: 72px 0, 0 72px, 0 0;
  }
}

@keyframes pulseBridge {
  50% {
    transform: scaleX(0.82);
    opacity: 0.65;
  }
}

@keyframes characterFloat {
  50% {
    transform: translateY(-4px);
  }
}

@keyframes shake {
  25% {
    transform: translateX(-5px);
  }

  75% {
    transform: translateX(5px);
  }
}

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

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    align-items: stretch;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding: 10px 0;
    gap: 10px;
  }

  .trainer,
  .reference-panel {
    padding: 16px;
  }

  .practice-stage::before,
  .practice-stage::after {
    display: none;
  }

  .topbar,
  .reference-header {
    flex-direction: column;
  }

  .timer-block {
    width: 100%;
  }

  .language-grid,
  .stats-row {
    grid-template-columns: 1fr;
  }

  .language-button {
    justify-content: flex-start;
  }

  .mode-button,
  .reset-button {
    flex: 1 1 150px;
  }

  .target-character {
    min-height: 150px;
  }

  .solution-panel {
    grid-template-columns: 1fr;
  }
}
