/* ─────────────────────────────────────────────────────────────────────────
   casoual-ui.css — Casoual Games Shared UI System  v1
   Prefix: .cg-  (Casoual Game)

   Usage in each game's <head>:
     <link rel="stylesheet" href="https://casoual.games/shared/casoual-ui.css?v=1">

   Then declare your game's accent color:
     :root { --accent: #edc22e; }   ← only this is required
   ───────────────────────────────────────────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;500;600;700;800;900&display=swap');

/* ── CSS variables + base font ──────────────────────────────────────────── */
:root {
  --accent:      #5b9fff;
  --accent-dark: color-mix(in srgb, var(--accent) 60%, black);
  --accent-glow: color-mix(in srgb, var(--accent) 35%, transparent);
  --cg-font: 'Nunito', 'Segoe UI', system-ui, sans-serif;
}

/* Propagate Nunito to all game bodies that opt in */
body { font-family: var(--cg-font); }


/* ═══════════════════════════════════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════════════════════════════════ */

.cg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 1.2rem;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 14px 48px;
  border-radius: 50px;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-dark) 100%);
  border: none;
  border-bottom: 5px solid var(--accent-dark);
  box-shadow:
    0 0 0 3px rgba(0,0,0,0.22),
    0 10px 30px var(--accent-glow);
  color: #fff;
  text-shadow: 0 2px 5px rgba(0,0,0,0.4);
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.08s ease, border-bottom-width 0.08s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  min-width: 180px;
}

.cg-btn:active {
  transform: translateY(3px);
  border-bottom-width: 2px;
}

/* Secondary / ghost button */
.cg-btn-ghost {
  background: rgba(255,255,255,0.08);
  border: 2px solid rgba(255,255,255,0.22);
  border-bottom-width: 2px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: rgba(255,255,255,0.8);
  box-shadow: none;
  text-shadow: none;
  font-weight: 700;
  font-size: 1rem;
}

.cg-btn-ghost:active {
  background: rgba(255,255,255,0.14);
  transform: scale(0.97);
}


/* ═══════════════════════════════════════════════════════════════════════
   LEADERBOARD CARD
   ═══════════════════════════════════════════════════════════════════════ */

.cg-lb {
  background: rgba(0,0,0,0.22);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 20px;
  padding: 14px 18px;
  width: 100%;
  max-width: 300px;
  box-sizing: border-box;
  /* Reserve space upfront to prevent layout shift when data loads */
  min-height: 220px;
  display: flex;
  flex-direction: column;
}

.cg-lb-title {
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.52);
  text-align: center;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.10);
  margin-bottom: 8px;
}

.cg-lb-row {
  display: flex;
  align-items: center;
  padding: 6px 6px;
  border-radius: 8px;
  font-size: 0.86rem;
  color: rgba(255,255,255,0.72);
  margin-top: 1px;
}

.cg-lb-rank {
  width: 26px;
  flex-shrink: 0;
  font-size: 0.72rem;
  color: rgba(255,255,255,0.40);
  font-weight: 700;
  text-align: center;
}

/* Medal icons — CSS only, no JS change needed beyond data-rank attribute */
.cg-lb-row[data-rank="1"] .cg-lb-rank,
.cg-lb-row[data-rank="2"] .cg-lb-rank,
.cg-lb-row[data-rank="3"] .cg-lb-rank { font-size: 0; }
.cg-lb-row[data-rank="1"] .cg-lb-rank::before { content: '🥇'; font-size: 14px; }
.cg-lb-row[data-rank="2"] .cg-lb-rank::before { content: '🥈'; font-size: 14px; }
.cg-lb-row[data-rank="3"] .cg-lb-rank::before { content: '🥉'; font-size: 14px; }

