/* One Different — GameCMB
   Dark modern brain-game aesthetic: deep navy/charcoal background, glassy
   panels, bright candy-neon tiles. Mobile-first; board sizing is computed
   in JS (renderer.js) so no calc()-in-CSS is relied on for the grid itself
   (documented project footgun — the game.css grid dimensions are computed
   in JS and written as inline px, not via CSS calc()). */

:root {
  --bg-0: #060912;
  --bg-1: #0b1120;
  --bg-2: #121a2e;
  --panel: rgba(18, 26, 46, 0.82);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text-0: #f4f6fb;
  --text-1: #aab2c8;
  --text-2: #6b7590;
  --accent: #6c8cff;
  --accent-2: #b06cff;
  --good: #34e0a1;
  --bad: #ff5c7a;
  --warn: #ffc857;
  --radius-lg: 22px;
  --radius-md: 14px;
  --shadow-soft: 0 18px 50px rgba(0, 0, 0, 0.45);
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(1100px 700px at 15% -10%, rgba(108, 140, 255, 0.16), transparent 60%),
    radial-gradient(900px 600px at 100% 0%, rgba(176, 108, 255, 0.14), transparent 55%),
    linear-gradient(180deg, var(--bg-0), var(--bg-1) 40%, var(--bg-2));
  color: var(--text-0);
  font-family: 'Poppins', 'Segoe UI', system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

a { color: var(--accent); }

/* the single most important rule in every GameCMB game: an author display
   rule elsewhere must never be able to out-rank [hidden]. */
[hidden] { display: none !important; }

.app-root {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 10px) 14px calc(var(--safe-bottom) + 16px);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px 14px;
}

.brand {
  font-weight: 800;
  letter-spacing: 0.06em;
  font-size: 1.15rem;
}
.brand span { color: var(--accent); }

.topbar-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text-0);
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
}
.icon-btn:active { transform: scale(0.94); }
.icon-btn[aria-pressed="false"] { opacity: 0.5; }

.stage {
  position: relative;
  flex: 1;
  min-height: 560px;
}

.screen {
  /*position: absolute;*/
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 14px;
  padding: 10px 4px;
  overflow-y: auto;
}

.glass-panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 26px 22px;
  width: 100%;
  max-width: 420px;
}

.logo-mark {
  width: 84px;
  height: 84px;
  margin: 0 auto 6px;
}

.title-lg {
  font-size: 2.1rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  margin: 0;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle { color: var(--text-1); margin: 0 0 6px; font-size: 1.02rem; }

.btn {
  appearance: none;
  border: none;
  border-radius: 16px;
  padding: 15px;
  font-size: .8rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  width: 100%;
  color: var(--text-0);
  transition: transform 0.12s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 30px rgba(108, 140, 255, 0.35);
}
.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-border);
}
.btn-row { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.btn-row.row-2 { flex-direction: row; }
.btn-row.row-2 .btn { flex: 1; }

.best-line {
  color: var(--text-1);
  font-size: 0.92rem;
  margin-top: 4px;
}
.best-line strong { color: var(--warn); }

/* How to play */
.howto-steps {
  text-align: left;
  color: var(--text-1);
  line-height: 1.5;
  margin: 6px 0 4px;
  padding-left: 0;
  list-style: none;
}
.howto-steps li { margin-bottom: 8px; padding-left: 22px; position: relative; }
.howto-steps li::before {
  content: '●';
  position: absolute;
  left: 0;
  color: var(--accent);
  font-size: 0.6rem;
  top: 8px;
}

/* Gameplay screen */
#screenGame { justify-content: flex-start; padding-top: 4px; }

.hud {
  width: 100%;
  max-width: 620px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.hud-item {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}
.hud-label { font-size: 0.62rem; letter-spacing: 0.08em; color: var(--text-2); font-weight: 700; }
.hud-item span:last-child { font-size: 1.05rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.hud-time span:last-child { color: var(--warn); }
.hud-time.time-low span:last-child { color: var(--bad); animation: pulse 0.5s infinite; }
.hud-combo-hot span:last-child { color: var(--good); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

.round-timer-track {
  width: 100%;
  max-width: 620px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  margin-bottom: 10px;
}
.round-timer-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--good), var(--warn), var(--bad));
  border-radius: inherit;
}

.board-wrap {
  position: relative;
  width: 100%;
  max-width: 640px;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board {
  position: relative;
  display: grid;
  gap: 8px;
  width: 100%;
  max-width: 600px;
  aspect-ratio: 1 / 1;
  /*padding: 14px;*/
  background: rgba(10, 14, 26, 0.55);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.35);
  touch-action: manipulation;
  place-items: center;
}

.tile {
  cursor: pointer;
  border: solid transparent;
  transition: transform 0.1s ease, filter 0.15s ease;
  will-change: transform;
  position: relative;
}
.tile:active { transform: scale(0.92); }
.tile.tile-correct { animation: tileCorrect 0.32s ease; }
.tile.tile-wrong-tap { animation: tileShake 0.32s ease; }

@keyframes tileCorrect {
  0% { transform: scale(1); filter: brightness(1); }
  40% { transform: scale(1.16); filter: brightness(1.5) drop-shadow(0 0 14px rgba(52, 224, 161, 0.85)); }
  100% { transform: scale(0.001); filter: brightness(1); opacity: 0; }
}
@keyframes tileShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px) scale(0.96); }
  40% { transform: translateX(6px) scale(0.96); }
  60% { transform: translateX(-4px) scale(0.96); }
  80% { transform: translateX(4px) scale(0.96); }
}

