/* ==========================================================================
   BestieMe BSTM Airdrop — Main Design System
   ========================================================================== */

/* ----- 1. CSS Variables (Design Tokens) ----- */
:root {
  /* Dark Theme (Default) */
  --bg-primary:    #0A0E1A;
  --bg-secondary:  #131829;
  --bg-tertiary:   #1A1F35;
  --bg-card:       #1A1F35;
  --bg-elevated:   #232846;
  --bg-overlay:    rgba(10, 14, 26, 0.85);

  --accent-1:      #6366F1;
  --accent-2:      #8B5CF6;
  --accent-glow:   #A78BFA;
  --gold:          #F59E0B;
  --gold-glow:     #FBBF24;

  --success:       #10B981;
  --warning:       #F59E0B;
  --danger:        #EF4444;
  --info:          #3B82F6;

  --text-primary:   #F8FAFC;
  --text-secondary: #94A3B8;
  --text-tertiary:  #64748B;
  --text-muted:     #475569;

  --border:        #1E293B;
  --border-light:  #334155;
  --border-glow:   rgba(139, 92, 246, 0.3);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 40px rgba(139, 92, 246, 0.3);
  --shadow-gold: 0 0 24px rgba(245, 158, 11, 0.4);

  --radius-sm:  8px;
  --radius-md:  12px;
  --radius-lg:  16px;
  --radius-xl:  24px;
  --radius-2xl: 32px;
  --radius-full: 9999px;

  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Monaco, Consolas, monospace;

  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

  --layout-sidebar-width: 240px;
  --layout-right-panel-width: 320px;
  --layout-topbar-height: 64px;
  --layout-max-width: 1600px;
}

/* Light Theme Override */
[data-theme="light"] {
  --bg-primary:    #FAFAFB;
  --bg-secondary:  #F1F5F9;
  --bg-tertiary:   #E2E8F0;
  --bg-card:       #FFFFFF;
  --bg-elevated:   #FFFFFF;
  --bg-overlay:    rgba(255, 255, 255, 0.85);

  --text-primary:   #0F172A;
  --text-secondary: #475569;
  --text-tertiary:  #64748B;
  --text-muted:     #94A3B8;

  --border:        #E2E8F0;
  --border-light:  #CBD5E1;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.12);
}

/* ----- 2. Reset + Base ----- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-primary);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  transition: background-color var(--transition-base), color var(--transition-base);
}

/* Animated background gradient (subtle) */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at top left, rgba(99, 102, 241, 0.08), transparent 50%),
    radial-gradient(ellipse at bottom right, rgba(139, 92, 246, 0.08), transparent 50%);
  z-index: -1;
  pointer-events: none;
}

img, svg, video {
  display: block;
  max-width: 100%;
  height: auto;
}

a {
  color: var(--accent-glow);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--accent-2);
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: transparent;
  border: none;
  outline: none;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

h1 { font-size: clamp(2rem, 4vw, 3rem); }
h2 { font-size: clamp(1.5rem, 3vw, 2.25rem); }
h3 { font-size: clamp(1.25rem, 2.5vw, 1.75rem); }
h4 { font-size: 1.25rem; }

p { margin-bottom: 1rem; }

::selection {
  background: var(--accent-2);
  color: white;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: var(--radius-sm);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent-1);
}

/* ----- 3. Utility Classes ----- */
.container {
  width: 100%;
  max-width: var(--layout-max-width);
  margin: 0 auto;
  padding: 0 var(--space-6);
}

.mono { font-family: var(--font-mono); }
.text-gradient {
  background: linear-gradient(135deg, var(--accent-glow), var(--gold-glow));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.glow {
  box-shadow: var(--shadow-glow);
}

.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ----- 4. Buttons ----- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-6);
  font-weight: 600;
  font-size: 0.9375rem;
  border-radius: var(--radius-md);
  transition: all var(--transition-base);
  user-select: none;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  color: white;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.5);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-elevated);
  border-color: var(--accent-1);
}

.btn-gold {
  background: linear-gradient(135deg, var(--gold), var(--gold-glow));
  color: #1A1F35;
  box-shadow: var(--shadow-gold);
  font-weight: 700;
}

