:root {
  --bg: #0e0e10;
  --surface: #17171a;
  --surface-hover: #202024;
  --line: #2a2a2f;
  --text: #ececee;
  --muted: #8f8f98;
  --amber: #e3b341;
  --amber-dim: #7a6229;
  --radius: 3px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--amber-dim); color: var(--text); }

/* --- Topbar --- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(14, 14, 16, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 1160px;
  margin: 0 auto;
  padding: 20px 28px;
  display: flex;
  align-items: center;
  gap: 32px;
}

.wordmark {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
  color: var(--amber);
  flex-shrink: 0;
}

.search-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

#search {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  padding: 11px 90px 11px 14px;
  outline: none;
  transition: border-color 0.15s ease;
}

#search:focus { border-color: var(--amber-dim); }
#search::placeholder { color: var(--muted); }

.search-count {
  position: absolute;
  right: 14px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

/* --- States --- */

main {
  max-width: 1160px;
  margin: 0 auto;
  padding: 32px 28px 80px;
}

.state {
  padding: 80px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
}

.error-title {
  color: var(--text);
  font-size: 17px;
  font-weight: 500;
  margin-bottom: 8px;
}

.error-detail {
  font-family: monospace;
  font-size: 12.5px;
  max-width: 560px;
  margin: 0 auto;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

/* --- Section head --- */

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-head h2 {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 500;
  font-size: 15px;
  color: var(--muted);
  letter-spacing: 0.01em;
  margin: 0;
}

/* --- Grid --- */

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

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.card:hover {
  border-color: var(--amber-dim);
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}

.card:active {
  transform: translateY(0);
}

.card-thumb {
  aspect-ratio: 16 / 9;
  background: #0a0a0b;
  position: relative;
  overflow: hidden;
}

.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-thumb-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--line);
}

.card-thumb-fallback svg { width: 32px; height: 32px; }

.card-duration {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0,0,0,0.75);
  color: var(--text);
  font-size: 11px;
  font-family: monospace;
  padding: 2px 6px;
  border-radius: 2px;
}

.card-body {
  padding: 12px 14px 14px;
}

.card-title {
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.4;
  margin: 0 0 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-folder {
  font-size: 11.5px;
  color: var(--muted);
  margin: 0;
}

/* --- Modal ---
   Bug note: the old version used the `hidden` attribute for visibility,
   but this rule's own `display: flex` has equal specificity to the
   browser's built-in `[hidden] { display: none }` rule, and author CSS
   always wins that tie — so the modal never actually hid. Fixed by
   keeping `[hidden]` as the hard "not in the DOM flow" switch and using
   a separate `.open` class purely to drive the fade/scale transition. */

.modal {
  display: none;
}

.modal:not([hidden]) {
  display: flex;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 11, 0.7);
  backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.18s ease;
}

.modal.open .modal-backdrop {
  opacity: 1;
}

.modal-panel {
  position: relative;
  width: 100%;
  max-width: 920px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translateY(10px) scale(0.98);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.modal.open .modal-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.15s ease;
}

.modal-close:hover {
  background: var(--amber);
  color: #1a1400;
  transform: scale(1.06);
}

.modal-player {
  aspect-ratio: 16 / 9;
  background: #000;
}

.modal-player iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

.modal-meta {
  padding: 18px 22px 22px;
  border-top: 1px solid var(--line);
}

.modal-meta h2 {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 17px;
  letter-spacing: -0.01em;
  margin: 0 0 5px;
}

.modal-meta p {
  font-size: 12.5px;
  color: var(--muted);
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

@media (max-width: 640px) {
  .topbar-inner { flex-direction: column; align-items: stretch; gap: 14px; }
  .wordmark { font-size: 19px; }
}
