/* Токены платформы (--bg, --surface, --ink, --accent и др.) приходят из shared/theme.css.
   Здесь поле 2048: сетка, плитки по значениям, анимации хода, окна. Общие кнопки и окна — как в «Сапёре». */
:root {
  --game-shadow: 0 2px 0 oklch(0.85 0.01 90), 0 8px 20px -8px oklch(0.3 0.03 260 / .25);
  --focus: oklch(0.55 0.18 260);
  --overlay: oklch(0.15 0.02 260 / .6);
  --board: oklch(0.78 0.03 70); --slot: oklch(0.86 0.025 75);
  --t2: oklch(0.95 0.02 85); --t4: oklch(0.92 0.04 85); --t8: oklch(0.8 0.12 60); --t16: oklch(0.75 0.15 50); --t32: oklch(0.7 0.17 40);
  --t64: oklch(0.64 0.2 32); --t128: oklch(0.86 0.12 95); --t256: oklch(0.84 0.14 95); --t512: oklch(0.82 0.15 92); --t1024: oklch(0.8 0.16 90); --t2048: oklch(0.78 0.17 88);
  --tbig: oklch(0.35 0.03 260); --tink: oklch(0.38 0.03 60); --tlight: oklch(0.99 0.01 90);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --game-shadow: 0 2px 0 oklch(0.16 0.01 260), 0 8px 20px -8px oklch(0 0 0 / .6);
    --focus: oklch(0.78 0.14 260);
    --board: oklch(0.3 0.02 260); --slot: oklch(0.36 0.02 260);
  }
}
:root[data-theme="dark"] {
  --game-shadow: 0 2px 0 oklch(0.16 0.01 260), 0 8px 20px -8px oklch(0 0 0 / .6);
  --focus: oklch(0.78 0.14 260);
  --board: oklch(0.3 0.02 260); --slot: oklch(0.36 0.02 260);
}


* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
button { transition: background-color .2s ease, border-color .2s ease, color .2s ease, transform .15s ease, box-shadow .2s ease; }
button:not(:disabled):active { transform: scale(.97); }
button:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

