.arcade-page .task-layout {
  grid-template-columns: minmax(0, 1fr) 280px;
}

.arcade-panel {
  overflow: hidden;
  font-family: "Outfit", "Segoe UI", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

.arcade-shell {
  display: grid;
  gap: 16px;
}

.arcade-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 18px 20px;
  border: 1px solid rgba(244, 168, 0, 0.35);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(28, 16, 0, 0.96), rgba(81, 47, 0, 0.92)),
    #1c1000;
  color: #fff9e6;
  box-shadow: 0 14px 34px rgba(28, 16, 0, 0.18);
}

.arcade-hero-copy {
  display: grid;
  gap: 7px;
}

.arcade-hero-copy strong {
  font-size: clamp(28px, 3.6vw, 44px);
  line-height: 1.05;
  letter-spacing: 0;
}

.arcade-hero-copy p {
  max-width: 640px;
  margin: 0;
  color: rgba(255, 249, 230, 0.78);
  font-size: 14px;
  font-weight: 700;
}

.arcade-hero-ducks {
  display: flex;
  align-items: center;
}

.arcade-hero-ducks img {
  width: clamp(58px, 9vw, 92px);
  height: clamp(58px, 9vw, 92px);
  object-fit: contain;
  margin-left: -14px;
  border-radius: var(--radius-lg);
  background: rgba(255, 249, 230, 0.12);
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.28));
}

.arcade-hero-ducks img:nth-child(2) {
  width: clamp(76px, 11vw, 116px);
  height: clamp(76px, 11vw, 116px);
  z-index: 1;
}

.arcade-hud {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  align-items: stretch;
}

.hud-card,
.mission-card,
.power-card,
.item-legend,
.mascot-card,
.rules-card {
  border: 1px solid var(--duck-cream-2);
  border-radius: var(--radius);
  background: #fffdf2;
  box-shadow: var(--shadow-soft);
}

.hud-card {
  min-height: 78px;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  column-gap: 9px;
  row-gap: 3px;
  padding: 12px;
  position: relative;
  overflow: hidden;
  min-width: 0;
}

.hud-card::after {
  content: "";
  position: absolute;
  inset: auto -18px -26px auto;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: rgba(255, 215, 0, 0.18);
}

.hud-card img {
  grid-row: span 2;
  width: 38px;
  height: 38px;
  object-fit: contain;
  position: relative;
  z-index: 1;
}

.hud-card span,
.arcade-kicker {
  color: #7a4a00;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hud-card strong {
  color: #1c1000;
  font-size: 24px;
  line-height: 1;
  position: relative;
  z-index: 1;
}

.hud-card--wide {
  background: linear-gradient(135deg, #fff8d0, #eff6ff);
}

.arcade-stage {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(260px, 292px);
  gap: 16px;
  align-items: stretch;
}

.arcade-board {
  position: relative;
  min-height: 520px;
  border-radius: var(--radius);
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(255, 215, 0, 0.18), transparent 34%),
    radial-gradient(circle at 76% 16%, rgba(74, 144, 217, 0.24), transparent 26%),
    #111827;
  border: 1px solid rgba(28, 16, 0, 0.15);
  box-shadow: 0 14px 44px rgba(28, 16, 0, 0.20);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: auto;
  max-height: min(72vh, 720px);
  aspect-ratio: 1;
  background: transparent;
  box-shadow: none;
}

.arcade-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  padding: 24px;
  color: #fff9e6;
  text-align: center;
  background: rgba(10, 10, 18, 0.58);
  backdrop-filter: blur(4px);
}

.arcade-overlay[hidden] {
  display: none;
}

.arcade-overlay img {
  width: 138px;
  height: 138px;
  object-fit: contain;
  filter: drop-shadow(0 12px 26px rgba(0, 0, 0, 0.36));
}

.arcade-overlay strong {
  font-size: clamp(28px, 5vw, 54px);
  line-height: 1;
}

.arcade-overlay span {
  max-width: 340px;
  color: rgba(255, 249, 230, 0.82);
  font-size: 14px;
  font-weight: 700;
}

.arcade-side {
  display: grid;
  gap: 12px;
  align-content: start;
}