.btn-gold:hover {
  transform: translateY(-2px);
  filter: brightness(1.1);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.btn-lg {
  padding: var(--space-4) var(--space-8);
  font-size: 1rem;
}

.btn-full { width: 100%; }

/* ----- 5. Cards ----- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  transition: border-color var(--transition-base), transform var(--transition-base);
}

.card-hover:hover {
  border-color: var(--border-light);
  transform: translateY(-2px);
}

.card-glow {
  border: 1px solid var(--border-glow);
  box-shadow: 0 0 24px rgba(139, 92, 246, 0.1);
}

/* Auth-state visibility — body class wins over inline display:none,
   so even if JS hasn't cleared inline styles yet (mid-deploy cache
   mismatch), CSS guarantees the correct section shows. */
/* Only hide the wrong-state elements. For the visible side, trust the
   per-element author rules (.tab-link flex, .sidebar-profile flex, div block).
   The JS in updateUIForSignedIn/Out clears any inline `display:none` from HTML. */
body.auth-signed-in [data-auth-state="signed-out"] { display: none !important; }
body.auth-signed-out [data-auth-state="signed-in"] { display: none !important; }

/* ----- 6. App Layout (PC: 3-column, locked viewport) -----
   On PC the whole shell is exactly viewport height. Topbar (grid row 1)
   and the two sidebars (columns 1 + 3 of app-main) never move. Only the
   center .content scrolls. Sidebars scroll independently when mouse is
   over them (their own overflow-y: auto).
*/
.app-shell {
  display: grid;
  grid-template-rows: var(--layout-topbar-height) 1fr;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.app-main {
  display: grid;
  grid-template-columns: var(--layout-sidebar-width) 1fr var(--layout-right-panel-width);
  gap: 0;
  overflow: hidden;
  min-height: 0;
}

/* Sidebars: prevent wheel-scroll from chaining out to the page when
   user reaches top/bottom of sidebar content */
.sidebar-left,
.sidebar-right {
  overscroll-behavior: contain;
}
.content {
  overscroll-behavior: contain;
}

/* ----- 7. Top Bar ----- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--layout-topbar-height);
  padding: 0 var(--space-6);
  background: var(--bg-overlay);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-weight: 800;
  font-size: 1.125rem;
  letter-spacing: -0.02em;
}

.topbar-brand img {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
}

.topbar-brand-name {
  background: linear-gradient(135deg, var(--accent-glow), var(--gold-glow));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.topbar-balance {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.9375rem;
}

.topbar-balance-icon {
  width: 20px;
  height: 20px;
  background: linear-gradient(135deg, var(--gold), var(--gold-glow));
  border-radius: 50%;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.topbar-action {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.topbar-action:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.topbar-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--border-light);
  cursor: pointer;
  transition: border-color var(--transition-fast);
}

.topbar-avatar:hover {
  border-color: var(--accent-1);
}

/* ----- 8. Left Sidebar (Book/Folder style tabs) -----
   Sidebar itself does NOT scroll. Only the inner .sidebar-scroll scrolls.
   The .sidebar-footer (profile) stays pinned to the bottom and never moves.
*/
.sidebar-left {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  /* Default layout — applies when .sidebar-left has tab-links directly
     as children (no inner .sidebar-scroll wrapper). The :has() override
     below disables these when the wrapper exists. */
  padding: var(--space-4) var(--space-3);
  gap: var(--space-2);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sidebar-left:has(> .sidebar-scroll) {
  /* When inner scroll wrapper exists, defer padding/gap/scroll to it */
  padding: 0;
  gap: 0;
  overflow: hidden;
}
.sidebar-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-4) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-height: 0;
}
.sidebar-footer {
  flex: 0 0 auto;
  padding: var(--space-3);
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}

/* Guest profile button (signed-out state) */
.sidebar-profile-guest {
  width: 100%;
  background: transparent;
  border: none;
  cursor: pointer;
  font: inherit;
  color: inherit;
  text-align: left;
}
.sidebar-profile-avatar-guest {
  display: grid;
  place-items: center;
  background: var(--bg-elevated);
  color: var(--accent-glow);
}
.sidebar-profile-avatar-guest svg {
  width: 20px;
  height: 20px;
}

/* BSTM card click affordance when signed-out */
.stat-card-clickable {
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.stat-card-clickable:hover {
  transform: translateY(-2px);
  border-color: var(--border-glow);
  box-shadow: 0 6px 20px rgba(139, 92, 246, 0.18);
}
.stat-card-clickable:focus-visible {
  outline: 2px solid var(--accent-glow);
  outline-offset: 2px;
}

.tab-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.9375rem;
  font-weight: 500;
  transition: all var(--transition-base);
  overflow: hidden;
}

/* Book/folder visual: top edge highlight */
.tab-link::before {
  content: '';
  position: absolute;
  top: 0;
  left: var(--space-4);
  right: var(--space-4);
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--border-light), transparent);
  opacity: 0.6;
}

