/* ===== Threes! — game UI =====
   Same sliding-tile shell as 2048 (CSS-grid background + absolutely-positioned
   animated tiles), but the tile palette follows Threes' blue/pink/yellow family
   and there is a "Next" preview chip in the controls row. */
.wrap {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex; flex-direction: column; align-items: center;
  gap: 12px;
  padding: clamp(22px, 5vw, 44px) 18px 40px;
  text-align: center;
}
.head { width: 100%; max-width: 460px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.title { margin: 0; font-size: clamp(30px, 8vw, 42px); letter-spacing: -.03em; }
.sub { margin: 0; color: var(--gc-text-muted); font-size: 14px; max-width: 420px; }
.sub b { color: var(--gc-text); }

.scoreboard { display: flex; gap: 8px; }
.score {
  min-width: 74px; padding: 6px 12px;
  background: var(--gc-surface-2); border: 1px solid var(--gc-border); border-radius: 10px;
  display: flex; flex-direction: column; align-items: center;
}
.score__k { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--gc-text-muted); font-weight: 700; }
.score__v { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.score--flash .score__v { animation: gain .3s ease; }
@keyframes gain { 30% { transform: scale(1.25); color: var(--gc-accent); } }

.controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; }
.btn {
  appearance: none; cursor: pointer; font: inherit; font-size: 14px; font-weight: 600;
  padding: 9px 16px; border-radius: 10px;
  border: 1px solid var(--gc-border); background: var(--gc-surface); color: var(--gc-text);
  transition: transform .06s ease, border-color .15s ease, background .15s ease;
}
.btn:hover { border-color: var(--gc-accent); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn:focus-visible { outline: none; box-shadow: var(--gc-ring); }
.btn--primary { background: var(--gc-accent); border-color: var(--gc-accent); color: var(--gc-on-accent); }

/* Next-tile preview chip. */
.next {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  background: var(--gc-surface-2); border: 1px solid var(--gc-border); border-radius: 10px;
}
.next__k { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--gc-text-muted); font-weight: 700; }
.next__slot { display: inline-flex; }
.mini {
  width: 34px; height: 34px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; line-height: 1; font-size: 18px;
}

/* Board: CSS-grid background cells + absolutely-positioned animated tiles. */
.board {
  --gap: clamp(6px, 2vw, 12px);
  position: relative;
  container-type: inline-size;
  width: min(calc(4 * 96px + 5 * var(--gap) + 2px), 100%);
  aspect-ratio: 1;
  background: var(--gc-surface-2);
  border: 1px solid var(--gc-border);
  border-radius: 14px;
  touch-action: none;
  outline: none;
  -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;
}

.grid { position: absolute; inset: var(--gap); display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); gap: var(--gap); }
.grid__cell { background: color-mix(in srgb, var(--gc-border) 55%, transparent); border-radius: 8px; }

.tiles { position: absolute; inset: 0; }
.tile {
  --cell: calc(25cqi - 1.25 * var(--gap));
  position: absolute;
  width: var(--cell); height: var(--cell);
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  font-weight: 800; line-height: 1;
  font-size: calc(var(--cell) * 0.46);
  background: #eee4da; color: #776e65;
  transform: var(--pos, translate(0, 0));
  transition: transform .12s ease-in-out;
  will-change: transform;
  -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;
}

/* Threes palette — shared by board tiles and the Next mini chip. */
.c1  { background: #6fa8dc; color: #fff; }
.c2  { background: #d1617c; color: #fff; }
.c3  { background: #f2cf4f; color: #3a3324; }
.c6  { background: #e8883f; color: #fff; }
.c12 { background: #dd6a3f; color: #fff; }
.c24 { background: #4fb0a3; color: #fff; }
.c48 { background: #f2cf4f; color: #3a3324; }
.c96 { background: #e8883f; color: #fff; }
.c192 { background: #dd6a3f; color: #fff; font-size: calc(var(--cell, 90px) * 0.36); }
.c384 { background: #f2cf4f; color: #3a3324; font-size: calc(var(--cell, 90px) * 0.36); }
.c768 { background: #e8883f; color: #fff; font-size: calc(var(--cell, 90px) * 0.36); }
.c1536 { background: #6fa8dc; color: #fff; font-size: calc(var(--cell, 90px) * 0.28); }
.c3072 { background: #8a5bd6; color: #fff; font-size: calc(var(--cell, 90px) * 0.28); }
.c6144 { background: #12a06e; color: #fff; font-size: calc(var(--cell, 90px) * 0.28); box-shadow: 0 0 24px rgba(18,160,110,.7); }
.csuper { background: #3c3a32; color: #f9f6f2; font-size: calc(var(--cell, 90px) * 0.24); }
/* The mini preview chip has no --cell, so pin its small-value font sizes. */
.mini.c192, .mini.c384, .mini.c768 { font-size: 14px; }
.mini.c1536, .mini.c3072, .mini.c6144, .mini.csuper { font-size: 11px; }

.tile--new { animation: appear .16s ease; }
.tile--pop { animation: pop .16s ease; }
@keyframes appear { from { transform: var(--pos) scale(0); } }
@keyframes pop { 50% { transform: var(--pos) scale(1.18); } }

/* Overlay */
.overlay {
  touch-action: manipulation;
  position: absolute; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  background: color-mix(in srgb, var(--gc-bg) 78%, transparent);
  border-radius: 14px;
  animation: fade .4s ease;
}
.overlay[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.overlay__msg { font-size: clamp(28px, 7vw, 42px); font-weight: 800; }
.overlay__spark svg { width: 56px; height: 56px; display: block; }
.overlay__actions { display: flex; gap: 10px; }

@media (prefers-reduced-motion: reduce) {
  .tile { transition: none; }
  .tile--new, .tile--pop, .score--flash .score__v, .overlay { animation: none; }
}
