/* =========================================================
   Incentivate Stack Builder — UI styling
   Brand (per design guide): Red #EC0000 (hover #C50000),
   Ink #212121, Grey #8A8A8A, Stroke #E0E0E0, White #FFFFFF.
   Premium · modern · minimal · light theme. Font: Inter.
   ========================================================= */

:root {
  --red:        #EC0000;
  --red-hover:  #C50000;
  --ink:        #212121;
  --grey:       #8A8A8A;
  --light-grey: #C9C8D3;
  --stroke:     #E0E0E0;
  --white:      #FFFFFF;
  --panel:      rgba(255, 255, 255, 0.78);
  --panel-solid:#FFFFFF;
  --shadow:     0 12px 40px rgba(33, 33, 33, 0.12);
  --shadow-sm:  0 4px 16px rgba(33, 33, 33, 0.10);
  --font:       'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  /* Blackletter display face for big titles (Thronefall-style). */
  --font-display: 'Grenze Gotisch', 'Inter', serif;
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #f5f7fa;
  font-family: var(--font);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

#game-canvas { position: fixed; inset: 0; display: block; width: 100%; height: 100%; }

/* Top scrim — sits between canvas and UI, fading the far skyline into the
   sky so the HUD reads on clean space (and gains contrast). */
#top-scrim {
  position: fixed; top: 0; left: 0; right: 0; height: 150px;
  pointer-events: none; z-index: 4;
  background: linear-gradient(
    to bottom,
    rgba(238, 241, 246, 0.85) 0%,
    rgba(238, 241, 246, 0.4) 55%,
    rgba(238, 241, 246, 0) 100%);
}

/* Impact flash overlay */
#flash { position: fixed; inset: 0; pointer-events: none; opacity: 0; z-index: 5; }
#flash.flash-anim { animation: flashFade 0.45s ease-out; }
@keyframes flashFade { 0% { opacity: 1; } 100% { opacity: 0; } }

/* UI overlay */
#ui { position: fixed; inset: 0; pointer-events: none; z-index: 10; }

/* ---------------- Logo ---------------- */
.logo-img { height: 26px; width: auto; display: block; }
.logo-img-big { height: 52px; width: auto; display: block; margin: 0 auto; }
#brand-bar { position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 20px 16px; gap: 12px; }
#logo { display: flex; align-items: center; min-width: 0; }

