/* === Brand: CSS Variables === */
:root {
  /* Typography */
  --font-body: 'DM Sans', sans-serif;
  --font-display: 'DM Serif Display', serif;

  /* Grey Scale */
  --grey-50:  #FAFAF9;
  --grey-100: #F5F5F4;
  --grey-200: #E7E5E4;
  --grey-300: #D6D3D1;
  --grey-400: #A8A29E;
  --grey-500: #78716C;
  --grey-600: #57534E;
  --grey-800: #292524;
  --grey-900: #1C1917;
  --grey-950: #0F0F0F;

  /* Accent */
  --pink: #FF2867;

  /* Semantic (Light Mode) */
  --bg: var(--grey-50);
  --surface: #FFFFFF;
  --text: var(--grey-900);
  --text-muted: var(--grey-600);
  --border: var(--grey-200);
  --accent: var(--pink);
  --accent-hover: #E6164F;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;
  --space-4xl: 6rem;

  /* Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1);
  --shadow-xl: 0 20px 50px rgba(0,0,0,0.12);

  /* Motion */
  --ease-out-quart: cubic-bezier(.165, .84, .44, 1);
  --ease-in-out-cubic: cubic-bezier(.645, .045, .355, 1);
  --dur-1: 120ms;
  --dur-2: 180ms;
  --dur-3: 240ms;
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;

  /* Sidebar */
  --sidebar-width: 220px;
  --sidebar-collapsed-width: 60px;
}

/* Dark Mode */
:root.dark {
  --bg: var(--grey-950);
  --surface: var(--grey-900);
  --text: var(--grey-50);
  --text-muted: var(--grey-400);
  --border: var(--grey-800);
  --accent-hover: #FF5088;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.4);
}

/* === Base Styles === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
}

body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
  line-height: 1.2;
  font-weight: 600;
}

h1 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 2.5rem;
}

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

button, .btn {
  font-family: var(--font-body);
  font-weight: 500;
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
}

.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  border-color: var(--text-muted);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover {
  color: var(--text);
  background: var(--grey-100);
}
:root.dark .btn-ghost:hover {
  background: var(--grey-800);
}

input, textarea, select {
  font-family: var(--font-body);
  font-size: 1rem;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--transition-fast);
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}

textarea {
  resize: vertical;
  min-height: 100px;
}

label {
  display: block;
  font-weight: 500;
  margin-bottom: var(--space-xs);
  color: var(--text);
}

/* === Layout === */
.app-content {
  min-height: 100dvh;
  padding: var(--space-lg);
}

.app-content.with-sidebar {
  margin-left: var(--sidebar-collapsed-width);
  transition: margin-left var(--dur-3) var(--ease-out-quart);
}

@media (max-width: 768px) {
  .app-content.with-sidebar {
    margin-left: 0;
  }
}

/* === Sidebar === */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-width);
  height: 100dvh;
  display: grid;
  grid-template-columns: var(--sidebar-collapsed-width) 1fr;
  overflow: clip;
  isolation: isolate;
  pointer-events: none;
  z-index: 200;
  transition: width var(--dur-3) var(--ease-out-quart);
}

.sidebar-icons, .sidebar-labels { pointer-events: auto; }

.sidebar-icons {
  grid-column: 1;
  display: grid;
  grid-template-rows: 56px 1fr auto;
  background: var(--surface);
  box-shadow: 1px 0 0 0 var(--border);
  contain: strict;
  will-change: transform;
  transform: translateZ(0);
  z-index: 2;
}

.sidebar-labels {
  grid-column: 2;
  display: grid;
  grid-template-rows: 56px 1fr auto;
  background: var(--surface);
  box-shadow: 1px 0 0 0 var(--border);
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
  overflow: hidden;
  transform: translateX(0);
  opacity: 1;
  transition: transform 240ms var(--ease-out-quart), opacity 200ms ease;
  will-change: transform, opacity;
  contain: layout style paint;
  z-index: 1;
}

.sidebar.collapsed .sidebar-labels {
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
}

.sidebar-header, .labels-header {
  display: flex;
  align-items: center;
  padding: 0 var(--space-sm);
}

.sidebar-nav, .labels-nav {
  display: flex;
  flex-direction: column;
  padding: var(--space-sm);
  gap: var(--space-xs);
}

.sidebar-actions, .labels-actions {
  display: flex;
  flex-direction: column;
  padding: var(--space-sm);
  gap: var(--space-xs);
  border-top: 1px solid var(--border);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 48px; height: 48px;
  margin: 0 auto;
  border: none; background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-md);
  cursor: pointer; padding: 0;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}
.icon-btn:hover {
  background: var(--grey-100);
  color: var(--text);
}
.icon-btn.active {
  background: var(--accent);
  color: white;
}
:root.dark .icon-btn:hover {
  background: var(--grey-800);
}
.icon-btn svg { width: 20px; height: 20px; }

.label-btn {
  display: flex;
  align-items: center;
  padding: var(--space-sm) var(--space-md);
  border: none; background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.9375rem;
  font-weight: 500;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}
.label-btn:hover {
  background: var(--grey-100);
  color: var(--text);
}
.label-btn.active {
  background: var(--accent);
  color: white;
}
:root.dark .label-btn:hover {
  background: var(--grey-800);
}

.brand-name {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
}

/* === Cards === */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
}

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

.form-error {
  color: #ef4444;
  font-size: 0.875rem;
  margin-top: var(--space-xs);
}

/* === Quest Canvas === */
.quest-canvas {
  position: fixed;
  inset: 0;
  z-index: 1;
  cursor: grab;
  touch-action: none;
}

.quest-canvas:active {
  cursor: grabbing;
}

