.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.stat-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.stat-row:first-child {
  padding-top: 0;
}

.stat-row__label {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.stat-row__value {
  font-family: var(--font-display);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  font-size: 1.15rem;
}

.panel--left .btn + .btn {
  margin-top: 10px;
}

.howto {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.55;
}

.leaderboard-my-best {
  margin: 0 0 12px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.panel__block.leaderboard .leaderboard-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.howto strong {
  color: var(--g2048-ui-accent, var(--green));
}

body[data-g2048-bg] .bg-glow--green {
  background: radial-gradient(circle, var(--g2048-page-glow-a, rgba(112, 255, 26, 0.15)), transparent 65%);
}

body[data-g2048-bg] .bg-glow--orange {
  background: radial-gradient(circle, var(--g2048-page-glow-b, rgba(255, 114, 24, 0.1)), transparent 65%);
}

body[data-g2048-bg] .bg-grid {
  background-image:
    linear-gradient(var(--g2048-page-grid, rgba(168, 255, 31, 0.035)) 1px, transparent 1px),
    linear-gradient(90deg, var(--g2048-page-grid, rgba(168, 255, 31, 0.035)) 1px, transparent 1px);
}

.controls-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.controls-list kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 2px 7px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  text-align: center;
}

.board-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  min-width: 0;
}

.board-shell {
  --board-size: min(72vw, 420px);
  --gap: 10px;
  --cell: calc((var(--board-size) - var(--gap) * 5) / 4);
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  padding: var(--gap);
  border-radius: 22px;
  background: var(--g2048-board-bg,
    linear-gradient(160deg, rgba(184, 255, 46, 0.08), transparent 40%),
    linear-gradient(145deg, #151c27, #0c121a));
  border: 1px solid var(--g2048-board-border, var(--border));
  box-shadow: var(--shadow);
  touch-action: none;
  user-select: none;
}

.board-shell[data-g2048-model="orbita"] {
  box-shadow:
    var(--shadow),
    0 0 28px rgba(92, 141, 255, 0.12),
    inset 0 0 40px rgba(32, 242, 242, 0.04);
}

.board-shell[data-g2048-model="bezdna"] {
  box-shadow:
    var(--shadow),
    0 0 28px rgba(123, 220, 181, 0.12),
    inset 0 0 40px rgba(72, 202, 228, 0.05);
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(4, var(--cell));
  grid-template-rows: repeat(4, var(--cell));
  gap: var(--gap);
  width: 100%;
  height: 100%;
}

.board-cell {
  border-radius: 12px;
  background: var(--g2048-cell-bg, rgba(255, 255, 255, 0.04));
  border: 1px solid var(--g2048-cell-border, rgba(255, 255, 255, 0.04));
}

.board-tiles {
  position: absolute;
  inset: var(--gap);
  pointer-events: none;
}

.tile {
  position: absolute;
  width: var(--cell);
  height: var(--cell);
  display: grid;
  place-items: center;
  border-radius: 12px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.1rem, 5vw, 1.85rem);
  color: #0a0f14;
  transition: transform 120ms ease-in-out, background 160ms ease, color 160ms ease, box-shadow 160ms ease;
  will-change: transform;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.15);
}

.tile--spawn {
  animation: tileSpawn 160ms ease-out;
}

.tile--merge {
  animation: tileMerge 180ms ease-out;
}

