:root {
  --bg: #0f0f0f;
  --bg-elevated: #1a1a1a;
  --bg-card: #222;
  --text: #f5f5f5;
  --text-muted: #999;
  --accent: #f5c518;
  --accent-text: #111;
  --danger: #e74c3c;
  --border: #333;
  --radius: 14px;
  --tab-h: 64px;
  --header-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f7f7f7;
    --bg-elevated: #fff;
    --bg-card: #fff;
    --text: #111;
    --text-muted: #666;
    --border: #e0e0e0;
  }
}

[data-theme="light"] {
  --bg: #f7f7f7;
  --bg-elevated: #fff;
  --bg-card: #fff;
  --text: #111;
  --text-muted: #666;
  --border: #e0e0e0;
}

[data-theme="dark"] {
  --bg: #0f0f0f;
  --bg-elevated: #1a1a1a;
  --bg-card: #222;
  --text: #f5f5f5;
  --text-muted: #999;
  --border: #333;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app { height: 100%; display: flex; flex-direction: column; }

.hidden { display: none !important; }

/* Screens */
.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Auth */
#auth-screen {
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse at top, #2a2200 0%, var(--bg) 60%);
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elevated);
  border-radius: 20px;
  padding: 32px 24px;
  border: 1px solid var(--border);
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.logo {
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent);
  text-align: center;
  letter-spacing: -0.5px;
}
.tagline { text-align: center; color: var(--text-muted); margin: 4px 0 24px; }
.tabs { display: flex; gap: 8px; margin-bottom: 20px; }
.tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  border-radius: 10px;
  cursor: pointer;
}
.tab.active { background: var(--accent); color: var(--accent-text); }
label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}
input[type="text"], input[type="password"], input[type="search"], select, textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

.btn {
  border: none;
  border-radius: 12px;
  padding: 12px 18px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform .1s, opacity .15s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-secondary { background: var(--bg-card); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; margin-top: 8px; }
.btn-icon {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 1.4rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
}
.error { color: var(--danger); font-size: 0.85rem; margin: 8px 0; }

/* Header */
.app-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px 0 20px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.app-header h1 { font-size: 1.25rem; margin: 0; font-weight: 700; }

/* Content */
#content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--tab-h) + var(--safe-bottom) + 8px);
}
.tab-panel { padding: 12px 16px; }

.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.filters input { flex: 1; }
.filters select { width: auto; min-width: 130px; }

/* Cards */
.card-list { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  cursor: pointer;
  transition: background .15s;
}
.card:active { background: var(--bg-elevated); }
.card-thumb {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  background: var(--border);
  object-fit: cover;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}
.card-body { flex: 1; min-width: 0; }
.card-title { font-weight: 700; margin: 0 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { font-size: 0.8rem; color: var(--text-muted); }
.stars { color: var(--accent); letter-spacing: 1px; font-size: 0.95rem; }

/* Profile */
.profile-card {
  background: var(--bg-card);
  border-radius: 20px;
  padding: 24px;
  text-align: center;
  border: 1px solid var(--border);
}
.avatar {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: var(--border);
  margin: 0 auto 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  object-fit: cover;
}
.profile-card h2 { margin: 0 0 4px; }
.profile-card .username { color: var(--text-muted); margin-bottom: 12px; }
.profile-card .bio { font-size: 0.95rem; color: var(--text-muted); }

/* Settings */
.settings-group {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
}
.settings-group label { margin-bottom: 16px; }
.settings-group label:last-child { margin-bottom: 0; }
.toggle {
  display: flex !important;
  justify-content: space-between;
  align-items: center;
  font-size: 1rem !important;
  color: var(--text) !important;
}
.toggle input { width: auto; margin: 0; }
.muted { color: var(--text-muted); }
.small { font-size: 0.8rem; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }

/* Tab bar */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: space-around;
  box-shadow: 0 -4px 20px rgba(0,0,0,.2);
  z-index: 50;
}
.tab-btn {
  background: none;
  border: none;
  color: var(--accent-text);
  opacity: 0.55;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 6px 10px;
  cursor: pointer;
}
.tab-btn .icon { font-size: 1.25rem; }
.tab-btn.active { opacity: 1; }

/* Install banner */
.install-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,.25);
}
.install-banner-content { flex: 1; font-size: 0.85rem; }
.install-banner-content strong { display: block; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.modal {
  background: var(--bg-elevated);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + var(--safe-bottom));
  overflow-y: auto;
  position: relative;
  animation: slideUp .25s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-close {
  position: absolute;
  top: 12px; right: 12px;
  background: var(--bg-card);
  border: none;
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text);
}
.star-picker {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin: 16px 0;
  font-size: 2rem;
  cursor: pointer;
}
.star-picker span { opacity: 0.3; transition: opacity .1s; }
.star-picker span.on { opacity: 1; color: var(--accent); }

/* Utility */
a { color: var(--accent); }

/* Install CTA on auth screen */
.install-cta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  background: rgba(245, 197, 24, 0.12);
  border: 1px solid rgba(245, 197, 24, 0.35);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 18px;
}
.install-cta-icon { font-size: 1.5rem; }
.install-cta-text { flex: 1; min-width: 140px; font-size: 0.85rem; }
.install-cta-text strong { display: block; margin-bottom: 2px; }
.btn-sm { padding: 8px 12px; font-size: 0.85rem; }
.install-steps {
  background: var(--bg);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  font-size: 0.9rem;
}
.install-step { margin-bottom: 12px; }
.install-step .platform {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  font-weight: 700;
}
.install-step ol { margin: 6px 0 0; padding-left: 20px; }
.install-step li { margin: 4px 0; }

/* Leaderboard */
.lb-section { margin-bottom: 22px; }
.lb-section h3 { margin: 0 0 10px; font-size: 1rem; }
.lb-row { align-items: center; }
.lb-rank {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Photos */
.thumb-img {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  object-fit: cover;
  display: block;
}
.photo-preview {
  margin: 8px 0 12px;
  border-radius: 12px;
  overflow: hidden;
  max-height: 180px;
}
.photo-preview img {
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  display: block;
}
.profile-actions { margin-top: 8px; }
.avatar img, img.avatar {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  margin: 0 auto 12px;
}

.ratings-list { margin-top: 12px; }
.rating-row {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: 0.9rem;
}
