:root {
  --bg: #060A05;
  --bg-card: #0B130A;
  --border: #1B2B17;
  --border-bright: #2E4628;
  --text: #F4F0DA;
  --text-muted: #7E8E73;
  --acid: #B8FF40;
  --acid-bright: #D2FF6E;
  --acid-dim: #5BC020;
  --gold: #F4C430;
  --orange: #FF8C42;
  --board-bg: #0B1612;
  --board-grid: #14211A;
}
* { 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(184, 255, 64, 0.08), transparent 45%),
    radial-gradient(ellipse at 110% 110%, rgba(244, 196, 48, 0.05), transparent 45%),
    var(--bg);
  touch-action: pan-x pan-y;
}

.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(11, 19, 10, 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(--acid); 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(11, 19, 10, 0.85);
  backdrop-filter: blur(8px);
  color: var(--text-muted); font-size: 16px;
  cursor: pointer; text-decoration: none;
}
.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-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(--acid); }
.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-difficulty {
  display: flex; align-items: center; justify-content: center;
  gap: 8px; padding-top: 14px; border-top: 1px solid var(--border);
  font-size: 13px; color: var(--text-muted);
  margin-bottom: 12px;
}
.diff-btn {
  background: transparent; border: 1px solid var(--border);
  color: var(--text-muted); font: inherit;
  padding: 5px 14px; border-radius: 999px; cursor: pointer;
  transition: all 0.15s;
}
.diff-btn.active { background: rgba(184, 255, 64, 0.15); border-color: rgba(184, 255, 64, 0.5); color: var(--acid); }
.diff-btn:hover:not(.active) { color: var(--text); border-color: var(--border-bright); }
.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: linear-gradient(135deg, #B8FF40 0%, #5BC020 100%);
  color: #082010; font-weight: 800;
  box-shadow: 0 4px 16px rgba(184, 255, 64, 0.25);
}
.btn-primary:hover { background: linear-gradient(135deg, #D2FF6E 0%, #80E830 100%); }
.btn-primary:disabled { background: #1A2818; color: #4A5848; cursor: not-allowed; box-shadow: none; }
.btn-secondary {
  background: rgba(184, 255, 64, 0.10); color: var(--acid);
  border-color: rgba(184, 255, 64, 0.35);
}
.btn-secondary:hover { background: rgba(184, 255, 64, 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-tip {
  background: rgba(184, 255, 64, 0.08);
  border: 1px solid rgba(184, 255, 64, 0.25);
  border-radius: 10px; padding: 12px;
  font-size: 13px; color: var(--text-muted);
}
.kbd {
  display: inline-block; padding: 1px 6px; margin: 0 2px;
  border: 1px solid var(--border-bright); border-radius: 5px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 11px; color: var(--acid);
}

.game-wrap {
  display: flex; flex-direction: column; align-items: center;
  width: 100%; max-width: 720px; gap: 14px;
}
.game-status {
  display: grid; grid-template-columns: 1fr 1fr 1fr auto;
  gap: 8px; width: 100%; max-width: 720px;
}
.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;
}
.status-value.score-bump { color: var(--acid-bright); }

.board-wrap {
  width: 100%; display: flex; justify-content: center; position: relative;
}
#board {
  width: 100%; max-width: 720px; aspect-ratio: 4/3;
  display: block;
  background: var(--board-bg);
  border: 2px solid var(--border-bright);
  border-radius: 10px;
  outline: none;
  user-select: none; -webkit-user-select: none;
  touch-action: none;
  box-shadow: 0 0 36px rgba(184, 255, 64, 0.12);
}
.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: 10px;
  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: 26px; font-weight: 800; color: var(--acid); letter-spacing: 0.02em; }
.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(184,255,64,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(--acid); 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(--acid); }
.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); }
.hs-status.success { color: var(--acid); }

.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(184, 255, 64, 0.12); border-color: rgba(184, 255, 64, 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(--board-grid);
  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(--acid); }
.rate-status { min-height: 18px; font-size: 12px; margin-bottom: 6px; color: var(--text-muted); text-align: center; }
.rate-status.error { color: var(--orange); }
.rate-status.success { color: var(--acid); }
.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(184,255,64,0.05);
  cursor: pointer; user-select: none; text-align: left;
}
.rate-signup input[type="checkbox"] { margin-top: 2px; accent-color: var(--acid); }
.rate-signup small { display: block; opacity: 0.75; font-size: 11px; }
.modal-actions { display: flex; flex-direction: column; gap: 8px; }

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

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

/* ─── Override board sizing for Tetris (1:2 portrait, square cells) ─── */
#board {
  width: 320px !important;
  height: 640px !important;
  max-width: 100% !important;
  aspect-ratio: auto !important;
  background: #0B1612 !important;
  margin: 0 auto;
  display: block !important;
}
.game-wrap { max-width: 420px !important; }
.board-wrap { width: 100% !important; max-width: 360px; margin: 0 auto; }
@media (max-width: 380px) {
  #board { width: 260px !important; height: 520px !important; }
}
