* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #faf5ff;
  --primary: #805ad5;
  --text: #2d3748;
  --board-bg: #c8b4e8;
  --cell-bg: rgba(178,150,220,0.5);
  --radius: 14px;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  color: var(--text);
  user-select: none;
  touch-action: none;
}

.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 16px;
  position: absolute;
  inset: 0;
}
.screen.active { display: flex; }

/* ---- Title ---- */
.logo {
  font-size: clamp(2.6rem, 10vw, 4.2rem);
  font-weight: 900;
  text-align: center;
  line-height: 1.1;
  color: var(--primary);
  text-shadow: 3px 3px 0 rgba(128,90,213,0.18);
  margin-bottom: 20px;
}

.title-scores {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #fff;
  padding: 10px 28px;
  border-radius: var(--radius);
  margin-bottom: 24px;
  box-shadow: 0 3px 12px rgba(0,0,0,0.07);
}
.title-scores span:last-child {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary);
}

.hint {
  margin-top: 20px;
  text-align: center;
  font-size: 0.78rem;
  color: #999;
  line-height: 1.9;
}

/* ---- Buttons ---- */
.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 50px;
  padding: 16px 48px;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 5px 18px rgba(128,90,213,0.4);
  transition: transform 0.1s;
  min-height: 52px;
}
.btn-primary:active { transform: scale(0.96); }

.btn-secondary {
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
  border-radius: 50px;
  padding: 12px 32px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 10px;
  min-height: 48px;
}

.btn-small {
  background: #fff;
  color: var(--primary);
  border: 2px solid var(--primary);
  border-radius: 50px;
  padding: 8px 20px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 44px;
}

.label {
  font-size: 0.62rem;
  color: #aaa;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: block;
  text-align: center;
}

/* ---- Game screen ---- */
#screen-game {
  justify-content: flex-start;
  padding: 0;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 420px;
  padding: 10px 16px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
  flex-shrink: 0;
  gap: 12px;
}

.score-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 60px;
}
.score-group span:last-child {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text);
}

/* ---- Board ---- */
.board-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 12px;
}

.board {
  position: relative;
  background: var(--board-bg);
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 6px 24px rgba(128,90,213,0.25);
  /* size set by JS */
}

.board-bg {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.cell {
  background: var(--cell-bg);
  border-radius: 8px;
  /* size set by JS */
}

.tiles {
  position: absolute;
  inset: 8px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

/* ---- Tiles ---- */
.tile {
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  cursor: default;
  transition: transform 0.1s;
  /* size controlled by grid */
}

.tile.new {
  animation: tileAppear 0.15s ease-out both;
}

.tile.merged {
  animation: tileMerge 0.15s ease-out both;
}

@keyframes tileAppear {
  from { transform: scale(0); }
  to   { transform: scale(1); }
}

@keyframes tileMerge {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* Tile colors by value */
.tile[data-val="2"]    { background: #ffc0cb; color: #6b2d3e; }
.tile[data-val="4"]    { background: #b5f5a8; color: #2d5c25; }
.tile[data-val="8"]    { background: #a8e6f0; color: #1a5c6b; }
.tile[data-val="16"]   { background: #ffb347; color: #6b3700; }
.tile[data-val="32"]   { background: #cc99ff; color: #3a006b; }
.tile[data-val="64"]   { background: #ff6b6b; color: #6b0000; }
.tile[data-val="128"]  { background: #6b9fff; color: #001a6b; }
.tile[data-val="256"]  { background: #5bdb8a; color: #00461f; }
.tile[data-val="512"]  { background: #ffd700; color: #4d3800; }
.tile[data-val="1024"] { background: linear-gradient(135deg,#ff6b9d,#ffd700,#6bffb8); color: #3a003a; }
.tile[data-val="2048"] { background: linear-gradient(135deg,#c0c0c0,#fff,#e8e8e8); color: #333; box-shadow: 0 0 20px 6px rgba(255,215,0,0.7); }
.tile[data-val="4096"] { background: linear-gradient(135deg,#ffd700,#ff4500); color: #fff; }
.tile[data-val="8192"] { background: #111; color: #ffd700; }

.tile .tile-name {
  font-size: clamp(0.45rem, 1.5vw, 0.65rem);
  opacity: 0.75;
  margin-top: 2px;
  text-align: center;
  line-height: 1;
}

/* ---- Overlay ---- */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
}
.overlay.hidden { display: none; }

.overlay-inner {
  background: #fff;
  border-radius: var(--radius);
  padding: 28px 36px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}
.overlay-emoji { font-size: 2.8rem; }
.overlay-title { font-size: 1.4rem; font-weight: 900; color: var(--primary); }
.overlay-sub   { font-size: 0.9rem; color: #888; }
.overlay-score, .overlay-hs { font-size: 1rem; font-weight: 700; }