.tab-link:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-light);
  transform: translateX(2px);
}

.tab-link.active {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(139, 92, 246, 0.15));
  border-color: var(--accent-1);
  color: var(--text-primary);
  box-shadow: 0 0 16px rgba(99, 102, 241, 0.2);
}

.tab-link.active::after {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: linear-gradient(180deg, var(--accent-1), var(--accent-2));
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.tab-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.tab-icon svg {
  width: 20px;
  height: 20px;
}

.tab-divider {
  height: 1px;
  background: var(--border);
  margin: var(--space-3) var(--space-2);
}

.sidebar-profile {
  margin-top: auto;
  padding: var(--space-3);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-base);
}

.sidebar-profile:hover {
  border-color: var(--accent-1);
}

.sidebar-profile-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
}

.sidebar-profile-info {
  flex: 1;
  min-width: 0;
}

.sidebar-profile-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-profile-status {
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

/* ----- 9. Main Content Area (Center) ----- */
.content {
  overflow-y: auto;
  padding: var(--space-8) var(--space-6);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-8);
}

/* ----- 10. Mining Circle (Pi/Rubi style) ----- */
.mining-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-6);
  position: relative;
}

.mining-circle-wrap {
  position: relative;
  width: min(380px, 70vw);
  aspect-ratio: 1;
}

.mining-orbit {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--border);
  background:
    radial-gradient(circle at 50% 50%, var(--bg-elevated), var(--bg-secondary));
  box-shadow:
    inset 0 0 60px rgba(139, 92, 246, 0.1),
    0 8px 60px rgba(0, 0, 0, 0.4);
}

.mining-orbit::before,
.mining-orbit::after {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  border: 1px dashed var(--border-light);
  opacity: 0.4;
  animation: rotate 60s linear infinite;
}

.mining-orbit::after {
  inset: -12px;
  animation: rotate 80s linear infinite reverse;
}

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

.mining-core {
  position: absolute;
  inset: 14%;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--bg-card), var(--bg-elevated));
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 2px solid var(--border-light);
  box-shadow: inset 0 0 40px rgba(139, 92, 246, 0.15);
}

/* Logo image — breathing animation until the video is ready */
.mining-core .mining-logo {
  width: 60%;
  height: 60%;
  object-fit: contain;
  transform-origin: center;
  animation: logoBreathe 4s ease-in-out infinite;
  transition: opacity 0.3s ease;
}

/* Video — scaled slightly larger than the core so its content fills
   the visible circle and hides any background ring between the core
   border and the orbit. */
.mining-core .mining-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: none;
  pointer-events: none;        /* No interactions/play button */
  background: transparent;
}
.mining-core.video-ready .mining-logo {
  display: none;
}
.mining-core.video-ready .mining-video {
  display: block;
}
/* When the video is ready, expand the core almost to the wrap edge
   so the inner dark band between core and orbit disappears. Keep a
   sliver of inset so the outer dashed orbit ring stays visible.
   Re-enable overflow:hidden so the video is clipped to the circle. */
.mining-core.video-ready {
  inset: 2%;
  border: none;
  background: transparent;
  box-shadow: none;
  overflow: hidden;
}
/* Belt-and-braces: hide any native controls on iOS/older browsers */
.mining-core .mining-video::-webkit-media-controls,
.mining-core .mining-video::-webkit-media-controls-enclosure,
.mining-core .mining-video::-webkit-media-controls-panel,
.mining-core .mining-video::-webkit-media-controls-start-playback-button {
  display: none !important;
  -webkit-appearance: none;
}

@keyframes logoBreathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.55); }
}

@media (prefers-reduced-motion: reduce) {
  .mining-core .mining-logo { animation: none; }
}

