:root {
  --bg: #060B08;
  --bg-card: #0E1612;
  --bg-alt: #0A1310;
  --border: #1F2A26;
  --border-bright: #2D3F37;
  --text: #F5F7F2;
  --text-muted: #8AA395;
  --green: #00A86B;
  --green-bright: #1FCB89;
  --gold: #F4C430;
  --orange-irish: #FF8C42;
  --board-bg: #0F1B17;
  --cell-bg: #182921;
  --hit: #FF5A4A;

  --cell-size: 88px;
  --gap: 10px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
body {
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 20% -10%, rgba(0, 168, 107, 0.10), transparent 45%),
    radial-gradient(ellipse at 110% 110%, rgba(244, 196, 48, 0.06), transparent 45%),
    var(--bg);
  touch-action: pan-x pan-y;
}

/* ─── Header (shared style with Battleship) ─── */
.bs-header {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px;
  padding-top: max(12px, env(safe-area-inset-top));
  z-index: 5;
  pointer-events: none;
}
.bs-header > * { pointer-events: auto; }
.bs-brand {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--text);
  font-size: 14px;
  background: rgba(12, 26, 20, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 12px;
}
.bs-brand img { width: 22px; }
.bs-brand strong { color: var(--green-bright); font-weight: 800; }
.bs-header-right { display: flex; gap: 6px; }
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(12, 26, 20, 0.85);
  backdrop-filter: blur(8px);
  color: var(--text-muted); font-size: 16px;
  cursor: pointer; text-decoration: none;
  transition: color 0.15s, border-color 0.15s;
}
.btn-icon:hover { color: var(--text); border-color: var(--border-bright); }

/* ─── Screens ─── */
.screen {
  display: none;
  min-height: 100vh;
  padding: 80px 20px 40px;
  align-items: center;
  justify-content: center;
}
.screen.active { display: flex; }

