/* 2048 — tokens from /assets/base.css */

html, body { min-height: 100%; }

body {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px 16px;
  min-height: 100vh;
  overflow-x: hidden;
}

.app {
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.top {
  width: 100%;
  text-align: center;
}
.top h1 {
  font-size: clamp(1.5rem, 3vw, 2rem);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.top h1.fade-out {
  opacity: 0;
  transform: translateY(-8px);
}
.top h1.fade-in {
  animation: title-in 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes title-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel {
  width: 100%;
  background: linear-gradient(145deg, rgba(16, 20, 38, 0.95), #090c18 50%, #05060f 100%);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 26px;
  padding: 20px 18px 18px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

[hidden] { display: none !important; }
.hidden { display: none !important; }

/* Panel fade in with staggered children */
.panel.show-anim {
  animation: panel-in 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.panel.show-anim > * {
  animation: child-in 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.panel.show-anim > *:nth-child(1) { animation-delay: 0.05s; }
.panel.show-anim > *:nth-child(2) { animation-delay: 0.1s; }
.panel.show-anim > *:nth-child(3) { animation-delay: 0.15s; }
.panel.show-anim > *:nth-child(4) { animation-delay: 0.2s; }
.panel.show-anim > *:nth-child(5) { animation-delay: 0.25s; }

@keyframes panel-in {
  from { opacity: 0; transform: scale(0.96) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes child-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Board entrance */
.board {
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.panel.show-anim .board {
  animation: board-in 0.4s cubic-bezier(0.22, 1, 0.36, 1) 0.1s both;
}
@keyframes board-in {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: scale(1); }
}

/* HUD entrance */
.panel.show-anim .hud {
  animation: child-in 0.3s cubic-bezier(0.22, 1, 0.36, 1) 0.05s both;
}

/* Menu */
.menu-panel { padding: 32px 28px 28px; gap: 20px; position: relative; z-index: 1; }

/* Decorative background — scattered tiles */
.menu-bg {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}
.bg-tile-scatter {
  position: absolute;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.3);
  opacity: 0.15;
  font-family: var(--font-sans);
}
.menu-highscore {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px 16px 12px 24px;
  text-align: center;
  display: flex;
  align-items: center;
  gap: 16px;
}
.hs-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.hs-trophy {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease, transform 0.12s ease;
}
.hs-trophy svg { width: 19px; height: 19px; }
.hs-trophy:hover {
  color: #ffd166;
  border-color: rgba(255, 209, 102, 0.5);
  background: rgba(255, 209, 102, 0.08);
  transform: translateY(-1px);
}
.hs-trophy:active { transform: scale(0.95); }
.hs-label {
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}
.hs-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  align-items: center;
}
.menu-actions .primary-btn {
  width: 100%;
}
.continue-btn {
  border-radius: var(--radius-pill);
  padding: 9px 18px;
  font-size: 0.8rem;
}
.continue-score {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.menu-hint {
  color: var(--muted);
  font-size: 0.7rem;
  text-align: center;
  opacity: 0.6;
}

/* Leaderboard overlay */
.lb-card {
  width: 100%;
  max-width: 320px;
  gap: 12px;
}
.lb-card h2 { font-size: 1.2rem; }
.lb-msg { margin: 0; }
.lb-list {
  width: 100%;
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  counter-reset: lb;
}
.lb-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 13px;
  counter-increment: lb;
}
.lb-list li::before {
  content: counter(lb);
  min-width: 18px;
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.lb-list li:nth-child(1)::before { color: #ffd166; }
.lb-list li:nth-child(2)::before { color: #c0c8d8; }
.lb-list li:nth-child(3)::before { color: #d49a6a; }
.lb-list li.me {
  border-color: rgba(138, 124, 255, 0.5);
  background: var(--accent-soft);
}
.lb-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lb-score {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* Score submit (game-over overlay) */
.lb-submit {
  display: flex;
  gap: 8px;
  width: 100%;
}
.lb-submit input {
  flex: 1;
  min-width: 0;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  text-align: center;
  padding: 9px 14px;
  transition: border-color 0.2s;
}
.lb-submit input::placeholder { color: var(--muted); opacity: 0.6; }
.lb-submit input:focus {
  outline: none;
  border-color: var(--accent);
}
.lb-submit .primary-btn { padding: 9px 18px; font-size: 13px; }
.lb-submit-done {
  margin: 0;
  font-size: 0.85rem;
  color: var(--accent);
}

/* Account line at the bottom of the leaderboard overlay */
.lb-account {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}
.lb-account:empty { display: none; }
.lb-account-btn {
  background: none;
  border: none;
  padding: 0;
  margin-left: 4px;
  font: inherit;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.lb-account-btn:hover { opacity: 0.8; }

/* HUD */
.hud {
  display: flex;
  justify-content: space-between;
  width: 100%;
  max-width: 360px;
  padding: 0 4px;
}
.hud-score {
  font-size: 0.85rem;
  color: var(--text);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.hud-score .score-bump {
  animation: score-pop 0.3s ease;
}
@keyframes score-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.3); color: var(--accent); }
  100% { transform: scale(1); }
}
.hud-score span {
  display: inline-block;
}
.hud-score .best-bump {
  animation: best-flash 0.6s ease;
}
@keyframes best-flash {
  0% { transform: scale(1); color: var(--text); }
  30% { transform: scale(1.4); color: #ffd66e; }
  100% { transform: scale(1); color: var(--text); }
}
.hud-label {
  font-size: 0.65rem;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
  margin-right: 6px;
}

.ghost-btn {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--text);
  padding: 0 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.12s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.ghost-btn:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}
.ghost-btn:active {
  transform: scale(0.97);
}

.game-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  width: 100%;
}
.game-actions .ghost-btn {
  border-radius: var(--radius-pill);
  padding: 9px 18px;
}

/* Board */
.board {
  width: 100%;
  max-width: 378px;
  background: #07090f;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px;
  touch-action: none;
  box-sizing: border-box;
}
.bg-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 8px;
}
.bg-cell {
  aspect-ratio: 1;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
  position: relative;
}

/* Tile fills its parent bg-cell */
.tile {
  position: absolute;
  inset: 0;
  z-index: 1;
}
.tile-inner {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-family: var(--font-sans);
  border-radius: 8px;
  color: var(--text);
  letter-spacing: -0.02em;
}
.tile.spawn .tile-inner {
  animation: tile-spawn 170ms ease backwards;
}
.tile.merge .tile-inner {
  animation: tile-merge 170ms ease;
}
@keyframes tile-spawn {
  0% { transform: scale(0.35); opacity: 0; }
  60% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes tile-merge {
  0% { transform: scale(1); }
  50% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

/* Tile colour palette */
.tile[data-v="2"] .tile-inner    { background: #1e2240; color: var(--text); }
.tile[data-v="4"] .tile-inner    { background: #2a2a55; color: var(--text); }
.tile[data-v="8"] .tile-inner    { background: #3d3787; color: #fff; }
.tile[data-v="16"] .tile-inner   { background: #564db8; color: #fff; }
.tile[data-v="32"] .tile-inner   { background: #7163e6; color: #fff; }
.tile[data-v="64"] .tile-inner   { background: #8a7cff; color: #fff; }
.tile[data-v="128"] .tile-inner  { background: #6e8cff; color: #fff; }
.tile[data-v="256"] .tile-inner  { background: #5dabff; color: #fff; }
.tile[data-v="512"] .tile-inner  { background: #4ec5ff; color: #0b0b12; }
.tile[data-v="1024"] .tile-inner { background: #5cffd4; color: #0b0b12; }
.tile[data-v="2048"] .tile-inner { background: #ffd66e; color: #0b0b12; box-shadow: 0 0 18px rgba(255,214,110,0.5); }
.tile[data-v="4096"] .tile-inner,
.tile[data-v="8192"] .tile-inner { background: #ff9d4e; color: #0b0b12; box-shadow: 0 0 18px rgba(255,157,78,0.5); }

/* Overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 22, 0.78);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
}
.overlay-card {
  position: relative;
  background: linear-gradient(145deg, #1a1c30, #0d0e1d);
  border: 1px solid rgba(138, 124, 255, 0.3);
  border-radius: 22px;
  padding: 28px 32px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  box-shadow: 0 0 40px rgba(138, 124, 255, 0.2);
  max-width: 320px;
}
.overlay-card h2 {
  font-size: 1.6rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}
.muted { color: var(--muted); font-size: 0.85rem; }
.overlay-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.overlay-actions .ghost-btn {
  border-radius: var(--radius-pill);
  padding: 9px 16px;
}
.ghost-btn.icon-only {
  padding: 0;
  width: 42px;
  min-width: 42px;
  height: 42px;
}
.ghost-btn.icon-only .icon {
  width: 20px;
  height: 20px;
}

.primary-btn {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-pill);
  padding: 11px 24px;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.18s ease, transform 0.12s ease, box-shadow 0.18s ease;
}
.primary-btn:hover {
  background: rgba(138, 124, 255, 0.25);
  transform: translateY(-1px);
  box-shadow: 0 0 18px rgba(138, 124, 255, 0.3);
}
.primary-btn:active {
  transform: scale(0.97);
  box-shadow: none;
}
.ghost-btn:active {
  transform: scale(0.97);
}

/* Title subtle glow on menu */
.menu-panel ~ .hidden + .top h1,
.top h1 {
  transition: text-shadow 0.3s;
}

/* Overlay entrance */
.overlay {
  animation: overlay-in 0.3s ease;
}
@keyframes overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
.overlay-card {
  animation: overlay-card-in 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes overlay-card-in {
  from { opacity: 0; transform: scale(0.92) translateY(16px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

@media (max-width: 600px) {
  body { padding: 12px 10px; }
  .app { gap: 12px; }
  .top h1 { font-size: 1.4rem; }
  .panel { padding: 14px 12px 12px; border-radius: 18px; }
  .menu-panel { padding: 20px 16px 18px; gap: 16px; }
  .menu-tagline { font-size: 0.75rem; }
  .menu-hint { font-size: 0.65rem; }
  .primary-btn { padding: 10px 20px; font-size: 13px; }
  .board { border-radius: 10px; padding: 5px; }
  .bg-grid { gap: 5px; }
  .bg-cell { border-radius: 6px; }
  .tile-inner { border-radius: 6px; }
  .bg-grid { gap: 5px; }
  .hud-score { font-size: 0.78rem; }
  .game-actions { gap: 8px; }
  .game-actions .ghost-btn { padding: 8px 14px; font-size: 12px; }
  .overlay-card { padding: 22px 24px; border-radius: 18px; }
  .overlay-card h2 { font-size: 1.3rem; }
  .bg-tile-scatter { opacity: 0.1; }
}

/* ==========================================================================
   Settings overlay (util-btns convention) - 2048 had no sound/settings before
   ========================================================================== */

/* .util-btn is inline-flex, so it beats the [hidden] attribute - guard it */
.util-btn[hidden] { display: none; }

.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  font-size: 14px;
  color: var(--text);
}

.seg {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 3px;
  gap: 2px;
}
.seg-btn {
  background: transparent;
  border: none;
  border-radius: var(--radius-pill);
  color: var(--muted);
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}