.tile[data-value="2"] {
  background: var(--g2048-tile-2, linear-gradient(145deg, #d7dee8, #b8c2d1));
  color: var(--g2048-tile-text-2, #0a0f14);
  box-shadow: 0 0 18px var(--g2048-tile-glow-2, transparent), inset 0 -2px 0 rgba(0, 0, 0, 0.12);
}
.tile[data-value="4"] {
  background: var(--g2048-tile-4, linear-gradient(145deg, #c5d0e0, #9eacc2));
  color: var(--g2048-tile-text-4, #0a0f14);
  box-shadow: 0 0 18px var(--g2048-tile-glow-4, transparent), inset 0 -2px 0 rgba(0, 0, 0, 0.12);
}
.tile[data-value="8"] {
  background: var(--g2048-tile-8, linear-gradient(145deg, #ffc56e, #ff9f1a));
  color: var(--g2048-tile-text-8, #1a1208);
  box-shadow: 0 0 18px var(--g2048-tile-glow-8, transparent), inset 0 -2px 0 rgba(0, 0, 0, 0.12);
}
.tile[data-value="16"] {
  background: var(--g2048-tile-16, linear-gradient(145deg, #ff9f5a, #f07316));
  color: var(--g2048-tile-text-16, #1a1008);
  box-shadow: 0 0 18px var(--g2048-tile-glow-16, transparent), inset 0 -2px 0 rgba(0, 0, 0, 0.12);
}
.tile[data-value="32"] {
  background: var(--g2048-tile-32, linear-gradient(145deg, #ff7b7b, #e23d3d));
  color: var(--g2048-tile-text-32, #1a0808);
  box-shadow: 0 0 18px var(--g2048-tile-glow-32, transparent), inset 0 -2px 0 rgba(0, 0, 0, 0.12);
}
.tile[data-value="64"] {
  background: var(--g2048-tile-64, linear-gradient(145deg, #ff5ca8, #d62472));
  color: var(--g2048-tile-text-64, #180810);
  box-shadow: 0 0 18px var(--g2048-tile-glow-64, transparent), inset 0 -2px 0 rgba(0, 0, 0, 0.12);
}
.tile[data-value="128"] {
  background: var(--g2048-tile-128, linear-gradient(145deg, #d8ff6a, #b8ff2e));
  color: var(--g2048-tile-text-128, #0a0f14);
  box-shadow: 0 0 22px var(--g2048-tile-glow-128, rgba(184, 255, 46, 0.28)), inset 0 -2px 0 rgba(0, 0, 0, 0.12);
  font-size: clamp(1rem, 4.4vw, 1.55rem);
}
.tile[data-value="256"] {
  background: var(--g2048-tile-256, linear-gradient(145deg, #a8ff55, #7ed321));
  color: var(--g2048-tile-text-256, #0a0f14);
  box-shadow: 0 0 24px var(--g2048-tile-glow-256, rgba(126, 211, 33, 0.3)), inset 0 -2px 0 rgba(0, 0, 0, 0.12);
  font-size: clamp(1rem, 4.4vw, 1.55rem);
}
.tile[data-value="512"] {
  background: var(--g2048-tile-512, linear-gradient(145deg, #6ef0ff, #2bb8d4));
  color: var(--g2048-tile-text-512, #041218);
  box-shadow: 0 0 24px var(--g2048-tile-glow-512, rgba(43, 184, 212, 0.3)), inset 0 -2px 0 rgba(0, 0, 0, 0.12);
  font-size: clamp(1rem, 4.4vw, 1.55rem);
}
.tile[data-value="1024"] {
  background: var(--g2048-tile-1024, linear-gradient(145deg, #c29bff, #8a4de8));
  color: var(--g2048-tile-text-1024, #120820);
  box-shadow: 0 0 26px var(--g2048-tile-glow-1024, rgba(138, 77, 232, 0.32)), inset 0 -2px 0 rgba(0, 0, 0, 0.12);
  font-size: clamp(0.9rem, 3.8vw, 1.3rem);
}
.tile[data-value="2048"] {
  background: var(--g2048-tile-2048, linear-gradient(145deg, #ffe23c, #ff9f1a));
  color: var(--g2048-tile-text-2048, #1a1205);
  box-shadow: 0 0 30px var(--g2048-tile-glow-2048, rgba(255, 159, 26, 0.4)), inset 0 -2px 0 rgba(0, 0, 0, 0.12);
  font-size: clamp(0.9rem, 3.8vw, 1.3rem);
}
.tile[data-value="4096"],
.tile[data-value="8192"],
.tile[data-value="16384"],
.tile[data-value="32768"],
.tile[data-value="65536"] {
  background: var(--g2048-tile-4096, linear-gradient(145deg, #ff4d9d, #b81f6a));
  color: var(--g2048-tile-text-4096, #1a0610);
  box-shadow: 0 0 28px var(--g2048-tile-glow-4096, rgba(255, 77, 157, 0.35)), inset 0 -2px 0 rgba(0, 0, 0, 0.12);
  font-size: clamp(0.8rem, 3.4vw, 1.15rem);
}

body[data-g2048-style="flat"] .tile {
  box-shadow: none !important;
  border-radius: 10px;
}

body[data-g2048-style="outline"] .tile {
  background: rgba(8, 12, 18, 0.55) !important;
  border: 2px solid var(--g2048-ui-accent, #a8ff1f);
  box-shadow: none !important;
  color: var(--g2048-ui-accent, #a8ff1f) !important;
}

body[data-g2048-style="outline"] .tile[data-value="128"],
body[data-g2048-style="outline"] .tile[data-value="256"],
body[data-g2048-style="outline"] .tile[data-value="512"],
body[data-g2048-style="outline"] .tile[data-value="1024"],
body[data-g2048-style="outline"] .tile[data-value="2048"],
body[data-g2048-style="outline"] .tile[data-value="4096"],
body[data-g2048-style="outline"] .tile[data-value="8192"],
body[data-g2048-style="outline"] .tile[data-value="16384"],
body[data-g2048-style="outline"] .tile[data-value="32768"],
body[data-g2048-style="outline"] .tile[data-value="65536"] {
  border-color: var(--g2048-tile-text-2048, #ffe23c);
  color: var(--g2048-tile-text-2048, #ffe23c) !important;
}

@keyframes tileSpawn {
  from { transform: scale(0.35); opacity: 0; }
  to { opacity: 1; }
}

@keyframes tileMerge {
  0% { transform: scale(1); }
  45% { transform: scale(1.14); }
  100% { transform: scale(1); }
}

.board-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  border-radius: 22px;
  background: rgba(7, 10, 14, 0.78);
  backdrop-filter: blur(6px);
  z-index: 3;
}

.board-overlay.hidden {
  display: none;
}

.board-overlay h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.6rem;
}

.board-overlay p {
  margin: 0 0 8px;
  color: var(--text-muted);
}

.board-overlay__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.board-overlay__actions .hidden {
  display: none;
}

.touch-controls {
  display: none;
  width: min(72vw, 280px);
  gap: 8px;
}

.touch-controls__row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.touch-btn {
  min-height: 48px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-card);
  color: var(--text);
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
}

.touch-btn--wide {
  width: 100%;
  margin-bottom: 8px;
}

.touch-btn:active {
  background: color-mix(in srgb, var(--g2048-ui-accent, #b8ff2e) 12%, transparent);
  border-color: color-mix(in srgb, var(--g2048-ui-accent, #b8ff2e) 35%, transparent);
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .panel--left,
  .panel--right {
    order: 2;
  }

  .board-wrap {
    order: 1;
  }

  .panel--right {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }

  .panel--right .panel__block {
    margin-bottom: 0;
  }
}

@media (max-width: 720px) {
  .header__stats {
    order: 3;
    width: 100%;
    margin-left: 0;
  }

  .board-shell {
    --board-size: min(92vw, 420px);
    --gap: 8px;
  }

  .touch-controls {
    display: grid;
  }

  .panel--right {
    grid-template-columns: 1fr;
  }
}