/* Rank 1 gold score */
.cg-lb-row[data-rank="1"] .cg-lb-score { color: #f59e0b; }
.cg-lb-row[data-rank="1"] .cg-lb-name  { color: rgba(255,255,255,0.9); }

.cg-lb-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.cg-lb-score {
  font-weight: 700;
  font-size: 0.86rem;
  color: rgba(255,255,255,0.65);
}

/* "Me" row highlight */
.cg-lb-row.me {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  border-left: 3px solid var(--accent);
  padding-left: 3px;
  color: #fff;
}

.cg-lb-row.me .cg-lb-score {
  color: var(--accent);
}

.cg-lb-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 0.82rem;
  color: rgba(255,255,255,0.28);
}


/* ═══════════════════════════════════════════════════════════════════════
   SCORE DISPLAY
   ═══════════════════════════════════════════════════════════════════════ */

.cg-score-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.cg-score-label {
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.62);
}

.cg-score-value {
  font-size: clamp(3rem, 20vw, 5.5rem);
  font-weight: 900;
  color: #fff;
  line-height: 1;
  letter-spacing: -0.02em;
}

.cg-score-best {
  font-size: 0.92rem;
  color: rgba(255,255,255,0.62);
}


/* ═══════════════════════════════════════════════════════════════════════
   NEW BEST BADGE
   ═══════════════════════════════════════════════════════════════════════ */

.cg-new-best {
  display: inline-block;
  padding: 5px 18px;
  border-radius: 20px;
  background: linear-gradient(90deg, var(--accent), var(--accent-dark));
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.35);
  box-shadow: 0 4px 20px var(--accent-glow);
  animation: cg-pop 0.45s cubic-bezier(0.34,1.5,0.64,1) both;
}

@keyframes cg-pop {
  from { transform: scale(0.2); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}


/* ═══════════════════════════════════════════════════════════════════════
   BACK LINK
   ═══════════════════════════════════════════════════════════════════════ */

.cg-back {
  position: absolute !important;
  bottom: max(10px, env(safe-area-inset-bottom, 0px)) !important;
  left: 10px !important;
  z-index: 100 !important;
  display: block;
  width: 52px;
  height: 52px;
  background: url("https://casoual.games/img/back.png") no-repeat center/contain;
  text-decoration: none;
  font-size: 0;
  border: none;
  padding: 0;
  opacity: 0.9;
  transition: opacity 0.15s, transform 0.12s;
  -webkit-tap-highlight-color: transparent;
}

.cg-back::before { display: none; }

.cg-back:hover  { opacity: 1; }
.cg-back:active { transform: scale(0.88); opacity: 1; }

@media(display-mode:standalone) { .cg-back { display: none !important; } }

/* Any screen containing a back button gets bottom clearance automatically */
*:has(> .cg-back) {
  padding-bottom: max(72px, calc(env(safe-area-inset-bottom, 0px) + 72px));
}


/* ═══════════════════════════════════════════════════════════════════════
   SUBTITLE
   Usage: <p class="cg-subtitle">Tap the right color. <span>Stay alive.</span></p>
   The optional <span> gets the accent colour.
   ═══════════════════════════════════════════════════════════════════════ */

.cg-subtitle {
  font-size: 1.1rem !important;
  font-weight: 700 !important;
  color: rgba(255,255,255,0.88) !important;
  text-align: center;
  letter-spacing: 0.01em;
  line-height: 1.45;
  font-family: var(--cg-font);
}

.cg-subtitle span {
  color: var(--accent);
}


/* ═══════════════════════════════════════════════════════════════════════
   MY SCORE LINE  — "PlayerName · best: 42"
   Usage: <p class="cg-my-score" id="menu-best"></p>
   Rendered via JS: renderMyScore(el, bestValue)
   ═══════════════════════════════════════════════════════════════════════ */

.cg-my-score {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  border-radius: 50px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.14);
  font-size: 0.88rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: rgba(255,255,255,0.72);
  font-family: var(--cg-font);
  min-height: unset;
}

.cg-my-score::before {
  content: '👑';
  font-size: 14px;
  line-height: 1;
}