/* Loading overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  pointer-events: none;
}

/* Zoom indicator */
.zoom-indicator {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  z-index: 50;
  pointer-events: none;
  box-shadow: var(--shadow-md);
}

:root.dark .zoom-indicator {
  background: var(--grey-800);
  border-color: var(--grey-700);
}

/* === Quest Panel === */
.quest-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 400px;
  height: 100dvh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-xl);
  transform: translateX(100%);
  transition: transform var(--dur-3) var(--ease-out-quart);
  z-index: 300;
  display: flex;
  flex-direction: column;
}

.quest-panel.open {
  transform: translateX(0);
}

@media (max-width: 480px) {
  .quest-panel {
    width: 100%;
  }
}

.quest-panel-header {
  padding: var(--space-md);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.quest-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md);
}

.quest-panel-image {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  border-radius: var(--radius-md);
  margin-bottom: var(--space-md);
}

.quest-panel-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  margin-bottom: var(--space-sm);
}

.quest-panel-description {
  color: var(--text-muted);
  margin-bottom: var(--space-lg);
  line-height: 1.6;
}

.quest-panel-meta {
  display: flex;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.quest-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
  background: var(--grey-100);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  color: var(--text-muted);
}
:root.dark .quest-badge {
  background: var(--grey-800);
}

.quest-badge.points {
  background: var(--accent);
  color: white;
  font-weight: 600;
}

/* === Modal === */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 400;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-3) var(--ease-out-quart);
}
.modal-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  z-index: 401;
  max-width: 500px;
  width: 90%;
  max-height: 90dvh;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-3) var(--ease-out-quart), transform var(--dur-3) var(--ease-out-quart);
}
.modal.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}

.modal-header {
  padding: var(--space-lg);
  border-bottom: 1px solid var(--border);
}

.modal-content {
  padding: var(--space-lg);
  overflow-y: auto;
  max-height: 60dvh;
}

.modal-footer {
  padding: var(--space-lg);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
}

/* === Leaderboard === */
.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 50px 1fr auto;
  align-items: center;
  padding: var(--space-md);
  border-bottom: 1px solid var(--border);
  gap: var(--space-md);
}

.leaderboard-rank {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--text-muted);
}

.leaderboard-rank.top-1 { color: #FFD700; }
.leaderboard-rank.top-2 { color: #C0C0C0; }
.leaderboard-rank.top-3 { color: #CD7F32; }

.leaderboard-user {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.leaderboard-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--grey-200);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--text);
}

.leaderboard-name {
  font-weight: 500;
}

.leaderboard-points {
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--accent);
}

.emoji-breakdown {
  display: flex;
  gap: var(--space-xs);
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* === File Upload === */
.file-upload {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}

.file-upload:hover {
  border-color: var(--accent);
  background: var(--grey-50);
}
:root.dark .file-upload:hover {
  background: var(--grey-800);
}

.file-upload input {
  display: none;
}

.file-upload-icon {
  width: 48px;
  height: 48px;
  color: var(--text-muted);
  margin-bottom: var(--space-sm);
}

.file-upload-text {
  color: var(--text-muted);
}

.file-upload-text span {
  color: var(--accent);
  font-weight: 500;
}

.file-preview {
  margin-top: var(--space-md);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.file-preview img {
  width: 100%;
  max-height: 300px;
  object-fit: cover;
}

/* === Submission Status === */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-md);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.status-pending {
  background: #FEF3C7;
  color: #92400E;
}
:root.dark .status-pending {
  background: #78350F;
  color: #FEF3C7;
}

.status-approved {
  background: #D1FAE5;
  color: #065F46;
}
:root.dark .status-approved {
  background: #064E3B;
  color: #D1FAE5;
}

.status-rejected {
  background: #FEE2E2;
  color: #991B1B;
}
:root.dark .status-rejected {
  background: #7F1D1D;
  color: #FEE2E2;
}

/* === Emoji Rewards === */
.emoji-reward {
  font-size: 1.5rem;
}

.emoji-selector {
  display: flex;
  gap: var(--space-sm);
}

.emoji-option {
  width: 48px;
  height: 48px;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  cursor: pointer;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}

.emoji-option:hover {
  border-color: var(--accent);
}

.emoji-option.selected {
  border-color: var(--accent);
  background: rgba(255, 40, 103, 0.1);
}

/* === Admin Dashboard === */
.admin-section {
  margin-bottom: var(--space-xl);
}

.admin-section-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--border);
}

.submission-card {
  display: grid;
  grid-template-columns: 120px 1fr auto;
  gap: var(--space-md);
  padding: var(--space-md);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-md);
}

.submission-photo {
  width: 120px;
  height: 90px;
  object-fit: cover;
  border-radius: var(--radius-md);
}

.submission-info h4 {
  font-weight: 600;
  margin-bottom: var(--space-xs);
}

.submission-info p {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.submission-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  align-items: flex-end;
}

/* === Auth Views === */
.auth-view {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-xl);
}

.auth-title {
  font-family: var(--font-display);
  font-size: 2rem;
  margin-bottom: var(--space-md);
  text-align: center;
}

.auth-subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: var(--space-xl);
}

.auth-footer {
  text-align: center;
  margin-top: var(--space-lg);
  color: var(--text-muted);
}

/* === Landing === */
.landing-view {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.landing-hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-2xl);
}

.landing-title {
  font-family: var(--font-display);
  font-size: 3.5rem;
  margin-bottom: var(--space-md);
}

.landing-subtitle {
  font-size: 1.25rem;
  color: var(--text-muted);
  max-width: 600px;
  margin-bottom: var(--space-xl);
}

.landing-actions {
  display: flex;
  gap: var(--space-md);
}

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

/* === Utility Classes === */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