/* Mini task circles around the orbit */
.orbit-task {
  position: absolute;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 2px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-base);
  box-shadow: var(--shadow-md);
  z-index: 2;
}

.orbit-task:hover {
  border-color: var(--accent-1);
  transform: scale(1.1);
  box-shadow: 0 0 20px rgba(99, 102, 241, 0.4);
}

.orbit-task.completed {
  background: linear-gradient(135deg, var(--success), #059669);
  border-color: var(--success);
}

.orbit-task svg { width: 24px; height: 24px; }

/* Positions for orbit tasks (top, right, bottom-left, etc.) */
.orbit-task.pos-top    { top: -28px; left: 50%; transform: translateX(-50%); }
.orbit-task.pos-tr     { top: 12%; right: -28px; }
.orbit-task.pos-br     { bottom: 22%; right: -28px; }
.orbit-task.pos-bl     { bottom: 22%; left: -28px; }
.orbit-task.pos-tl     { top: 12%; left: -28px; }

.orbit-task:hover.pos-top { transform: translateX(-50%) scale(1.1); }

/* Mining Button */
.mining-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.btn-mine {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-8);
  background: linear-gradient(135deg, var(--gold), var(--gold-glow));
  color: #1A1F35;
  font-weight: 700;
  font-size: 1rem;
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-gold);
  transition: all var(--transition-base);
  letter-spacing: 0.02em;
}

.btn-mine:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 0 40px rgba(245, 158, 11, 0.6);
}

.btn-mine:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  box-shadow: none;
}

.btn-mine svg { width: 22px; height: 22px; }

.mining-countdown {
  font-family: var(--font-mono);
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.05em;
}

.mining-countdown.active {
  color: var(--success);
}

/* ----- 11. Right Panel ----- */
.sidebar-right {
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  padding: var(--space-6) var(--space-4);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}

.stat-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  margin-bottom: var(--space-2);
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}

.stat-value-gold {
  background: linear-gradient(135deg, var(--gold), var(--gold-glow));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.stat-meta {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

/* ----- 12. Hero (Landing Page) ----- */
.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-6);
  padding: var(--space-12) var(--space-4);
  max-width: 800px;
  margin: 0 auto;
}

/* Tight variant: badge sits high near topbar */
.hero-tight {
  padding-top: 0;
  gap: var(--space-2);
}
.hero-tight > .hero-badge {
  margin-top: calc(var(--space-5) * -1);
  margin-bottom: var(--space-2);
}
.hero-tight > .hero-badge + .mining-stage {
  margin-top: 0;
}

/* Personal stat cards: BSTM logo / Referrals icon + live values */
.stat-card-personal {
  padding: var(--space-3) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}
.stat-personal-head {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-bottom: var(--space-1);
  white-space: nowrap;
  flex-wrap: nowrap;
}
.stat-personal-coin {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  object-fit: contain;
  flex-shrink: 0;
}
.stat-personal-icon {
  width: 15px;
  height: 15px;
  color: var(--accent-glow);
  flex-shrink: 0;
}
.stat-personal-name {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  text-transform: uppercase;
}
.stat-personal-divider {
  color: var(--text-tertiary);
  margin: 0 0.1em;
}
.stat-countdown {
  font-family: var(--font-mono, monospace);
  font-weight: 600;
  color: var(--accent-glow);
  font-variant-numeric: tabular-nums;
}
.stat-countdown.idle {
  color: var(--text-tertiary);
  font-family: inherit;
  font-weight: normal;
}

/* Sign-in button placed inside the left sidebar */
.sidebar-signin-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-3) var(--space-3);
  font-size: 0.875rem;
  font-weight: 700;
  border-radius: var(--radius-md);
  margin: var(--space-2) 0;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: rgba(139, 92, 246, 0.1);
  border: 1px solid var(--border-glow);
  border-radius: var(--radius-full);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--accent-glow);
}

.hero-title {
  font-size: clamp(2.5rem, 6vw, 4.5rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.hero-subtitle {
  font-size: clamp(1rem, 2vw, 1.25rem);
  color: var(--text-secondary);
  max-width: 600px;
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-4);
  width: 100%;
  max-width: 700px;
  margin-top: var(--space-6);
}

.hero-cta {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  justify-content: center;
  margin-top: var(--space-4);
}

/* ----- 13. Mobile Drawer ----- */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-base);
}

