:root {
  --bg: #0a0a0a;
  --card: #141414;
  --card2: #1c1c1c;
  --border: #242424;
  --accent: #ff3b3b;
  --accent-glow: rgba(255, 59, 59, 0.25);
  --text: #f2f2f2;
  --text2: #a0a0a0;
  --social: #2196f3;
  --skill: #ffb300;
  --chaos: #ff3b3b;
  --gold: #ffd700;
  --radius: 12px;
  --nav-h: 72px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

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

html { background: var(--bg); }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  min-height: 100svh;
  overscroll-behavior: none;
}

a { color: inherit; text-decoration: none; }

/* ---- OFFLINE BAR ---- */
.offline-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: #1a1a00;
  border-bottom: 1px solid #333300;
  color: #ffdd00;
  font-size: 0.8rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  padding-top: calc(8px + var(--safe-top));
}

.offline-bar.hidden { display: none; }

.sync-btn {
  background: #333300;
  border: 1px solid #555500;
  color: #ffdd00;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
  cursor: pointer;
  min-height: 32px;
}

/* ---- VIEWS ---- */
#app {
  min-height: 100svh;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom));
}

.view { display: none; padding: 16px; }
.view.active { display: block; }

/* ---- VIEW HEADER ---- */
.view-header {
  padding: 20px 0 16px;
  margin-bottom: 4px;
}

.view-header h2 {
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: -1px;
  line-height: 1;
  text-transform: uppercase;
}

.view-sub { color: var(--text2); font-size: 0.85rem; margin-top: 4px; }

/* ---- HERO ---- */
.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100svh - var(--nav-h) - var(--safe-bottom));
  padding: 40px 20px;
  text-align: center;
}

.hero-logo {
  width: 80px;
  height: 80px;
  background: var(--accent);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 900;
  color: #fff;
  margin-bottom: 24px;
  box-shadow: 0 0 40px var(--accent-glow);
}

.hero-title {
  font-size: clamp(2.5rem, 10vw, 4rem);
  font-weight: 900;
  letter-spacing: -2px;
  text-transform: uppercase;
  line-height: 1;
}

.hero-title span { color: var(--accent); }

.hero-sub { color: var(--text2); font-size: 1.1rem; margin: 12px 0 32px; }

.hero-cta { display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%; max-width: 320px; }

.already-joined {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  width: 100%;
  text-align: center;
  font-size: 0.9rem;
  color: var(--text2);
  margin-bottom: 4px;
}

.already-joined strong { color: var(--text); display: block; font-size: 1.1rem; margin-bottom: 4px; }

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 24px;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s, transform 0.1s;
  user-select: none;
  -webkit-user-select: none;
}

.btn:active { transform: scale(0.96); opacity: 0.85; }

.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 4px 20px var(--accent-glow); }
.btn-secondary { background: var(--card2); color: var(--text); border: 1px solid var(--border); }
.btn-full { width: 100%; }
.btn-xl { min-height: 60px; font-size: 1.15rem; padding: 0 40px; }

/* ---- FORMS ---- */
.form-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-group label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text2);
}

.form-group input {
  width: 100%;
  background: var(--card2);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1.05rem;
  padding: 14px 16px;
  min-height: 52px;
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}

.form-group input:focus { border-color: var(--accent); }

.status-msg {
  font-size: 0.85rem;
  color: var(--text2);
  text-align: center;
  min-height: 20px;
}

.status-msg.error { color: #ff6b6b; }
.status-msg.ok { color: #4caf50; }

/* ---- QUESTS ---- */
.quests-header { display: flex; align-items: center; justify-content: space-between; }

.round-badge {
  background: var(--card2);
  border: 1px solid var(--border);
  color: var(--text2);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 10px;
  border-radius: 999px;
}

.round-badge.hidden { display: none; }

.quests-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
}

/* ---- QUEST CARD ---- */
.quest-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  position: relative;
  overflow: hidden;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.2s ease, opacity 0.2s ease, box-shadow 0.15s;
}

