/* =====================================================================
   2048 — стили игры
   Использует дизайн-токены из base.css (:root).
   Все правила ограничены классом .game-2048, чтобы не задевать сайт.
   ===================================================================== */

.game-2048 {
    max-width: 520px;
    margin-inline: auto;
}

/* ---------- Шапка игры ---------- */
.game-2048__head {
    text-align: center;
    margin-bottom: 1.1rem;
}
.logo-tiles {
    display: inline-flex;
    gap: .28rem;
    font-size: clamp(1.6rem, 6vw, 2.3rem);
    font-weight: 800;
    letter-spacing: .02em;
    line-height: 1;
}
.logo-tiles span {
    display: inline-grid;
    place-items: center;
    width: 1.5em;
    height: 1.5em;
    border-radius: var(--radius-sm);
    color: var(--ink);
}
.logo-tiles span:nth-child(1) { background: #F3D9CB; }
.logo-tiles span:nth-child(2) { background: #DCE8D4; }
.logo-tiles span:nth-child(3) { background: #C75B2C; color: #fff; }
.logo-tiles span:nth-child(4) { background: #A8481F; color: #fff; }
.game-2048__lead {
    color: var(--ink-muted);
    margin-top: .5rem;
    font-size: .98rem;
}

/* ---------- Подсказка ---------- */
.game-2048__help {
    font-size: .9rem;
    color: var(--ink-muted);
    text-align: center;
    margin-bottom: 1rem;
    line-height: 1.5;
}
.game-2048__help kbd {
    font: inherit;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: 5px;
    padding: 0 .3rem;
    font-size: .82rem;
}

/* ---------- Счета ---------- */
.scores-2048 {
    display: flex;
    justify-content: center;
    gap: .6rem;
    margin-bottom: 1.1rem;
}
.score-box {
    position: relative;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: .45rem .9rem;
    text-align: center;
    min-width: 96px;
    box-shadow: var(--shadow-sm);
}
.score-box__label {
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--ink-muted);
    font-weight: 700;
}
.score-box__value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--ink);
    line-height: 1.15;
    font-variant-numeric: tabular-nums;
}
.score-box--best .score-box__value { color: var(--terracotta-d); }
.score-box__add {
    position: absolute;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
    font-size: 1rem;
    font-weight: 800;
    color: var(--sage-d);
    opacity: 0;
    pointer-events: none;
}
.score-box__add.is-active {
    animation: g2048-add .8s ease-in-out;
}

/* ---------- Доска ---------- */
.board-2048 {
    --cell: clamp(58px, 17vw, 86px);
    --gap: 10px;
    position: relative;
    width: fit-content;
    margin-inline: auto;
    padding: var(--gap);
    background: var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    touch-action: none;
}
.tile-container-2048 {
    position: relative;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: var(--gap);
    width: calc(4 * var(--cell) + 3 * var(--gap));
    aspect-ratio: 1;
}
/* Фоновые ячейки — статичная CSS-сетка, симметрия гарантируется вёрсткой */
.cell-bg {
    background: var(--card);
    opacity: .55;
    border-radius: var(--radius-sm);
}
/* Плитки позиционируются в JS по реальной геометрии ячеек (offset*),
   поэтому размер/позицию НЕ читаем из CSS-переменных — измеряем DOM. */
.tile-2048 {
    position: absolute;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: #fff;
    font-size: calc(var(--cell) * 0.42);
    line-height: 1;
    border-radius: var(--radius-sm);
    box-sizing: border-box;
    transition: top 110ms ease-in-out, left 110ms ease-in-out;
    will-change: top, left;
}

/* Тёплая шкала: кремовый → терракота → глубокий коричневый.
   Чем больше значение, тем насыщеннее и темнее плитка. */
.tile-2048[data-v="2"]    { background: #F4EBDA; color: var(--ink); }
.tile-2048[data-v="4"]    { background: #EFD9BE; color: var(--ink); }
.tile-2048[data-v="8"]    { background: #E9BC8E; color: var(--ink); }
.tile-2048[data-v="16"]   { background: #E29F63; }
.tile-2048[data-v="32"]   { background: #D98244; }
.tile-2048[data-v="64"]   { background: #C75B2C; }
.tile-2048[data-v="128"]  { background: #B14E22; font-size: calc(var(--cell) * 0.36); }
.tile-2048[data-v="256"]  { background: #9A4118; font-size: calc(var(--cell) * 0.36); }
.tile-2048[data-v="512"]  { background: #823312; font-size: calc(var(--cell) * 0.36); }
.tile-2048[data-v="1024"] { background: #6B2710; font-size: calc(var(--cell) * 0.30); }
.tile-2048[data-v="2048"] {
    background: #531D0B;
    font-size: calc(var(--cell) * 0.30);
    box-shadow: 0 0 0 3px var(--terracotta), 0 4px 14px rgba(199, 91, 44, .45);
}
.tile-2048[data-v="4096"],
.tile-2048[data-v="8192"],
.tile-2048[data-v="16384"] { background: #3A1408; font-size: calc(var(--cell) * 0.26); }

.tile-2048--pop {
    animation: g2048-pop .26s ease-in-out forwards;
}
.tile-2048--shrink {
    animation: g2048-shrink .12s ease-in-out forwards;
}

/* ---------- Конец игры ---------- */
.end-2048 {
    position: absolute;
    inset: 0;
    z-index: -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .75rem;
    background: rgba(58, 46, 42, .88);
    color: #fff;
    border-radius: var(--radius);
    opacity: 0;
    transition: opacity .3s ease-in-out;
    text-align: center;
    padding: 1rem;
}
.end-2048.is-active {
    opacity: 1;
    z-index: 1000;
}
.end-2048__title { font-size: 1.8rem; font-weight: 800; }
.end-2048__face { font-size: 2.6rem; line-height: 1; }

/* ---------- Кнопка снизу ---------- */
.game-2048__actions {
    display: flex;
    justify-content: center;
    margin-top: 1.4rem;
}

/* ---------- Анимации ---------- */
@keyframes g2048-pop {
    0%   { transform: scale(.5); opacity: 0; }
    90%  { transform: scale(1.12); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}
@keyframes g2048-shrink {
    0%   { transform: scale(1); opacity: 1; }
    100% { transform: scale(.9); opacity: .85; }
}
@keyframes g2048-add {
    0%   { opacity: 1; top: 0; }
    100% { opacity: 0; top: -120%; }
}

@media (prefers-reduced-motion: reduce) {
    .tile-2048 { transition: none !important; }
    .tile-2048--pop,
    .tile-2048--shrink,
    .score-box__add.is-active { animation: none !important; }
}