/* ---------------- HUD: score stack ---------------- */
/* Centered score stack — Score large on top, Best smaller beneath. */
#score-stack {
  position: absolute; top: 84px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  text-align: center; pointer-events: none;
}
#score-wrap { display: flex; flex-direction: column; align-items: center; gap: 2px; }
#best-wrap {
  display: inline-flex; align-items: baseline; gap: 6px;
  padding: 4px 12px; background: var(--panel);
  border: 1px solid var(--stroke); border-radius: 999px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow-sm);
}
.hud-label {
  font-size: 11px; font-weight: 600; letter-spacing: 1.5px;
  text-transform: uppercase; color: var(--grey);
}
#best-wrap .hud-label { font-size: 10px; letter-spacing: 1px; }
#best-wrap .hud-value { font-size: 15px; font-weight: 700; }
.hud-value { font-family: var(--font-display); font-size: 48px; font-weight: 700; line-height: 1; color: var(--ink); }
.combo {
  font-size: 13px; font-weight: 800; color: var(--red);
  opacity: 0; transform: translateY(-4px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.combo.show { opacity: 1; transform: translateY(0); }

/* ---------------- Floating popups ---------------- */
#popup-layer { position: absolute; inset: 0; overflow: hidden; }
.score-popup {
  position: absolute; font-weight: 800; font-size: 26px; color: var(--ink);
  text-shadow: 0 2px 10px rgba(255, 255, 255, 0.7);
  transform: translate(-50%, -50%);
  animation: floatUp 1s ease-out forwards; white-space: nowrap;
}
.score-popup.perfect { color: var(--red); }
@keyframes floatUp {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  20%  { opacity: 1; transform: translate(-50%, -65%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -130%) scale(1); }
}

/* ---------------- Debug panel ---------------- */
#debug-panel {
  position: absolute; top: 80px; right: 22px;
  padding: 12px 16px; border-radius: 12px;
  background: rgba(255, 255, 255, 0.9); border: 1px solid var(--stroke);
  font-size: 12px; line-height: 1.7; font-variant-numeric: tabular-nums;
  pointer-events: none; min-width: 168px; color: var(--ink);
  box-shadow: var(--shadow-sm);
}
#debug-panel b { color: var(--red); }
#debug-panel.hidden { display: none; }

/* ---------------- Screens ---------------- */
.screen {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: auto;
  background: radial-gradient(ellipse at center, rgba(255,255,255,0.55), rgba(233,237,243,0.82));
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  transition: opacity 0.35s ease;
}
.screen.hidden { opacity: 0; pointer-events: none; }
.screen-inner {
  text-align: center; padding: 36px 40px; max-width: 480px; width: min(480px, 92vw);
  background: var(--panel-solid); border: 1px solid var(--stroke);
  border-radius: 14px; box-shadow: var(--shadow);
  animation: rise 0.45s ease;
  max-height: calc(100vh - 32px); overflow-y: auto;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}
.brand-big { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 14px; }
.brand-big h1 {
  font-family: var(--font-display);
  font-size: 46px; font-weight: 700; line-height: 1;
  letter-spacing: 0.5px; color: var(--ink);
}
.tap-hint { font-size: 14px; color: var(--grey); margin-bottom: 26px; }

/* Welcome copy */
.eyebrow {
  font-size: 12px; font-weight: 700; letter-spacing: 2.5px;
  text-transform: uppercase; color: var(--grey); margin-top: 4px;
}
.prize-line { font-size: 15px; color: var(--ink); margin-bottom: 16px; }
.prize-line b { color: var(--red); }
/* Prominent "your award will be sent to <email>" callout. */
.award-note {
  display: block; margin: 4px auto 18px; padding: 14px 16px; max-width: 100%;
  background: #fdeeee; border: 1px solid #f6cccc; border-radius: 12px;
  font-size: 14px; color: var(--ink); line-height: 1.5;
}
.award-note b {
  display: block; margin-top: 4px;
  font-size: 19px; font-weight: 800; color: var(--red);
  word-break: break-all;
}
.award-note.hidden { display: none; }

/* Loading spinner */
.spinner {
  width: 42px; height: 42px; margin: 22px auto 4px;
  border: 4px solid var(--stroke); border-top-color: var(--red);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- Buttons ---------------- */
.btn-primary, .btn-secondary {
  font-family: var(--font-display); font-size: 21px; font-weight: 700; letter-spacing: 0.5px;
  padding: 13px 40px; border: none; border-radius: 10px; cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.btn-wide { width: 100%; }
.btn-primary {
  color: #fff; background: var(--red);
  box-shadow: 0 10px 26px rgba(236, 0, 0, 0.32);
}
.btn-primary:hover { background: var(--red-hover); transform: translateY(-2px); box-shadow: 0 14px 32px rgba(197, 0, 0, 0.4); }
.btn-secondary {
  color: var(--ink); background: #fff; border: 1.5px solid var(--stroke);
}
.btn-secondary:hover { transform: translateY(-2px); border-color: var(--grey); }
.btn-primary:active, .btn-secondary:active { transform: translateY(1px) scale(0.98); }
.btn-row { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }

/* Game over / pause */
.go-title { font-family: var(--font-display); font-size: 40px; font-weight: 700; margin-bottom: 18px; color: var(--ink); letter-spacing: 0.5px; }
.go-scores { display: flex; gap: 12px; justify-content: center; margin-bottom: 18px; }
.go-score {
  display: flex; flex-direction: column; gap: 6px; padding: 16px 24px;
  background: #f7f8fb; border: 1px solid var(--stroke); border-radius: 10px; min-width: 130px;
}
.go-value { font-family: var(--font-display); font-size: 40px; font-weight: 700; color: var(--red); }
.new-best {
  display: inline-block; margin: -8px 0 14px; padding: 5px 14px;
  font-size: 13px; font-weight: 700; color: var(--red);
  background: #fdeaea; border-radius: 999px;
}
.new-best.hidden { display: none; }

/* ---------------- Signup form ---------------- */
.signup-inner { padding-top: 30px; }
.signup-title { font-family: var(--font-display); font-size: 40px; font-weight: 700; letter-spacing: 0.5px; margin: 2px 0 8px; }
.signup-inner .logo-img-big { margin-bottom: 6px; }
#signup-form { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; text-align: left; }
#signup-form input {
  font-family: var(--font); font-size: 15px; color: var(--ink);
  padding: 13px 15px; border: 1.5px solid var(--stroke); border-radius: 10px;
  background: #fbfbfd; outline: none; width: 100%;
  user-select: text; -webkit-user-select: text;
  transition: border-color 0.15s ease, background 0.15s ease;
}
#signup-form input::placeholder { color: var(--light-grey); }
#signup-form input:focus { border-color: var(--red); background: #fff; }
.form-note { font-size: 12.5px; color: var(--grey); text-align: center; margin-top: 2px; }
/* Prize reminder shown right under the work-email input. */
.award-hint {
  margin: -2px 2px 2px; padding: 9px 12px;
  background: #fdeeee; border: 1px solid #f6cccc; border-radius: 9px;
  font-size: 13px; font-weight: 700; color: var(--red); text-align: center;
}
.form-error { font-size: 13px; font-weight: 600; color: var(--red); text-align: center; min-height: 0; }
.form-error:empty { display: none; }

/* ---------------- Leaderboard (game over) ---------------- */
.leaderboard {
  margin: 0 0 18px; border: 1px solid var(--stroke); border-radius: 12px;
  background: #fbfbfd; overflow: hidden; text-align: left;
}
.leaderboard.hidden { display: none; }
/* Header: Incentivate logo centered on top, then title + count on one row. */
.lb-head {
  display: flex; flex-direction: column; align-items: stretch; gap: 8px;
  padding: 12px 16px 10px; border-bottom: 1px solid var(--stroke);
  background: #fff;
}
.lb-brand { height: 18px; width: auto; display: block; margin: 0 auto; }
.lb-head-row {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
}
.lb-title {
  font-size: 11px; font-weight: 700; letter-spacing: 1.5px;
  text-transform: uppercase; color: var(--grey);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lb-top { font-size: 12px; font-weight: 600; color: var(--ink); white-space: nowrap; flex: 0 0 auto; }
.lb-top b { color: var(--red); }
.lb-rows { list-style: none; }
.lb-row {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 16px; font-size: 14px; border-bottom: 1px solid #f0f1f5;
}
.lb-row:last-child { border-bottom: none; }
.lb-rank { min-width: 34px; font-family: var(--font-display); font-size: 18px; font-weight: 700; color: var(--grey); }
.lb-name { flex: 1; font-family: var(--font-display); font-size: 17px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-family: var(--font-display); font-size: 20px; font-weight: 700; }
.lb-row.me { background: #fdeeee; }
.lb-row.me .lb-rank, .lb-row.me .lb-score { color: var(--red); }
.lb-row.me .lb-name::after { content: ' (You)'; font-weight: 700; color: var(--red); font-size: 12px; }
.lb-status { font-size: 12.5px; color: var(--grey); margin: -6px 0 16px; }
.lb-status.hidden { display: none; }

/* ---------------- Leaderboard page ---------------- */
.me-stats { display: flex; gap: 10px; justify-content: center; margin-bottom: 14px; }
.me-stat {
  flex: 1; display: flex; flex-direction: column; gap: 4px;
  padding: 12px 8px; background: #f7f8fb;
  border: 1px solid var(--stroke); border-radius: 10px; min-width: 0;
}
.me-stat-value { font-family: var(--font-display); font-size: 28px; font-weight: 700; color: var(--red); }
.board-list { margin-bottom: 16px; }
.board-list .lb-rows { max-height: 38vh; overflow-y: auto; }
.lb-games { font-weight: 500; color: var(--grey); font-size: 12px; margin-left: 6px; }

/* Mobile gate */
.gate-title { font-family: var(--font-display); font-size: 32px; font-weight: 700; margin: 14px 0 10px; }

/* Settings (pause menu) */
.settings { display: flex; flex-direction: column; gap: 16px; margin-bottom: 28px; width: 280px; max-width: 100%; margin-inline: auto; }
.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  font-size: 14px; font-weight: 600; color: var(--ink);
}
.setting-row input[type="range"] { flex: 1; accent-color: var(--red); cursor: pointer; }

/* ---------------- Icon buttons ---------------- */
.icon-btn {
  position: absolute; width: 46px; height: 46px; font-size: 19px;
  border-radius: 50%; border: 1px solid var(--stroke);
  background: var(--panel); color: var(--ink); cursor: pointer;
  pointer-events: auto; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  transition: transform 0.15s ease; box-shadow: var(--shadow-sm);
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn iconify-icon { font-size: 22px; line-height: 1; display: block; }
/* Bottom-right control cluster — kept clear of the top HUD cards. */
#mute-btn { bottom: 18px; right: 18px; }
#pause-btn { bottom: 18px; right: 74px; }
.icon-btn.hidden { display: none; }

/* ---------------- Responsive ---------------- */
@media (max-width: 640px) {
  .brand-big h1 { font-size: 40px; }
  .go-title { font-size: 34px; }
  .signup-title { font-size: 34px; }
  .hud-value { font-size: 36px; }
  .hud-label { font-size: 10px; letter-spacing: 1.2px; }
  #best-wrap .hud-value { font-size: 14px; }
  .go-value { font-size: 30px; }
  .go-scores { flex-direction: row; gap: 10px; }
  .go-score { padding: 14px 16px; min-width: 0; flex: 1; }
  .screen-inner { padding: 28px 22px; max-width: 88vw; }
  .logo-img { height: 22px; }
  .logo-img-big { height: 44px; }
  #score-stack { top: 72px; }
  #brand-bar { padding: max(12px, env(safe-area-inset-top)) 14px 12px; }
  #debug-panel { top: 70px; right: 14px; font-size: 10px; min-width: 140px; padding: 9px 12px; }
  .btn-primary, .btn-secondary { padding: 14px 30px; font-size: 15px; }
  #mute-btn { bottom: max(16px, env(safe-area-inset-bottom)); right: 16px; }
  #pause-btn { bottom: max(16px, env(safe-area-inset-bottom)); right: 70px; }
}

/* Short landscape (phones held sideways): tighten vertical rhythm. */
@media (max-height: 460px) {
  .brand-big { gap: 10px; margin-bottom: 14px; }
  .logo-img-big { height: 36px; }
  .brand-big h1 { font-size: 22px; }
  .tap-hint { margin-bottom: 16px; }
  .screen-inner { padding: 20px 26px; }
  .spinner { margin: 12px auto 2px; }
}
