:root {
  color-scheme: dark;
  --bg: #000;
  --text: #fff;
  --text-secondary: rgba(255, 255, 255, 0.65);
  --accent: #fe2c55;
  --accent-glow: rgba(254, 44, 85, 0.4);
  --glass: rgba(255, 255, 255, 0.08);
  --glass-border: rgba(255, 255, 255, 0.1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  overscroll-behavior: none;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ───── Shell ───── */

.game-shell {
  position: relative;
  width: min(420px, 100vw);
  height: min(860px, 100dvh);
  overflow: hidden;
  background: #000;
}

@media (min-width: 521px) {
  .game-shell {
    border-radius: 32px;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 24px 80px rgba(0, 0, 0, 0.6);
  }
}

/* ───── Top bar ───── */

.top-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 10px) 14px 10px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.7) 0%, rgba(0, 0, 0, 0.3) 70%, transparent 100%);
  pointer-events: none;
}

.top-bar > * {
  pointer-events: auto;
}

.top-bar-left, .top-bar-right {
  flex: 0 0 auto;
  min-width: 56px;
}

.top-bar-right {
  display: flex;
  justify-content: flex-end;
}

.logo {
  font-size: 18px;
  font-weight: 900;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #fe2c55, #ff6b6b, #ffd93d);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.top-bar-center {
  display: flex;
  gap: 0;
}

.tab {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 6px 14px;
  cursor: pointer;
  position: relative;
  transition: color 0.2s;
}

.tab.active {
  color: var(--text);
}

.tab.active::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 28px;
  height: 3px;
  background: var(--text);
  border-radius: 2px;
}

.timer-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  transition: color 0.3s, border-color 0.3s;
}

.timer-badge.warning {
  color: #ffd93d;
  border-color: rgba(255, 217, 61, 0.25);
}

.timer-badge.critical {
  color: var(--accent);
  border-color: var(--accent-glow);
  animation: pulse-badge 0.6s ease-in-out infinite alternate;
}

@keyframes pulse-badge {
  to { opacity: 0.7; }
}

/* ───── Stage ───── */

.stage {
  position: absolute;
  inset: 0;
  z-index: 4;
  background: #000;
  overflow: hidden;
}

.stage iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  /* Ensure game canvas isn't hidden behind shell UI */
  pointer-events: auto;
}

.stage-pane {
  position: absolute;
  inset: 0;
  transform: translate3d(0, 0, 0);
  will-change: transform, opacity;
}

.stage-pane.enter {
  transform: translate3d(0, 100%, 0);
}

.stage.animating .stage-pane {
  transition: transform 350ms cubic-bezier(0.16, 1, 0.3, 1);
}

.stage.animating .stage-pane.exit {
  transform: translate3d(0, -100%, 0);
}

.stage.animating .stage-pane.enter.enter-active {
  transform: translate3d(0, 0, 0);
}

/* ───── Loading overlay ───── */

.loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.loading-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.loader {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ───── Bottom info ───── */

.bottom-info {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 18px);
  left: 14px;
  right: 80px;
  z-index: 12;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.game-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.game-title {
  font-size: 15px;
  font-weight: 700;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.7);
  line-height: 1.3;
}

.game-status {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.game-status.live {
  color: #25f4ee;
}

.game-status.ended {
  color: var(--text-secondary);
}

.score-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 700;
  color: #ffd93d;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

/* ───── Action sidebar ───── */

.action-sidebar {
  position: absolute;
  right: 8px;
  bottom: calc(var(--safe-bottom) + 80px);
  z-index: 12;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  pointer-events: none; /* let touches pass through to game */
}
.action-sidebar .action-btn {
  pointer-events: auto; /* but buttons themselves are tappable */
}

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s;
}

.action-btn:active {
  transform: scale(0.88);
}

.action-btn svg {
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.5));
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.action-btn:active svg {
  transform: scale(1.15);
}

