:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #14141f;
  --bg-tertiary: #1e1e2e;
  --bg-card: #1a1a2e;
  --text-primary: #ffffff;
  --text-secondary: #a0a0b0;
  --text-muted: #606070;
  --accent-primary: #00d4ff;
  --accent-secondary: #00ff88;
  --accent-warm: #ff9f43;
  --danger: #ff4466;
  --focus-ring: #00d4ff;
  --focus-glow: rgba(0, 212, 255, 0.4);
  --success: #00ff88;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  /* board geometry — kept in sync with app.js */
  --board-size: 460px;
  --cell-gap: 12px;
  --cell-size: 100px; /* (460 - 12*5) / 4 = 100 */
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  width: 600px;
  height: 600px;
  overflow: hidden;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
}

/* --- Screens --- */
.screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 0;
  left: 0;
}
.screen.hidden { display: none; }

/* --- Header --- */
.header {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  background: var(--bg-secondary);
  gap: 12px;
  flex-shrink: 0;
}
.header h1 {
  font-size: 22px;
  font-weight: 700;
  flex: 1;
}
.header-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 600;
  color: var(--accent-secondary);
}
.back-btn {
  background: transparent;
  color: var(--text-primary);
  font-size: 22px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
}

/* score blocks in game header */
.score-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  padding: 4px 12px;
  min-width: 64px;
}
.score-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text-secondary);
}
.score-value {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-primary);
}

/* --- Content Area --- */
.content {
  flex: 1;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* --- Focus States (critical for EMG/D-pad) --- */
.focusable {
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease, background 0.12s ease;
  border: 2px solid transparent;
  cursor: pointer;
  min-height: 44px;
}
.focusable:focus {
  outline: none;
  border-color: var(--focus-ring);
  box-shadow: 0 0 20px var(--focus-glow);
}

/* --- Navigation Bar --- */
.nav-bar {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  background: transparent;
  flex-shrink: 0;
}
.nav-item {
  flex: 1;
  padding: 14px 16px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.nav-item:focus { background: var(--bg-card); }
.nav-item.primary {
  background: var(--accent-primary);
  color: var(--bg-primary);
}
.nav-item.primary:focus { background: #33ddff; }

/* ===================== MENU ===================== */
.menu-content {
  align-items: center;
  justify-content: center;
  gap: 28px;
}
.menu-logo {
  display: flex;
  gap: 12px;
}
.logo-tile {
  width: 88px;
  height: 88px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 44px;
  font-weight: 800;
  color: #1a1208;
}
.lt-2 { background: #ffd24a; }
.lt-0 { background: #ff9f43; color: #fff; }
.lt-4 { background: #ff7a59; color: #fff; }
.lt-8 { background: #ff4d8d; color: #fff; }

.menu-tagline {
  font-size: 18px;
  color: var(--text-secondary);
  font-weight: 500;
}
.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 280px;
}

/* ===================== GAME ===================== */
.game-content {
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.board {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: var(--cell-gap);
  border: 2px solid transparent;
}
.board:focus {
  outline: none;
  border-color: var(--focus-ring);
  box-shadow: 0 0 20px var(--focus-glow);
}

.grid-bg {
  position: absolute;
  inset: var(--cell-gap);
  display: grid;
  grid-template-columns: repeat(4, var(--cell-size));
  grid-template-rows: repeat(4, var(--cell-size));
  gap: var(--cell-gap);
}
.grid-cell {
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
}

.tiles {
  position: absolute;
  inset: var(--cell-gap);
}

.tile {
  position: absolute;
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 44px;
  color: #1a1208;
  /* movement animation — cheap GPU transform */
  transition: transform 0.10s ease-in-out;
  will-change: transform;
}
.tile.spawn { animation: tile-spawn 0.14s ease; }
.tile.merged { animation: tile-merge 0.16s ease; }

@keyframes tile-spawn {
  0% { transform: var(--pos) scale(0.1); }
  100% { transform: var(--pos) scale(1); }
}
@keyframes tile-merge {
  0% { transform: var(--pos) scale(1); }
  50% { transform: var(--pos) scale(1.18); }
  100% { transform: var(--pos) scale(1); }
}

/* Tile color ramp — dark, escalating brightness/hue. Never pure black. */
.tile.v2    { background: #ede0c8; color: #5a4a2a; }
.tile.v4    { background: #ede0b0; color: #5a4a2a; }
.tile.v8    { background: #f2b179; color: #fff; }
.tile.v16   { background: #f59563; color: #fff; }
.tile.v32   { background: #f67c5f; color: #fff; }
.tile.v64   { background: #f65e3b; color: #fff; }
.tile.v128  { background: #edcf72; color: #fff; font-size: 38px; }
.tile.v256  { background: #edcc61; color: #fff; font-size: 38px; }
.tile.v512  { background: #edc850; color: #fff; font-size: 38px; }
.tile.v1024 { background: #00b4d8; color: #fff; font-size: 30px; }
.tile.v2048 { background: #00d4ff; color: #08222b; font-size: 30px; box-shadow: 0 0 24px rgba(0, 212, 255, 0.55); }
.tile.vbig  { background: #00ff88; color: #06301c; font-size: 28px; box-shadow: 0 0 24px rgba(0, 255, 136, 0.5); }

.game-hint {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

/* ===================== OVERLAY ===================== */
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(10, 10, 15, 0.93);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.overlay.hidden { display: none; }

.overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 40px;
}
.overlay-title {
  font-size: 36px;
  font-weight: 800;
  color: var(--danger);
  text-transform: uppercase;
  letter-spacing: 4px;
}
.overlay-title.win { color: var(--accent-primary); }
.overlay-score {
  font-size: 64px;
  font-weight: 800;
  color: var(--accent-secondary);
  line-height: 1;
}
.overlay-label {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.overlay-best {
  font-size: 14px;
  color: var(--accent-warm);
  margin-bottom: 16px;
  min-height: 18px;
}
.overlay-btn { width: 240px; }

/* ===================== HOW TO PLAY ===================== */
.howto-content {
  justify-content: space-between;
  padding: 16px 24px;
}
.howto-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 8px;
}
.howto-list li {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 18px;
  color: var(--text-primary);
  line-height: 1.3;
}
.howto-key {
  flex-shrink: 0;
  min-width: 88px;
  text-align: center;
  padding: 8px 10px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  font-size: 18px;
  font-weight: 700;
  color: var(--accent-primary);
}

/* --- Utility --- */
.hidden { display: none !important; }