.drawer-overlay.open {
  opacity: 1;
  visibility: visible;
}

.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(320px, 85vw);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  z-index: 101;
  transform: translateX(-100%);
  transition: transform var(--transition-base);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: var(--space-4);
}

.drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-4);
}

.drawer-close {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
}

.drawer-close:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

/* ---- Mobile/tablet drawer: pin profile/signout block to bottom, prevent text cut-off ---- */
@media (max-width: 1023px) {
  .drawer {
    padding-bottom: max(var(--space-4), env(safe-area-inset-bottom, 0px));
  }
  .drawer .tab-link {
    min-height: 48px;
    padding-top: 12px;
    padding-bottom: 12px;
    line-height: 1.3;
    box-sizing: border-box;
    display: flex;
    align-items: center;
  }
  /* The tab-divider sits between top tabs and bottom profile section.
     margin-top: auto pushes everything from divider downward to the bottom
     of the flex column WHEN content is short enough — so the profile / Guest /
     Sign out block always sits at the bottom of the drawer.
     When tabs overflow vertically, drawer's overflow-y: auto kicks in and
     the top tabs scroll while the entire post-divider section is still
     reachable by scrolling to bottom. */
  .drawer .tab-divider {
    margin-top: auto;
  }
  /* Extra vertical space for the bottom section so text isn't clipped */
  .drawer .tab-divider {
    margin-bottom: var(--space-2);
  }
}

.menu-toggle {
  display: none;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  transition: background var(--transition-fast);
}

.menu-toggle:hover {
  background: var(--bg-card);
}

/* ----- 14. Forms ----- */
.form-group {
  margin-bottom: var(--space-4);
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: var(--space-2);
  color: var(--text-primary);
}

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.9375rem;
  transition: border-color var(--transition-fast);
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  border-color: var(--accent-1);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

/* ----- 15. Page-specific (Article style for Whitepaper, FAQ, etc.) ----- */
.article {
  max-width: 760px;
  margin: 0 auto;
  padding: var(--space-8) var(--space-4);
}

.article h1 { margin-bottom: var(--space-4); }
.article h2 { margin: var(--space-10) 0 var(--space-4); }
.article h3 { margin: var(--space-6) 0 var(--space-3); color: var(--accent-glow); }
.article p { margin-bottom: var(--space-4); color: var(--text-secondary); line-height: 1.75; }
.article ul, .article ol { margin: 0 0 var(--space-4) var(--space-6); color: var(--text-secondary); }
.article li { margin-bottom: var(--space-2); }
.article strong { color: var(--text-primary); }
.article hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-8) 0; }

.article-meta {
  display: flex;
  gap: var(--space-4);
  color: var(--text-tertiary);
  font-size: 0.875rem;
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border);
}

/* ----- 16. View Transitions ----- */
@supports (view-transition-name: x) {
  ::view-transition-old(root) {
    animation: fade-out 200ms ease;
  }
  ::view-transition-new(root) {
    animation: fade-in 250ms ease;
  }
}

@keyframes fade-out {
  to { opacity: 0; }
}

@keyframes fade-in {
  from { opacity: 0; }
}