.action-btn.like.liked svg {
  fill: var(--accent);
  stroke: var(--accent);
  animation: pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

.action-label {
  font-size: 11px;
  font-weight: 600;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

/* ───── Swipe hint ───── */

.swipe-hint {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--safe-bottom) + 4px);
  z-index: 11;
  display: flex;
  align-items: center;
  gap: 4px;
  color: rgba(255, 255, 255, 0.35);
  font-size: 11px;
  font-weight: 600;
  pointer-events: none;
  animation: bob 2s ease-in-out infinite;
}

@keyframes bob {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-4px); }
}

.swipe-hint.hidden {
  opacity: 0;
  transition: opacity 0.5s;
}

/* ───── Heart burst ───── */

.heart-burst {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0);
  z-index: 30;
  pointer-events: none;
  opacity: 0;
}

.heart-burst.active {
  animation: heart-pop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes heart-pop {
  0% { transform: translate(-50%, -50%) scale(0); opacity: 1; }
  50% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}

/* ───── Toast ───── */

.toast {
  position: absolute;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  bottom: calc(var(--safe-bottom) + 100px);
  z-index: 25;
  padding: 8px 16px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ───── Score card ───── */

#score-card {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s;
}

#score-card.visible {
  opacity: 1;
}

.sc-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.sc-content {
  position: relative;
  text-align: center;
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.sc-result {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.3px;
}

.sc-score {
  font-size: 64px;
  font-weight: 900;
  background: linear-gradient(135deg, #ffd93d, #ff6b6b);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.1;
}

.sc-score-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 16px;
}

.sc-actions {
  display: flex;
  gap: 10px;
}

.sc-btn {
  padding: 12px 24px;
  border-radius: 24px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: transform 0.15s, opacity 0.15s;
}

.sc-btn:active {
  transform: scale(0.95);
}

.sc-replay {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.sc-next {
  background: var(--accent);
  color: #fff;
}

.sc-auto {
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-secondary);
}

/* ───── Rotate prompt ───── */

#rotate-prompt {
  position: absolute;
  inset: 0;
  z-index: 35;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  opacity: 0;
  transition: opacity 0.3s;
}

#rotate-prompt.visible {
  opacity: 1;
}

.rp-icon {
  font-size: 48px;
  animation: rp-wobble 1.5s ease-in-out infinite;
}

@keyframes rp-wobble {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-20deg); }
  75% { transform: rotate(20deg); }
}

.rp-msg {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  text-align: center;
}

.rp-sub {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
}

/* ───── Mobile full-bleed ───── */

@media (max-width: 520px) {
  .game-shell {
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
  }

  .top-bar {
    padding-top: calc(var(--safe-top) + 8px);
  }

  .action-sidebar {
    right: 6px;
  }
}

/* ── Shell Polish Additions ──────────────────────── */

/* Shake animation */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}

/* Streak counter */
.streak-counter {
  font-size: 14px;
  font-weight: 700;
  color: #ffd740;
  margin-right: 8px;
  text-shadow: 0 0 8px rgba(255, 215, 64, 0.5);
}

@keyframes pulse-glow {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); text-shadow: 0 0 16px rgba(255, 215, 64, 0.8); }
  100% { transform: scale(1); }
}

/* Share button style */
.action-btn.share svg {
  stroke: rgba(255, 255, 255, 0.85);
}

/* ── Profile Icon ────────────────────────────────── */
.profile-icon {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--glass); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; cursor: pointer;
  border: 1.5px solid var(--glass-border);
  transition: transform 0.15s;
  vertical-align: middle;
  flex-shrink: 0;
}
.profile-icon:active { transform: scale(0.9); }

/* Fix: top-bar-left should be horizontal */
.top-bar-left {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  flex-direction: row !important;
}

