/* ============================================================
   BLOCK BREAKER — Neon Arcade
   Aesthetic: deep-space indigo, glassmorphic panels, electric glow
   ============================================================ */

:root {
  --bg-0: #05060e;
  --bg-1: #0a0c1c;
  --bg-2: #11132b;

  --cyan:    #00f0ff;
  --magenta: #ff2bd6;
  --lime:    #aaff2e;
  --gold:    #ffd23f;
  --violet:  #a06bff;
  --rose:    #ff5470;

  --ink:      #eaf6ff;
  --ink-dim:  #8da6c8;
  --line:     rgba(0, 240, 255, 0.18);

  --glass:      rgba(14, 20, 44, 0.62);
  --glass-edge: rgba(120, 200, 255, 0.22);

  --shadow-cyan: 0 0 24px rgba(0, 240, 255, 0.45);

  --font-display: "Chakra Petch", system-ui, sans-serif;
  --font-mono: "Share Tech Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg-0);
  color: var(--ink);
  font-family: var(--font-display);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ---------- Stage & atmosphere ---------- */
#stage {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(120% 90% at 50% -10%, var(--bg-2), transparent 60%),
    radial-gradient(100% 80% at 50% 120%, #1a0b2e, transparent 55%),
    var(--bg-0);
}

.bg-grid {
  position: absolute; inset: -2px;
  background-image:
    linear-gradient(rgba(0,240,255,0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,43,214,0.05) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(circle at 50% 40%, #000 30%, transparent 78%);
  animation: drift 24s linear infinite;
}
@keyframes drift { to { background-position: 46px 92px, 92px 46px; } }

.bg-glow {
  position: absolute; width: 60vmax; height: 60vmax; border-radius: 50%;
  background: radial-gradient(circle, rgba(0,240,255,0.10), transparent 60%);
  filter: blur(40px);
  animation: hue 18s ease-in-out infinite alternate;
}
@keyframes hue { from { filter: blur(40px) hue-rotate(0deg);} to { filter: blur(60px) hue-rotate(80deg);} }

.bg-scan {
  position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,0.18) 0 1px, transparent 1px 3px);
  mix-blend-mode: overlay; opacity: 0.4;
}

/* ---------- Game frame ---------- */
#frame {
  position: relative;
  /* Fill the screen while preserving the 4:3 aspect (black bars top/bottom in
     portrait, sides in landscape). Capped on large desktops. */
  width: min(100vw, calc(100dvh * 4 / 3), 1100px);
  aspect-ratio: 800 / 600;
  border-radius: 18px;
  background: linear-gradient(160deg, rgba(10,16,38,0.9), rgba(6,8,20,0.95));
  border: 1px solid var(--glass-edge);
  box-shadow:
    0 0 0 1px rgba(0,0,0,0.6),
    0 30px 80px rgba(0,0,0,0.7),
    inset 0 0 60px rgba(0,240,255,0.05);
  overflow: hidden;
}

canvas#game {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  touch-action: none;
  border-radius: 18px;
}

/* ---------- HUD ---------- */
.hud {
  position: absolute; top: 0; left: 0; right: 0; z-index: 6;
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px;
  font-family: var(--font-mono);
  background: linear-gradient(180deg, rgba(5,6,14,0.9), transparent);
  pointer-events: none;
}
.hud-group { display: flex; align-items: center; gap: 12px; }
.hud-group.center { flex: 1; justify-content: center; }
.hud-group.right { justify-content: flex-end; }
.hud-cell { display: flex; flex-direction: column; line-height: 1; }
.hud-center { align-items: center; }
.hud-right { align-items: flex-end; }
.hud-label { font-size: 9px; letter-spacing: 3px; color: var(--ink-dim); }
.hud-value { font-size: clamp(15px, 3.4vw, 22px); color: var(--cyan); text-shadow: var(--shadow-cyan); margin-top: 3px; }
.hud-value.lives { color: var(--rose); text-shadow: 0 0 16px rgba(255,84,112,0.7); letter-spacing: 2px; }