.tile-tick {
  position: absolute;
  top: 6%;
  left: 50%;
  width: 10%;
  height: 22%;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 3px;
  transform: translateX(-50%);
  pointer-events: none;
}

.tile-pattern-striped {
  background-image: repeating-linear-gradient(45deg, rgba(0,0,0,0.22) 0 6px, transparent 6px 12px);
}
.tile-pattern-dotted {
  background-image: radial-gradient(rgba(0,0,0,0.28) 22%, transparent 24%);
  background-size: 22% 22%;
}

.feedback-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}

.particle {
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  pointer-events: none;
  animation: particleBurst 480ms ease-out forwards;
}
@keyframes particleBurst {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(var(--px), var(--py)) scale(0.2); opacity: 0; }
}

.floater {
  position: absolute;
  font-weight: 800;
  font-size: 1.1rem;
  pointer-events: none;
  color: var(--good);
  animation: floatUp 620ms ease-out forwards;
  text-shadow: 0 2px 10px rgba(0,0,0,0.5);
  white-space: nowrap;
}
.floater.floater-bad { color: var(--bad); }
@keyframes floatUp {
  0% { transform: translate(-50%, 0); opacity: 1; }
  100% { transform: translate(-50%, -46px); opacity: 0; }
}

.combo-banner {
  position: absolute;
  top: 8%;
  left: 50%;
  transform: translateX(-50%);
  font-weight: 900;
  font-size: 1.6rem;
  letter-spacing: 0.04em;
  color: var(--warn);
  text-shadow: 0 4px 18px rgba(255, 200, 87, 0.55);
  animation: comboPop 620ms ease-out forwards;
  pointer-events: none;
}
@keyframes comboPop {
  0% { transform: translateX(-50%) scale(0.6); opacity: 0; }
  25% { transform: translateX(-50%) scale(1.15); opacity: 1; }
  100% { transform: translateX(-50%) scale(1); opacity: 0; }
}

.countdown-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 9, 18, 0.78);
  border-radius: var(--radius-lg);
  z-index: 5;
}
.countdown-num {
  font-size: 5rem;
  font-weight: 900;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: countPop 0.9s ease;
}
@keyframes countPop {
  0% { transform: scale(0.5); opacity: 0; }
  30% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* Game over */
.score-big {
  font-size: 2.6rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin: 2px 0;
}
.pb-badge {
  display: inline-block;
  background: linear-gradient(120deg, var(--warn), #ff9a5a);
  color: #241300;
  font-weight: 800;
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  padding: 5px 12px;
  border-radius: 999px;
  margin-bottom: 6px;
}
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 10px 0;
}
.stat-cell {
  background: rgba(255,255,255,0.04);
  border-radius: 10px;
  padding: 8px 4px;
}
.stat-cell .hud-label { display: block; }
.stat-cell strong { font-size: 1.05rem; }
.encourage-msg { color: var(--text-1); font-size: 0.95rem; min-height: 1.2em; }

/* Nickname */
.nickname-input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: rgba(255,255,255,0.05);
  color: var(--text-0);
  font-size: 1.05rem;
  text-align: center;
  margin: 8px 0;
}
.nickname-input:focus { outline: 2px solid var(--accent); }
.field-hint { color: var(--text-2); font-size: 0.8rem; }
.field-error { color: var(--bad); font-size: 0.85rem; min-height: 1.1em; }

/* Leaderboard */
.tabs { display: flex; gap: 6px; width: 100%; max-width: 460px; }
.tab-btn {
  flex: 1;
  padding: 10px 6px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: rgba(255,255,255,0.04);
  color: var(--text-1);
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
}
.tab-btn[aria-selected="true"] {
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  color: #fff;
  border-color: transparent;
}
.lb-list {
  width: 100%;
  max-width: 460px;
  max-height: 46vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 2px;
}
.lb-row {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,0.03);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.95rem;
}
.lb-row.lb-you { background: rgba(108, 140, 255, 0.18); border: 1px solid rgba(108,140,255,0.4); }
.lb-rank { font-weight: 800; color: var(--text-2); }
.lb-name { text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 800; font-variant-numeric: tabular-nums; }
.lb-empty { color: var(--text-2); padding: 20px 0; }
.lb-you-row {
  width: 100%;
  max-width: 460px;
  text-align: center;
  color: var(--text-1);
  font-size: 0.88rem;
  margin-top: 4px;
}

.ad-slot {
  min-height: 90px;
  margin: 16px 0 6px;
  border-radius: var(--radius-md);
  border: 1px dashed var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  font-size: 0.78rem;
}

.seo-copy {
  color: var(--text-1);
  font-size: 0.92rem;
  line-height: 1.6;
  padding: 6px 4px 26px;
}
.seo-copy h2, .seo-copy h3 { color: var(--text-0); }
.seo-copy a { color: var(--accent); }

.site-footer {
  text-align: center;
  color: var(--text-2);
  font-size: 0.78rem;
  padding: 10px 0 4px;
}

.spinner-inline {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.25);
  border-top-color: var(--text-0);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

:fullscreen .stage,
.stage:fullscreen {
  background: var(--bg-0);
  padding: 16px;
}

@media (max-width: 380px) {
  .title-lg { font-size: 1.7rem; }
  .hud-item span:last-child { font-size: 0.92rem; }
}

@media (min-width: 700px) {
  .board { max-width: 560px; }
}

@media (prefers-reduced-motion: reduce) {
  .tile, .particle, .floater, .combo-banner, .countdown-num, .tile.tile-correct, .tile.tile-wrong-tap, .round-timer-bar {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
