/* Fill The Gap — Game CMB. Dark neon arcade theme. Mobile-first. */

:root {
  --bg: #080A12;
  --panel: #111522;
  --panel-2: #161b2c;
  --line: #232a42;
  --text: #eef1fb;
  --text-dim: #97a0c2;
  --cyan: #37f2e0;
  --purple: #9b6bff;
  --pink: #ff5fb0;
  --lime: #b4ff4d;
  --danger: #ff5470;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 20px 60px rgba(0,0,0,0.5);
}

/* Standing GameCMB convention: [hidden] must always win over any author
   display rule on the same element (overlays/modals/screens), because CSS
   origin (author beats user-agent) means any `.screen{display:flex}`-style
   rule would otherwise keep an element visible after `el.hidden = true`. */
[hidden] { display: none !important; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 800px at 50% -10%, #131a2e 0%, var(--bg) 55%);
  color: var(--text);
  font-family: "Space Grotesk", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

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

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

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 0 16px;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 24px 16px 32px;
  overflow-y: auto;
}

.screen-static { position: relative; padding: 0; }

#stage { position: relative; flex: 1; min-height: 100vh; min-height: 100dvh; }

.brand {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}
.brand-title {
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.14em;
  color: var(--text-dim);
  text-transform: uppercase;
}

.icon-btn {
  min-width: 44px;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn:focus-visible, .choice-btn:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.icon-row { display: flex; gap: 8px; }

/* ---------- Start screen ---------- */
.start-hero { text-align: center; margin: 8px 0 4px; }
.logo-title {
  font-size: 44px;
  line-height: 1.02;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 12px 0 6px;
  background: linear-gradient(120deg, var(--cyan), var(--purple) 55%, var(--pink));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline { color: var(--text-dim); font-size: 15px; margin: 0 0 22px; }

.demo-frame { display: flex; justify-content: center; margin: 8px 0 24px; }
.demo-piece { width: 96px; height: 96px; filter: drop-shadow(0 0 18px rgba(55,242,224,0.35)); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 64px;
  border-radius: var(--radius-sm);
  border: none;
  font-weight: 700;
  font-size: 17px;
  cursor: pointer;
  letter-spacing: 0.02em;
}
.btn-primary {
  background: linear-gradient(120deg, var(--cyan), var(--purple));
  color: #04101a;
  box-shadow: 0 8px 30px rgba(55,242,224,0.25);
}
.btn-secondary {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
}
.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--line);
}
.btn + .btn { margin-top: 12px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { margin-top: 0; }

.stat-line {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  margin: 18px 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
#home-best { color: var(--lime); font-weight: 800; font-size: 15px; }

.nick-line { text-align: center; color: var(--text-dim); font-size: 13px; margin-bottom: 18px; }
.nick-line button { background: none; border: none; color: var(--cyan); cursor: pointer; font: inherit; padding: 0 4px; }
#home-nick-name { color: var(--text); font-weight: 700; }

.challenge-card {
  background: var(--panel);
  border: 1px solid var(--purple);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  text-align: center;
  margin-bottom: 18px;
}
.challenge-card strong { color: var(--pink); font-size: 20px; }

.home-links { text-align: center; margin-top: 6px; }
.home-links a { color: var(--text-dim); font-size: 13px; text-decoration: underline; cursor: pointer; }

/* ---------- How to play ---------- */
.panel-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}
.panel-card h2 { margin: 0 0 8px; font-size: 18px; }
.panel-card p, .panel-card li { color: var(--text-dim); line-height: 1.55; font-size: 14.5px; }
.rules-list { margin: 6px 0 0; padding-left: 20px; }

/* ---------- Countdown ---------- */
#screen-countdown { align-items: center; justify-content: center; text-align: center; }
#countdown-num {
  font-size: 96px;
  font-weight: 800;
  background: linear-gradient(120deg, var(--cyan), var(--pink));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
#countdown-num.pop { animation: popIn 0.5s ease; }
@keyframes popIn { 0% { transform: scale(0.5); opacity: 0; } 60% { transform: scale(1.2); opacity: 1; } 100% { transform: scale(1); } }

/* ---------- Game screen ---------- */
#screen-game { padding-top: 14px; }
.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.hud-title { font-weight: 800; letter-spacing: 0.1em; font-size: 13px; color: var(--text-dim); text-transform: uppercase; }

.hud-mid {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  margin-bottom: 6px;
}
.hud-score-label { font-size: 12px; letter-spacing: 0.12em; color: var(--text-dim); text-transform: uppercase; }
.hud-score-value { font-size: 34px; font-weight: 800; line-height: 1.05; }
#hud-combo-wrap {
  justify-self: end;
  text-align: right;
  color: var(--text-dim);
  font-weight: 800;
  font-size: 16px;
  transition: color 0.15s, transform 0.15s;
}
#hud-combo-wrap.is-active { color: var(--lime); transform: scale(1.08); }