/* ----- 17. Responsive (Mobile/Tablet) ----- */
@media (max-width: 1023px) {
  /* Simple, proven pattern (matches a working mobile site):
       - body: overflow-x: hidden so wide elements don't cause sideways scroll.
       - topbar: position: sticky; top: 0 — stays at top, scrolls correctly.
     No extra touch-action, will-change, transform, overflow-x: clip,
     or -webkit-overflow-scrolling — those caused conflicts. */
  body {
    overflow-x: hidden;
  }
  .app-shell {
    display: block;
    height: auto;
    min-height: auto;
    overflow: visible;
  }
  .topbar {
    position: sticky;
    top: 0;
    z-index: 100;
  }
  .app-main {
    display: block;       /* not grid on mobile — simpler stacking */
    width: 100%;
    max-width: 100vw;
    overflow: visible;
  }
  .content {
    display: block;
    overflow: visible;
    height: auto;
    padding: var(--space-3) var(--space-4) var(--space-6);
    width: 100%;
    max-width: 100vw;
    min-width: 0;
    box-sizing: border-box;
  }
  .hero {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }
  /* Balance: badge sits tightly between topbar and circle */
  .hero-tight {
    padding-top: 0;
    gap: var(--space-3);
  }

  /* Slightly more breathing room between topbar and badge on mobile */
  .hero-tight > .hero-badge {
    margin-top: 0;
  }

  /* Stats: lock 3 cards on a single row, shrink to fit */
  .hero-stats {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 6px;
    width: 100%;
    max-width: 100%;
  }
  .hero-stats .card,
  .hero-stats .stat-card-personal {
    padding: 8px 6px;
    min-width: 0;
    gap: 2px;
  }
  .hero-stats .stat-personal-head {
    gap: 4px;
    margin-bottom: 2px;
    font-size: 0.625rem;
  }
  .hero-stats .stat-personal-coin,
  .hero-stats .stat-personal-icon {
    width: 13px;
    height: 13px;
  }
  .hero-stats .stat-personal-name {
    font-size: 0.625rem;
    letter-spacing: 0.02em;
  }
  .hero-stats .stat-value {
    font-size: 0.9375rem;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .hero-stats .stat-meta {
    font-size: 0.5625rem;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .hero-stats .stat-countdown {
    font-size: 0.625rem;
  }

  .sidebar-left {
    display: none;
  }

  /* Right sidebar stacks below main content on mobile (don't hide it).
     Critical: override overflow:auto from desktop — otherwise the
     sidebar becomes an internal scroll container and traps touch
     gestures, blocking body scroll when user drags from that area. */
  .sidebar-right {
    display: block;
    overflow: visible;
    width: 100%;
    max-width: 100%;
    padding: 0 var(--space-4) var(--space-8);
  }
  .sidebar-right > * {
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
  }

  .menu-toggle {
    display: flex;
  }

  .topbar {
    padding: 0 var(--space-4);
  }

  /* Mobile: stack everything vertically (4% smaller than tablet baseline) */
  .mining-circle-wrap {
    width: min(269px, 67vw);
  }

  .hero {
    width: 100%;
    max-width: 100%;
  }
}

@media (max-width: 480px) {
  .mining-circle-wrap {
    width: 69vw;
  }

  .orbit-task {
    width: 44px;
    height: 44px;
  }

  .orbit-task svg { width: 20px; height: 20px; }

  .btn-mine {
    padding: var(--space-3) var(--space-6);
    font-size: 0.9375rem;
  }

  /* Higher specificity than body.auth-signed-in [data-auth-state="signed-in"] */
  .topbar .topbar-balance[data-auth-state] {
    display: none !important;
  }
}

/* ----- 18. Reduced Motion ----- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ----- 19. Print ----- */
@media print {
  .sidebar-left, .sidebar-right, .topbar, .drawer, .drawer-overlay {
    display: none !important;
  }
}

/* ----- Task page (tasks.html) — global so SPA-swap injected markup styles correctly ----- */
.task-grid { display: grid; gap: var(--space-4); margin-top: var(--space-6); }
.task-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-5); display: flex; align-items: center; gap: var(--space-4); transition: border-color var(--transition-base); flex-wrap: wrap; }
.task-card:hover { border-color: var(--border-light); }
.task-card.done { opacity: 0.6; border-color: var(--success); }
.task-icon-large {
  width: 56px !important; height: 56px !important;
  min-width: 56px; max-width: 56px; min-height: 56px; max-height: 56px;
  flex: 0 0 56px;
  border-radius: var(--radius-md);
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  overflow: hidden; box-sizing: border-box;
}
.task-icon-large svg { width: 28px !important; height: 28px !important; max-width: 28px; max-height: 28px; color: white; display: block; }
.task-body { flex: 1 1 200px; min-width: 0; }
.task-title { font-weight: 700; font-size: 1.0625rem; margin-bottom: 2px; }
.task-desc { font-size: 0.875rem; color: var(--text-secondary); }
.task-reward { font-family: var(--font-mono); font-weight: 700; color: var(--gold); margin-right: var(--space-3); white-space: nowrap; }
@media (max-width: 480px) {
  .task-card { padding: var(--space-4); gap: var(--space-3); }
  .task-icon-large {
    width: 44px !important; height: 44px !important;
    min-width: 44px; max-width: 44px; min-height: 44px; max-height: 44px;
    flex: 0 0 44px;
  }
  .task-icon-large svg { width: 22px !important; height: 22px !important; max-width: 22px; max-height: 22px; }
  .task-reward { margin-right: 0; }
}

