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

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

html, body {
  width: 600px; height: 600px; overflow: hidden;
  background: #000;
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-feature-settings: 'tnum' 1;
}

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

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

.screen.hidden { display: none; }

.focusable {
  transition: box-shadow 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
  border: 2px solid transparent;
  cursor: pointer;
  outline: none;
}
.focusable:focus {
  border-color: var(--focus-ring);
  box-shadow: 0 0 20px var(--focus-glow);
}

.hidden { display: none !important; }

/* ============ HOME ============ */
.home-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 56px 40px 40px;
}
.brand { text-align: center; margin-bottom: 24px; }
.brand-tile {
  font-size: 84px;
  font-weight: 800;
  letter-spacing: -2px;
  color: var(--accent);
  text-shadow: 0 0 30px rgba(0, 212, 255, 0.35);
  line-height: 1;
}
.brand-sub {
  font-size: 16px;
  color: var(--text-secondary);
  margin-top: 8px;
  letter-spacing: 0.5px;
}
.best-card {
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 14px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 28px;
  min-width: 180px;
}
.best-label {
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--text-muted);
  font-weight: 600;
}
.best-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 2px;
}
.menu {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 320px;
}
.menu-btn {
  height: 64px;
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 20px;
  font-weight: 600;
  font-family: inherit;
}
.menu-btn.primary {
  background: linear-gradient(135deg, #00d4ff 0%, #0099cc 100%);
  color: #001a22;
}
.menu-btn:focus { transform: translateY(-1px); }

/* ============ GAME ============ */
.game-header {
  height: 72px;
  padding: 14px 24px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.title-sm {
  font-size: 36px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -1px;
}
.score-group { display: flex; gap: 10px; }
.score-box {
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  padding: 6px 16px;
  text-align: center;
  min-width: 86px;
}
.score-label {
  font-size: 10px;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  font-weight: 600;
}
.score-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
}

.board-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board {
  position: relative;
  width: 460px;
  height: 460px;
  background: var(--bg-secondary);
  border-radius: 16px;
  padding: 10px;
}
.board:focus {
  border-color: var(--focus-ring);
  box-shadow: 0 0 30px var(--focus-glow);
}

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

.tiles {
  position: absolute;
  inset: 10px;
}
.tile {
  position: absolute;
  width: 100px;
  height: 100px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 44px;
  color: #fff;
  transition: transform 0.12s ease;
  will-change: transform;
}
.tile.pop { animation: pop 0.16s ease; }
.tile.merged { animation: merge 0.18s ease; z-index: 2; }
@keyframes pop {
  0% { transform: var(--xy) scale(0); }
  60% { transform: var(--xy) scale(1.08); }
  100% { transform: var(--xy) scale(1); }
}
@keyframes merge {
  0% { transform: var(--xy) scale(1); }
  50% { transform: var(--xy) scale(1.18); }
  100% { transform: var(--xy) scale(1); }
}

/* Tile palette — adapted for dark waveguide background */
.tile.v2    { background: #2a2a3e; }
.tile.v4    { background: #353548; }
.tile.v8    { background: #4a4470; color: #fff; }
.tile.v16   { background: #5a4f95; }
.tile.v32   { background: #6a5fbf; }
.tile.v64   { background: #ff7a59; }
.tile.v128  { background: #ffb155; font-size: 38px; }
.tile.v256  { background: #ffcb45; color: #1a1a00; font-size: 38px; }
.tile.v512  { background: #00d4ff; color: #001a22; font-size: 38px; }
.tile.v1024 { background: #00ff88; color: #001a0e; font-size: 30px; }
.tile.v2048 { background: linear-gradient(135deg, #00ff88, #00d4ff); color: #001a22; font-size: 30px; box-shadow: 0 0 24px rgba(0, 255, 136, 0.45); }
.tile.vBig  { background: linear-gradient(135deg, #ff7a59, #ffcb45); color: #1a0a00; font-size: 26px; }

.game-footer {
  height: 44px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-secondary);
  font-size: 13px;
}
.hint { display: inline-flex; align-items: center; gap: 6px; }
.kbd {
  display: inline-block;
  padding: 2px 8px;
  background: var(--bg-tertiary);
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-primary);
  font-weight: 600;
  letter-spacing: 0.5px;
}

/* ============ OVERLAY ============ */
.overlay {
  position: absolute;
  inset: 10px;
  border-radius: 12px;
  background: rgba(10, 10, 15, 0.92);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 10;
}
.overlay-title {
  font-size: 44px;
  font-weight: 800;
  color: var(--danger);
  letter-spacing: -1px;
}
.overlay-title.accent {
  color: var(--accent-secondary);
  text-shadow: 0 0 24px rgba(0, 255, 136, 0.45);
}
.overlay-score {
  font-size: 16px;
  color: var(--text-secondary);
}
.overlay-score span {
  color: var(--text-primary);
  font-weight: 700;
}
.overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
  width: 240px;
}
.overlay-btn {
  height: 52px;
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 17px;
  font-weight: 600;
  font-family: inherit;
}
.overlay-btn.primary {
  background: linear-gradient(135deg, #00d4ff 0%, #0099cc 100%);
  color: #001a22;
}

/* ============ HELP ============ */
.help-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 48px 60px 32px;
}
.help-title {
  font-size: 40px;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: 22px;
  letter-spacing: -1px;
}
.help-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 28px;
  font-size: 17px;
  color: var(--text-secondary);
  line-height: 1.45;
  max-width: 460px;
}
.help-list li {
  background: var(--bg-secondary);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
}
.help-list b {
  color: var(--accent-secondary);
  font-weight: 700;
}
.help-wrap .menu-btn { width: 240px; }
