:root {
  /* Premium OLED Dark Theme */
  --bg-main: #000000;
  --bg-panel: #0a0a0a;
  --bg-surface: #141414;
  --bg-hover: #1f1f1f;
  
  --border-subtle: #1e1e1e;
  --border-strong: #2a2a2a;
  
  --text-main: #ffffff;
  --text-muted: #8e8e93; /* iOS-like muted gray */
  --text-inverse: #000000;
  
  /* Modern sharp accent (Electric Indigo / Neon Blue vibe) */
  --accent: #5e5ce6;
  --accent-light: #7d7aff;
  --accent-alpha: rgba(94, 92, 230, 0.15);
  
  --danger: #ff453a;
  --danger-alpha: rgba(255, 69, 58, 0.15);
  --success: #32d74b;
  --success-alpha: rgba(50, 215, 75, 0.15);
  --star-color: #ffd60a;
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 99px;
  
  --nav-height: 80px;
  --nav-safe-offset: calc(var(--nav-height) + var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 12px)) + 28px);
}

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text-main);
  background-color: var(--bg-main);
  overscroll-behavior-y: none; /* Prevents pull-to-refresh blank spaces */
}

/* Base Layout */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 600px;
  margin: 0 auto;
  background-color: var(--bg-main);
}

.content-area {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px var(--nav-safe-offset);
  scroll-padding-bottom: var(--nav-safe-offset);
}

/* Typography */
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 22px; margin-bottom: 16px; }
h3 { font-size: 16px; margin-bottom: 4px; color: var(--text-main); }
.muted { color: var(--text-muted); font-size: 13px; margin: 0; line-height: 1.4; }
.eyebrow { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }

/* Header */
.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: var(--bg-main);
  position: sticky;
  top: 0;
  z-index: 10;
}

.nav-left { display: flex; align-items: center; gap: 12px; }
.avatar-placeholder {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  display: grid; place-items: center;
  color: var(--text-muted);
}
.user-info { display: flex; flex-direction: column; }
.user-info strong { font-size: 16px; font-weight: 700; }

/* Context Switcher */
.context-bar {
  padding: 0 16px 16px;
}
.context-selector {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.context-icon { color: var(--text-muted); width: 18px; height: 18px; }
.select-wrapper { position: relative; flex: 1; display: flex; align-items: center; }
.context-select {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  width: 100%;
  outline: none;
  cursor: pointer;
  padding-right: 24px;
}
.select-arrow {
  position: absolute; right: 0; width: 16px; height: 16px;
  color: var(--text-muted); pointer-events: none;
}

/* Bottom Navigation (Native-like) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0; 
  right: 0;
  background: rgba(10, 10, 10, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-strong);
  padding-bottom: var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 12px));
  z-index: 100;
}

.tab-panel:last-child,
.panel:last-child,
.list-group:last-child {
  margin-bottom: 8px;
}
.tabs {
  display: flex;
  justify-content: space-between;
  max-width: 600px;
  margin: 0 auto;
  padding: 10px 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs.with-admin {
  justify-content: flex-start;
  gap: 4px;
}
.tabs::-webkit-scrollbar { display: none; }
.tab-button {
  flex: 1 0 auto;
  min-width: 74px;
  background: transparent;
  color: var(--text-muted);
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 6px;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
}
.tab-button i { width: 18px; height: 18px; }
.tab-button.active {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.04);
}

/* Panels & Transitions */
.panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: fadeSlide 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes fadeSlide {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.hidden { display: none !important; }

/* Section Titles */
.section-header {
  display: flex; justify-content: space-between; align-items: flex-end;
  margin-bottom: 4px;
}

/* Lists & Items (Replaces bulky cards) */
.list-group {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border-strong);
}
.list-item:last-child { border-bottom: none; }
.list-item-content { flex: 1; padding-right: 16px; }
.list-item-meta { display: flex; gap: 12px; margin-top: 6px; font-size: 13px; font-weight: 600; color: var(--accent); }
.list-item-meta .neutral { color: var(--text-muted); font-weight: 500; }
.list-item.compact {
  padding: 14px 16px;
}

/* Grid Stats */
.stats-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px; /* Creates clean 1px inner borders */
  background: var(--border-strong);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.stat-box {
  background: var(--bg-surface);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-box strong { font-size: 20px; font-weight: 800; }
.stat-box span { font-size: 12px; color: var(--text-muted); font-weight: 500; }

/* Buttons */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-family: inherit; font-size: 14px; font-weight: 700;
  cursor: pointer;
  width: 100%;
  transition: transform 0.1s, opacity 0.2s;
}
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { background: var(--bg-hover); color: var(--text-muted); cursor: not-allowed; }
.btn-primary.hidden { display: none !important; }

.btn-secondary {
  background: var(--bg-hover);
  color: var(--text-main);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-family: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer; width: 100%;
}
.btn-secondary:active { background: var(--border-strong); }

.btn-sm { padding: 8px 14px; font-size: 13px; width: auto; border-radius: 6px; }
.btn-danger { background: var(--danger-alpha); color: var(--danger); }

.button-row { display: flex; gap: 10px; margin-top: 16px; }
.segmented-control {
  display: inline-flex;
  gap: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  padding: 4px;
  border-radius: var(--radius-pill);
}
.segment-button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-weight: 700;
  font-size: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-pill);
}
.segment-button.active {
  background: var(--accent-alpha);
  color: var(--text-main);
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 700;
  border: 1px solid var(--border-strong);
  background: var(--bg-hover);
  color: var(--text-muted);
}
.badge.success {
  color: var(--success);
  background: var(--success-alpha);
  border-color: rgba(50,215,75,0.2);
}
.badge.danger {
  color: var(--danger);
  background: var(--danger-alpha);
  border-color: rgba(255,69,58,0.2);
}