.cg-my-score strong {
  color: #fff;
  font-weight: 900;
  font-size: 1rem;
  letter-spacing: 0;
}

.cg-my-name {
  color: rgba(255,255,255,0.75);
  font-weight: 700;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
  font-family: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: rgba(255,255,255,0.22);
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s;
}

.cg-my-name:hover { opacity: 0.6; }


/* ═══════════════════════════════════════════════════════════════════════
   BEST SCORE BADGE
   Usage: <div class="cg-best">Best: <span>6</span></div>
   ═══════════════════════════════════════════════════════════════════════ */

.cg-best {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 18px;
  border-radius: 20px;
  background: rgba(255,255,255,0.09);
  border: 1px solid rgba(255,255,255,0.15);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: rgba(255,255,255,0.68);
  text-transform: uppercase;
}

.cg-best::before {
  content: '👑';
  font-size: 12px;
}

.cg-best span {
  color: #fff;
  font-weight: 800;
  font-size: 0.9rem;
}


/* ═══════════════════════════════════════════════════════════════════════
   SCREEN LAYOUT (optional helper)
   Wrap screen contents with .cg-screen for consistent centering
   ═══════════════════════════════════════════════════════════════════════ */

.cg-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  min-height: 100dvh;
  padding: 28px 20px max(72px, calc(env(safe-area-inset-bottom, 0px) + 72px));
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: #fff;
  text-align: center;
  box-sizing: border-box;
}


/* ═══════════════════════════════════════════════════════════════════════
   SHARED HOME MENU  — generated by Casoual.menu.render()
   Container: <div id="screen-home" class="screen active cg-screen-home">
   The container becomes the single source of truth for the menu UI.
   ═══════════════════════════════════════════════════════════════════════ */

.cg-screen-home.active,
.cg-screen-home:not([class*="screen"]):not(.overlay) {
  display: flex;
}
.cg-screen-home {
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  padding: max(16px, env(safe-area-inset-top, 0px)) 20px max(88px, calc(env(safe-area-inset-bottom, 0px) + 84px)) !important;
  box-sizing: border-box;
  font-family: var(--cg-font);
  color: #fff;
  text-align: center;
  height: 100dvh !important;
  position: relative;
  overflow: hidden !important;
}

/* Background — image with accent gradient fallback. Page sets --cg-bg-image
   via JS once probe loads; otherwise gradient shows.
   Note: var() needs a fallback because the background shorthand rejects undefined values. */
body.cg-has-bg {
  background-color: #06070a !important;
  background-image:
    var(--cg-bg-image, linear-gradient(transparent, transparent)),
    linear-gradient(160deg,
      color-mix(in srgb, var(--accent) 28%, #06070a) 0%,
      #06070a 65%,
      color-mix(in srgb, var(--accent) 14%, #06070a) 100%) !important;
  background-size: cover, cover !important;
  background-position: center, center !important;
  background-repeat: no-repeat, no-repeat !important;
  background-attachment: fixed, fixed !important;
}
.cg-screen-home::before {
  /* Always-on dark vignette so titles/leaderboard stay legible over any bg */
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,0.20) 0%, rgba(0,0,0,0.55) 100%);
  pointer-events: none;
  z-index: 0;
}
.cg-screen-home > * { position: relative; z-index: 1; }

/* ── Title area ─────────────────────────────────────────────────────── */
.cg-title-area {
  margin-top: 4px;
  margin-bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60px;
  flex-shrink: 0;
}

.cg-title-img {
  display: block;
  max-width: min(320px, 75vw);
  max-height: 160px;
  width: auto;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 6px 22px rgba(0,0,0,0.55));
}

.cg-title-text {
  font-size: clamp(2.6rem, 12vw, 4.2rem);
  font-weight: 900;
  letter-spacing: -0.025em;
  line-height: 1;
  color: var(--accent);
  text-shadow:
    0 3px 0 color-mix(in srgb, var(--accent) 50%, black),
    0 6px 22px rgba(0,0,0,0.55),
    0 1px 0 rgba(255,255,255,0.25) inset;
  -webkit-text-stroke: 1px rgba(0,0,0,0.55);
  font-family: var(--cg-font);
}

