/* ==========================================================================
   2048 — multiplayer board
   ========================================================================== */
.g2048 .gamebar-center { justify-content: center; }
.timer {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 86px; height: 36px; padding: 0 14px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line);
  font: 600 18px/1 var(--font-display); font-variant-numeric: tabular-nums; letter-spacing: 0.02em;
}
.timer.urgent, .timer:has(.urgent) { color: #ff8f8f; border-color: rgba(255, 107, 107, 0.4); animation: pulse 1s ease-in-out infinite; }

.g2048-main {
  flex: 1; min-width: 0; min-height: 0;
  display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px;
  max-width: 1180px; margin: 0 auto; padding: 20px 20px 16px;
}
.g2048-play { min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: var(--board); }
.stat { padding: 10px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.stat small { display: block; color: var(--muted); font-size: 12px; font-weight: 600; }
.stat strong { font: 600 24px/1.15 var(--font-display); font-variant-numeric: tabular-nums; }
.stat strong span { color: var(--faint); font-size: 16px; }

.g2048 { --board: min(460px, calc(100dvh - 300px), calc(100vw - 420px)); }
.board {
  position: relative;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--gap);
  padding: var(--gap); border-radius: calc(var(--gap) * 1.6);
  background: #1d2129;
}
.board.main { --gap: calc(var(--board) * 0.025); width: var(--board); aspect-ratio: 1; outline: none; touch-action: none; }
.board.main:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.cell { position: relative; border-radius: calc(var(--gap) * 1.1); background: rgba(255, 255, 255, 0.045); aspect-ratio: 1; }
.tile {
  position: absolute; inset: 0; border-radius: inherit;
  display: grid; place-items: center;
  font: 700 calc(var(--board) * 0.1) / 1 var(--font-display); color: #776e65;
  transition: background 0.12s;
}
.tile.d3 { font-size: calc(var(--board) * 0.085); }
.tile.d4 { font-size: calc(var(--board) * 0.068); }
.tile.d5 { font-size: calc(var(--board) * 0.056); }
.tile.spawn { animation: t-spawn 0.2s var(--ease) 0.05s backwards; }
.tile.merged { animation: t-merge 0.22s var(--ease); z-index: 1; }
@keyframes t-spawn { from { transform: scale(0.2); opacity: 0; } }
@keyframes t-merge { 50% { transform: scale(1.14); } }

.t-2 { background: #eee4da; }
.t-4 { background: #ede0c8; }
.t-8 { background: #f2b179; color: #fff; }
.t-16 { background: #f59563; color: #fff; }
.t-32 { background: #f67c5f; color: #fff; }
.t-64 { background: #f65e3b; color: #fff; }
.t-128 { background: #edcf72; color: #fff; box-shadow: 0 0 18px rgba(237, 207, 114, 0.25); }
.t-256 { background: #edcc61; color: #fff; box-shadow: 0 0 22px rgba(237, 204, 97, 0.32); }
.t-512 { background: #edc850; color: #fff; box-shadow: 0 0 26px rgba(237, 200, 80, 0.4); }
.t-1024 { background: #edc53f; color: #fff; box-shadow: 0 0 30px rgba(237, 197, 63, 0.48); }
.t-2048 { background: #edc22e; color: #fff; box-shadow: 0 0 36px rgba(237, 194, 46, 0.6); }
.t-super { background: #8b5cf6; color: #fff; box-shadow: 0 0 36px rgba(139, 92, 246, 0.5); }

.board-over {
  position: absolute; inset: 0; z-index: 3; border-radius: inherit;
  display: grid; place-content: center; gap: 6px; text-align: center;
  background: rgba(14, 15, 19, 0.78); backdrop-filter: blur(3px);
  animation: fade 0.3s;
}
.board-over strong { font-size: 26px; }
.board-over span { color: var(--accent); font-weight: 700; }
.board-over small { color: var(--muted); font-size: 13px; }

.controls-hint { color: var(--faint); font-size: 12px; display: flex; align-items: center; gap: 4px; }
kbd {
  display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 5px;
  border-radius: 6px; border: 1px solid var(--line-2); border-bottom-width: 2px;
  color: var(--muted); font: 600 11px var(--font);
}
.dpad { display: none; }

/* live ranking */
.ranking {
  min-height: 0; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; align-self: center; max-height: 100%;
}
.ranking-head { display: flex; align-items: baseline; gap: 10px; padding: 14px 16px 10px; }
.ranking-head span { font-weight: 700; font-size: 14px; display: inline-flex; align-items: center; gap: 8px; }
.ranking-head span::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--red); animation: pulse 1.6s infinite; }
.ranking-head small { color: var(--faint); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; text-align: right; }
.ranking ol { list-style: none; margin: 0; padding: 0 8px 8px; overflow: auto; display: grid; gap: 4px; }
.rank-row {
  position: relative;
  display: grid; grid-template-columns: 18px 34px minmax(0, 1fr) auto; align-items: center; gap: 10px;
  padding: 10px; border-radius: 12px;
  transition: background 0.3s;
}
.rank-row:has(.board) { grid-template-rows: auto auto; }
.rank-row.me { background: var(--accent-soft); }
.rank-row.over { opacity: 0.6; }
.rank-pos { color: var(--faint); font-weight: 700; font-size: 13px; text-align: center; }
.rank-row:first-of-type .rank-pos { color: var(--accent); }
.rank-row .avatar { width: 34px; height: 34px; }
.rank-name strong { display: block; font-size: 14px; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-name small { color: var(--faint); font-size: 12px; }
.rank-score { font: 600 20px var(--font-display); font-variant-numeric: tabular-nums; }
.rank-row .bubble { left: 60px; }
.board.mini { --gap: 3px; grid-column: 3 / -1; width: 100%; max-width: 116px; padding: 3px; border-radius: 7px; background: #1a1d24; }
.board.mini .cell { border-radius: 3px; }
.board.mini .tile { font-size: 0; }
.solo { padding: 4px 18px 16px; color: var(--faint); font-size: 13px; }

/* chat open: keep board visible next to drawer on wide screens */
@media (min-width: 1200px) {
  .g2048.chat-open .g2048-main { padding-right: 360px; }
}

@media (max-width: 960px) {
  .g2048 { --board: min(440px, calc(100vw - 32px), calc(100dvh - 330px)); }
  .g2048 .game-body { overflow-y: auto; }
  .g2048-main { grid-template-columns: 1fr; grid-template-rows: auto auto; align-content: start; padding: 16px; gap: 16px; }
  .ranking { align-self: stretch; }
  .ranking ol { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
  .rank-row:has(.board) { grid-template-columns: 18px 34px minmax(0, 1fr) auto; }
}
@media (max-width: 640px) {
  .g2048 { --board: min(calc(100vw - 24px), calc(100dvh - 330px)); }
  .g2048-main { padding: 12px; gap: 12px; }
  .ranking { order: -1; }
  .ranking-head { padding: 10px 12px 6px; }
  .ranking-head small { display: none; }
  .ranking ol { grid-template-columns: 1fr 1fr; padding: 0 6px 6px; }
  .rank-row, .rank-row:has(.board) { grid-template-columns: 26px minmax(0, 1fr) auto; grid-template-rows: auto; gap: 8px; padding: 6px 8px; }
  .rank-pos, .board.mini, .rank-name small { display: none; }
  .rank-row .avatar { width: 26px; height: 26px; }
  .rank-name strong { font-size: 13px; }
  .rank-score { font-size: 16px; }
  .stat { padding: 7px 10px; }
  .stat strong { font-size: 19px; }
  .timer { min-width: 66px; height: 32px; font-size: 16px; }
  .controls-hint { display: none; }
  .g2048-play { gap: 12px; justify-content: flex-start; }
}
@media (pointer: coarse) {
  .controls-hint { display: none; }
  .dpad { display: grid; grid-template-columns: repeat(4, 52px); gap: 8px; }
  .dpad button { height: 44px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); font-size: 14px; }
  .dpad button:active { background: var(--surface-3); color: var(--text); }
}