.timer-track {
  height: 8px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
  margin-bottom: 4px;
}
#timer-bar {
  height: 100%;
  width: 100%;
  transform-origin: left center;
  background: linear-gradient(90deg, var(--cyan), var(--lime));
  transition: transform 80ms linear, background-color 0.2s;
  border-radius: 999px;
}
#timer-bar.danger { background: linear-gradient(90deg, var(--pink), var(--danger)); }
#timer-label { display: block; text-align: right; font-size: 12px; color: var(--text-dim); margin-bottom: 14px; }

#gap-stage { display: flex; justify-content: center; margin-bottom: 6px; position: relative; }
.gap-frame {
  width: 190px;
  height: 190px;
  border-radius: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: var(--shadow);
}
.gap-frame.anim-in { animation: gapIn 0.28s ease; }
@keyframes gapIn { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.gap-outline { width: 108px; height: 108px; opacity: 0.22; }
.gap-outline svg .piece-shape, .gap-outline svg .piece-shape-stroke { stroke-dasharray: 6 5; fill: none !important; stroke: var(--cyan); stroke-width: 3; }
.gap-mark {
  position: absolute;
  font-size: 40px;
  font-weight: 800;
  color: var(--text-dim);
}
#gap-stage.flash-correct .gap-frame { animation: flashGood 0.4s ease; }
#gap-stage.flash-wrong .gap-frame { animation: flashBad 0.4s ease; }
@keyframes flashGood { 0% { box-shadow: 0 0 0 0 rgba(180,255,77,0.6);} 100% { box-shadow: 0 0 0 24px rgba(180,255,77,0);} }
@keyframes flashBad { 0%, 100% { transform: translateX(0);} 20% { transform: translateX(-6px);} 40% { transform: translateX(6px);} 60% { transform: translateX(-4px);} 80% { transform: translateX(4px);} }

.piece-svg { width: 100%; height: 100%; }
.piece-shape, .piece-shape-stroke { fill: var(--cyan); }
.piece-shape-stroke { stroke: var(--cyan); fill: none; }

#choices {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 10px;
}
#choices[aria-label*="4 options"], #choices:has(.choice-btn:nth-child(4)) { grid-template-columns: repeat(2, 1fr); }
#choices:has(.choice-btn:nth-child(5)) { grid-template-columns: repeat(3, 1fr); }

.choice-btn {
  position: relative;
  min-height: 78px;
  border-radius: var(--radius-sm);
  background: var(--panel);
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  cursor: pointer;
}
.choice-btn svg { width: 56%; height: 56%; }
.choice-letter {
  position: absolute;
  top: 6px;
  left: 8px;
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 700;
}
.choice-btn:active { transform: scale(0.97); }
.choice-btn.is-correct { border-color: var(--lime); box-shadow: 0 0 0 2px rgba(180,255,77,0.35) inset; }
.choice-btn.is-correct .piece-shape, .choice-btn.is-correct .piece-shape-stroke { fill: var(--lime); stroke: var(--lime); }
.choice-btn.is-wrong { border-color: var(--danger); }
.choice-btn.is-wrong .piece-shape, .choice-btn.is-wrong .piece-shape-stroke { fill: var(--danger); stroke: var(--danger); }
.choice-btn.shake { animation: shakeBtn 0.4s ease; }
@keyframes shakeBtn { 0%, 100% { transform: translateX(0);} 20% { transform: translateX(-6px);} 40% { transform: translateX(6px);} 60% { transform: translateX(-4px);} 80% { transform: translateX(4px);} }
.choice-btn[disabled] { cursor: default; }

.hearts-row { display: flex; justify-content: center; gap: 8px; margin-top: 18px; }
.heart { font-size: 22px; }
.heart.full { color: var(--pink); }
.heart.empty { color: var(--line); }