.hud-btn {
  pointer-events: auto;
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--glass); border: 1px solid var(--glass-edge);
  color: var(--cyan); font-family: var(--font-mono); font-size: 13px;
  backdrop-filter: blur(8px); cursor: pointer; flex: 0 0 auto;
  box-shadow: 0 0 14px rgba(0,240,255,0.22);
  transition: transform .12s, box-shadow .12s, color .12s;
}
.hud-btn:hover { box-shadow: 0 0 22px rgba(0,240,255,0.4); }
.hud-btn:active { transform: scale(0.9); }
.hud-btn.muted { color: var(--ink-dim); box-shadow: none; opacity: .55; }

/* ---------- Power-up tray ---------- */
.powerup-tray {
  position: absolute; left: 50%; transform: translateX(-50%);
  top: 46px; z-index: 6; display: flex; gap: 6px; pointer-events: none;
}
.pu-chip {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 1px;
  padding: 3px 8px; border-radius: 20px;
  border: 1px solid currentColor; background: rgba(0,0,0,0.4);
  text-shadow: 0 0 8px currentColor; box-shadow: 0 0 12px currentColor;
  animation: chipIn .3s ease;
}
@keyframes chipIn { from { opacity:0; transform: translateY(-6px) scale(.8);} }

/* ---------- Screens (overlays) ---------- */
.screen {
  position: absolute; inset: 0; z-index: 20;
  display: none; align-items: center; justify-content: center;
  padding: 10px 12px; overflow-y: auto;
  background: radial-gradient(120% 100% at 50% 30%, rgba(8,10,24,0.78), rgba(4,5,12,0.94));
  backdrop-filter: blur(6px);
}
.screen.active { display: flex; flex-direction: column; animation: fade .35s ease; }
@keyframes fade { from { opacity: 0; } }

.panel {
  width: min(96%, 400px);
  text-align: center;
  padding: 16px 18px 14px;
  border-radius: 16px;
  background: var(--glass);
  border: 1px solid var(--glass-edge);
  box-shadow: 0 16px 48px rgba(0,0,0,0.6), inset 0 0 24px rgba(0,240,255,0.05);
  display: flex; flex-direction: column; gap: 8px;
}

.tag {
  align-self: center; font-family: var(--font-mono); font-size: 9px;
  letter-spacing: 4px; color: var(--cyan); padding: 4px 12px; border-radius: 30px;
  border: 1px solid var(--line); text-shadow: var(--shadow-cyan);
}
.tag.gold { color: var(--gold); border-color: rgba(255,210,63,0.4); text-shadow: 0 0 16px rgba(255,210,63,0.6); }

.logo {
  /* Frame-relative font: cap at ~44px so two lines fit without crowding */
  font-size: clamp(26px, 4.8vw, 44px); font-weight: 700; line-height: 0.9;
  letter-spacing: 2px; margin: 2px 0;
  color: var(--ink); text-shadow: 0 0 28px rgba(0,240,255,0.5);
}
.logo span { display: block; color: var(--magenta); text-shadow: 0 0 28px rgba(255,43,214,0.6); }

.subtitle { color: var(--ink-dim); font-size: 12px; line-height: 1.4; max-width: 32ch; margin: 0 auto; }

.screen-title { font-size: clamp(24px, 6vw, 40px); font-weight: 700; letter-spacing: 4px; text-shadow: var(--shadow-cyan); color: var(--cyan); }
.screen-title.danger { color: var(--rose); text-shadow: 0 0 26px rgba(255,84,112,0.7); }
.screen-title.win { color: var(--gold); text-shadow: 0 0 30px rgba(255,210,63,0.7); }

