:root {
  --accent:       #ff3eb0;
  --accent-hover: #ed3aa3;
  --page-bg:      #161616;
  --cell-bg:      #1e1e1e;
  --divider:      #2c2c2c;
  --text:         #e8e8e8;
  --muted:        #999;
  --overlay-bg:   rgba(8, 8, 8, 0.9);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page-bg);
  color: var(--text);
  font-family: 'Fira Code', monospace;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- header ---------- */

.profile {
  position: sticky;
  top: 0;
  z-index: 60;
  background: var(--page-bg);
  border-bottom: 1px solid var(--divider);
  margin-bottom: 12px;
}

.profile-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  max-width: 1800px;
  margin: 0 auto;
  padding: 16px 20px;
}

.identity {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.headshot {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  flex: none;
}

.profile .name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.profile .title {
  margin-top: 3px;
  color: var(--muted);
  font-size: 14px;
}

.links-wrapper {
  display: flex;
  align-items: center;
  gap: 18px;
  flex: none;
}

.links-wrapper .link {
  color: var(--text);
  display: inline-flex;
  align-items: center;
  transition: color 0.15s, opacity 0.15s;
  opacity: 0.8;
}

.links-wrapper .link:hover { color: var(--accent); opacity: 1; }

.admin-link { font-size: 12px; color: var(--muted); }

/* ---------- layout ---------- */

.layout {
  display: grid;
  grid-template-columns: 190px 1fr;
  gap: 28px;
  max-width: 1800px;
  margin: 0 auto;
  padding: 0 20px 120px;
}

.sidebar {
  position: sticky;
  /* matches the header's 12px margin-bottom exactly, so the gap between the
     header and the tag list never shifts when the sidebar sticks on scroll */
  top: calc(var(--header-h, 85px) + 12px);
  align-self: start;
  max-height: calc(100vh - var(--header-h, 85px) - 52px);
  overflow-y: auto;
  /* top padding lines the first group heading up with the year heading text
     (it's inside the sticky element, so the stuck position is unaffected) */
  padding: 11px 0 24px;
}

.sidebar-heading {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 12px;
}

/* mobile-only controls (see media query at the bottom) */
.tags-toggle,
.sidebar-close { display: none; }

.tag-group + .tag-group { margin-top: 18px; }

.tag-group-heading {
  color: #666;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 0 0 4px;
}

.tag-btn {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  background: none;
  border: none;
  padding: 4px 0;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  text-align: left;
  transition: color 0.12s;
}

.tag-btn:hover { color: var(--accent); }
.tag-btn .count { color: var(--muted); font-size: 14px; margin-left: auto; }

/* active tag: white × appears next to the text on hover (no layout shift) */
.tag-btn .tag-x {
  display: none;
  color: #fff;
  font-size: 20px;
  width: 14px;
  height: 10px;
  align-self: center; /* center in the row (button aligns children to baseline) */
  align-items: center;
  justify-content: center;
  overflow: visible;
}

.tag-btn.active:hover .tag-x { display: inline-flex; }
.tag-btn.active { color: var(--accent); font-weight: 600; }
.tag-btn.active .count { color: var(--accent); }
.tag-btn.disabled { color: #4a4a4a; pointer-events: none; }
.tag-btn.disabled .count { color: #4a4a4a; }

.clear-tags {
  margin-top: 14px;
  background: none;
  border: 1px solid var(--text);
  border-radius: 3px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: 4px 10px;
  cursor: pointer;
  transition: background 0.15s;
}

.clear-tags:hover { background: rgba(255, 255, 255, 0.12); }

/* ---------- grid ---------- */

#grid { --tile-w: 300px; min-width: 0; }

.year-section { margin-bottom: 48px; }

.year-heading {
  position: sticky;
  top: var(--header-h, 85px);
  z-index: 40;
  background: var(--page-bg);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.14em;
  margin: 0 0 18px;
  border-bottom: 1px solid var(--divider);
  padding: 10px 0 10px;
}

.year-count {
  color: #5c5c5c;
  font-weight: 400;
  letter-spacing: normal;
}

.tiles {
  display: grid;
  /* --tile-w is a target, not a floor: tiles may shrink to 75% of it so an extra
     column fits sooner — avoids the huge stretched-tile zones between breakpoints */
  grid-template-columns: repeat(auto-fill, minmax(min(calc(var(--tile-w) * 0.75), 100%), 1fr));
  gap: 26px 20px; /* rows / columns */
}

.tile {
  margin: 0;
  user-select: none;
  -webkit-user-select: none;
}

.tile .media-box { cursor: pointer; }

/* content keeps its natural aspect ratio, left-aligned in the grid cell;
   portrait pieces grow the row (height-capped) with empty room to the right */
.tile .cell {
  display: flex;
  justify-content: flex-start;
}

.tile .media-box {
  position: relative;
  max-width: 100%;
  border-radius: 4px;
  overflow: hidden;
  background-color: var(--cell-bg);
  background-size: cover;
  background-position: center;
}

.tile .media-box img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: calc(var(--tile-w) * 1.4);
  opacity: 0;
  transition: opacity 0.25s ease;
  -webkit-user-drag: none;
}

.tile .media-box img.loaded { opacity: 1; }

/* hover preview clip laid over the poster thumb */
.tile .tile-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
  z-index: 1;
}

.tile .tile-preview.on { opacity: 1; }

/* gallery scrub position dots */
.tile .scrub-dots {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 8px;
  display: flex;
  justify-content: center;
  gap: 5px;
  pointer-events: none;
  z-index: 2;
}

.tile .scrub-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.45);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  transition: background 0.12s ease, transform 0.12s ease;
}

