/* 2048 "Kiln" theme, v0.2.0 */

:root {
  --board-w: min(92vw, 440px, 62vh);
  --gap: clamp(8px, 2.2vw, 12px);
  --cell: calc((var(--board-w) - 5 * var(--gap)) / 4);
  --radius: calc(var(--cell) * 0.12);

  --bg: #101116;
  --bg-glow: #1c1e2a;
  --board: #1d1f29;
  --cell-bg: #262937;
  --ink: #e9ebf3;
  --muted: #8b90a3;
  --chip-bg: #1d1f29;
  --btn-bg: #2b2e3d;
  --btn-hot: #c25a24;

  --slide-ms: 130ms;
  --slide-ease: cubic-bezier(0.25, 0.6, 0.3, 1);
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  background: var(--bg) radial-gradient(120vmax 70vmax at 50% -20%, var(--bg-glow), var(--bg) 60%);
  color: var(--ink);
  font-family: "Archivo", system-ui, -apple-system, sans-serif;
  display: flex;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.app {
  width: var(--board-w);
  padding: clamp(16px, 4vh, 40px) 0 24px;
}

/* Header */

.top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.wordmark {
  margin: 0;
  font-size: clamp(40px, 12vw, 56px);
  font-weight: 900;
  line-height: 0.9;
  letter-spacing: -0.03em;
  background: linear-gradient(100deg, #e9ebf3 20%, #f4b324 55%, #c25a24 90%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

.tagline {
  margin: 6px 0 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.scores { display: flex; gap: 8px; }

.chip {
  position: relative;
  background: var(--chip-bg);
  border-radius: 10px;
  padding: 8px 14px;
  min-width: 72px;
  text-align: center;
}

.chip-label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.chip-value {
  display: block;
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.score-add {
  position: absolute;
  inset-inline: 0;
  top: 4px;
  text-align: center;
  font-size: 16px;
  font-weight: 800;
  color: #f4b324;
  pointer-events: none;
  animation: score-float 650ms ease-out forwards;
}

@keyframes score-float {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-26px); }
}

/* Controls */

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 18px 0 10px;
}

.account {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.account[hidden] { display: none; }

.account-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.btn {
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  background: var(--btn-bg);
  border: none;
  border-radius: 10px;
  padding: 9px 16px;
  cursor: pointer;
  transition: background 120ms ease, transform 120ms ease, opacity 120ms ease;
}

.btn:hover:not(:disabled) { background: #363a4d; }
.btn:active:not(:disabled) { transform: scale(0.96); }
.btn:disabled { opacity: 0.4; cursor: default; }

.btn-primary { background: var(--btn-hot); }
.btn-primary:hover:not(:disabled) { background: #d3682e; }

.btn-small {
  font-size: 13px;
  padding: 7px 12px;
}

:focus-visible {
  outline: 2px solid #f4b324;
  outline-offset: 2px;
}

/* Board */

.board {
  position: relative;
  width: var(--board-w);
  height: var(--board-w);
  background: var(--board);
  border-radius: calc(var(--radius) + var(--gap));
  touch-action: none;
  user-select: none;
  outline-offset: 4px;
}

.cells {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
  padding: var(--gap);
  width: 100%;
  height: 100%;
}

.cell {
  background: var(--cell-bg);
  border-radius: var(--radius);
}

/* Tiles */

.tiles {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.tile {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--cell);
  height: var(--cell);
  transition: transform var(--slide-ms) var(--slide-ease);
  will-change: transform;
  z-index: 1;
}

.tile-inner {
  width: 100%;
  height: 100%;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  font-size: calc(var(--cell) * 0.45);
}

.tile.d3 .tile-inner { font-size: calc(var(--cell) * 0.37); }
.tile.d4 .tile-inner { font-size: calc(var(--cell) * 0.30); }
.tile.d5 .tile-inner { font-size: calc(var(--cell) * 0.24); }

.tile.spawn .tile-inner {
  animation: spawn 170ms var(--slide-ms) cubic-bezier(0.35, 1.4, 0.6, 1) backwards;
}

@keyframes spawn {
  from { transform: scale(0.3); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.tile.merge { z-index: 2; }

.tile.merge .tile-inner {
  animation: pop 190ms calc(var(--slide-ms) * 0.75) ease-out backwards;
}

@keyframes pop {
  0%   { transform: scale(0); opacity: 0; }
  55%  { transform: scale(1.16); opacity: 1; }
  100% { transform: scale(1); }
}

/* Heat ramp: cool stone warms through ember and amber to white-hot, then plasma */

.v2    .tile-inner { background: #3b3f4d; color: #c9cedd; }
.v4    .tile-inner { background: #494656; color: #d6d1e2; }
.v8    .tile-inner { background: #64474e; color: #f2dbd8; }
.v16   .tile-inner { background: #83483f; color: #ffe4d8; }
.v32   .tile-inner { background: #a34c31; color: #ffebdc; box-shadow: 0 0 14px rgba(255, 110, 50, 0.18); }
.v64   .tile-inner { background: #c25a24; color: #fff1df; box-shadow: 0 0 18px rgba(255, 120, 50, 0.28); }
.v128  .tile-inner { background: #d97a1e; color: #fff6e3; box-shadow: 0 0 22px rgba(255, 140, 40, 0.34); }
.v256  .tile-inner { background: #e9961c; color: #fff8e6; box-shadow: 0 0 26px rgba(255, 160, 40, 0.40); }
.v512  .tile-inner { background: #f4b324; color: #4a3305; box-shadow: 0 0 30px rgba(255, 185, 50, 0.46); }
.v1024 .tile-inner { background: #fbd04c; color: #4a3a05; box-shadow: 0 0 34px rgba(255, 205, 80, 0.52); }
.v2048 .tile-inner { background: #fff4c9; color: #6b4e00; box-shadow: 0 0 42px rgba(255, 235, 160, 0.65); }
.super .tile-inner { background: #eaf3ff; color: #274b8f; box-shadow: 0 0 44px rgba(140, 190, 255, 0.6); }

/* Overlay */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: rgba(16, 17, 22, 0.72);
  backdrop-filter: blur(4px);
  border-radius: calc(var(--radius) + var(--gap));
  animation: overlay-in 250ms ease-out backwards;
}

.overlay[hidden] { display: none; }

@keyframes overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.overlay-title {
  margin: 0;
  font-size: clamp(26px, 8vw, 36px);
  font-weight: 900;
  letter-spacing: -0.02em;
}

.overlay-actions { display: flex; gap: 10px; }

/* Footer */

.hint {
  margin: 14px 0 0;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

/* Leaderboard */

.leaderboard {
  margin-top: 28px;
  padding-top: 18px;
  border-top: 1px solid rgba(233, 235, 243, 0.08);
}

.leaderboard[hidden] { display: none; }

.lb-title {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.lb-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.lb-list li {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 8px 2px;
  border-bottom: 1px solid rgba(233, 235, 243, 0.06);
  font-size: 15px;
  font-weight: 600;
}

.lb-list li:last-child { border-bottom: none; }

.lb-rank {
  width: 22px;
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.lb-list li:first-child .lb-rank { color: #f4b324; }

.lb-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-score {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.lb-tile {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  min-width: 44px;
  text-align: right;
}

.lb-empty {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}

/* Auth dialog */

.auth-dialog {
  background: var(--board);
  color: var(--ink);
  border: 1px solid rgba(233, 235, 243, 0.1);
  border-radius: 16px;
  padding: 24px;
  width: min(90vw, 340px);
}

.auth-dialog::backdrop {
  background: rgba(16, 17, 22, 0.7);
  backdrop-filter: blur(4px);
}

.auth-title {
  margin: 0;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: -0.02em;
}

.auth-sub {
  margin: 6px 0 18px;
  font-size: 13px;
  color: var(--muted);
}

.field {
  display: block;
  margin-bottom: 12px;
}

.field span {
  display: block;
  margin-bottom: 5px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.field input {
  width: 100%;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  background: var(--cell-bg);
  border: 1px solid rgba(233, 235, 243, 0.1);
  border-radius: 8px;
  padding: 9px 12px;
}

.field input:focus {
  outline: 2px solid #f4b324;
  outline-offset: 1px;
  border-color: transparent;
}

.auth-error {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 600;
  color: #ff8f6b;
}

.auth-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}

@media (prefers-reduced-motion: reduce) {
  .tile { transition-duration: 1ms; }
  .tile.spawn .tile-inner,
  .tile.merge .tile-inner,
  .overlay,
  .score-add { animation-duration: 1ms; animation-delay: 0ms; }
}