.quest-card.dragging { transition: none; }

.quest-card.swipe-right { transform: translateX(110%) !important; opacity: 0; }
.quest-card.swipe-left { transform: translateX(-110%) !important; opacity: 0; }

.quest-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
}

.cat-social::before { background: var(--social); }
.cat-skill::before { background: var(--skill); }
.cat-chaos::before { background: var(--chaos); }

.quest-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.quest-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 8px;
  border-radius: 4px;
}

.badge-social { background: rgba(33, 150, 243, 0.15); color: var(--social); }
.badge-skill { background: rgba(255, 179, 0, 0.15); color: var(--skill); }
.badge-chaos { background: rgba(255, 59, 59, 0.15); color: var(--chaos); }

.quest-multiplier {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text2);
}

.quest-text {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 14px;
}

.quest-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.quest-timer {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text2);
  font-variant-numeric: tabular-nums;
}

.quest-timer.urgent { color: #ff6b6b; }

.quest-timer svg { width: 14px; height: 14px; flex-shrink: 0; }

.btn-quest-done {
  min-height: 44px;
  padding: 0 18px;
  font-size: 0.9rem;
  border-radius: 8px;
  background: transparent;
  border: 1.5px solid var(--accent);
  color: var(--accent);
  cursor: pointer;
  font-weight: 700;
  transition: background 0.15s, color 0.15s, transform 0.1s;
  flex-shrink: 0;
}

.btn-quest-done:active { transform: scale(0.94); background: var(--accent); color: #fff; }

/* Swipe hint overlays */
.swipe-hint-right, .swipe-hint-left {
  position: absolute;
  top: 0; bottom: 0;
  width: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 0.8rem;
  text-transform: uppercase;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s;
}

.swipe-hint-right { right: 0; background: linear-gradient(to left, rgba(76,175,80,0.3), transparent); color: #4caf50; }
.swipe-hint-left { left: 0; background: linear-gradient(to right, rgba(255,59,59,0.3), transparent); color: #ff6b6b; }

/* ---- LEADERBOARD ---- */
.lb-list { display: flex; flex-direction: column; gap: 8px; }

.lb-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  transition: transform 0.35s ease, opacity 0.35s ease;
}

.lb-row.rank-1 { border-color: var(--gold); background: #111000; }

.lb-rank {
  width: 32px;
  text-align: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}

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

.lb-nick {
  font-weight: 800;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-title {
  font-size: 0.7rem;
  color: var(--gold);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.lb-stats {
  text-align: right;
  flex-shrink: 0;
}

.lb-rep {
  font-size: 1.2rem;
  font-weight: 900;
  color: var(--accent);
}

.lb-quests { font-size: 0.72rem; color: var(--text2); }

/* ---- GALLERY ---- */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

@media (min-width: 400px) { .gallery-grid { grid-template-columns: repeat(3, 1fr); } }

.gallery-thumb {
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  background: var(--card);
  cursor: pointer;
  position: relative;
}

.gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s;
}

.gallery-thumb:active img { transform: scale(0.96); }

.gallery-thumb-caption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.8));
  padding: 20px 6px 6px;
  font-size: 0.7rem;
  color: #ccc;
  font-weight: 600;
}

/* ---- PROFILE ---- */
.profile-content { display: flex; flex-direction: column; gap: 12px; }

.profile-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.profile-card h3 { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text2); margin-bottom: 10px; }

.profile-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.profile-item:last-child { border-bottom: none; }
.profile-item-label { font-size: 0.85rem; color: var(--text2); }
.profile-item-value { font-weight: 700; }

/* ---- BOTTOM NAV ---- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(10, 10, 10, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: var(--nav-h);
  gap: 4px;
  color: var(--text2);
  font-size: 0.65rem;
  font-weight: 600;
  transition: color 0.15s;
}

.nav-item svg { width: 22px; height: 22px; }
.nav-item.active { color: var(--accent); }

.nav-center {
  color: transparent;
  flex-shrink: 0;
}

.nav-center span { color: var(--text2); font-size: 0.65rem; font-weight: 600; margin-top: 4px; }
.nav-center.active span { color: var(--accent); }

.nav-center-btn {
  width: 56px;
  height: 56px;
  background: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px var(--accent-glow);
  transition: transform 0.15s;
  margin-bottom: 2px;
}

.nav-center:active .nav-center-btn { transform: scale(0.92); }
.nav-center-btn svg { width: 26px; height: 26px; color: #fff; }

/* ---- PHOTO MODAL ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal-sheet {
  background: var(--card);
  border-radius: 20px 20px 0 0;
  width: 100%;
  padding: 12px 20px 32px;
  padding-bottom: calc(32px + var(--safe-bottom));
  position: relative;
  transform: translateY(100%);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-overlay.active .modal-sheet { transform: translateY(0); }

.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  margin: 0 auto;
}

.modal-title {
  font-size: 1rem;
  font-weight: 800;
  text-align: center;
}

.photo-preview-wrap {
  border-radius: 12px;
  overflow: hidden;
  background: var(--card2);
  aspect-ratio: 4/3;
}

.photo-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-preview.hidden { display: none; }

.photo-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text2);
  font-size: 0.85rem;
  cursor: pointer;
}

.photo-placeholder svg { width: 48px; height: 48px; }

.modal-actions { display: flex; flex-direction: column; gap: 10px; }

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  background: var(--card2);
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text2);
}

.modal-close svg { width: 18px; height: 18px; }

/* ---- LIGHTBOX ---- */
.lightbox {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 300;
  display: flex;
  flex-direction: column;
}

.lightbox.hidden { display: none; }

.lightbox-close {
  position: absolute;
  top: calc(16px + var(--safe-top));
  right: 16px;
  z-index: 10;
  width: 44px;
  height: 44px;
  background: rgba(0,0,0,0.6);
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #fff;
}

.lightbox-close svg { width: 22px; height: 22px; }

.lightbox-track {
  flex: 1;
  display: flex;
  overflow: hidden;
  touch-action: pan-y;
}

.lightbox-slide {
  flex: 0 0 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-slide img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.lightbox-dots {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 10px;
}

.lb-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,0.3);
  transition: background 0.2s;
}

