/**
 * Тренажёр систем счисления — уровни и падающие карточки
 */

html:has(.page--radix-trainer),
body.page-radix-trainer-body {
  height: 100%;
  max-height: 100dvh;
  overflow: hidden;
}

.page--radix-trainer {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.page--radix-trainer .header {
  flex-shrink: 0;
}

.page--radix-trainer .radix-main {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  width: min(52rem, 100%);
  margin: 0 auto;
  padding: 0 clamp(1rem, 3vw, 2rem) 0.75rem;
  overflow: hidden;
}

/* Игровое поле — ~80% ширины окна, высота — остаток экрана */
.page--radix-trainer .radix-main:has([data-radix-play]:not([hidden])) {
  width: min(80vw, 100%);
  max-width: none;
}

.page--radix-trainer .radix-hero {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-top: 0.35rem;
  padding-bottom: 0.25rem;
  overflow: hidden;
}

/* display:flex выше перебивает UA-стиль [hidden] — явно скрываем панели */
.page--radix-trainer .radix-hero[hidden],
.radix-play[hidden] {
  display: none !important;
}

.radix-levels {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
  flex: 1 1 auto;
  min-height: 0;
  margin: 0.45rem 0 0;
  padding: 0;
  list-style: none;
  align-content: start;
  overflow: hidden;
}

.radix-level {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
  width: 100%;
  min-height: 0;
  padding: 0.75rem 0.95rem;
  border-radius: 14px;
  border: 1px solid rgba(96, 165, 250, 0.22);
  background: linear-gradient(
    165deg,
    rgba(38, 48, 62, 0.95) 0%,
    rgba(24, 30, 40, 0.98) 100%
  );
  box-shadow:
    0 4px 20px rgba(0, 0, 0, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  transition:
    border-color 0.22s ease,
    box-shadow 0.22s ease,
    transform 0.22s ease;
}

.radix-level:hover {
  transform: translateY(-2px);
  border-color: rgba(96, 165, 250, 0.5);
  box-shadow:
    0 8px 28px rgba(37, 99, 235, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.radix-level:focus-visible {
  outline: 2px solid rgba(96, 165, 250, 0.7);
  outline-offset: 2px;
}

.radix-level__num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.65rem;
  height: 1.65rem;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #dbeafe;
  background: linear-gradient(145deg, rgba(59, 130, 246, 0.5), rgba(37, 99, 235, 0.3));
  border: 1px solid rgba(96, 165, 250, 0.4);
}

.radix-level__title {
  font-size: 0.95rem;
  font-weight: 650;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.radix-level__hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

[data-theme="light"] .radix-level {
  border-color: rgba(37, 99, 235, 0.18);
  background: linear-gradient(165deg, #ffffff 0%, #eff6ff 100%);
  box-shadow:
    0 4px 16px rgba(26, 36, 48, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.95);
}

[data-theme="light"] .radix-level__num {
  color: #1e3a8a;
}

.radix-play {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  box-sizing: border-box;
  width: 80vw;
  max-width: 100%;
  height: auto;
  min-height: 0;
  margin: 0.65rem auto 0;
  padding: clamp(0.85rem, 2vw, 1.35rem);
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: linear-gradient(
    165deg,
    rgba(32, 38, 44, 0.9) 0%,
    rgba(20, 24, 29, 0.94) 55%,
    rgba(18, 22, 27, 0.92) 100%
  );
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.28),
    0 1px 0 rgba(255, 255, 255, 0.06) inset;
  backdrop-filter: blur(14px) saturate(1.08);
  -webkit-backdrop-filter: blur(14px) saturate(1.08);
  overflow: hidden;
}

.radix-play::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(
    135deg,
    rgba(59, 130, 246, 0.45) 0%,
    rgba(255, 255, 255, 0.08) 45%,
    rgba(5, 184, 125, 0.35) 100%
  );
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

[data-theme="light"] .radix-play {
  border-color: rgba(15, 23, 42, 0.08);
  background: linear-gradient(
    165deg,
    rgba(255, 255, 255, 0.97) 0%,
    rgba(239, 246, 255, 0.95) 100%
  );
  box-shadow:
    0 12px 36px rgba(15, 23, 42, 0.08),
    0 1px 0 rgba(255, 255, 255, 0.95) inset;
}

.radix-play__toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  flex-shrink: 0;
  margin-bottom: 0.85rem;
}

.radix-play__meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.radix-play__level-label {
  font-weight: 600;
  color: var(--text);
}

.radix-play__score strong {
  color: #34d399;
  font-variant-numeric: tabular-nums;
}

.radix-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.45rem 0.9rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: inherit;
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  transition:
    background 0.2s ease,
    border-color 0.2s ease;
}

.radix-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(96, 165, 250, 0.35);
}

.radix-btn--ghost {
  background: transparent;
}

.radix-btn--start {
  min-width: 8.5rem;
  min-height: 3rem;
  padding: 0.75rem 1.75rem;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #eff6ff;
  border-color: rgba(96, 165, 250, 0.55);
  background: linear-gradient(145deg, #3b82f6 0%, #1d4ed8 100%);
  box-shadow:
    0 8px 24px rgba(37, 99, 235, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.radix-btn--start:hover {
  border-color: rgba(147, 197, 253, 0.7);
  background: linear-gradient(145deg, #60a5fa 0%, #2563eb 100%);
}

.radix-start {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
}

.radix-start[hidden] {
  display: none !important;
}

.radix-play__prompt {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  text-align: center;
  flex-shrink: 0;
}

.radix-fall {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  flex: 1 1 auto;
  min-height: 11rem;
  margin-bottom: 1.25rem;
  border-radius: 14px;
  border: 1px dashed rgba(96, 165, 250, 0.25);
  background:
    radial-gradient(ellipse 70% 50% at 50% 100%, rgba(59, 130, 246, 0.12), transparent 70%),
    rgba(0, 0, 0, 0.15);
  overflow: hidden;
}

[data-theme="light"] .radix-fall {
  border-color: rgba(37, 99, 235, 0.2);
  background:
    radial-gradient(ellipse 70% 50% at 50% 100%, rgba(59, 130, 246, 0.1), transparent 70%),
    rgba(239, 246, 255, 0.6);
}

.radix-tile {
  position: absolute;
  left: 50%;
  top: 0.5rem;
  bottom: auto;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  min-width: 4.5rem;
  padding: 0.85rem 1.1rem;
  border-radius: 12px;
  border: 1px solid rgba(96, 165, 250, 0.4);
  background: linear-gradient(160deg, #3b82f6 0%, #1d4ed8 100%);
  color: #fff;
  box-shadow:
    0 10px 28px rgba(37, 99, 235, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
  font-family: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  animation: radix-tile-fall 22s cubic-bezier(0.33, 0.05, 0.25, 1) both;
  z-index: 2;
  will-change: top, transform, opacity;
}

.radix-tile__base {
  font-size: 0.7rem;
  font-weight: 600;
  opacity: 0.85;
  letter-spacing: 0.04em;
}

.radix-tile--exit {
  animation: radix-tile-exit 0.4s ease forwards;
}

.radix-tile--success {
  border-color: rgba(52, 211, 153, 0.7);
  background: linear-gradient(160deg, #34d399 0%, #059669 100%);
  box-shadow:
    0 10px 28px rgba(5, 150, 105, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

@keyframes radix-tile-fall {
  from {
    opacity: 1;
    top: 0.5rem;
    transform: translate(-50%, 0) scale(0.96);
  }
  to {
    opacity: 1;
    top: calc(100% - 1.25rem);
    transform: translate(-50%, -100%) scale(1);
  }
}

@keyframes radix-tile-exit {
  from {
    opacity: 1;
    top: calc(100% - 1.25rem);
    transform: translate(-50%, -100%) scale(1);
  }
  to {
    opacity: 0;
    top: calc(100% - 1.25rem);
    transform: translate(-50%, -60%) scale(0.9);
  }
}

.radix-answers {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.65rem;
  flex-shrink: 0;
}

.radix-answer {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 3rem;
  padding: 0.65rem 0.5rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: linear-gradient(165deg, rgba(45, 52, 60, 0.95), rgba(28, 33, 40, 0.98));
  color: inherit;
  font-family: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  font-size: 1.05rem;
  font-weight: 650;
  cursor: pointer;
  transition:
    transform 0.15s ease,
    border-color 0.15s ease,
    background 0.15s ease,
    box-shadow 0.15s ease;
}

.radix-answer:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(96, 165, 250, 0.45);
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.15);
}

.radix-answer:disabled {
  cursor: default;
}

.radix-answer--correct {
  border-color: rgba(52, 211, 153, 0.65);
  background: linear-gradient(165deg, rgba(16, 185, 129, 0.45), rgba(5, 150, 105, 0.35));
  color: #ecfdf5;
}

.radix-answer--wrong {
  border-color: rgba(248, 113, 113, 0.55);
  background: linear-gradient(165deg, rgba(239, 68, 68, 0.35), rgba(185, 28, 28, 0.28));
  animation: radix-shake 0.35s ease;
}

[data-theme="light"] .radix-answer {
  border-color: rgba(15, 23, 42, 0.1);
  background: linear-gradient(165deg, #fff, #f1f5f9);
}

@keyframes radix-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-4px);
  }
  75% {
    transform: translateX(4px);
  }
}

.radix-flash {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  background: rgba(5, 150, 105, 0.18);
  backdrop-filter: blur(2px);
  pointer-events: none;
  z-index: 5;
  animation: radix-flash-in 0.45s ease both;
}

.radix-flash__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 999px;
  font-size: 1.5rem;
  font-weight: 700;
  color: #ecfdf5;
  background: linear-gradient(145deg, #34d399, #059669);
  box-shadow: 0 8px 24px rgba(5, 150, 105, 0.45);
}

.radix-flash__text {
  font-size: 1.1rem;
  font-weight: 700;
  color: #a7f3d0;
}

@keyframes radix-flash-in {
  from {
    opacity: 0;
  }
  30% {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

@media (max-width: 640px) {
  .radix-levels {
    grid-template-columns: 1fr;
  }

  .radix-play {
    width: 100%;
  }

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

  .radix-fall {
    min-height: 7rem;
  }

  .radix-tile {
    font-size: 1.25rem;
    min-width: 4rem;
  }
}
