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

  --board-bg: #0A1612;
  --cell-bg: #112019;
  --cell-bg-2: #0E1A14;
  --wall-color: #2D5142;
  --block-color-a: #34D993;
  --block-color-b: #1A8055;
  --cheese-a: #F4C430;
  --cheese-b: #D9A410;
  --cell-size: 32px;
  --gap: 0px;
}
* { 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);
}

/* Header (shared style) */
.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); }

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

/* ─── Title ─── */
.title-card {
  max-width: 540px; 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(36px, 6vw, 56px); 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; }

.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; }

.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-list .hl-gold { color: var(--gold); font-weight: 700; }
.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 ─── */
.game-wrap {
  display: flex; flex-direction: column; align-items: center;
  width: 100%; max-width: 800px; gap: 14px;
}
.game-status {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 8px; width: 100%; max-width: 720px;
}
.status-cell {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; padding: 8px 12px; 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: 18px; font-weight: 700; color: var(--text);
  font-variant-numeric: tabular-nums; margin-top: 2px;
}
.status-value.score-bump { color: var(--green-bright); }
.status-value.lives-warn { color: var(--orange-irish); }

.board-wrap {
  width: 100%; display: flex; justify-content: center;
}
.board {
  position: relative;
  background: var(--board-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  outline: none;
}
.grid-bg {
  display: grid;
  grid-template-columns: repeat(var(--cols, 20), var(--cell-size));
  grid-template-rows: repeat(var(--rows, 14), var(--cell-size));
  gap: 0;
}
.grid-bg .cell {
  width: var(--cell-size); height: var(--cell-size);
  background: var(--cell-bg);
  position: relative;
}
.grid-bg .cell:nth-child(odd) { background: var(--cell-bg-2); }
.grid-bg .cell.wall {
  background: linear-gradient(135deg, #2D5142 0%, #1B342A 100%);
  border: 1px solid #3D6855;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.2);
}
.grid-bg .cell.hole {
  background: radial-gradient(circle at center, #000 30%, var(--cell-bg) 50%);
}

.entities {
  position: absolute; inset: 4px;
  pointer-events: none;
}
.ent {
  position: absolute;
  width: var(--cell-size); height: var(--cell-size);
  display: flex; align-items: center; justify-content: center;
  transform: translate(
    calc(var(--col, 0) * var(--cell-size)),
    calc(var(--row, 0) * var(--cell-size))
  );
  transition: transform 0.16s ease-out;
  font-size: calc(var(--cell-size) * 0.7);
  line-height: 1;
}
.ent.spawn { animation: entSpawn 0.22s ease-out; }
.ent.fade-out { animation: entFade 0.25s ease-out forwards; }
@keyframes entSpawn {
  0% { transform: translate(calc(var(--col,0) * var(--cell-size)), calc(var(--row,0) * var(--cell-size))) scale(0.3); opacity: 0; }
  100% { transform: translate(calc(var(--col,0) * var(--cell-size)), calc(var(--row,0) * var(--cell-size))) scale(1); opacity: 1; }
}
@keyframes entFade {
  0% { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(var(--col,0) * var(--cell-size)), calc(var(--row,0) * var(--cell-size))) scale(0.5); }
}
.block {
  background: linear-gradient(135deg, var(--block-color-a) 0%, var(--block-color-b) 100%);
  border-radius: 5px;
  box-shadow:
    inset 0 1px 1px rgba(255,255,255,0.18),
    inset 0 -1px 1px rgba(0,0,0,0.2),
    0 1px 2px rgba(0,0,0,0.2);
  margin: 2px;
  width: calc(var(--cell-size) - 4px);
  height: calc(var(--cell-size) - 4px);
}
.cheese {
  background: linear-gradient(135deg, var(--cheese-a) 0%, var(--cheese-b) 100%);
  border-radius: 5px;
  box-shadow:
    inset 0 1px 2px rgba(255,255,255,0.3),
    inset 0 -1px 1px rgba(0,0,0,0.25),
    0 0 12px rgba(244,196,48,0.35);
  margin: 4px;
  width: calc(var(--cell-size) - 8px);
  height: calc(var(--cell-size) - 8px);
  animation: cheesePulse 2s ease-in-out infinite alternate;
}
@keyframes cheesePulse {
  0% { box-shadow: inset 0 1px 2px rgba(255,255,255,0.3), 0 0 8px rgba(244,196,48,0.3); }
  100% { box-shadow: inset 0 1px 2px rgba(255,255,255,0.3), 0 0 18px rgba(244,196,48,0.55); }
}
.mouse {
  font-size: calc(var(--cell-size) * 0.78);
  filter: drop-shadow(0 0 4px rgba(255,255,255,0.4));
  z-index: 3;
}
.cat {
  font-size: calc(var(--cell-size) * 0.78);
  filter: drop-shadow(0 0 6px rgba(255,140,66,0.5));
  z-index: 2;
}
.cat.angry { animation: catShake 0.4s ease-in-out infinite; }
@keyframes catShake {
  0%, 100% { transform: translate(calc(var(--col,0) * var(--cell-size)), calc(var(--row,0) * var(--cell-size))) rotate(0deg); }
  25% { transform: translate(calc(var(--col,0) * var(--cell-size)), calc(var(--row,0) * var(--cell-size))) rotate(-3deg); }
  75% { transform: translate(calc(var(--col,0) * var(--cell-size)), calc(var(--row,0) * var(--cell-size))) rotate(3deg); }
}
.cat.trapped { animation: catTrapped 0.4s ease-out forwards; }
@keyframes catTrapped {
  0% { transform: translate(calc(var(--col,0) * var(--cell-size)), calc(var(--row,0) * var(--cell-size))) scale(1); }
  50% { transform: translate(calc(var(--col,0) * var(--cell-size)), calc(var(--row,0) * var(--cell-size))) scale(1.3); }
  100% { transform: translate(calc(var(--col,0) * var(--cell-size)), calc(var(--row,0) * var(--cell-size))) scale(0.4); opacity: 0; }
}
.mouse.hit { animation: mouseHit 0.5s ease-out; }
@keyframes mouseHit {
  0%, 100% { transform: translate(calc(var(--col,0) * var(--cell-size)), calc(var(--row,0) * var(--cell-size))); }
  20% { transform: translate(calc(var(--col,0) * var(--cell-size) - 6px), calc(var(--row,0) * var(--cell-size))); }
  60% { transform: translate(calc(var(--col,0) * var(--cell-size) + 6px), calc(var(--row,0) * var(--cell-size))); }
}

/* Overlay (game over / level complete) */
.board-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6, 11, 8, 0.88);
  backdrop-filter: blur(4px);
  border-radius: 10px;
  z-index: 4;
}
.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; }

/* ─── HS modal + Leaderboard + Rate (shared) ─── */
.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); }

.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; 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;
}
.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; }

.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; }

/* ─── Responsive ─── */
@media (max-width: 760px) {
  :root { --cell-size: 26px; }
  .status-value { font-size: 15px; }
  .status-cell { padding: 6px 10px; }
}
@media (max-width: 540px) {
  :root { --cell-size: 22px; }
}
@media (max-width: 380px) {
  :root { --cell-size: 18px; }
}

/* ─── 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; }
}