.btn {
  cursor: pointer; border: none; border-radius: 12px;
  font-family: var(--font-display); font-weight: 700; letter-spacing: 3px;
  font-size: 14px; padding: 12px 18px; transition: transform .12s, filter .12s, box-shadow .12s;
}
.btn.primary {
  color: var(--bg-0);
  background: linear-gradient(135deg, var(--cyan), var(--violet));
  box-shadow: 0 0 26px rgba(0,240,255,0.45);
}
.btn.primary:hover { filter: brightness(1.1); box-shadow: 0 0 40px rgba(0,240,255,0.65); }
.btn.ghost { color: var(--ink-dim); background: transparent; border: 1px solid var(--glass-edge); font-size: 12px; padding: 9px 14px; }
.btn.ghost:hover { color: var(--cyan); border-color: var(--line); }
.btn:active { transform: scale(0.96); }

.best-line, .stat-row { font-family: var(--font-mono); color: var(--ink-dim); font-size: 12px; }
.best-line span { color: var(--gold); }
.stat-row { display: flex; justify-content: space-between; padding: 3px 6px; letter-spacing: 1px; }
.stat-row b { color: var(--cyan); font-weight: 400; }

.new-best { color: var(--gold); font-family: var(--font-mono); letter-spacing: 2px; font-size: 12px; text-shadow: 0 0 16px rgba(255,210,63,0.7); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

.controls-hint { display: flex; flex-direction: column; gap: 3px; color: var(--ink-dim); font-size: 10px; font-family: var(--font-mono); opacity: .7; }
.controls-hint .touch-only { display: none; }
/* On touch devices, swap the keyboard hint for the drag/tap hint */
@media (hover: none) and (pointer: coarse) {
  .controls-hint .touch-only { display: block; color: var(--cyan); }
  .controls-hint > span:first-child { display: none; }
}
kbd {
  display: inline-block; padding: 1px 6px; border-radius: 5px; font-size: 10px;
  background: rgba(0,240,255,0.08); border: 1px solid var(--line); color: var(--cyan);
}

/* ---------- Level banner ---------- */
.screen.banner { background: rgba(4,5,12,0.55); }
.banner-inner { text-align: center; }
.banner-num { font-size: clamp(40px, 11vw, 70px); font-weight: 700; letter-spacing: 6px; color: var(--magenta); text-shadow: 0 0 36px rgba(255,43,214,0.6); }
.banner-name { font-family: var(--font-mono); font-size: clamp(13px, 3.4vw, 18px); letter-spacing: 6px; color: var(--cyan); margin-top: 6px; text-shadow: var(--shadow-cyan); }
.banner-bar { width: 220px; max-width: 60vw; height: 3px; margin: 18px auto 0; background: rgba(255,255,255,0.08); border-radius: 4px; overflow: hidden; }
.banner-bar span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--cyan), var(--magenta)); }
.screen.banner.active .banner-inner { animation: bannerIn .5s cubic-bezier(.2,.9,.3,1.2); }
.screen.banner.active .banner-bar span { animation: load 1.5s ease forwards; }
@keyframes bannerIn { from { opacity: 0; transform: scale(.85) translateY(10px);} }
@keyframes load { to { width: 100%; } }

.hidden { display: none !important; }

@media (max-width: 560px) {
  #frame { width: 96vw; border-radius: 14px; }
}

/* ============================================================
   ENHANCEMENTS: auth, leaderboard, FX layers, rotate nudge
   ============================================================ */

/* ---------- Auth row ---------- */
.auth-row {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  margin-top: 2px; font-family: var(--font-mono); font-size: 12px;
}
.auth-status { color: var(--ink-dim); letter-spacing: 1px; }
.auth-status b { color: var(--cyan); font-weight: 400; }
.auth-link {
  background: none; border: none; color: var(--rose); cursor: pointer;
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 1px;
  text-decoration: underline; padding: 0;
}
.fb-btn {
  display: inline-flex; align-items: center; gap: .5rem;
  background: #fff; color: #1c1e21; font-weight: 600; font-size: .82rem;
  padding: .5rem 1rem; border-radius: 8px; border: 1px solid #dadde1;
  cursor: pointer; font-family: inherit;
}
.fb-btn:empty { display: none; } /* hidden until SDK injects content */

