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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #111;
  color: #eee;
  min-height: 100vh;
}

header {
  padding: 1.25rem 2rem;
  border-bottom: 1px solid #222;
  display: flex;
  align-items: center;
  gap: 1rem;
}

header h1 {
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #888;
}

main { padding: 1.25rem 2rem 3rem; }

/* ── Filter bar ──────────────────────────────────────────────────────────── */
#filter-bar {
  margin-bottom: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  align-items: flex-start;
}

.filter-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.filter-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #555;
  margin-right: 0.25rem;
  white-space: nowrap;
}

.filter-group select {
  background: #1e1e1e;
  color: #ddd;
  border: 1px solid #2a2a2a;
  border-radius: 4px;
  padding: 0.3rem 0.6rem;
  font-size: 0.82rem;
  cursor: pointer;
}
.filter-group select:focus { outline: none; border-color: #444; }

.filter-divider {
  width: 1px;
  height: 1.5rem;
  background: #252525;
  align-self: center;
}

#btn-random {
  background: none;
  border: 1px solid #2a2a2a;
  border-radius: 4px;
  color: #666;
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
}
#btn-random:hover { color: #bbb; border-color: #555; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 99px;
  padding: 0.2rem 0.65rem;
  font-size: 0.8rem;
  color: #ddd;
}

.pill-remove {
  background: none;
  border: none;
  color: #888;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  padding: 0;
}
.pill-remove:hover { color: #eee; }

.add-tag-wrap { position: relative; }

.btn-add-tag {
  background: none;
  border: 1px dashed #333;
  border-radius: 99px;
  color: #555;
  padding: 0.2rem 0.7rem;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
}
.btn-add-tag:hover { border-color: #555; color: #888; }

.tag-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: #1e1e1e;
  border: 1px solid #333;
  border-radius: 6px;
  min-width: 160px;
  max-height: 260px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
.tag-dropdown.hidden { display: none; }

.dropdown-item {
  padding: 0.45rem 0.85rem;
  font-size: 0.82rem;
  cursor: pointer;
  color: #ccc;
}
.dropdown-item:hover { background: #2a2a2a; }
.dropdown-item.disabled { color: #444; cursor: default; }

.search-group input {
  background: #1e1e1e;
  border: 1px solid #2a2a2a;
  border-radius: 4px;
  color: #ddd;
  padding: 0.3rem 0.75rem;
  font-size: 0.82rem;
  width: 180px;
}
.search-group input:focus { outline: none; border-color: #444; }

#btn-clear-filters {
  background: none;
  border: 1px solid #333;
  border-radius: 4px;
  color: #666;
  padding: 0.25rem 0.75rem;
  font-size: 0.78rem;
  cursor: pointer;
  white-space: nowrap;
}
#btn-clear-filters:hover { color: #aaa; border-color: #555; }
#btn-clear-filters.hidden { display: none; }

#result-count {
  font-size: 0.75rem;
  color: #444;
  align-self: center;
}

/* ── Semester sections ───────────────────────────────────────────────────── */
.sem-section { margin-bottom: 3rem; }

.sem-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid #222;
  padding-bottom: 0.6rem;
}

.sem-header h2 {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #666;
}

.btn-collapse {
  background: none;
  border: none;
  color: #444;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0;
  line-height: 1;
}
.btn-collapse:hover { color: #888; }

.sem-body.collapsed { display: none; }

/* ── Student sections ────────────────────────────────────────────────────── */
.student-section { margin-bottom: 2rem; }

.student-name {
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: #777;
  margin-bottom: 0.6rem;
  text-transform: uppercase;
}

.student-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 3px;
}

/* ── Flat filtered grid ──────────────────────────────────────────────────── */
.flat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 3px;
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  cursor: pointer;
  background: #1a1a1a;
}

.card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.2s;
}
.card:hover img { transform: scale(1.04); }

.card-overlay {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
  padding: 2rem 0.6rem 0.55rem;
  opacity: 0;
  transition: opacity 0.2s;
  font-size: 0.72rem;
  line-height: 1.4;
}
.card:hover .card-overlay { opacity: 1; }

.card-student { font-weight: 600; color: #eee; }
.card-semester { color: #aaa; }
.card-tags { color: #888; margin-top: 1px; }

.empty, .loading-msg { color: #444; padding: 2rem 0; font-size: 0.9rem; }

/* ── Lightbox ────────────────────────────────────────────────────────────── */
#lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
#lightbox.hidden { display: none; }

#lightbox-close {
  position: absolute; top: 1rem; right: 1.25rem;
  background: none; border: none;
  color: #666; font-size: 2rem; cursor: pointer; line-height: 1;
}
#lightbox-close:hover { color: #ccc; }

#lightbox-inner {
  display: flex;
  gap: 2rem;
  max-width: 95vw;
  max-height: 90vh;
}

#lightbox-left {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 60vw;
}

#lightbox-img {
  max-height: 70vh;
  max-width: 100%;
  object-fit: contain;
  border-radius: 3px;
}

#lightbox-meta { font-size: 0.83rem; line-height: 1.6; }
#lightbox-student { font-weight: 600; font-size: 0.92rem; }
#lightbox-tags { color: #888; margin-top: 2px; }
#lightbox-desc { color: #666; font-style: italic; margin-top: 4px; }

#btn-find-similar {
  background: #1e1e1e; border: 1px solid #333;
  color: #bbb; padding: 0.4rem 0.9rem;
  border-radius: 4px; cursor: pointer; font-size: 0.82rem;
  align-self: flex-start;
}
#btn-find-similar:hover { background: #2a2a2a; }

#lightbox-right { width: 300px; overflow-y: auto; }
#lightbox-right.hidden { display: none; }
#lightbox-right h3 {
  font-size: 0.72rem; text-transform: uppercase;
  letter-spacing: 0.08em; color: #555; margin-bottom: 0.75rem;
}

#similar-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
}

.sim-card { aspect-ratio: 1; overflow: hidden; cursor: pointer; background: #1a1a1a; }
.sim-card img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.15s; }
.sim-card:hover img { transform: scale(1.06); }

.loading { color: #444; font-size: 0.82rem; padding: 0.5rem 0; }

@media (max-width: 640px) {
  main { padding: 1rem; }
  .student-grid, .flat-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  #lightbox-inner { flex-direction: column; }
  #lightbox-left { max-width: 90vw; }
  #lightbox-right { width: 100%; }
  .filter-row { gap: 0.5rem 1rem; }
}