/* ── Tagline (2 lines: white + accent) ──────────────────────────────── */
.cg-tagline {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-family: var(--cg-font);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: 0.005em;
  text-align: center;
  margin: 0;
  text-shadow: 0 1px 4px rgba(0,0,0,0.45);
  flex-shrink: 0;
}
.cg-tagline-1 { color: rgba(255,255,255,0.92); }
.cg-tagline-2 { color: var(--accent); font-weight: 800; }

/* ── Play button stack ──────────────────────────────────────────────── */
.cg-btn-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: 4px 0;
  flex-shrink: 0;
}

/* ── Footer (3 zones: back logo · google play · feedback) ───────────── */
.cg-footer {
  position: absolute;
  bottom: max(12px, env(safe-area-inset-bottom, 0px));
  left: 0;
  right: 0;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  z-index: 50;
  pointer-events: none; /* zones re-enable */
}
.cg-footer > * { pointer-events: auto; }

.cg-footer-back {
  display: block;
  width: 52px;
  height: 52px;
  background: url("https://casoual.games/img/back.png") no-repeat center/contain;
  text-decoration: none;
  font-size: 0;
  border: none;
  padding: 0;
  opacity: 0.9;
  transition: opacity 0.15s, transform 0.12s;
  -webkit-tap-highlight-color: transparent;
}
.cg-footer-back:hover  { opacity: 1; }
.cg-footer-back:active { transform: scale(0.88); opacity: 1; }
.cg-footer-back img { display: none; } /* fallback hidden, bg image used */

.cg-footer-gp {
  display: block;
  height: 44px;
  opacity: 0.92;
  transition: opacity 0.15s, transform 0.12s;
  -webkit-tap-highlight-color: transparent;
  margin: 0 auto;
}
.cg-footer-gp img { height: 44px; width: auto; display: block; }
.cg-footer-gp:active { transform: scale(0.96); }

.cg-footer-feedback {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  border: 1.5px solid rgba(255,255,255,0.18);
  color: rgba(255,255,255,0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.cg-footer-feedback:hover {
  background: rgba(255,255,255,0.14);
  color: #fff;
  border-color: rgba(255,255,255,0.32);
}
.cg-footer-feedback:active { transform: scale(0.92); }

@media(display-mode:standalone) {
  .cg-footer-back { display: none; }
}

/* ── Best score badge: don't shrink ─────────────────────────────────── */
.cg-screen-home .cg-my-score {
  flex-shrink: 0;
}

/* ── Leaderboard fills remaining vertical space with internal scroll ── */
.cg-screen-home .cg-lb {
  margin-top: 4px;
  flex: 1 1 auto;
  min-height: 140px;
  width: 100%;
  max-width: 320px;
  overflow: hidden;
  padding: 14px 14px 6px;
}
.cg-screen-home .cg-lb-title {
  flex-shrink: 0;
}
.cg-lb-rows {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* Subtle fade-out at bottom hints "scroll for more" */
  mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 14px), transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 14px), transparent 100%);
  padding-right: 4px;
}
.cg-lb-rows::-webkit-scrollbar { width: 4px; }
.cg-lb-rows::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }
.cg-screen-home .cg-lb-empty {
  flex: 1 1 auto;
  min-height: 0;
}
/* Me-row pinned below top-N when player isn't in top-N */
.cg-lb-row.cg-lb-me-out {
  margin-top: 6px;
  border-top: 1px dashed rgba(255,255,255,0.18);
  padding-top: 6px;
}


/* ═══════════════════════════════════════════════════════════════════════
   GAME-OVER SCREEN  — generated by Casoual.gameover.render()
   Container: any element with class "cg-screen-gameover"; toggled with .active.
   Works with both .screen and .overlay parent containers.
   ═══════════════════════════════════════════════════════════════════════ */