.title-card {
  max-width: 520px; width: 100%; text-align: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 36px 28px;
}
.title-card h1 {
  font-size: clamp(48px, 9vw, 72px); font-weight: 900; letter-spacing: -0.02em;
  margin: 0 0 10px;
  line-height: 1;
}
.title-card h1 .green { color: var(--green-bright); }
.title-tag {
  margin: 0 0 24px; color: var(--text-muted); font-size: 15px;
}
.title-buttons { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.title-best {
  font-size: 13px; color: var(--text-muted);
  padding-top: 12px; border-top: 1px solid var(--border);
}
.title-best span { color: var(--gold); font-weight: 800; }

/* ─── Buttons ─── */
.btn {
  font: inherit; font-weight: 700; font-size: 14px;
  padding: 11px 22px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-primary {
  background: var(--green); color: #002618;
  box-shadow: 0 4px 16px rgba(0, 168, 107, 0.25);
}
.btn-primary:hover { background: var(--green-bright); }
.btn-primary:disabled { background: #1A2925; color: #4A6058; cursor: not-allowed; box-shadow: none; }
.btn-secondary {
  background: rgba(0, 168, 107, 0.10); color: var(--green-bright);
  border-color: rgba(0, 168, 107, 0.35);
}
.btn-secondary:hover { background: rgba(0, 168, 107, 0.20); }
.btn-ghost {
  background: transparent; color: var(--text-muted);
  border-color: var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--border-bright); }
.hidden { display: none !important; }

/* ─── Card screens ─── */
.screen-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 24px 24px;
  width: 100%; max-width: 540px;
  position: relative;
}
.screen-card.narrow { max-width: 380px; text-align: center; }
.screen-card h2 { margin: 0 0 14px; font-size: 22px; font-weight: 800; letter-spacing: -0.01em; }
.btn-close {
  position: absolute; top: 12px; right: 12px;
  width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid var(--border); background: transparent;
  color: var(--text-muted); font-size: 18px; cursor: pointer;
}
.btn-close:hover { color: var(--text); border-color: var(--border-bright); }

.howto-list {
  margin: 12px 0 16px; padding-left: 18px;
  color: var(--text-muted); font-size: 14px; line-height: 1.6;
}
.howto-list li { margin-bottom: 8px; }
.howto-list strong { color: var(--text); }
.howto-tip {
  background: rgba(0, 168, 107, 0.07);
  border: 1px solid rgba(0, 168, 107, 0.22);
  border-radius: 10px;
  padding: 12px;
  font-size: 13px; color: var(--text-muted);
}

/* ─── Game wrapper ─── */
.game-wrap {
  display: flex; flex-direction: column; align-items: center;
  width: 100%; max-width: 460px; gap: 18px;
}

.game-status {
  display: grid; grid-template-columns: 1fr 1fr auto;
  gap: 10px; width: 100%;
  align-items: center;
}
.status-cell {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 14px;
  text-align: center;
}
.status-label {
  font-size: 10px; font-weight: 800; letter-spacing: 0.18em;
  color: var(--text-muted); text-transform: uppercase;
}
.status-value {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 22px; font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
  transition: color 0.2s;
}
.status-value.score-bump { color: var(--green-bright); }

/* ─── Board ─── */
.board-wrap {
  width: 100%; display: flex; justify-content: center;
}
.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, var(--cell-size));
  grid-template-rows: repeat(4, var(--cell-size));
  gap: var(--gap);
  padding: var(--gap);
  background: var(--board-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  outline: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.cell {
  background: var(--cell-bg);
  border-radius: 8px;
}
.tiles {
  position: absolute;
  inset: var(--gap);
  pointer-events: none;
}
.tile {
  position: absolute;
  width: var(--cell-size);
  height: var(--cell-size);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-family: 'Inter', sans-serif;
  font-size: calc(var(--cell-size) * 0.42);
  border-radius: 8px;
  color: #062018;
  background: linear-gradient(135deg, #34D993 0%, #1FCB89 100%);
  box-shadow: 0 4px 12px rgba(0,168,107,0.15);
  transition: transform 0.13s ease-in-out;
  transform: translate(
    calc(var(--col, 0) * (var(--cell-size) + var(--gap))),
    calc(var(--row, 0) * (var(--cell-size) + var(--gap)))
  );
}
.tile.spawn { animation: tileSpawn 0.18s ease-out; }
.tile.merged { animation: tileMerge 0.2s ease-out; z-index: 2; }
@keyframes tileSpawn {
  0% { transform: translate(calc(var(--col,0) * (var(--cell-size) + var(--gap))), calc(var(--row,0) * (var(--cell-size) + var(--gap)))) scale(0.4); opacity: 0; }
  100% { transform: translate(calc(var(--col,0) * (var(--cell-size) + var(--gap))), calc(var(--row,0) * (var(--cell-size) + var(--gap)))) scale(1); opacity: 1; }
}
@keyframes tileMerge {
  0% { transform: translate(calc(var(--col,0) * (var(--cell-size) + var(--gap))), calc(var(--row,0) * (var(--cell-size) + var(--gap)))) scale(1); }
  50% { transform: translate(calc(var(--col,0) * (var(--cell-size) + var(--gap))), calc(var(--row,0) * (var(--cell-size) + var(--gap)))) scale(1.18); }
  100% { transform: translate(calc(var(--col,0) * (var(--cell-size) + var(--gap))), calc(var(--row,0) * (var(--cell-size) + var(--gap)))) scale(1); }
}

/* Tile colors — gradient from bright green (low) → gold (mid) → orange (high) → red (super high) */
.tile-2     { background: linear-gradient(135deg, #34D993 0%, #1FCB89 100%); color: #062018; }
.tile-4     { background: linear-gradient(135deg, #2BC48A 0%, #00A86B 100%); color: #062018; }
.tile-8     { background: linear-gradient(135deg, #75D670 0%, #4ABE3D 100%); color: #062018; }
.tile-16    { background: linear-gradient(135deg, #C9D33B 0%, #9BB22D 100%); color: #1A1F02; }
.tile-32    { background: linear-gradient(135deg, #F4C430 0%, #D9A410 100%); color: #2A1F00; }
.tile-64    { background: linear-gradient(135deg, #FFB04A 0%, #E8902A 100%); color: #2A1A00; }
.tile-128   { background: linear-gradient(135deg, #FF8C42 0%, #E66B1F 100%); color: #fff; font-size: calc(var(--cell-size) * 0.36); }
.tile-256   { background: linear-gradient(135deg, #FF6E3A 0%, #DD4F18 100%); color: #fff; font-size: calc(var(--cell-size) * 0.36); }
.tile-512   { background: linear-gradient(135deg, #FF5A4A 0%, #C8302C 100%); color: #fff; font-size: calc(var(--cell-size) * 0.36); }
.tile-1024  { background: linear-gradient(135deg, #E84545 0%, #951D1D 100%); color: #fff; font-size: calc(var(--cell-size) * 0.32); box-shadow: 0 0 24px rgba(232,69,69,0.4); }
.tile-2048  {
  background: linear-gradient(135deg, #F4C430 0%, #FF8C42 50%, #E84545 100%);
  color: #fff; font-size: calc(var(--cell-size) * 0.32);
  box-shadow: 0 0 32px rgba(244,196,48,0.6);
  animation: tileGlow 1.5s ease-in-out infinite alternate;
}
.tile-super {
  background: linear-gradient(135deg, #1FCB89 0%, #F4C430 50%, #E84545 100%);
  color: #fff; font-size: calc(var(--cell-size) * 0.30);
  box-shadow: 0 0 32px rgba(31,203,137,0.6);
}
@keyframes tileGlow {
  0% { box-shadow: 0 0 24px rgba(244,196,48,0.4); }
  100% { box-shadow: 0 0 40px rgba(244,196,48,0.85); }
}

/* ─── Game-over overlay ─── */
.board-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6, 11, 8, 0.85);
  backdrop-filter: blur(4px);
  border-radius: 14px;
  z-index: 3;
}
.board-overlay[hidden] { display: none; }
.overlay-card { text-align: center; padding: 20px 28px; max-width: 340px; }
.overlay-card h3 {
  margin: 0 0 8px; font-size: 24px; font-weight: 800;
  color: var(--text);
  letter-spacing: -0.01em;
}
.overlay-card p {
  margin: 0 0 16px; color: var(--text-muted); font-size: 14px;
}
.overlay-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

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

/* ─── Rate modal (shared style) ─── */
.rate-card { padding-top: 36px; }
.rate-sub { margin: 4px 0 14px; color: var(--text-muted); font-size: 13px; }
.rate-stars { display: flex; justify-content: center; gap: 6px; margin: 6px 0 16px; }
.star-btn {
  background: none; border: none; cursor: pointer;
  font-size: 32px; line-height: 1;
  color: rgba(244, 196, 48, 0.22);
  padding: 4px 6px; border-radius: 6px;
  transition: color 0.12s, transform 0.12s;
}
.star-btn:hover { color: rgba(244, 196, 48, 0.65); transform: scale(1.08); }
.star-btn.lit { color: var(--gold); text-shadow: 0 0 14px rgba(244, 196, 48, 0.5); }
.rate-form { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; text-align: left; }
.rate-form input, .rate-form textarea {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text); font: inherit; font-size: 14px;
  resize: vertical; outline: none;
}
.rate-form input:focus, .rate-form textarea:focus { border-color: var(--green); }
.rate-status { min-height: 18px; font-size: 12px; margin-bottom: 6px; color: var(--text-muted); text-align: center; }
.rate-status.error { color: var(--orange-irish); }
.rate-status.success { color: var(--green-bright); }
.rate-signup {
  display: flex; align-items: flex-start; gap: 9px;
  font-size: 12px; color: var(--text-muted); line-height: 1.4;
  padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 10px; background: rgba(0,168,107,0.05);
  cursor: pointer; user-select: none; text-align: left;
}
.rate-signup input[type="checkbox"] { margin-top: 2px; accent-color: var(--green); }
.rate-signup small { display: block; opacity: 0.75; font-size: 11px; }
.modal-actions { display: flex; flex-direction: column; gap: 8px; }

/* ─── High Score modal ─── */
.hs-card { padding-top: 28px; text-align: center; }
.hs-trophy { font-size: 44px; margin-bottom: 4px; }
.hs-card h2 { margin-bottom: 6px; }
.hs-sub { margin: 0 0 18px; color: var(--text-muted); font-size: 13px; }
.hs-score-display {
  background: linear-gradient(135deg, rgba(244,196,48,0.10) 0%, rgba(255,140,66,0.10) 100%);
  border: 1px solid rgba(244,196,48,0.3);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}
.hs-score-num {
  font-size: 36px; font-weight: 900;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  color: var(--gold);
  letter-spacing: -0.02em;
  text-shadow: 0 0 20px rgba(244,196,48,0.4);
}
.hs-rank {
  font-size: 12px; color: var(--text-muted);
  margin-top: 4px;
}
.hs-rank.high { color: var(--green-bright); font-weight: 700; }
.hs-form { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; text-align: left; }
.hs-form input {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text); font: inherit; font-size: 14px;
  outline: none;
}
.hs-form input:focus { border-color: var(--gold); }
.hs-disclaimer {
  margin: 4px 0 8px;
  font-size: 11px; color: var(--text-muted);
  line-height: 1.4;
}
.hs-status { min-height: 18px; font-size: 12px; margin-bottom: 6px; color: var(--text-muted); text-align: center; }
.hs-status.error { color: var(--orange-irish); }
.hs-status.success { color: var(--green-bright); }

/* ─── Leaderboard ─── */
.lb-card { padding-top: 36px; max-width: 480px; }
.lb-sub { margin: 0 0 16px; color: var(--text-muted); font-size: 13px; }
.lb-list {
  list-style: none; counter-reset: rank; padding: 0; margin: 0;
}
.lb-list li {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 6px;
  counter-increment: rank;
}
.lb-list li.you {
  background: rgba(0, 168, 107, 0.12);
  border-color: rgba(0, 168, 107, 0.4);
}
.lb-list li.lb-empty {
  justify-content: center; color: var(--text-muted); font-size: 13px;
}
.lb-rank {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--cell-bg);
  font-weight: 800; font-size: 14px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.lb-rank.gold { background: linear-gradient(135deg, #F4C430 0%, #D9A410 100%); color: #2A1F00; box-shadow: 0 0 14px rgba(244,196,48,0.4); }
.lb-rank.silver { background: linear-gradient(135deg, #C0C8C4 0%, #94A097 100%); color: #1A1F1B; }
.lb-rank.bronze { background: linear-gradient(135deg, #C58E5C 0%, #8E6238 100%); color: #1F1208; }
.lb-name {
  flex: 1; min-width: 0;
  font-weight: 700; font-size: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lb-score {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-weight: 800; font-size: 15px;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

/* ─── Responsive ─── */
@media (max-width: 480px) {
  :root { --cell-size: calc(min(20vw, 76px)); --gap: 8px; }
  .game-wrap { gap: 14px; }
  .status-value { font-size: 18px; }
}
@media (max-width: 360px) {
  :root { --cell-size: 64px; --gap: 6px; }
}

/* ─── Clear Back-to-Games button ─── */
.btn-back {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0 14px; height: 36px;
  border-radius: 8px;
  border: 1px solid rgba(184, 255, 64, 0.45);
  background: linear-gradient(135deg, rgba(184,255,64,0.18) 0%, rgba(91,192,32,0.18) 100%);
  color: var(--acid, #B8FF40);
  font-size: 13px; font-weight: 700; letter-spacing: 0.04em;
  text-decoration: none; cursor: pointer;
  transition: all 0.15s;
}
.btn-back:hover {
  background: linear-gradient(135deg, rgba(184,255,64,0.28) 0%, rgba(91,192,32,0.28) 100%);
  color: #fff;
  border-color: rgba(184, 255, 64, 0.7);
}
.btn-back .ba-arrow { font-size: 16px; line-height: 1; }
@media (max-width: 540px) {
  .btn-back { padding: 0 10px; font-size: 12px; }
}