@keyframes fade-up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes pop-in { from { transform: scale(.82); opacity: .4; } to { transform: scale(1); opacity: 1; } }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes reveal { from { transform: scale(.7); opacity: .2; } to { transform: none; opacity: 1; } }
@keyframes pop { 0% { transform: scale(.6); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes shake-board { 0%, 100% { transform: none; } 20% { transform: translateX(-4px); } 40% { transform: translateX(4px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(2px); } }
@keyframes glow { 0% { box-shadow: var(--game-shadow); } 50% { box-shadow: 0 0 0 6px var(--accent-soft), 0 0 24px var(--accent); } 100% { box-shadow: var(--game-shadow); } }

.app { max-width: 900px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.screen { display: flex; flex-direction: column; gap: 14px; animation: fade-up .35s ease backwards; }
.muted-text { color: var(--muted); line-height: 1.5; margin: 0; }
.noscript { margin: 0; padding: 12px 16px; background: var(--accent-soft); color: var(--ink); text-align: center; }

/* Кнопки */
.theme-btn {
  width: 44px; height: 44px; flex: none; padding: 0; border-radius: 12px; font-size: 20px; font-weight: 700;
  border: 2px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none;
}
.theme-btn svg { width: 22px; height: 22px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.btn-primary, .btn-secondary, .btn-play {
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none; font-family: inherit; cursor: pointer;
}
.btn-primary {
  min-height: 52px; border-radius: 14px; border: none; padding: 0 18px;
  background: var(--accent); color: var(--accent-ink); font-size: 16px; font-weight: 700;
}
.btn-secondary {
  min-height: 52px; border-radius: 14px; border: 2px solid var(--line); padding: 0 18px;
  background: var(--surface); color: var(--ink); font-size: 16px;
}
.btn-secondary.small { min-height: 44px; padding: 0 14px; border-radius: 12px; font-size: 15px; }
.btn-secondary.wide { padding: 0 22px; min-height: clamp(46px, 7vh, 56px); font-size: 17px; }
.btn-play {
  min-height: clamp(46px, 7vh, 56px); border-radius: 14px; border: none; background: var(--accent); color: var(--accent-ink);
  font-size: 18px; font-weight: 700; box-shadow: var(--game-shadow);
}

/* Стартовый экран */
.start {
  max-width: 440px; margin: 0 auto; width: 100%;
  min-height: calc(100vh - 32px); min-height: calc(100dvh - 32px);
  display: flex; flex-direction: column; justify-content: center; gap: clamp(10px, 2.6vh, 24px);
}
.brand-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.hero { display: flex; flex-direction: column; align-items: flex-start; gap: clamp(4px, 1.2vh, 10px); }
.hero h1 { margin: 0; font-size: clamp(32px, 6.5vh, 48px); letter-spacing: -0.02em; line-height: 1; }
.start-actions { display: flex; gap: 10px; }
.start-actions .btn-play { flex: 1; }

/* Баланс в шапке игры */
.bal { display: inline-flex; align-items: center; gap: 5px; height: 32px; padding: 0 10px 0 7px; border-radius: 20px; background: var(--surface); border: 1px solid var(--line); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bal b { font-size: 14px; }
.coin { width: 14px; height: 14px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, oklch(0.92 0.14 95), oklch(0.74 0.16 80)); box-shadow: inset 0 0 0 1.5px oklch(0.62 0.14 75); }
@media (max-width: 380px) { .game-title { display: none; } .screen > .topbar .top-actions:last-child { margin-left: auto; } }

/* Игровой экран */
.screen > .topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.game-title { font-weight: 700; font-size: 17px; text-align: center; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  background: var(--surface); color: var(--ink); font-size: 16px; cursor: pointer;
}
.mode-btn[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); font-weight: 700; }
.hint-touch, .hint-keys { text-align: center; font-size: 14px; }
.hint-keys { display: none; }
@media (hover: hover) and (pointer: fine) {
  .hint-keys { display: block; }
  .hint-touch, .mode { display: none; }
}

/* Окна */
.overlay {
  position: fixed; inset: 0; background: var(--overlay); z-index: 10;
  display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade-in .22s ease both;
}
.overlay.closing { animation: fade-out .18s ease forwards; }
.dialog {
  animation: pop-in .28s cubic-bezier(.2, .8, .3, 1) both; background: var(--surface); width: 100%; max-width: 400px;
  border-radius: var(--r-win); padding: 24px; display: flex; flex-direction: column; gap: 14px;
}
.dialog h2 { margin: 0; font-size: 28px; }
.dialog small { font-size: 14px; color: var(--muted); }
.dialog-actions { display: flex; gap: 10px; }
.dialog-actions > * { flex: 1; }
.end { text-align: center; align-items: stretch; }
.big-time { font-size: 56px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.record { color: var(--accent); font-weight: 800; font-size: 18px; }
.reward { color: var(--accent); font-weight: 800; font-size: 18px; }
.end-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.sheet-overlay { align-items: flex-end; padding: 0; }
.sheet-overlay .dialog { animation: sheet-up .32s cubic-bezier(.2, .8, .3, 1) both; }
.dialog.rules { max-width: 560px; max-height: 88vh; overflow: auto; border-radius: 24px 24px 0 0; padding: 22px; gap: 16px; }
.rules-head { display: flex; justify-content: space-between; align-items: center; }
.rules-head h2 { font-size: 26px; }
.rule { display: flex; flex-direction: column; gap: 6px; }
.rule span { color: var(--muted); line-height: 1.5; }

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

/* Стартовый экран */
.logo { display: grid; grid-template-columns: repeat(4, 44px); gap: 6px; }
.logo .tile { position: static; width: 44px; height: 44px; font-size: 18px; transform: none; animation: none; }
.logo .tile.small { font-size: 13px; }
.scores { display: flex; gap: 10px; }
.rewards-note { font-size: 14px; }

/* Игровой экран */
.screen:has(.board) { max-width: 520px; margin: 0 auto; width: 100%; align-items: stretch; }
.hud { display: flex; gap: 10px; align-items: stretch; }
.hud .btn-secondary.small { margin-left: auto; align-self: center; }
.score-box { display: flex; flex-direction: column; justify-content: center; min-width: 88px; padding: 6px 14px; border-radius: 14px; background: var(--surface); box-shadow: var(--game-shadow); }
.score-box small { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.score-box b { font-size: 22px; font-variant-numeric: tabular-nums; line-height: 1.15; }
.toast { min-height: 40px; display: flex; align-items: center; justify-content: center; padding: 8px 14px; border-radius: 12px; background: var(--accent-soft); color: var(--ink); font-weight: 700; text-align: center; animation: fade-up .25s ease both; }
.toast.dim { font-weight: 500; color: var(--muted); }
.toast.empty { background: none; animation: none; }

.board-wrap { display: flex; justify-content: center; }
.board {
  --gap: clamp(8px, 2.4vw, 12px);
  position: relative; width: min(100%, 460px); aspect-ratio: 1; border-radius: 16px; background: var(--board); box-shadow: var(--game-shadow);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; outline: none;
}
.board:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.cells { position: absolute; inset: var(--gap); display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--gap); }
.cells i { border-radius: 10px; background: var(--slot); }
.tiles { position: absolute; inset: var(--gap); }
.tile {
  position: absolute; left: 0; top: 0; width: calc((100% - 3 * var(--gap)) / 4); height: calc((100% - 3 * var(--gap)) / 4); border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: clamp(22px, 8vw, 44px); font-variant-numeric: tabular-nums;
  color: var(--tink); background: var(--t2); line-height: 1;
  transform: translate(calc(var(--x) * (100% + var(--gap))), calc(var(--y) * (100% + var(--gap))));    /* проценты сдвига — от размера самой плитки */
  transition: transform .11s ease-in-out;
}
.tile.small { font-size: clamp(18px, 6.4vw, 34px); }
.tile.tiny { font-size: clamp(14px, 5vw, 26px); }
.tile.v4 { background: var(--t4); }
.tile.v8 { background: var(--t8); color: var(--tlight); } .tile.v16 { background: var(--t16); color: var(--tlight); } .tile.v32 { background: var(--t32); color: var(--tlight); }
.tile.v64 { background: var(--t64); color: var(--tlight); }
.tile.v128 { background: var(--t128); } .tile.v256 { background: var(--t256); } .tile.v512 { background: var(--t512); }
.tile.v1024 { background: var(--t1024); } .tile.v2048 { background: var(--t2048); box-shadow: 0 0 22px oklch(0.85 0.15 90 / .55); }
.tile.vbig { background: var(--tbig); color: var(--tlight); }
.tile.fresh { animation: tile-in .18s ease .06s backwards; }
.tile.merged { animation: tile-pop .18s ease; z-index: 1; }
@keyframes tile-in { from { opacity: 0; scale: .3; } to { opacity: 1; scale: 1; } }
@keyframes tile-pop { 0% { scale: .8; } 55% { scale: 1.14; } 100% { scale: 1; } }
.board.nudge-left { animation: nudge-x .18s ease; --n: -5px; } .board.nudge-right { animation: nudge-x .18s ease; --n: 5px; }
.board.nudge-up { animation: nudge-y .18s ease; --n: -5px; } .board.nudge-down { animation: nudge-y .18s ease; --n: 5px; }
@keyframes nudge-x { 50% { translate: var(--n) 0; } }
@keyframes nudge-y { 50% { translate: 0 var(--n); } }
.live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.hint-touch, .hint-keys { text-align: center; font-size: 14px; }
.hint-keys { display: none; }
@media (hover: hover) and (pointer: fine) { .hint-keys { display: block; } .hint-touch { display: none; } }
.big-score { font-size: 52px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
@media (max-width: 360px) { .score-box { min-width: 72px; padding: 6px 10px; } .score-box b { font-size: 19px; } }