.tile .scrub-dots span.on {
  background: var(--accent);
  transform: scale(1.25);
}

.tile .badge {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 18px;
  height: 18px;
  color: #fff;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.8));
  pointer-events: none;
}

.tile .time-badge {
  position: absolute;
  right: 8px;
  bottom: 8px;
  z-index: 2;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 3px;
  pointer-events: none;
}

.tile .caption {
  margin-top: 7px;
  cursor: default;
  /* captions are selectable text (the tile itself blocks selection for dragging) */
  user-select: text;
  -webkit-user-select: text;
}

.tile .note-line {
  font-size: 14px;
  color: var(--text);
  line-height: 1.5;
  word-break: break-word;
}

.tile .tags-line {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
  word-break: break-word;
}

/* admin selection + delete controls */
.tile-check,
.tile-del {
  position: absolute;
  top: 8px;
  width: 22px;
  height: 22px;
  border-radius: 3px;
  border: 2px solid #fff;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
  opacity: 0;
  transition: opacity 0.18s ease, border-color 0.18s ease, background 0.18s ease, transform 0.18s ease;
  z-index: 2;
}

.tile-check { left: 8px; }
.tile-check:hover { border-color: var(--accent); transform: scale(1.08); }
.tile-del { left: 38px; font-size: 15px; line-height: 1; }

.tile:hover .tile-check,
.tile:hover .tile-del,
.tile.checked .tile-check { opacity: 1; }

.tile-del:hover { border-color: var(--accent); color: var(--accent); }

.tile.checked .tile-check {
  background: var(--accent);
  border-color: var(--accent);
}

/* traditional checkmark: thick stroke drawn with rotated borders */
.tile.checked .tile-check::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 5px;
  height: 10px;
  border-right: 3px solid #000;
  border-bottom: 3px solid #000;
  transform: translate(-50%, -60%) rotate(45deg);
  animation: check-pop 0.18s ease-out;
}

@keyframes check-pop {
  from { transform: translate(-50%, -60%) rotate(45deg) scale(0.3); opacity: 0; }
  to   { transform: translate(-50%, -60%) rotate(45deg) scale(1); opacity: 1; }
}

.tile.checked .media-box { outline: 2px solid var(--accent); outline-offset: 2px; }

/* bulk action bar */
.bulk-bar {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(10, 10, 10, 0.95);
  border: 1px solid var(--divider);
  border-radius: 6px;
  padding: 10px 16px;
  font-size: 12px;
  z-index: 95;
}

.bulk-bar button {
  font-family: inherit;
  font-size: 12px;
  background: none;
  border: 1px solid var(--divider);
  border-radius: 4px;
  color: var(--text);
  padding: 6px 12px;
  cursor: pointer;
}

.bulk-bar button:hover { border-color: var(--accent); color: var(--accent); }

button.danger {
  border-color: var(--accent) !important;
  color: var(--accent) !important;
}

button.danger:hover {
  background: var(--accent);
  color: #000 !important;
}