#toast-layer { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.toast {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.6);
  font-weight: 800;
  font-size: 22px;
  padding: 6px 14px;
  border-radius: 10px;
  background: rgba(17,21,34,0.9);
  border: 1px solid var(--line);
  animation: toastPop 1.1s ease forwards;
  white-space: nowrap;
}
.toast-combo { color: var(--lime); }
.toast-perfect { color: var(--pink); }
.toast-life { color: var(--cyan); }
.toast-wrong { color: var(--danger); }
@keyframes toastPop {
  0% { opacity: 0; transform: translate(-50%,-50%) scale(0.5); }
  20% { opacity: 1; transform: translate(-50%,-50%) scale(1.15); }
  35% { transform: translate(-50%,-50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%,-70%) scale(1); }
}
.score-pop {
  position: absolute;
  font-weight: 800;
  color: var(--lime);
  font-size: 18px;
  transform: translate(-50%, 0);
  animation: floatUp 0.9s ease forwards;
}
@keyframes floatUp { 0% { opacity: 1; transform: translate(-50%,0);} 100% { opacity: 0; transform: translate(-50%,-46px); } }

@media (prefers-reduced-motion: reduce) {
  .gap-frame.anim-in, #countdown-num.pop, .choice-btn.shake, #gap-stage.flash-correct .gap-frame,
  #gap-stage.flash-wrong .gap-frame, .toast, .score-pop { animation: none !important; }
}

/* ---------- Game over ---------- */
.go-hero { text-align: center; margin: 10px 0 6px; }
.go-hero h2 { font-size: 26px; margin: 0 0 4px; letter-spacing: 0.05em; color: var(--text-dim); }
#go-score { font-size: 48px; font-weight: 800; color: var(--lime); }
.badge-highscore {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  background: linear-gradient(120deg, var(--pink), var(--purple));
  font-weight: 800;
  font-size: 13px;
  color: #fff;
}
#go-combo, #go-best-line { color: var(--text-dim); font-size: 14px; margin: 4px 0; text-align: center; }

.nickname-form { margin-top: 14px; }
.nickname-form label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.08em; }
#nickname-input {
  width: 100%;
  min-height: 52px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 0 14px;
  font-size: 16px;
  margin-bottom: 10px;
}
#submit-result { margin: 8px 0; font-size: 13.5px; text-align: center; }
.submit-ok { color: var(--lime); }
.submit-err { color: var(--danger); }

.challenge-share { margin-top: 16px; }
.challenge-share label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.08em; }
.share-row { display: flex; gap: 8px; margin-top: 6px; }
#challenge-share-link {
  flex: 1;
  min-height: 48px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text-dim);
  padding: 0 10px;
  font-size: 12.5px;
}

/* ---------- Leaderboard ---------- */
.lb-tabs { display: flex; gap: 8px; margin: 10px 0 14px; }
.lb-tab {
  flex: 1;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text-dim);
  font-weight: 700;
  cursor: pointer;
}
.lb-tab.is-active { color: #04101a; background: linear-gradient(120deg, var(--cyan), var(--lime)); border-color: transparent; }
#leaderboard-list { list-style: none; margin: 0; padding: 0; }
.lb-row, .lb-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 8px;
}
.lb-loading { color: var(--text-dim); justify-content: center; }
.lb-rank { width: 34px; font-weight: 800; }
.lb-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-you { color: var(--cyan); font-size: 12px; }
.lb-score { font-weight: 800; color: var(--lime); }

.below-fold {
  max-width: 640px;
  margin: 0 auto;
  padding: 40px 18px 60px;
  color: var(--text-dim);
  line-height: 1.7;
  font-size: 15px;
}
.below-fold h2 { color: var(--text); font-size: 21px; margin: 28px 0 10px; }
.below-fold h2:first-child { margin-top: 0; }
.below-fold ul { padding-left: 20px; }
.below-fold details { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; margin-bottom: 10px; }
.below-fold summary { cursor: pointer; font-weight: 700; color: var(--text); }
.ad-slot {
  max-width: 640px;
  margin: 24px auto;
  min-height: 90px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.site-footer {
  text-align: center;
  padding: 24px 16px 40px;
  color: var(--text-dim);
  font-size: 12.5px;
}
.site-footer a { color: var(--text-dim); }

@media (min-width: 640px) {
  .logo-title { font-size: 54px; }
  .gap-frame { width: 220px; height: 220px; }
}