/* ---------- Leaderboard ---------- */
.leaderboard {
  width: 100%; margin: 2px 0; padding: 8px 10px 6px;
  border-radius: 10px; border: 1px solid var(--glass-edge);
  background: rgba(0,0,0,0.25);
}
.lb-title {
  font-family: var(--font-mono); font-size: 9px; letter-spacing: 3px;
  color: var(--gold); text-align: center; margin-bottom: 6px;
  text-shadow: 0 0 10px rgba(255,210,63,0.5);
}
.lb-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; max-height: 130px; overflow-y: auto; }
.lb-list li {
  display: grid; grid-template-columns: 18px 1fr auto; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: 11px; color: var(--ink-dim);
  padding: 2px 3px; border-radius: 5px;
}
.lb-list li .lb-rank { color: var(--violet); text-align: right; }
.lb-list li .lb-name { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-list li .lb-pts { color: var(--cyan); }
.lb-list li.me { background: rgba(0,240,255,0.08); }
.lb-list li.me .lb-rank { color: var(--gold); }
.lb-loading, .lb-empty { display: block !important; text-align: center; color: var(--ink-dim); opacity: .6; font-size: 10px; }
.lb-source { font-size: 9px; letter-spacing: 2px; color: var(--ink-dim); opacity: .5; text-align: center; margin-top: 4px; }

/* ---------- Score flash (juice) ---------- */
.hud-value.flash { animation: scoreFlash .4s ease; }
@keyframes scoreFlash {
  0% { transform: scale(1); color: var(--cyan); }
  40% { transform: scale(1.35); color: var(--gold); text-shadow: 0 0 24px var(--gold); }
  100% { transform: scale(1); }
}

/* ---------- Shield edge glow (juice) ---------- */
.edge-glow {
  position: absolute; inset: 0; z-index: 5; pointer-events: none;
  border-radius: 18px; opacity: 0; transition: opacity .2s;
  box-shadow: inset 0 0 40px 6px rgba(255,43,214,0.55), inset 0 0 100px 14px rgba(255,43,214,0.25);
}
.edge-glow.active { opacity: 1; animation: edgePulse 1.4s ease-in-out infinite; }
@keyframes edgePulse { 50% { opacity: .55; } }

/* ---------- Full-frame flash (level clear / life lost) ---------- */
.flash {
  position: absolute; inset: 0; z-index: 7; pointer-events: none;
  border-radius: 18px; opacity: 0; background: #fff;
}
.flash.clear { animation: flashWhite .5s ease; }
.flash.hurt  { background: var(--rose); animation: flashHurt .45s ease; }
@keyframes flashWhite { 0% { opacity: .55; } 100% { opacity: 0; } }
@keyframes flashHurt  { 0% { opacity: .4; } 100% { opacity: 0; } }

/* ---------- Rotate-to-landscape nudge ---------- */
.rotate-nudge {
  position: absolute; inset: 0; z-index: 40; display: none;
  flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: rgba(4,5,12,0.96); text-align: center; border-radius: 18px;
}
.rotate-nudge.show { display: flex; }
.rotate-icon { font-size: 64px; color: var(--cyan); text-shadow: var(--shadow-cyan); animation: rotateHint 2s ease-in-out infinite; }
@keyframes rotateHint { 0%,100% { transform: rotate(-12deg);} 50% { transform: rotate(78deg);} }
.rotate-nudge p { font-family: var(--font-display); font-weight: 700; letter-spacing: 2px; color: var(--ink); font-size: 18px; line-height: 1.5; }
.rotate-nudge p span { font-family: var(--font-mono); font-weight: 400; font-size: 12px; letter-spacing: 3px; color: var(--ink-dim); }