.mission-card,
.power-card,
.item-legend,
.rules-card {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.mascot-card {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 10px;
  align-items: center;
  padding: 12px;
  background: linear-gradient(135deg, #fffdf2, #eff6ff);
  height: 112px;
  min-height: 112px;
  max-height: 112px;
}

.mascot-card img,
.card-head img {
  width: 54px;
  height: 54px;
  object-fit: contain;
  filter: drop-shadow(0 5px 10px rgba(28, 16, 0, 0.14));
}

.mascot-card > div {
  min-width: 0;
  overflow: hidden;
}

.mascot-card strong {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 4px;
  font-size: clamp(11px, 1vw, 13px);
  line-height: 1.3;
  word-break: break-word;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-head img {
  width: 34px;
  height: 34px;
}

.mission-card strong {
  font-size: 17px;
}

.mission-card p {
  margin: 0;
  color: var(--duck-muted);
  font-size: 13px;
  font-weight: 800;
}

.mission-bar {
  height: 10px;
  overflow: hidden;
  border-radius: 99px;
  background: #f5e4be;
}

.mission-bar span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--duck-yellow), var(--duck-blue));
  transition: width 0.18s ease;
}

.power-row,
.item-legend div {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  min-height: 28px;
  color: var(--duck-muted);
  font-size: 12px;
  font-weight: 800;
}

.rules-card p {
  margin: 0;
  color: var(--duck-muted);
  font-size: 13px;
  font-weight: 750;
  line-height: 1.45;
}

.power-row {
  grid-template-columns: 1fr auto;
}

.power-row b {
  color: var(--duck-blue-dark);
}

.item-legend b {
  color: var(--duck-ink);
}

.item-dot {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.65), 0 2px 7px rgba(0, 0, 0, 0.14);
}