/* Tasks page balance strip — flex when visible (signed-in) */
.balance-strip { display: flex !important; }
body.auth-signed-out .balance-strip { display: none !important; }

/* Topbar profile avatar — clickable link to /profile.html */
.topbar-avatar-link {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  line-height: 0;
}
.topbar-avatar-link:hover .topbar-avatar {
  border-color: var(--accent-1);
}

/* ─── Referral first-login popup ─── */
.bm-ref-popup {
  position: fixed;
  inset: 0;
  z-index: 11000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}
.bm-ref-popup.visible { display: flex; }
.bm-ref-popup-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 10, 22, 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.bm-ref-popup-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  max-width: 460px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  animation: bm-ref-pop 0.25s ease-out;
}
@keyframes bm-ref-pop {
  from { transform: translateY(10px) scale(0.96); opacity: 0; }
  to   { transform: translateY(0)    scale(1);    opacity: 1; }
}
.bm-ref-popup-emoji {
  font-size: 2.6rem;
  margin-bottom: var(--space-2);
}
.bm-ref-popup-card h2 {
  margin: 0 0 var(--space-2);
  font-size: 1.3rem;
  background: linear-gradient(120deg, #10b981, #6366f1);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.bm-ref-popup-card p {
  color: var(--text-secondary);
  font-size: 0.92rem;
  line-height: 1.55;
  margin: 0 0 var(--space-4);
}
.bm-ref-popup-card strong { color: var(--text-primary); }
#bm-ref-popup-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-family: "JetBrains Mono", monospace;
  font-size: 1rem;
  letter-spacing: 1px;
  text-align: center;
  text-transform: uppercase;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
#bm-ref-popup-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
}
.bm-ref-popup-error {
  color: #f87171;
  font-size: 0.82rem;
  margin: var(--space-2) 0 0;
  min-height: 1.1em;
  display: none;
}
.bm-ref-popup-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-4);
  flex-wrap: wrap;
}
.bm-ref-popup-actions .btn { flex: 1; min-width: 0; }
.bm-ref-popup-fine {
  margin: var(--space-4) 0 0;
  font-size: 0.74rem;
  color: var(--text-tertiary);
  line-height: 1.45;
}
body.bm-ref-popup-lock { overflow: hidden; }

/* Success toast after applying a code */
.bm-ref-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(60px);
  z-index: 11500;
  background: linear-gradient(120deg, #10b981, #6366f1);
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 12px 22px;
  border-radius: 999px;
  box-shadow: 0 12px 32px rgba(16, 185, 129, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.35s ease, opacity 0.35s ease;
}
.bm-ref-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ─── Service-worker update toast ─── */
.bm-sw-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(80px);
  z-index: 11800;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px 12px 14px;
  border-radius: 14px;
  background: linear-gradient(120deg, #1f2937 0%, #312e81 60%, #1f2937 100%);
  border: 1px solid rgba(139, 92, 246, 0.55);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(99, 102, 241, 0.3);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  max-width: calc(100vw - 32px);
}
.bm-sw-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}
.bm-sw-toast-icon {
  font-size: 1.6rem;
  flex-shrink: 0;
}
.bm-sw-toast-body { flex: 1; min-width: 0; }
.bm-sw-toast-title {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 2px;
}
.bm-sw-toast-sub {
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.72);
}
.bm-sw-toast-count { font-weight: 700; color: #c7d2fe; }
.bm-sw-toast-btn {
  background: linear-gradient(120deg, #6366f1, #8b5cf6);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 8px 18px;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}
.bm-sw-toast-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(139, 92, 246, 0.5);
}
.bm-sw-toast-dismiss {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.55);
  font-size: 1.3rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
  margin-left: -4px;
}
.bm-sw-toast-dismiss:hover { color: #fff; }
@media (max-width: 480px) {
  .bm-sw-toast { flex-wrap: wrap; }
  .bm-sw-toast-btn { width: 100%; }
}