.lb-dot.active { background: #fff; }

.lightbox-caption {
  padding: 10px 20px calc(20px + var(--safe-bottom));
  text-align: center;
}

.lightbox-caption strong { display: block; color: var(--accent); font-size: 0.9rem; }
.lightbox-caption span { font-size: 0.8rem; color: #aaa; }

/* ---- END SCREEN ---- */
.end-screen {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: #0a0a0a;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.end-screen.hidden { display: none; }

.confetti-canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.end-content { position: relative; z-index: 1; padding: 40px 24px; max-width: 400px; }

.end-crown { font-size: 4rem; margin-bottom: 16px; animation: bounce 1s infinite alternate; }

@keyframes bounce { from { transform: translateY(0); } to { transform: translateY(-12px); } }

.end-title {
  font-size: 2rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: -1px;
  color: var(--gold);
  margin-bottom: 8px;
}

.end-winner {
  font-size: 2.5rem;
  font-weight: 900;
  color: var(--text);
  margin-bottom: 32px;
}

.end-leaderboard { display: flex; flex-direction: column; gap: 8px; margin-bottom: 32px; }

.end-lb-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card);
  border-radius: 8px;
  padding: 10px 16px;
}

.end-lb-row:first-child { border: 1.5px solid var(--gold); }

/* ---- TOAST ---- */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--card2);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 700;
  font-size: 0.9rem;
  padding: 10px 20px;
  border-radius: 999px;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 500;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

/* ---- MISC ---- */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text2); }
.loading-state { text-align: center; padding: 40px 20px; color: var(--text2); font-size: 0.9rem; }

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 12px;
}

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