/* Gallery — dark mobile-first shell. No Pico. */

:root {
  --g-bg: #0b0b0f;
  --g-panel: #15151d;
  --g-panel-2: #1e1e28;
  --g-border: #2a2a36;
  --g-text: #f5f5f8;
  --g-text-dim: #9a9ab0;
  --g-accent: #8e44ad;
  --g-accent-2: #6c3483;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--g-bg); color: var(--g-text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
body.g-body-lock { overflow: hidden; }
a { color: var(--g-accent); text-decoration: none; }

/* ==== Top bar ==== */
.g-topbar {
  position: sticky;
  top: 0;
  background: rgba(11, 11, 15, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--g-border);
  z-index: 20;
}
.g-topbar-inner {
  max-width: 1800px;
  margin: 0 auto;
  padding: 10px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.g-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.g-logo {
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, var(--g-accent), var(--g-accent-2));
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 15px;
}
.g-title { font-weight: 700; font-size: 16px; letter-spacing: 0.3px; }

.g-search {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--g-border);
  background: var(--g-panel);
  color: var(--g-text);
  font-size: 14px;
  outline: none;
}
.g-search:focus { border-color: var(--g-accent); }

/* ==== URL submit ==== */
.g-url-submit {
  display: flex;
  gap: 6px;
  align-items: center;
}
.g-url-input {
  flex: 1;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--g-border);
  background: var(--g-panel);
  color: var(--g-text);
  font-size: 13px;
  outline: none;
  font-family: inherit;
}
.g-url-input:focus { border-color: var(--g-accent); }
.g-url-btn {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background: var(--g-accent);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.g-url-btn:hover { background: var(--g-accent-2); }

.g-filter-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
  align-items: center;
}
.g-filter-row::-webkit-scrollbar { display: none; }

.g-select {
  flex: 0 0 auto;
  padding: 7px 10px;
  background: var(--g-panel);
  color: var(--g-text);
  border: 1px solid var(--g-border);
  border-radius: 8px;
  font-size: 13px;
  outline: none;
}
.g-select:focus { border-color: var(--g-accent); }

.g-admin-link {
  flex: 0 0 auto;
  padding: 7px 12px;
  background: var(--g-panel);
  border: 1px solid var(--g-border);
  border-radius: 8px;
  font-size: 13px;
  color: var(--g-text-dim);
}
.g-admin-link:hover { color: var(--g-text); }

.g-count {
  font-size: 11px;
  color: var(--g-text-dim);
  margin-left: 8px;
  font-weight: 500;
}

/* ==== Date range ==== */
.g-date-range {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  background: var(--g-panel);
  border: 1px solid var(--g-border);
  border-radius: 8px;
}
.g-date-input {
  background: transparent;
  border: none;
  color: var(--g-text);
  font-size: 12px;
  padding: 5px 2px;
  outline: none;
  font-family: inherit;
  color-scheme: dark;
  min-width: 112px;
}
.g-date-sep { color: var(--g-text-dim); font-size: 12px; }
.g-date-clear {
  background: transparent;
  color: var(--g-text-dim);
  border: none;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.g-date-clear:hover { color: var(--g-text); }

@media (max-width: 700px) {
  .g-date-range {
    flex-wrap: wrap;
    justify-content: center;
  }
}

/* ==== Bulk select ==== */
.g-bulk-toggle {
  flex: 0 0 auto;
  padding: 7px 12px;
  background: var(--g-panel);
  color: var(--g-text);
  border: 1px solid var(--g-border);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}
.g-bulk-toggle.g-bulk-on {
  background: var(--g-accent);
  border-color: var(--g-accent);
}
.g-bulk-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px 8px;
  background: var(--g-panel-2);
  border: 1px solid var(--g-accent);
  border-radius: 8px;
  margin-top: 6px;
}
.g-bulk-bar[hidden] { display: none; }

/* Embedded-mode overrides: when gallery is loaded inside an iframe
 * (e.g. the mindmap's player overlay) we hide the topbar/filters and
 * let the focus overlay fill the window.
 */
