/* WEB PANEL PROXY public CSS */
* {
    box-sizing: border-box;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
  html, body {
    height: 100%;
    margin: 0;
  }
  body {
    background: radial-gradient(circle at 50% 15%, #2b2418 0%, #14100a 80%);
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Segoe UI', system-ui, sans-serif;
    color: #f5ede0;
    padding: 12px;
    overflow: hidden;
  }
  .game-wrapper {
    background: #1d1811;
    padding: 18px 22px 22px;
    border-radius: 28px;
    box-shadow: 0 22px 44px rgba(0,0,0,.85), inset 0 0 0 1px rgba(255,210,140,.14);
    max-width: 100%;
  }
  .top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    flex-wrap: wrap;
  }
  .title {
    font-size: 42px;
    font-weight: 800;
    letter-spacing: 1px;
    margin: 0;
    background: linear-gradient(180deg, #ffe9a8, #e6a52a 70%, #a86a12);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: 0 3px 10px rgba(255,180,60,.25);
  }
  .scores {
    display: flex;
    gap: 10px;
  }
  .score-box {
    background: #3a3123;
    padding: 8px 18px;
    border-radius: 12px;
    text-align: center;
    min-width: 90px;
    box-shadow: inset 0 3px 8px #16110a, 0 3px 0 #100c07;
    border-bottom: 2px solid #564a34;
  }
  .score-box .label {
    font-size: 11px;
    letter-spacing: 1.5px;
    color: #b8a686;
    font-weight: 700;
    text-transform: uppercase;
  }
  .score-box .value {
    font-size: 22px;
    font-weight: 800;
    color: #ffd966;
    line-height: 1.15;
  }

  .board-wrap {
    position: relative;
    width: 460px;
    max-width: 100%;
    aspect-ratio: 1 / 1;
    margin: 0 auto;
  }
  .board {
    position: absolute;
    inset: 0;
    background: #4a3f2c;
    border-radius: 16px;
    padding: 12px;
    box-shadow: 0 0 0 3px #2c2418, inset 0 0 40px rgba(0,0,0,.5);
    overflow: hidden;
  }

  /* Фон-сетка из пустых ячеек */
  .grid-bg {
    position: absolute;
    inset: 12px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 12px;
    pointer-events: none;
  }
  .grid-bg .cell {
    background: rgba(238, 220, 180, .10);
    border-radius: 10px;
  }

  /* Слой с плитками */
  .tiles-layer {
    position: absolute;
    inset: 12px;
    pointer-events: none;
  }

  /* Позиция и размер плитки задаются JS-переменными */
  .tile {
    position: absolute;
    /* --cell-size, --gap, --col, --row задаются в JS */
    left: 0;
    top: 0;
    width: var(--cell-size, 100px);
    height: var(--cell-size, 100px);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: min(9vmin, 42px);
    line-height: 1;
    color: #4a3f2c;
    /* смещение в клетку */
    transform: translate(
      calc(var(--col, 0) * (var(--cell-size) + var(--gap, 12px))),
      calc(var(--row, 0) * (var(--cell-size) + var(--gap, 12px)))
    );
    transition: transform .13s ease-in-out;
    will-change: transform;
    box-shadow: inset 0 0 0 2px rgba(255,255,255,.06);
    overflow: hidden;
  }
  /* Только что созданная плитка — анимация появления */
  .tile.spawn {
    animation: spawn .18s ease-out;
  }
  @keyframes spawn {
    0% { transform:
      translate(
        calc(var(--col, 0) * (var(--cell-size) + var(--gap, 12px))),
        calc(var(--row, 0) * (var(--cell-size) + var(--gap, 12px)))
      ) scale(0);
    }
    100% { transform:
      translate(
        calc(var(--col, 0) * (var(--cell-size) + var(--gap, 12px))),
        calc(var(--row, 0) * (var(--cell-size) + var(--gap, 12px)))
      ) scale(1);
    }
  }
  /* Слияние — короткое увеличение */
  .tile.merged {
    animation: pop .18s ease-out;
  }
  @keyframes pop {
    0%, 100% {
      transform: translate(
        calc(var(--col, 0) * (var(--cell-size) + var(--gap, 12px))),
        calc(var(--row, 0) * (var(--cell-size) + var(--gap, 12px)))
      ) scale(1);
    }
    50% {
      transform: translate(
        calc(var(--col, 0) * (var(--cell-size) + var(--gap, 12px))),
        calc(var(--row, 0) * (var(--cell-size) + var(--gap, 12px)))
      ) scale(1.16);
    }
  }

  /* Меньший шрифт для многозначных */
  .tile.t128,
  .tile.t256,
  .tile.t512 { font-size: min(7.5vmin, 34px); }
  .tile.t1024,
  .tile.t2048 { font-size: min(6vmin, 28px); }
  .tile.tsuper { font-size: min(5vmin, 24px); }

  .t2     { background: #eee4da; color: #776e65; }
  .t4     { background: #ede0c8; color: #776e65; }
  .t8     { background: #f2b179; color: #f9f6f2; }
  .t16    { background: #f59563; color: #f9f6f2; }
  .t32    { background: #f67c5f; color: #f9f6f2; }
  .t64    { background: #f65e3b; color: #f9f6f2; }
  .t128   { background: #edcf72; color: #f9f6f2; }
  .t256   { background: #edcc61; color: #f9f6f2; }
  .t512   { background: #edc850; color: #f9f6f2; }
  .t1024  { background: #edc53f; color: #f9f6f2; }
  .t2048  { background: linear-gradient(180deg, #ffd966, #edc22e); color: #f9f6f2; box-shadow: 0 0 24px rgba(255,215,90,.7); }
  .tsuper { background: linear-gradient(180deg, #a06bff, #5c2bd6); color: #fff; }

  .overlay {
    position: absolute;
    inset: 0;
    background: rgba(28, 22, 14, .88);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    text-align: center;
    padding: 20px;
    z-index: 10;
  }
  .overlay.win { background: rgba(52, 40, 16, .92); }
  .overlay h2 {
    margin: 0;
    font-size: 38px;
    letter-spacing: 2px;
    color: #ffd966;
    text-shadow: 0 0 26px rgba(255,210,80,.7);
  }
  .overlay p {
    margin: 0;
    font-size: 15px;
    color: #cbb88f;
    max-width: 320px;
    line-height: 1.55;
  }
  .overlay .big-score {
    font-size: 28px;
    font-weight: 800;
    color: #7ee8c0;
    text-shadow: 0 0 18px rgba(110,240,190,.5);
  }
  .btn {
    margin-top: 4px;
    background: linear-gradient(180deg, #d9a53a, #a8781d);
    border: 0;
    color: #2a1e0c;
    font-weight: 800;
    font-size: 16px;
    letter-spacing: 1px;
    padding: 12px 34px;
    border-radius: 40px;
    box-shadow: 0 5px 0 #5e420e, 0 9px 16px rgba(0,0,0,.6);
    cursor: pointer;
    transition: transform .07s ease, box-shadow .07s ease;
    font-family: inherit;
  }
  .btn:active {
    transform: translateY(4px);
    box-shadow: 0 1px 0 #5e420e, 0 5px 10px rgba(0,0,0,.6);
  }
  .btn.ghost {
    background: transparent;
    color: #e6cf9a;
    box-shadow: inset 0 0 0 2px #7a5c22;
    padding: 10px 26px;
    font-size: 14px;
  }
  .btn.ghost:active {
    transform: translateY(2px);
    box-shadow: inset 0 0 0 2px #7a5c22;
  }
  .controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 14px;
    flex-wrap: wrap;
  }
  .ctrl-btn {
    background: #3a3123;
    border: 0;
    color: #f0e2c8;
    font-weight: 700;
    font-size: 14px;
    padding: 10px 22px;
    border-radius: 12px;
    box-shadow: 0 4px 0 #100c07;
    cursor: pointer;
    font-family: inherit;
    transition: transform .06s ease, box-shadow .06s ease;
  }
  .ctrl-btn:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 #100c07;
  }
  .hint {
    text-align: center;
    margin-top: 12px;
    color: #8a7856;
    font-size: 12.5px;
    line-height: 1.5;
  }
  .dpad {
    display: none;
    justify-content: center;
    align-items: center;
    margin-top: 14px;
    gap: 8px;
    flex-direction: column;
  }
  .dpad-row { display: flex; gap: 8px; }
  .dpad-btn {
    width: 58px;
    height: 58px;
    background: #3a3123;
    border: 0;
    color: #ffd966;
    font-size: 22px;
    border-radius: 14px;
    box-shadow: 0 4px 0 #100c07;
    cursor: pointer;
    font-family: inherit;
    touch-action: manipulation;
  }
  .dpad-btn:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 #100c07;
  }
  @media (hover: none) and (pointer: coarse) {
    .dpad { display: flex; }
    .hint { display: none; }
  }