/* ── Premium Purchase Modal ──────────────────────── */
.premium-modal { position: fixed; inset: 0; z-index: 200; opacity: 0; transition: opacity 0.3s; }
.premium-modal.visible { opacity: 1; }
.pm-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.7); }
.pm-card {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: #1a1a1f; border-radius: 20px 20px 0 0;
  padding: 32px 24px calc(24px + var(--safe-bottom));
  transform: translateY(100%); transition: transform 0.35s cubic-bezier(.4,0,.2,1);
}
.premium-modal.visible .pm-card { transform: translateY(0); }
.pm-title { font-size: 24px; font-weight: 800; text-align: center; margin-bottom: 8px; }
.pm-subtitle { font-size: 14px; color: var(--text-secondary); text-align: center; margin-bottom: 24px; }
.pm-options { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.pm-option {
  padding: 16px; border-radius: 14px; border: 1.5px solid var(--glass-border);
  background: var(--glass); color: #fff; font-size: 16px; font-weight: 600;
  cursor: pointer; text-align: center; transition: background 0.15s;
}
.pm-option:first-child { background: linear-gradient(135deg, #7c4dff33, #e040fb33); border-color: #7c4dff55; }
.pm-option:active { background: rgba(255,255,255,0.15); }
.pm-skip { background: none; border: none; color: var(--text-secondary); font-size: 14px; cursor: pointer; width: 100%; padding: 12px; }

/* ── Premium Feed Card ───────────────────────────── */
.premium-feed-card {
  position: absolute; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1a0a2e, #0a0a1f);
  opacity: 0; transition: opacity 0.4s;
}
.premium-feed-card.visible { opacity: 1; }
.pfc-content { text-align: center; padding: 24px; }
.pfc-emoji { font-size: 64px; margin-bottom: 16px; }
.pfc-headline { font-size: 24px; font-weight: 800; margin-bottom: 8px; }
.pfc-sub { font-size: 14px; color: var(--text-secondary); margin-bottom: 32px; }
.pfc-cta {
  display: block; width: 100%; padding: 16px; border-radius: 14px; border: none;
  background: linear-gradient(135deg, #7c4dff, #e040fb); color: #fff;
  font-size: 16px; font-weight: 700; cursor: pointer; margin-bottom: 12px;
  animation: cta-pulse 2s ease-in-out infinite;
}
@keyframes cta-pulse {
  0%, 100% { box-shadow: 0 0 20px rgba(124,77,255,0.3); }
  50% { box-shadow: 0 0 40px rgba(224,64,251,0.5); }
}
.pfc-skip { background: none; border: none; color: var(--text-secondary); font-size: 14px; cursor: pointer; padding: 12px; }

/* ── Auth Bottom Sheet ───────────────────────────── */
.auth-sheet { position: fixed; inset: 0; z-index: 200; opacity: 0; transition: opacity 0.3s; }
.auth-sheet.visible { opacity: 1; }
.as-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.7); }
.as-card {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: #1a1a1f; border-radius: 20px 20px 0 0;
  padding: 32px 24px calc(24px + var(--safe-bottom));
  transform: translateY(100%); transition: transform 0.35s cubic-bezier(.4,0,.2,1);
}
.auth-sheet.visible .as-card { transform: translateY(0); }
.as-title { font-size: 22px; font-weight: 800; text-align: center; margin-bottom: 8px; }
.as-sub { font-size: 14px; color: var(--text-secondary); text-align: center; margin-bottom: 20px; }
.as-email { font-size: 16px; text-align: center; margin-bottom: 8px; color: var(--text-secondary); }
.as-plan { font-size: 14px; text-align: center; margin-bottom: 20px; font-weight: 600; }
.as-input {
  display: block; width: 100%; padding: 14px 16px; border-radius: 12px;
  border: 1.5px solid var(--glass-border); background: var(--glass);
  color: #fff; font-size: 16px; margin-bottom: 12px; outline: none;
}
.as-input:focus { border-color: var(--accent); }
.as-btn {
  display: block; width: 100%; padding: 14px; border-radius: 12px; border: none;
  font-size: 15px; font-weight: 600; cursor: pointer; margin-bottom: 8px;
}
/* ── Game Counter ────────────────────────────────── */
.game-counter {
  font-size: 11px; color: rgba(255,255,255,0.25);
  margin-top: 2px;
}

/* ── Rewarded Ad on Score Card ────────────────────── */
.sc-rewarded-ad {
  margin-top: 16px; padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
  text-align: center;
}
.sc-ad-icon { font-size: 20px; margin-right: 6px; vertical-align: middle; }
.sc-btn.sc-ad-btn {
  background: rgba(255, 193, 7, 0.15) !important;
  border-color: rgba(255, 193, 7, 0.3) !important;
  color: #ffc107 !important;
  width: 100%; margin-bottom: 8px;
}
.sc-btn.sc-ad-btn:active { background: rgba(255, 193, 7, 0.25) !important; }
.sc-ad-note {
  font-size: 12px; color: var(--text-secondary);
  text-decoration: underline; text-underline-offset: 2px;
}

.as-continue { background: var(--accent); color: #fff; }
.as-upgrade { background: linear-gradient(135deg, #7c4dff, #e040fb); color: #fff; }
.as-guest { background: none; color: var(--text-secondary); }
.as-logout { background: var(--glass); color: var(--text-secondary); }

/* ── Logo Icon ───────────────────────────────────── */
.logo-icon {
  width: 28px; height: 28px; border-radius: 6px;
  margin-right: 6px; vertical-align: middle;
}

/* ── Trending Page ───────────────────────────────── */
.trending-page {
  position: absolute; inset: 0;
  padding: calc(var(--safe-top, 0px) + 56px) 0 calc(var(--safe-bottom, 0px) + 16px);
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
}
.trending-header {
  padding: 20px 20px 12px;
}
.trending-header h2 {
  font-size: 22px; font-weight: 800; margin-bottom: 4px;
}
.trending-sub {
  font-size: 13px; color: var(--text-secondary);
}
.trending-list {
  padding: 0 12px;
}
.trending-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  transition: background 0.15s;
}
.trending-item:active { background: rgba(255,255,255,0.04); }
.trending-rank {
  width: 36px; text-align: center;
  font-size: 20px; font-weight: 700;
  color: var(--text-secondary); flex-shrink: 0;
}
.trending-info { flex: 1; min-width: 0; }
.trending-title {
  font-size: 15px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.trending-meta {
  font-size: 12px; color: var(--text-secondary); margin-top: 2px;
}
.trending-plays {
  font-size: 13px; color: var(--text-secondary);
  white-space: nowrap; flex-shrink: 0;
}
.trending-play-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); color: #000; border: none;
  font-size: 14px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: transform 0.15s;
}
.trending-play-btn:active { transform: scale(0.9); }

/* ── PWA Install Prompt ──────────────────────────── */
.pwa-install-banner {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 300;
  background: #1a1a1f; border-top: 1px solid rgba(255,255,255,0.08);
  padding: 14px 16px calc(14px + var(--safe-bottom, 0px));
  display: flex; align-items: center; gap: 12px;
  transform: translateY(100%); transition: transform 0.35s cubic-bezier(.4,0,.2,1);
}
.pwa-install-banner.visible { transform: translateY(0); }
.pwa-install-icon { width: 40px; height: 40px; border-radius: 10px; flex-shrink: 0; }
.pwa-install-text { flex: 1; }
.pwa-install-title { font-size: 14px; font-weight: 700; }
.pwa-install-sub { font-size: 12px; color: var(--text-secondary); }
.pwa-install-btn {
  padding: 8px 16px; border-radius: 8px; border: none;
  background: var(--accent); color: #000; font-size: 13px;
  font-weight: 700; cursor: pointer; flex-shrink: 0;
}
.pwa-install-dismiss {
  background: none; border: none; color: var(--text-secondary);
  font-size: 18px; cursor: pointer; padding: 4px; flex-shrink: 0;
}
