/* 2048 — calm paper edition */

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.page-head h1 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: clamp(28px, 4.4vw, 40px);
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1.05;
}
.page-head .sub {
  color: var(--ink-soft);
  margin: 6px 0 0;
  font-size: 14px;
  min-height: 1.4em;
  max-width: 46ch;
}
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.score-group {
  display: flex;
  gap: 8px;
  margin-right: 4px;
}
.score-box {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 72px;
  box-shadow: var(--shadow);
}
.score-label {
  font: 600 10px 'Inter', sans-serif;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
.score-value {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: 20px;
  line-height: 1.1;
  color: var(--ink);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
  transition: color 200ms ease;
}
.score-value.is-bumped {
  color: var(--accent);
  animation: t48-score-bump 380ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes t48-score-bump {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.18); }
  100% { transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .score-value.is-bumped { animation: none; }
}

.play {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.board-wrap {
  display: flex;
  justify-content: center;
}

/* Board: a square that scales with viewport but caps at 480px */
.board {
  --size: min(480px, 92vw, calc(100vh - 320px));
  --gap: 10px;
  --cells: 4;
  --tile: calc((var(--size) - var(--gap) * (var(--cells) + 1)) / var(--cells));
  position: relative;
  width: var(--size);
  height: var(--size);
  background: #e8dcbf;
  border-radius: 14px;
  padding: var(--gap);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5),
              0 1px 0 rgba(31, 58, 95, 0.08),
              0 20px 36px -22px rgba(31, 58, 95, 0.35);
  outline: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.board:focus-visible {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5),
              0 0 0 3px rgba(31, 58, 95, 0.25),
              0 20px 36px -22px rgba(31, 58, 95, 0.35);
}

.grid-bg {
  position: absolute;
  inset: var(--gap);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: var(--gap);
  pointer-events: none;
}
.cell {
  background: #d8c89f;
  border-radius: 10px;
}

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

.tile {
  position: absolute;
  width: var(--tile);
  height: var(--tile);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  font-size: calc(var(--tile) * 0.42);
  color: var(--ink);
  background: #f3ead4;
  box-shadow: inset 0 -1px 0 rgba(31, 58, 95, 0.08),
              0 1px 0 rgba(31, 58, 95, 0.06);
  transition: transform 120ms ease;
  will-change: transform;
  transform: translate(var(--x), var(--y));
}

/* Tile palette — soft creams at low values, warming up to deep accent / cinnabar at high values.
   Harmonised with --accent (#1f3a5f) and --accent-soft (#f4e3b2). */
.tile[data-value="2"]    { background: #f6ecd2; color: #4a3f24; }
.tile[data-value="4"]    { background: #f0dfae; color: #4a3717; }
.tile[data-value="8"]    { background: #e8c485; color: #3d260a; }
.tile[data-value="16"]   { background: #dca866; color: #fbf6ea; }
.tile[data-value="32"]   { background: #cf8a4a; color: #fbf6ea; }
.tile[data-value="64"]   { background: #be6b3a; color: #fbf6ea; }
.tile[data-value="128"]  { background: #a84a30; color: #fbf6ea; font-size: calc(var(--tile) * 0.36); }
.tile[data-value="256"]  { background: #8b3a3a; color: #fbf6ea; font-size: calc(var(--tile) * 0.36); }
.tile[data-value="512"]  { background: #5b6f8e; color: #fbf6ea; font-size: calc(var(--tile) * 0.36); }
.tile[data-value="1024"] { background: #2d5a8c; color: #fbf6ea; font-size: calc(var(--tile) * 0.3); }
.tile[data-value="2048"] { background: #1f3a5f; color: #f4e3b2; font-size: calc(var(--tile) * 0.3); box-shadow: 0 0 0 2px #f4e3b2 inset, 0 2px 0 rgba(31, 58, 95, 0.18); }
.tile[data-value="4096"] { background: #14253d; color: #f4e3b2; font-size: calc(var(--tile) * 0.3); }
.tile[data-value="8192"] { background: #0c1a2e; color: #f4e3b2; font-size: calc(var(--tile) * 0.28); }

/* Spawn pop */
@keyframes tileSpawn {
  0%   { transform: translate(var(--x), var(--y)) scale(0); opacity: 0; }
  60%  { transform: translate(var(--x), var(--y)) scale(1.06); opacity: 1; }
  100% { transform: translate(var(--x), var(--y)) scale(1); opacity: 1; }
}
.tile.is-new {
  animation: tileSpawn 180ms ease-out;
}

/* Merge pop */
@keyframes tileMerge {
  0%   { transform: translate(var(--x), var(--y)) scale(1); }
  45%  { transform: translate(var(--x), var(--y)) scale(1.18); }
  100% { transform: translate(var(--x), var(--y)) scale(1); }
}
.tile.is-merged {
  animation: tileMerge 200ms ease-out;
  z-index: 2;
}

/* Win overlay */
.win-overlay {
  position: fixed; inset: 0; background: rgba(28, 42, 58, 0.55);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
  backdrop-filter: blur(2px);
}
.win-overlay[hidden] { display: none; }
.win-card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 28px 30px; text-align: center; box-shadow: var(--shadow-lift); max-width: 360px;
  animation: cardIn 220ms ease-out;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}
.win-title {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: 28px;
  margin: 0 0 6px;
  color: var(--accent);
  letter-spacing: -0.02em;
}
.win-title.is-loss { color: var(--ink); }
.win-sub {
  color: var(--ink-soft);
  margin: 0 0 18px;
  font-size: 14px;
  line-height: 1.5;
}
.win-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

/* Aside */
.aside-info { margin-top: 22px; }
.aside-info details {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
}
.aside-info summary {
  cursor: pointer;
  font: 700 14px 'Inter', sans-serif;
  color: var(--ink);
}
.aside-info .help-body {
  margin-top: 10px;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.55;
}
.aside-info .help-body p { margin: 0 0 8px; }
.aside-info .help-body ul { margin: 0; padding-left: 18px; }
.aside-info .help-body li { margin: 4px 0; }

@media (max-width: 560px) {
  .page-head { gap: 12px; }
  .head-actions { width: 100%; justify-content: space-between; }
  .score-group { margin-right: 0; }
  .score-box { min-width: 64px; padding: 6px 10px; }
  .score-value { font-size: 18px; }
  .play { padding: 12px; }
  .board { --gap: 8px; }
}