.item-dot--berry { background: #ef4444; }
.item-dot--coffee { background: #92400e; }
.item-dot--scroll { background: #60a5fa; }
.item-dot--shield { background: #22c55e; }
.item-dot--star { background: #facc15; }
.item-dot--portal { background: #a855f7; }

.arcade-controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.arcade-help {
  margin: 0;
  padding: 12px;
  color: #7a4a00;
  background: var(--duck-cream);
  border: 1px solid var(--duck-cream-2);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 800;
}

.touch-pad {
  display: none;
  width: min(260px, 100%);
  margin: 0 auto;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(2, 52px);
  justify-content: center;
  gap: 8px;
}

.touch-pad button {
  border: 2px solid var(--duck-cream-2);
  border-radius: 12px;
  background: #fff;
  color: #1c1000;
  font-weight: 900;
  box-shadow: var(--shadow-soft);
}

.touch-pad button[data-dir="up"] { grid-column: 2; }
.touch-pad button[data-dir="left"] { grid-column: 1; grid-row: 2; }
.touch-pad button[data-dir="down"] { grid-column: 2; grid-row: 2; }
.touch-pad button[data-dir="right"] { grid-column: 3; grid-row: 2; }

@media (max-width: 1100px) {
  .arcade-page .task-layout,
  .arcade-stage {
    grid-template-columns: 1fr;
  }

  .arcade-side {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .arcade-controls,
  .arcade-help,
  .rules-card {
    grid-column: span 2;
  }
}

@media (max-width: 720px) {
  .arcade-hero {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .arcade-hero-ducks {
    justify-content: center;
  }

  .arcade-hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hud-card--wide {
    grid-column: span 2;
  }

  .arcade-side {
    grid-template-columns: 1fr;
  }

  .arcade-controls,
  .arcade-help,
  .rules-card {
    grid-column: auto;
  }

  .arcade-board {
    min-height: 320px;
  }

  .touch-pad {
    display: grid;
  }
}

/* Column wrapper: game board + touch pad stacked */
.game-2048-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Arcade 2048 ─────────────────────────────────────────────────────────── */

.arcade-hud--four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

/* Board container — override default arcade-board to center the grid */
.game-2048-board {
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
}

/* The actual 4×4 game wrapper */
.game-2048-wrap {
  --g2: 10px;
  --p2: 12px;
  position: relative;
  width: min(480px, 100%);
  aspect-ratio: 1;
  background: linear-gradient(150deg, #110c00 0%, #0d1424 100%);
  border-radius: var(--radius-lg);
  padding: var(--p2);
  box-shadow:
    0 0 0 2px rgba(244, 168, 0, 0.38),
    0 0 0 5px rgba(244, 168, 0, 0.08),
    0 28px 72px rgba(0, 0, 0, 0.6),
    inset 0 1px 0 rgba(255, 249, 230, 0.07);
}

/* Both layers share the same grid geometry */
.game-2048-bg,
.game-2048-tiles {
  position: absolute;
  inset: var(--p2, 12px);
  display: grid;
  grid-template: repeat(4, 1fr) / repeat(4, 1fr);
  gap: var(--g2, 10px);
}

/* Empty background cells */
.cell-2048 {
  border-radius: var(--radius);
  background: rgba(255, 215, 0, 0.055);
  border: 1px solid rgba(255, 215, 0, 0.09);
}

/* ── Tile ──────────────────────────────────────────────────────────────────── */

.tile-2048 {
  grid-row: var(--r);
  grid-column: var(--c);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px;
  background: var(--t-bg);
  color: var(--t-fg);
  border-radius: var(--radius);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.15),
    0 4px 16px rgba(0, 0, 0, 0.38),
    0 0 24px var(--t-glow);
  user-select: none;
  position: relative;
  overflow: hidden;
  z-index: 1;
}

/* Shine overlay */
.tile-2048::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    140deg,
    rgba(255, 255, 255, 0.24) 0%,
    rgba(255, 255, 255, 0.07) 40%,
    transparent 70%
  );
  border-radius: inherit;
  pointer-events: none;
}

.tile-2048 img {
  width: min(70%, 68px);
  height: min(70%, 68px);
  object-fit: contain;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.24));
  pointer-events: none;
  position: relative;
  z-index: 1;
}

.tile-2048 b {
  font-size: clamp(12px, 1.7vw, 20px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0;
  position: relative;
  z-index: 1;
}

/* Smaller font for long numbers */
.tile-2048[data-v="1024"] b,
.tile-2048[data-v="2048"] b { font-size: clamp(10px, 1.45vw, 17px); }
.tile-2048[data-v="4096"] b,
.tile-2048[data-v="8192"] b,
.tile-2048[data-v="16384"] b { font-size: clamp(8px, 1.1vw, 12px); }

/* ── Special tiles ─────────────────────────────────────────────────────────── */

.tile-2048[data-v="2048"] {
  background: linear-gradient(135deg, #f59e0b 0%, #ef4444 55%, #8b5cf6 100%);
  color: #fff9e6;
  box-shadow:
    0 0 0 2px rgba(255, 215, 0, 0.7),
    0 4px 16px rgba(0, 0, 0, 0.4),
    0 0 42px rgba(245, 158, 11, 0.95),
    0 0 84px rgba(245, 158, 11, 0.3);
  animation: glow2048 1.6s ease-in-out infinite alternate;
}

.tile-2048[data-v="4096"],
.tile-2048[data-v="8192"],
.tile-2048[data-v="16384"] {
  background: linear-gradient(135deg, #06b6d4 0%, #8b5cf6 55%, #ec4899 100%);
  color: #fff9e6;
  box-shadow:
    0 0 0 2px rgba(139, 92, 246, 0.8),
    0 4px 16px rgba(0, 0, 0, 0.4),
    0 0 50px rgba(139, 92, 246, 1),
    0 0 90px rgba(139, 92, 246, 0.4);
}

@keyframes glow2048 {
  from {
    box-shadow:
      0 0 0 2px rgba(255, 215, 0, 0.7),
      0 0 42px rgba(245, 158, 11, 0.95);
  }
  to {
    box-shadow:
      0 0 0 3px rgba(255, 215, 0, 1),
      0 0 70px rgba(239, 68, 68, 0.95),
      0 0 120px rgba(139, 92, 246, 0.55);
  }
}

/* ── Tile animations ───────────────────────────────────────────────────────── */

@keyframes tileSpawn {
  0%   { transform: scale(0);    opacity: 0; }
  55%  { transform: scale(1.15); opacity: 1; }
  80%  { transform: scale(0.96); }
  100% { transform: scale(1);    opacity: 1; }
}

@keyframes tileMerge {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.24); }
  70%  { transform: scale(0.93); }
  100% { transform: scale(1); }
}

.tile--spawn { animation: tileSpawn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
.tile--merge { animation: tileMerge 0.22s ease both; }

/* ── Tier grid (sidebar reference panel) ──────────────────────────────────── */

.tier-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.tier-item {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 11px;
  font-weight: 800;
  color: var(--duck-muted);
  line-height: 1.2;
}

.tier-tile {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 9px;
  background: var(--t-bg, #fffdf2);
  color: var(--t-fg, #7a4a00);
  box-shadow:
    0 0 12px var(--t-glow, rgba(244, 168, 0, 0.2)),
    0 2px 7px rgba(0, 0, 0, 0.14);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  position: relative;
  overflow: hidden;
}

.tier-tile::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(140deg, rgba(255, 255, 255, 0.22) 0%, transparent 55%);
  pointer-events: none;
}

.tier-tile img {
  width: 60%;
  height: 60%;
  object-fit: contain;
  position: relative;
  z-index: 1;
  filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
}

.tier-tile b {
  font-size: 7.5px;
  font-weight: 900;
  line-height: 1;
  position: relative;
  z-index: 1;
  letter-spacing: 0;
}

.tier-tile--2048 {
  background: linear-gradient(135deg, #f59e0b, #ef4444, #8b5cf6);
  color: #fff9e6;
  box-shadow:
    0 0 16px rgba(245, 158, 11, 0.75),
    0 2px 7px rgba(0, 0, 0, 0.2);
}

/* ── Responsive tweaks ─────────────────────────────────────────────────────── */

@media (max-width: 1100px) {
  .game-2048-wrap {
    width: min(460px, 88vw);
  }
}

@media (max-width: 720px) {
  .arcade-panel {
    padding: 12px;
  }

  .arcade-shell {
    gap: 12px;
  }

  .arcade-stage {
    grid-template-columns: minmax(0, 1fr);
  }

  .game-2048-board {
    padding: 12px 8px;
  }

  .game-2048-wrap {
    --g2: 7px;
    --p2: 9px;
    width: min(340px, calc(100vw - 48px));
    border-radius: var(--radius-lg);
  }

  .arcade-hud--four {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .arcade-hud--four .hud-card--wide {
    grid-column: span 2;
  }

  .hud-card strong { font-size: 20px; }

  .tier-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .arcade-hero-copy strong {
    font-size: clamp(22px, 6vw, 36px);
  }

  .arcade-board {
    min-height: 280px;
  }

  .mascot-card {
    grid-template-columns: 52px 1fr;
    height: 96px;
    min-height: 96px;
    max-height: 96px;
  }

  .mascot-card img { width: 42px; height: 42px; }

  .touch-pad {
    grid-template-columns: repeat(3, 72px);
    grid-template-rows: repeat(2, 60px);
    width: min(260px, 100%);
    gap: 8px;
  }

  .touch-pad button {
    font-size: 20px;
    border-radius: var(--radius);
  }
}

/* ── Score delta ("+N" bay lên trong HUD) ────────────────────────────────── */

.score-delta {
  position: absolute;
  bottom: 6px;
  right: 10px;
  font-style: normal;
  font-size: 12px;
  font-weight: 900;
  color: #16a34a;
  opacity: 0;
  pointer-events: none;
  z-index: 2;
}

.score-delta.pop {
  animation: deltaPop 1.1s ease both;
}

@keyframes deltaPop {
  0%   { opacity: 1; transform: translateY(0) scale(1.1); }
  25%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(-14px) scale(0.85); }
}

/* ── Score card bump khi điểm tăng ──────────────────────────────────────── */

.hud-card.bump {
  animation: cardBump 0.3s ease both;
}

@keyframes cardBump {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.06); background: #fef9c3; }
  100% { transform: scale(1); }
}

/* ── Board shake khi hướng không hợp lệ ─────────────────────────────────── */

@keyframes boardShake {
  0%, 100% { transform: translateX(0); }
  15%  { transform: translateX(-7px); }
  35%  { transform: translateX(6px); }
  55%  { transform: translateX(-4px); }
  75%  { transform: translateX(3px); }
}

.game-2048-wrap.shake {
  animation: boardShake 0.36s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

/* ── Ẩn hero section khi game bắt đầu ───────────────────────────────────── */

.arcade-hero--gone {
  display: none;
}

/* ── Điểm cuối to trong overlay ─────────────────────────────────────────── */

.overlay-score {
  font-size: clamp(36px, 7vw, 64px);
  font-weight: 900;
  color: #fcd34d;
  line-height: 1;
  text-shadow: 0 4px 20px rgba(245, 158, 11, 0.55);
  letter-spacing: 0;
}