/* confirm modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 250;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal {
  background: #141414;
  border: 1px solid var(--divider);
  border-radius: 8px;
  padding: 22px;
  width: min(400px, calc(100vw - 40px));
}

.modal-text { font-size: 13px; line-height: 1.6; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.modal-actions button {
  font-family: inherit;
  font-size: 12px;
  background: none;
  border: 1px solid var(--divider);
  border-radius: 4px;
  color: var(--text);
  padding: 7px 14px;
  cursor: pointer;
}

/* admin drag reorder */
body.admin .tile { touch-action: none; }
.tile.drag-placeholder { opacity: 0.25; }
.tile.drag-clone {
  position: fixed;
  z-index: 200;
  pointer-events: none;
  opacity: 0.9;
  transform: scale(0.97);
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
}

.drag-count {
  position: absolute;
  top: -8px;
  right: -8px;
  min-width: 22px;
  height: 22px;
  border-radius: 11px;
  background: var(--accent);
  color: #000;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
}

.grid-loading {
  display: flex;
  justify-content: center;
  padding: 90px 0;
}

.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid var(--divider);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.empty-state {
  color: var(--muted);
  font-size: 12px;
  padding: 60px 0;
  text-align: center;
}

/* ---------- zoom controls ---------- */

.zoom-controls {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  gap: 8px;
  z-index: 90;
}

.zoom-controls button {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--divider);
  background: rgba(20, 20, 20, 0.9);
  color: var(--text);
  font-family: inherit;
  font-size: 18px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.zoom-controls button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------- fullscreen viewer ---------- */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--overlay-bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.viewer[hidden] { display: none; }

.viewer-stage {
  position: absolute;
  inset: 28px 48px 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.viewer-stage img,
.viewer-stage video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 2px;
}

.viewer-stage img.blur-up {
  filter: blur(14px);
  transform: scale(1.02);
}

.viewer-close,
.viewer-nav {
  position: absolute;
  z-index: 110;
  background: none;
  border: none;
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  transition: color 0.15s;
  line-height: 1;
}

.viewer-close:hover,
.viewer-nav:hover { color: var(--accent); }

.viewer-close { top: 10px; right: 16px; font-size: 42px; padding: 10px 14px; }

.viewer-nav {
  top: 50%;
  transform: translateY(-50%);
  font-size: 44px;
  padding: 20px 14px;
}

/* default positions before JS measures the media; then positioned next to it */
.viewer-nav.prev { left: 8px; }
.viewer-nav.next { left: auto; right: 8px; }
.viewer-nav[disabled] { opacity: 0.25; pointer-events: none; }

.viewer-meta {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 16px 20px;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 20px;
  font-size: 12px;
}

#viewer-counter { color: var(--muted); }
#viewer-counter:empty { display: none; }
#viewer-note { color: var(--text); }
#viewer-tags { color: var(--muted); }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  bottom: 76px;
  left: 50%;
  transform: translateX(-50%);
  background: #000;
  border: 1px solid var(--accent);
  color: var(--text);
  font-size: 12px;
  padding: 10px 18px;
  border-radius: 4px;
  z-index: 300;
}

/* ---------- responsive ---------- */

@media (max-width: 700px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 0 14px 100px;
  }

  /* tags collapse into a toggle button + fullscreen overlay dropdown */
  .tags-toggle {
    display: inline-flex;
    width: fit-content;
    background: none;
    border: 1px solid var(--divider);
    border-radius: 4px;
    color: var(--text);
    font-family: inherit;
    font-size: 12px;
    padding: 7px 14px;
    cursor: pointer;
    margin-bottom: 4px;
  }

  .tags-toggle:active { border-color: var(--accent); }

  .sidebar { display: none; }

  body.tags-open { overflow: hidden; }
  body.tags-open .zoom-controls { display: none; }

  body.tags-open .sidebar {
    display: block;
    position: fixed;
    top: var(--header-h, 85px);
    left: 0;
    right: 0;
    bottom: 0;
    align-self: stretch; /* desktop align-self:start would collapse the fixed overlay's height */
    z-index: 70;
    background: rgba(12, 12, 12, 0.98);
    max-height: none;
    overflow-y: auto;
    padding: 18px 20px 40px;
  }

  .sidebar-close {
    display: inline-flex;
    background: none;
    border: 1px solid var(--text);
    border-radius: 4px;
    color: var(--text);
    font-family: inherit;
    font-size: 12px;
    padding: 6px 14px;
    cursor: pointer;
    margin-bottom: 18px;
  }

  /* one column per tag group */
  body.tags-open #tag-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 18px 24px;
    align-items: start;
  }

  body.tags-open .tag-group + .tag-group { margin-top: 0; } /* columns align; grid gap spaces them */

  .viewer-stage { inset: 40px 10px 60px; }
  .viewer-nav { display: none; } /* swipe/tap-side handled in js */
}