body.g-embedded .g-topbar,
body.g-embedded #g-grid,
body.g-embedded #g-sentinel,
body.g-embedded #g-empty,
body.g-embedded #g-loading { display: none !important; }
body.g-embedded { background: #000; }
.g-bulk-bar .g-bulk-cancel { margin-left: auto; }
.g-bulk-count { font-size: 12px; color: var(--g-text); }
.g-bulk-btn {
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 12px;
  background: var(--g-panel);
  color: var(--g-text);
  border: 1px solid var(--g-border);
  cursor: pointer;
}
.g-bulk-primary {
  background: var(--g-accent);
  border-color: var(--g-accent);
  color: #fff;
}
.g-bulk-primary:disabled {
  background: var(--g-panel);
  color: var(--g-text-dim);
  border-color: var(--g-border);
  cursor: not-allowed;
}
.g-bulk-hint {
  font-size: 11px;
  color: var(--g-text-dim);
  text-align: center;
  padding: 4px 0;
}

/* ==== Grid ==== */
.g-grid {
  display: grid;
  gap: 6px;
  padding: 6px;
  max-width: 1800px;
  margin: 0 auto;
  grid-template-columns: repeat(2, 1fr);
}
@media (min-width: 700px)  { .g-grid { grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 8px; } }
@media (min-width: 1100px) { .g-grid { grid-template-columns: repeat(6, 1fr); } }
@media (min-width: 1600px) { .g-grid { grid-template-columns: repeat(8, 1fr); } }

.g-tile {
  position: relative;
  aspect-ratio: 9 / 16;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  border: 1px solid var(--g-border);
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.g-tile:hover { transform: translateY(-1px); border-color: var(--g-accent); }
.g-tile video,
.g-tile .g-tile-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  display: block;
  background: #000;
}
.g-tile .g-tile-blank {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #121217, #1d1d25);
}
.g-tile .g-tile-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 6px;
  background: linear-gradient(to top, rgba(0,0,0,0.65) 0%, rgba(0,0,0,0) 35%, rgba(0,0,0,0) 65%, rgba(0,0,0,0.5) 100%);
  pointer-events: none;
}
.g-tile .g-tile-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 4px;
}
.g-tile .g-tile-bottom {
  color: #fff;
  font-size: 11px;
  line-height: 1.3;
  display: flex;
  flex-direction: column;
  gap: 2px;
  pointer-events: none;
}
.g-tile .g-tile-creator {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.g-tile .g-tile-duration {
  background: rgba(0,0,0,0.65);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 600;
  color: #fff;
}
.g-tile .g-tile-bottom-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 4px;
}
.g-tile .g-tile-date {
  color: rgba(255,255,255,0.7);
  font-size: 10px;
  white-space: nowrap;
  flex-shrink: 0;
}
.g-tile .g-tile-status {
  align-self: flex-start;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: #fff;
}
.g-tile .g-tile-status.s-downloaded { background: #3b5b8a; }
.g-tile .g-tile-status.s-failed { background: #8a3b3b; }
.g-tile .g-tile-status.s-pending,
.g-tile .g-tile-status.s-downloading,
.g-tile .g-tile-status.s-transcribing,
.g-tile .g-tile-status.s-formatting,
.g-tile .g-tile-status.s-uploading { background: #6c3483; }
.g-tile .g-tile-status.s-nomedia { background: #5a4a1f; }
.g-tile .g-tile-status.s-notx { background: #1f4f5a; }
.g-tile .g-tile-status.s-waiting { background: #3a3a48; color: #d0c38a; }

.g-tile .g-tile-action {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 6px 12px;
  background: var(--g-accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: auto;
  z-index: 2;
}
.g-tile:hover .g-tile-action,
.g-tile.g-tile-touch .g-tile-action { opacity: 1; }

.g-tile.g-selected {
  border-color: var(--g-accent);
  border-width: 3px;
  transform: translateY(-1px);
}
.g-tile.g-selected::after {
  content: "✓";
  position: absolute;
  top: 6px;
  left: 6px;
  width: 22px;
  height: 22px;
  background: var(--g-accent);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 13px;
  z-index: 3;
}

.g-sentinel { height: 30px; }
.g-empty, .g-loading {
  text-align: center;
  color: var(--g-text-dim);
  padding: 40px 16px;
}

/* ==== Focus overlay ==== */
.g-focus {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.96);
  z-index: 100;
  display: flex;
  flex-direction: column;
}
.g-focus[hidden] { display: none; }
.g-focus-inner {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}
.g-focus-video-wrap {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #000;
  touch-action: pan-y;
  overflow: hidden;
  min-height: 0;
}
.g-focus-video-frame {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
#g-focus-video {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  background: #000;
}
.g-focus-meta {
  position: relative;
  flex: 0 0 auto;
  padding: 10px 16px 12px;
  background: var(--g-panel);
  border-top: 1px solid var(--g-border);
  max-height: 40vh;
  overflow-y: auto;
}
.g-focus-title {
  font-weight: 700;
  font-size: 16px;
  line-height: 1.3;
  color: var(--g-text);
  overflow-wrap: anywhere;
}

.g-focus-actions {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.g-act-muted {
  opacity: 0.7;
  cursor: not-allowed !important;
}
.g-act-btn {
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(4px);
}
.g-act-btn:hover { background: rgba(0,0,0,0.8); border-color: rgba(255,255,255,0.45); }
.g-act-accent {
  background: var(--g-accent);
  border-color: var(--g-accent);
}
.g-act-accent:hover { background: var(--g-accent-2); border-color: var(--g-accent-2); }
.g-act-danger {
  background: rgba(128, 30, 30, 0.65);
  border-color: rgba(255, 100, 100, 0.5);
}
.g-act-danger:hover { background: rgba(160, 35, 35, 0.85); }

/* ==== Reprocess dialog ==== */
.g-dialog {
  background: var(--g-panel);
  color: var(--g-text);
  border: 1px solid var(--g-border);
  border-radius: 10px;
  padding: 18px 20px;
  min-width: 280px;
  max-width: 90vw;
}
.g-dialog::backdrop { background: rgba(0, 0, 0, 0.7); }
.g-dialog h3 { margin: 0 0 12px; font-size: 16px; }
.g-dialog-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--g-text-dim);
}
.g-dialog-field select,
.g-dialog-field input {
  padding: 7px 10px;
  background: var(--g-panel-2);
  color: var(--g-text);
  border: 1px solid var(--g-border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
}
.g-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}
.g-dialog-actions button {
  padding: 7px 14px;
  border-radius: 6px;
  background: var(--g-panel-2);
  color: var(--g-text);
  border: 1px solid var(--g-border);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}
.g-dialog-primary {
  background: var(--g-accent) !important;
  border-color: var(--g-accent) !important;
  color: #fff !important;
}
.g-focus-sub {
  font-size: 12px;
  color: var(--g-text-dim);
  margin-top: 4px;
}
/* ==== Captions ==== */
#g-focus-video::cue {
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 1.05rem;
  line-height: 1.35;
}
.g-cc-toggle {
  position: absolute;
  top: 12px;
  right: 60px;
  z-index: 5;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.4px;
  cursor: pointer;
  font-family: inherit;
  backdrop-filter: blur(4px);
}
.g-cc-toggle:hover { background: rgba(0, 0, 0, 0.75); border-color: rgba(255, 255, 255, 0.5); }
.g-cc-toggle.g-cc-active { border-color: rgba(255, 255, 255, 0.6); }

.g-cc-editorial {
  position: absolute;
  left: 6%;
  right: 6%;
  bottom: 18%;
  z-index: 3;
  pointer-events: none;
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
}
.g-cc-editorial[hidden] { display: none; }
.g-cc-editorial .g-cc-chunk {
  font-family: "Cormorant Garamond", "EB Garamond", "Libre Baskerville", Georgia, serif;
  font-weight: 500;
  font-size: clamp(1.6rem, 3.6vw, 3rem);
  line-height: 1.15;
  letter-spacing: 0.01em;
  color: #fff;
  max-width: min(55ch, 55%);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.55);
  animation: g-cc-fade 0.22s ease-out both;
}
@keyframes g-cc-fade {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.g-focus-hint {
  position: absolute;
  top: 12px;
  left: 12px;
  font-size: 11px;
  color: rgba(255,255,255,0.5);
  padding: 4px 8px;
  background: rgba(0,0,0,0.45);
  border-radius: 6px;
  pointer-events: none;
}

/* Bookmark markers along the bottom of the video frame — small dots the
 * user can click to seek, positioned by percent of duration. The strip is
 * hidden until there's at least one bookmark + a known duration. */
.g-bookmark-strip {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 46px;     /* clear of native video controls */
  height: 14px;
  pointer-events: none;
  z-index: 4;
}
.g-bookmark-strip[hidden] { display: none; }
.g-bookmark-marker {
  position: absolute;
  top: 2px;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  background: #ffd166;
  border: 2px solid #1e1e28;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  pointer-events: auto;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}
.g-bookmark-marker:hover {
  transform: scale(1.3);
  transition: transform 0.1s ease;
}
.g-close {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 5;
  background: rgba(0,0,0,0.55);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.g-close:hover { background: rgba(255,255,255,0.18); }

/* ==== Drawer (desktop: always visible column; mobile: slide in) ==== */
.g-drawer {
  flex: 0 0 380px;
  max-width: 380px;
  height: 100%;
  background: var(--g-panel);
  border-left: 1px solid var(--g-border);
  overflow-y: auto;
  position: relative;
}
.g-drawer-close {
  display: none;
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0,0,0,0.4);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  font-size: 18px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
}
.g-drawer-content {
  padding: 18px 18px 40px;
  color: var(--g-text);
  line-height: 1.55;
  font-size: 13px;
}
.g-drawer-content h1 { font-size: 20px; margin: 0 0 10px; }
.g-drawer-content h2 { font-size: 16px; margin: 18px 0 8px; color: var(--g-accent); }
.g-drawer-content h3 { font-size: 14px; margin: 14px 0 6px; }
.g-drawer-content p { margin: 6px 0; }
.g-drawer-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin: 8px 0;
}
.g-drawer-content table th,
.g-drawer-content table td {
  border: 1px solid var(--g-border);
  padding: 4px 8px;
  text-align: left;
}
.g-drawer-content table th { background: var(--g-panel-2); }
.g-drawer-content code {
  background: var(--g-panel-2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}
.g-drawer-content pre {
  background: var(--g-panel-2);
  padding: 10px;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 12px;
}
.g-drawer-content ul, .g-drawer-content ol { padding-left: 20px; }
.g-drawer-content a { color: var(--g-accent); word-break: break-word; }

.g-toast { position:fixed; bottom:2rem; left:50%; transform:translateX(-50%);
  background:#333; color:#fff; padding:.75rem 1.5rem; border-radius:8px; z-index:9999; }
.g-error-detail { color:#e74c3c; font-size:.9em; word-break:break-word; }

@media (max-width: 900px) {
  .g-drawer {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 90vw;
    max-width: 420px;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    z-index: 6;
  }
  .g-focus.g-drawer-open .g-drawer {
    transform: translateX(0);
  }
  .g-drawer-close { display: inline-flex; align-items: center; justify-content: center; }
}

/* ==== Week headers in the grid ==== */
.g-week-header {
  grid-column: 1 / -1;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--g-text-dim);
  padding: 14px 4px 4px;
  border-top: 1px solid var(--g-border);
  margin-top: 4px;
}
.g-week-header:first-child { border-top: 0; margin-top: 0; padding-top: 4px; }

/* ==== Editable date button in focus sub ==== */
.g-date-edit {
  background: transparent;
  color: var(--g-text);
  border: 1px dashed transparent;
  border-radius: 4px;
  padding: 1px 6px;
  font: inherit;
  cursor: pointer;
}
.g-date-edit:hover { border-color: rgba(255,255,255,0.35); }
.g-date-edit.g-date-edit--empty { color: var(--g-text-dim); font-style: italic; }

/* ==== Custom datepicker popover ==== */
.g-datepicker {
  position: absolute;
  z-index: 60;
  background: var(--g-panel-2);
  border: 1px solid var(--g-border);
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.5);
  min-width: 240px;
  font-size: 13px;
  color: var(--g-text);
}
.g-datepicker[hidden] { display: none; }
.g-dp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 8px;
}
.g-dp-nav {
  background: transparent;
  color: var(--g-text);
  border: 1px solid var(--g-border);
  border-radius: 6px;
  padding: 2px 8px;
  cursor: pointer;
}
.g-dp-nav:hover { background: var(--g-panel); }
.g-dp-label { font-weight: 600; letter-spacing: 0.03em; }
.g-dp-dow {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  font-size: 11px;
  color: var(--g-text-dim);
  text-align: center;
  margin-bottom: 4px;
}
.g-dp-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}
.g-dp-day {
  background: transparent;
  color: var(--g-text);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 0;
  font: inherit;
  cursor: pointer;
  text-align: center;
}
.g-dp-day:hover { background: var(--g-panel); }
.g-dp-day--muted { color: var(--g-text-dim); opacity: 0.5; }
.g-dp-day--today { border-color: var(--g-border); }
.g-dp-day--selected { background: var(--g-accent); color: #fff; }
.g-dp-day--selected:hover { background: var(--g-accent-2); }
.g-dp-foot {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}
.g-dp-close {
  background: transparent;
  color: var(--g-text-dim);
  border: 1px solid var(--g-border);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 12px;
}
.g-dp-close:hover { color: var(--g-text); background: var(--g-panel); }
