*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f0f13;
  --bg-card: #1a1a22;
  --bg-hover: #22222e;
  --border: #2a2a38;
  --text: #e8e8ed;
  --text-dim: #8888a0;
  --accent: #9b6dff;
  --accent-hover: #b08aff;
  --flag-color: #ff6b6b;
  --flag-bg: rgba(255, 107, 107, 0.12);
  --success: #4ecdc4;
  --radius: 10px;
  --radius-lg: 14px;
}

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ──────────────────────────────────────────── */

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 40px 32px;
}

/* ── Header ──────────────────────────────────────────── */

.header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 40px;
}

.header h1 {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.back-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}

.back-button:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.header-stats {
  font-size: 14px;
  color: var(--text-dim);
}

.header-stats .flagged-count {
  color: var(--flag-color);
}

/* ── Project list ────────────────────────────────────── */

.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 20px;
}

.project-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.2s;
}

.project-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.project-card-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: var(--bg);
}

.project-card-body {
  padding: 20px;
}

.project-card-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 6px;
}

.project-card-meta {
  font-size: 14px;
  color: var(--text-dim);
}

/* ── Chapter headings ────────────────────────────────── */

.chapter-heading {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-dim);
  margin-top: 36px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.chapter-heading:first-of-type {
  margin-top: 0;
}

.chapter-number {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  display: block;
  margin-bottom: 2px;
}

/* ── Scene grid ──────────────────────────────────────── */

.scene-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 8px;
}

.scene-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}

.scene-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.scene-card.flagged {
  border-color: var(--flag-color);
  background: var(--flag-bg);
}

.scene-card-img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: #111;
  display: block;
}

.scene-card-body {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.scene-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.scene-card-number {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
}

.scene-card-description {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.scene-card-flag {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--flag-color);
  flex-shrink: 0;
}

/* ── Lightbox ────────────────────────────────────────── */

.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.lightbox-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.lightbox {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 90vw;
  max-width: 1200px;
  max-height: 90vh;
  display: grid;
  grid-template-columns: 1fr 380px;
  overflow: hidden;
}

.lightbox-image-container {
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
}

.lightbox-image {
  max-width: 100%;
  max-height: 90vh;
  object-fit: contain;
}

.lightbox-sidebar {
  border-left: 1px solid var(--border);
  padding: 28px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  z-index: 10;
}

.lightbox-close:hover {
  background: rgba(0, 0, 0, 0.8);
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  z-index: 10;
}

.lightbox-nav:hover {
  background: rgba(0, 0, 0, 0.75);
}

.lightbox-nav.prev { left: 16px; }
.lightbox-nav.next { right: 400px; }

.lightbox-scene-number {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.lightbox-section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}

.lightbox-prompt {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
}

.lightbox-meta {
  font-size: 13px;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.lightbox-full-res-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
  margin-top: 4px;
}

.lightbox-full-res-link:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

#lightbox-image-link {
  display: contents;
  cursor: pointer;
}

/* ── Flag controls ───────────────────────────────────── */

.flag-section {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.flag-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
  width: 100%;
}

.flag-toggle:hover {
  border-color: var(--flag-color);
  color: var(--text);
}

.flag-toggle.active {
  background: var(--flag-bg);
  border-color: var(--flag-color);
  color: var(--flag-color);
}

.flag-note {
  width: 100%;
  min-height: 60px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
}

.flag-note::placeholder {
  color: var(--text-dim);
}

.flag-note:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── Responsive ──────────────────────────────────────── */

@media (max-width: 900px) {
  .lightbox {
    grid-template-columns: 1fr;
    max-height: 95vh;
  }

  .lightbox-image-container {
    max-height: 50vh;
  }

  .lightbox-sidebar {
    max-height: 45vh;
  }

  .lightbox-nav.next {
    right: 16px;
  }

  .container {
    padding: 24px 16px;
  }
}

/* ── Loading ─────────────────────────────────────────── */

.loading {
  text-align: center;
  padding: 80px 0;
  color: var(--text-dim);
  font-size: 16px;
}
