/* ============================================================
   Космос 2048 — визуальная система
   ============================================================ */

:root {
  --space-0: #060B1F;
  --space-1: #0A1230;
  --space-2: #16224A;
  --space-3: #1E2E63;
  --cell-bg: rgba(255, 255, 255, 0.045);
  --ink: #EAF0FF;
  --ink-dim: #8A93C4;
  --gold: #FFC24B;
  --violet: #6C5CE7;

  --board: 320px;
  --cell: 70px;
  --gap: 10px;
  --radius: 14px;

  --dur-slide: 110ms;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);

  --font-ui: "Segoe UI", "SF Pro Text", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-num: "Segoe UI", "SF Pro Display", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(1100px 680px at 16% -10%, #1C2B6B 0%, transparent 60%),
    radial-gradient(880px 580px at 90% 6%, #2E1C5C 0%, transparent 55%),
    radial-gradient(700px 500px at 50% 108%, #123A6E 0%, transparent 60%),
    var(--space-1);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

/* Звёздная пыль на фоне — статичная, без анимации */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.5;
  background-image:
    radial-gradient(1.4px 1.4px at 12% 22%, rgba(255,255,255,0.7), transparent),
    radial-gradient(1.2px 1.2px at 68% 12%, rgba(255,255,255,0.55), transparent),
    radial-gradient(1.6px 1.6px at 84% 62%, rgba(255,255,255,0.5), transparent),
    radial-gradient(1.1px 1.1px at 32% 78%, rgba(255,255,255,0.5), transparent),
    radial-gradient(1.3px 1.3px at 52% 44%, rgba(255,255,255,0.35), transparent),
    radial-gradient(1.2px 1.2px at 8% 62%, rgba(255,255,255,0.4), transparent),
    radial-gradient(1.5px 1.5px at 94% 30%, rgba(255,255,255,0.45), transparent);
}

/* ---------------- Загрузочный экран ---------------- */

.boot {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  background: var(--space-1);
  z-index: 50;
}

.boot__orbit {
  display: flex;
  gap: 10px;
}

.boot__orbit span {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--gold);
  opacity: 0.25;
  animation: pulse 1.1s infinite var(--ease);
}

.boot__orbit span:nth-child(2) { animation-delay: 0.15s; }
.boot__orbit span:nth-child(3) { animation-delay: 0.3s; }

@keyframes pulse {
  0%, 100% { opacity: 0.2; transform: scale(0.85); }
  45% { opacity: 1; transform: scale(1.1); }
}

.boot__text {
  margin: 0;
  color: var(--ink-dim);
  font-size: 14px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

/* ---------------- Каркас ---------------- */

.app {
  position: relative;
  z-index: 1;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
  max-width: 620px;
  margin: 0 auto;
}

.topbar {
  width: 100%;
  max-width: var(--board);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.wordmark {
  margin: 0;
  display: flex;
  flex-direction: column;
  line-height: 0.94;
}

.wordmark__b {
  font-family: var(--font-num);
  font-size: 36px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-shadow: 0 0 18px rgba(96, 165, 250, 0.35);
}

.wordmark__a {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #7FB2F0;
}

.scores {
  display: flex;
  gap: 8px;
}

.score {
  position: relative;
  min-width: 78px;
  padding: 7px 10px 8px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.07);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.score__label {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.score__value {
  font-family: var(--font-num);
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.score--best .score__value { color: var(--gold); }

.score.is-bumped { animation: bump 240ms var(--ease); }

@keyframes bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.score__gain {
  position: absolute;
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 17px;
  color: var(--gold);
  pointer-events: none;
  animation: floatUp 700ms var(--ease) forwards;
}

@keyframes floatUp {
  0% { opacity: 0.95; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-32px); }
}

/* ---------------- Поле ---------------- */

.stage { position: relative; }

.board {
  position: relative;
  width: var(--board);
  height: var(--board);
  padding: var(--gap);
  border-radius: calc(var(--radius) + 6px);
  background: linear-gradient(155deg, var(--space-2) 0%, var(--space-3) 100%);
  border: 1px solid rgba(96, 165, 250, 0.28);
  box-shadow:
    0 0 0 1px rgba(56, 189, 248, 0.12),
    0 0 32px rgba(56, 189, 248, 0.18),
    0 18px 50px rgba(3, 6, 20, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  outline: none;
  touch-action: none;
}

.board:focus-visible {
  box-shadow: 0 0 0 3px var(--violet), 0 18px 50px rgba(3, 6, 20, 0.6);
}

.board__cells,
.board__tiles {
  position: absolute;
  inset: var(--gap);
}

.cell {
  position: absolute;
  width: var(--cell);
  height: var(--cell);
  border-radius: var(--radius);
  background: var(--cell-bg);
}

.tile {
  position: absolute;
  width: var(--cell);
  height: var(--cell);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-num);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  background: var(--tile-bg, #4A6FD0);
  box-shadow: var(--tile-glow, none), inset 0 1px 0 rgba(255, 255, 255, 0.24);
  font-size: calc(var(--cell) * 0.4);
  transition: transform var(--dur-slide) var(--ease);
  will-change: transform;
  overflow: hidden;
  z-index: 2;
}

.tile__art {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 104%;
  height: 104%;
  transform: translate(-50%, -50%);
  color: var(--tile-art, #0B1B44);
  opacity: 0.3;
  pointer-events: none;
}

.tile__num {
  position: relative;
  z-index: 1;
  font-size: inherit;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
}

.tile--ghost { z-index: 1; }
.tile--d3 { font-size: calc(var(--cell) * 0.33); }
.tile--d4 { font-size: calc(var(--cell) * 0.27); }
.tile--d5 { font-size: calc(var(--cell) * 0.22); }

.tile--new { animation: appear 160ms var(--ease); }

@keyframes appear {
  0% { opacity: 0; transform: var(--pos) scale(0.4); }
  100% { opacity: 1; transform: var(--pos) scale(1); }
}

.tile--merged { animation: merge 190ms var(--ease); }

@keyframes merge {
  0% { transform: var(--pos) scale(1); }
  45% { transform: var(--pos) scale(1.16); }
  100% { transform: var(--pos) scale(1); }
}

/* ---------------- Оверлей завершения ---------------- */

.overlay {
  position: absolute;
  inset: 0;
  border-radius: calc(var(--radius) + 6px);
  background: rgba(7, 11, 28, 0.86);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 5;
  animation: fade 220ms var(--ease);
}

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.overlay__card {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
}

.overlay__eyebrow {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.overlay__title {
  margin: 0;
  font-family: var(--font-num);
  font-size: 27px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.overlay__sub {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--ink-dim);
  line-height: 1.4;
}

.overlay__actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 230px;
}

/* ---------------- Кнопки ---------------- */

.hint {
  margin: 0;
  font-size: 12px;
  color: var(--ink-dim);
  text-align: center;
  min-height: 16px;
  transition: opacity 300ms var(--ease);
}

.hint.is-hidden { opacity: 0; }

.controls {
  width: 100%;
  max-width: var(--board);
  display: flex;
  gap: 8px;
}

.btn {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  min-height: 46px;
  padding: 0 10px;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 13px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  background: rgba(255, 255, 255, 0.07);
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 140ms var(--ease), transform 100ms var(--ease);
}

.btn:hover { background: rgba(255, 255, 255, 0.12); }
.btn:active { transform: scale(0.97); }

.btn:focus-visible {
  outline: 2px solid var(--violet);
  outline-offset: 2px;
}

.btn[disabled] {
  opacity: 0.38;
  cursor: default;
  pointer-events: none;
}

.btn--icon {
  flex: 0 0 46px;
  padding: 0;
}

.btn--wide { width: 100%; flex: none; }

.btn--primary {
  background: var(--gold);
  border-color: transparent;
  color: #1A1204;
}

.btn--primary:hover { background: #FFD070; }

.btn__icon {
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
  display: block;
  color: currentColor;
}

.btn__text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn__badge {
  flex: 0 0 auto;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.32);
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

/* ---------------- Шкала эволюции (сигнатура) ---------------- */

.ladder {
  width: 100%;
  max-width: var(--board);
}

.ladder__title {
  margin: 0 0 7px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.ladder__rail {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  padding-bottom: 5px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.16) transparent;
}

.ladder__rail::-webkit-scrollbar { height: 4px; }
.ladder__rail::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 2px;
}

.rung {
  flex: 0 0 auto;
  width: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  opacity: 0.3;
  transition: opacity 300ms var(--ease);
}

.rung.is-unlocked { opacity: 1; }

.rung.is-fresh .rung__dot { animation: merge 500ms var(--ease); }

.rung__dot {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--tile-bg, #4A6FD0);
  box-shadow: var(--tile-glow, none);
  display: flex;
  align-items: center;
  justify-content: center;
}

.rung__icon {
  width: 74%;
  height: 74%;
  display: block;
  color: inherit;
}

.rung__name {
  font-size: 12px;
  line-height: 1.2;
  text-align: center;
  color: var(--ink-dim);
  letter-spacing: 0.01em;
}

.rung.is-unlocked .rung__name { color: var(--ink); }

/* ---------------- Панель настроек ---------------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(7, 11, 28, 0.7);
  animation: fade 200ms var(--ease);
}

.sheet__panel {
  width: 100%;
  max-width: 460px;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  border-radius: 22px 22px 0 0;
  background: var(--space-2);
  border-top: 1px solid rgba(255, 255, 255, 0.09);
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: slideUp 240ms var(--ease);
}

@keyframes slideUp {
  from { transform: translateY(16%); }
  to { transform: translateY(0); }
}

.sheet__title {
  margin: 0;
  font-family: var(--font-num);
  font-size: 20px;
  font-weight: 700;
}

.sheet__note {
  margin: 0;
  font-size: 12px;
  color: var(--ink-dim);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field__label {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.segmented {
  display: flex;
  gap: 5px;
  padding: 4px;
  border-radius: 13px;
  background: rgba(0, 0, 0, 0.24);
}

.segmented__btn {
  flex: 1;
  min-height: 38px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-dim);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 140ms var(--ease), color 140ms var(--ease);
}

.segmented__btn:hover { color: var(--ink); }

.segmented__btn.is-active {
  background: rgba(255, 255, 255, 0.12);
  color: var(--ink);
}

.segmented__btn:focus-visible {
  outline: 2px solid var(--violet);
  outline-offset: 1px;
}

/* ---------------- Тост открытия ---------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 16px 10px 11px;
  border-radius: 15px;
  background: rgba(20, 26, 59, 0.97);
  border: 1px solid rgba(255, 255, 255, 0.11);
  box-shadow: 0 14px 36px rgba(3, 6, 20, 0.55);
  animation: toastIn 300ms var(--ease);
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 14px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.toast.is-leaving { animation: toastOut 260ms var(--ease) forwards; }

@keyframes toastOut {
  to { opacity: 0; transform: translate(-50%, 10px); }
}

.toast__chip {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  background: var(--tile-bg, #4A6FD0);
  box-shadow: var(--tile-glow, none);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.toast__icon {
  width: 74%;
  height: 74%;
  display: block;
  color: inherit;
}

.toast__body {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.toast__eyebrow {
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.toast__name {
  font-size: 15px;
  font-weight: 700;
}

/* ---------------- Ландшафт на низких экранах ---------------- */

/* Низкий ландшафт: поле остаётся главным, второстепенное убираем,
   чтобы ничего не обрезалось границами игровой области (п. 1.10.1) */
@media (orientation: landscape) and (max-height: 560px) {
  .app { gap: 8px; padding-top: 8px; }
  .hint,
  .ladder { display: none; }
  .wordmark__b { font-size: 26px; }
  .score { min-width: 68px; padding: 5px 9px 6px; }
  .score__value { font-size: 17px; }
  .btn { min-height: 40px; }
}

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

/* Узкие экраны: шапка не должна распирать раскладку */
@media (max-width: 360px) {
  .wordmark__b { font-size: 29px; }
  .wordmark__a { font-size: 9.5px; letter-spacing: 0.1em; }
  .score { min-width: 64px; padding: 6px 8px 7px; }
  .score__value { font-size: 18px; }
  .score__label { font-size: 9px; letter-spacing: 0.08em; }
}