/* Inputs */
.input-field {
  background: var(--bg-main);
  border: 1px solid var(--border-strong);
  color: var(--text-main);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-family: inherit; font-size: 14px;
  width: 100%; outline: none;
}
.input-field:focus { border-color: var(--accent); }
.input-row { display: flex; gap: 8px; margin-top: 12px; }

/* Effects/Tags */
.tags-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.tag {
  background: var(--accent-alpha);
  color: var(--accent-light);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 600;
  border: 1px solid rgba(94, 92, 230, 0.2);
}
.tag span { color: var(--text-muted); font-weight: 400; margin-left: 4px; }

/* Leaderboard */
.rank-list { padding: 0; margin: 0; list-style: none; }
.rank-item {
  display: flex; align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
}
.rank-item:last-child { border-bottom: none; }
.rank-pos {
  width: 28px; font-weight: 800; color: var(--text-muted); font-size: 14px;
}
.rank-item:nth-child(1) .rank-pos { color: var(--star-color); }
.rank-info { flex: 1; }
.rank-info strong { display: block; font-size: 15px; }
.rank-score { font-weight: 700; color: var(--accent); font-size: 14px; }

/* Toasts / Banners */
.toast-container {
  position: fixed; top: 16px; left: 16px; right: 16px; z-index: 1000;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.banner {
  padding: 12px 16px; border-radius: var(--radius-md);
  font-size: 13px; font-weight: 600;
  backdrop-filter: blur(10px);
  animation: slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}
.banner.error { background: var(--danger-alpha); color: var(--danger); border: 1px solid rgba(255,69,58,0.3); }
.banner.success { background: var(--success-alpha); color: var(--success); border: 1px solid rgba(50,215,75,0.3); }

/* States */
.loading-panel { align-items: center; justify-content: center; min-height: 40vh; color: var(--text-muted); }
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border-strong);
  border-top-color: var(--text-main);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-panel { align-items: center; text-align: center; justify-content: center; min-height: 40vh; }
.empty-panel .btn-primary {
  margin-top: 18px;
  max-width: 280px;
}
.empty-icon {
  width: 64px; height: 64px;
  border-radius: 50%; background: var(--bg-surface); border: 1px solid var(--border-strong);
  display: grid; place-items: center; margin-bottom: 16px; color: var(--text-muted);
}
.empty-icon i { width: 32px; height: 32px; }

@media (max-width: 420px) {
  .tab-button {
    min-width: 68px;
  }
}