.cg-screen-gameover {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  padding: max(20px, env(safe-area-inset-top, 0px)) 20px max(88px, calc(env(safe-area-inset-bottom, 0px) + 84px)) !important;
  height: 100dvh !important;
  width: 100%;
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 30;
  background: rgba(8,9,10,0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-family: var(--cg-font);
  color: #fff;
  text-align: center;
  box-sizing: border-box;
  overflow-y: auto !important;
}
.cg-screen-gameover.active { display: flex; }

/* Title — adapts color for win/lose */
.cg-go-title {
  font-size: clamp(1.7rem, 7vw, 2.3rem);
  font-weight: 900;
  letter-spacing: -0.02em;
  margin: 4px 0 0;
  color: rgba(255,255,255,0.92);
  text-shadow: 0 2px 12px rgba(0,0,0,0.5);
  flex-shrink: 0;
}
.cg-go-title[data-result="win"]  { color: var(--accent); }
.cg-go-title[data-result="lose"] { color: #ef4444; }

/* Score block */
.cg-go-score-label {
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.5);
  margin: 0;
  flex-shrink: 0;
}
.cg-go-score {
  font-size: clamp(3rem, 16vw, 4.5rem);
  font-weight: 900;
  line-height: 1;
  margin: 0;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, white));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}

/* Stars row (level mode) */
.cg-go-stars {
  display: flex;
  gap: 14px;
  margin: 6px 0 8px;
  flex-shrink: 0;
}
.cg-go-star {
  font-size: 2.6rem;
  opacity: 0.18;
  transform: scale(0.7);
  transition: opacity .35s cubic-bezier(.34,1.6,.64,1), transform .35s cubic-bezier(.34,1.6,.64,1), color .35s, text-shadow .35s;
  color: rgba(255,255,255,0.5);
}
.cg-go-star.earned {
  opacity: 1;
  transform: scale(1);
  color: var(--accent);
  text-shadow: 0 0 22px color-mix(in srgb, var(--accent) 50%, transparent);
}

/* Subtitle / stats / almost */
.cg-go-subtitle {
  font-size: 1rem;
  color: rgba(255,255,255,0.7);
  margin: 0;
  font-weight: 600;
  flex-shrink: 0;
}
.cg-go-stats {
  font-size: 0.92rem;
  color: rgba(255,255,255,0.55);
  white-space: pre-line;
  margin: 0;
  font-weight: 500;
  flex-shrink: 0;
}
.cg-go-stats strong {
  color: rgba(255,255,255,0.85);
  font-weight: 800;
}
.cg-go-almost {
  font-size: 0.92rem;
  color: var(--accent);
  font-weight: 700;
  margin: 0;
  flex-shrink: 0;
}

/* New-best name annotation */
.cg-new-best-name {
  display: block;
  font-size: 0.72rem;
  opacity: 0.7;
  margin-top: 2px;
  font-weight: 600;
}

/* Ad container */
.cg-ad-container {
  margin: 4px 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 320px;
  flex-shrink: 0;
}
.cg-ad-container:empty { display: none; }

/* Actions stack (primary + extras) */
.cg-go-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: 4px 0;
  flex-shrink: 0;
}

/* Like + feedback meta row */
.cg-go-meta-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  flex-shrink: 0;
}
.cg-like {
  background: none;
  border: 2px solid rgba(255,255,255,0.18);
  color: rgba(255,255,255,0.6);
  padding: 9px 22px;
  border-radius: 50px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.cg-like.liked {
  border-color: var(--accent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.cg-feedback-link {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.3);
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: 0.04em;
  padding: 6px 12px;
}
.cg-feedback-link:hover { color: rgba(255,255,255,0.6); }

/* Best badge stays compact within gameover */
.cg-screen-gameover .cg-my-score {
  flex-shrink: 0;
}
