@font-face {
  font-family: "HomeVideo";
  src: url("fonts/HomeVideo-Regular.woff2") format("woff2"),
       url("fonts/HomeVideo-Regular.woff") format("woff");
  font-weight: 400;
  font-display: swap;
}

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

:root {
  --fg: #ffffff;
  --dim: #666666;
  --label: #323232; /* field labels: project / tags / add */
  --pad: 24px;
  --gap: 24px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1); /* ease-out-expo-ish */
}

html, body {
  background: #000;
  color: var(--fg);
  font-family: "HomeVideo", monospace;
  font-size: 12px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

input, button, label, textarea { font-family: inherit; font-size: 12px; }

/* generic hover for interactive text: dim -> white */
.hoverable, #cols button, #modes button, #filters .chip, #detail-close, #f-delete,
.suggest div, .chip-x, #btn-filter, #auth-links button, #auth-code-ok {
  color: var(--dim);
  cursor: pointer;
  transition: color 0.2s var(--ease);
}
.hoverable:hover, #cols button:hover, #modes button:hover, #filters .chip:hover,
#detail-close:hover, #f-delete:hover, .suggest div:hover, .chip-x:hover,
#btn-filter:hover, #auth-links button:hover, #auth-code-ok:hover {
  color: var(--fg);
}
#btn-filter.active { color: var(--fg); }

/* ---- top bar ---------------------------------------------------------- */
/* not sticky: the bar scrolls away with the page */
#bar {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: var(--pad) var(--pad) 4px;
  background: #000;
}
#logo { height: 29px; flex: 0 0 auto; display: flex; align-items: center; opacity: 0.85; transition: opacity 0.2s var(--ease); }
#logo:hover { opacity: 1; }
#logo svg { height: 29px; width: auto; display: block; }

/* search lives centered in the bar, between logo and the filter button */
#searchwrap {
  flex: 1;
  display: flex; justify-content: center; align-items: baseline; gap: 8px;
  min-width: 0;
}
#search-label { color: var(--dim); display: none; } /* "Search" prefix */
#searchwrap.searching #search-label { display: inline; }
#search {
  background: transparent;
  border: none;
  color: var(--fg);
  padding: 0;
  outline: none;
  width: auto;
}
#search::placeholder { color: var(--dim); }

/* actions pinned to the far right of the bar */
#actions { flex: 0 0 auto; display: flex; gap: 16px; align-items: center; }

/* filter + view options: right-aligned, sits right under the bar in normal flow
   (the bar's reduced bottom padding keeps it close to the filter button).
   Collapsed by default; expands on .open by animating the grid row 0fr->1fr,
   which pushes the grid below it down. easeOutExpo, 0.2s. */
#filter-panel {
  overflow: hidden;
  height: 0; /* collapsed by default; JS animates the height (easeOutExpo, 0.2s) */
  transition: height 0.2s var(--ease);
  background: #000;
}
/* the actual layout + padding — clipped by #filter-panel when collapsed */
#filter-row {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end;
  column-gap: 28px; row-gap: 10px;
  padding: 0 var(--pad) 16px;
}

/* force the tags onto their own line below the projects */
.frow-break { flex-basis: 100%; height: 0; margin: 0; }

/* mobile-only search inside the filter panel (hidden on desktop) */
#search-m {
  display: none;
  flex-basis: 100%;
  background: transparent; border: none; outline: none;
  color: var(--fg); padding: 0 0 4px;
}
#search-m::placeholder { color: var(--dim); }

/* column-count buttons: desktop shows 5/4/3, mobile shows 2/1
   (needs #cols prefix to beat the specificity of "#cols button") */
#cols .mobcol { display: none; }

/* column count shown as little squares */
#cols button { display: inline-flex; align-items: center; gap: 2px; padding: 2px 0; }
#cols button i { width: 5px; height: 5px; background: currentColor; display: block; }

/* tighter spacing for filter chips, especially when they wrap to a new line */
#filters {
  display: flex; flex-wrap: wrap;
  flex: 1 1 100%; justify-content: flex-end;
  column-gap: 12px; row-gap: 4px;
}
#filters .chip { white-space: nowrap; }
#filters .chip.active { color: var(--fg); }

#cols, #modes { display: flex; gap: 10px; }
#cols button.active, #modes button.active { color: var(--fg); }

button { background: transparent; border: none; }

#status { color: var(--dim); text-align: right; }

/* ---- grid ------------------------------------------------------------- */
#grid { padding: var(--pad); }

/* masonry: equal width, natural height, vertical flow.
   extra bottom space so the hover caption never touches the item below. */
#grid[data-mode="masonry"] { column-gap: var(--gap); }
#grid[data-mode="masonry"] .cell { margin-bottom: calc(var(--gap) + 16px); }
#grid[data-mode="masonry"][data-cols="5"] { column-count: 5; }
#grid[data-mode="masonry"][data-cols="4"] { column-count: 4; }
#grid[data-mode="masonry"][data-cols="3"] { column-count: 3; }
#grid[data-mode="masonry"][data-cols="2"] { column-count: 2; }
#grid[data-mode="masonry"][data-cols="1"] { column-count: 1; }

/* top aligned: row by row, items align to top (gaps appear) */
#grid[data-mode="grid"] { display: grid; column-gap: var(--gap); row-gap: calc(var(--gap) + 16px); align-items: start; }
#grid[data-mode="grid"][data-cols="5"] { grid-template-columns: repeat(5, 1fr); }
#grid[data-mode="grid"][data-cols="4"] { grid-template-columns: repeat(4, 1fr); }
#grid[data-mode="grid"][data-cols="3"] { grid-template-columns: repeat(3, 1fr); }
#grid[data-mode="grid"][data-cols="2"] { grid-template-columns: repeat(2, 1fr); }
#grid[data-mode="grid"][data-cols="1"] { grid-template-columns: repeat(1, 1fr); }

.cell {
  break-inside: avoid;
  cursor: pointer;
  display: block;
  position: relative;
}
.cell img,
.cell video {
  width: 100%;
  height: auto;
  display: block;
  transition: transform 0.2s var(--ease);
}
.cell:hover img,
.cell:hover video { transform: translateY(-6px); }
.cell .cap {
  position: absolute;
  top: 100%; left: 0;
  margin-top: 2px;
  color: var(--dim);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s var(--ease);
  pointer-events: none;
}
.cell:hover .cap { opacity: 1; }
/* while searching, always show the caption (the matched tag / project) */
#grid.searching .cell .cap { opacity: 1; }

/* ---- detail / edit view ---------------------------------------------- */
#detail {
  position: fixed; inset: 0; z-index: 50;
  background: #000;
}
#detail .stage {
  position: absolute;
  top: var(--pad); left: 0; right: 0;
  bottom: 64px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 var(--pad);
}
#detail .stage img, #detail .stage video {
  max-width: 80vw; max-height: 90%; display: block;
}

#detail .nav { position: fixed; top: 56px; bottom: 64px; width: 30vw; z-index: 51; }
#detail .nav.prev { left: 0; cursor: w-resize; }
#detail .nav.next { right: 0; cursor: e-resize; }

#detail-close {
  position: fixed; top: var(--pad); right: var(--pad); z-index: 53;
}

/* edit panel: single horizontal row along the bottom */
.panel {
  position: fixed; left: var(--pad); right: var(--pad); bottom: var(--pad); z-index: 52;
  display: flex; gap: 40px; align-items: baseline;
}
.field { display: flex; gap: 12px; align-items: baseline; }
.field.tags { flex: 1; min-width: 0; }
.field .key { color: var(--label); flex: 0 0 auto; }

.combo { position: relative; }
.panel input {
  background: transparent; border: none; outline: none;
  color: var(--dim); padding: 0; line-height: 1.4; width: 120px;
  transition: color 0.2s var(--ease);
}
.panel input:hover, .panel input:focus { color: var(--fg); }
#f-tag { width: 80px; }
.panel input::placeholder { color: var(--label); }

.tags-edit { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; }
#tag-chips { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.tag-chip {
  color: var(--dim); white-space: nowrap; cursor: pointer;
  transition: color 0.2s var(--ease);
}
.tag-chip:hover { color: var(--fg); }

#f-delete { flex: 0 0 auto; }

/* suggestion dropdowns - same black/font style, open upward above the bar */
.suggest {
  position: absolute; left: 0; bottom: 100%; margin-bottom: 8px;
  background: #000; display: flex; flex-direction: column;
  max-height: 180px; overflow-y: auto; min-width: 120px; z-index: 60;
}
.suggest div { padding: 2px 0; white-space: nowrap; color: var(--dim); transition: color 0.2s var(--ease); }
.suggest div:hover, .suggest div.active { color: var(--fg); }

/* ---- login / setup / reset overlay ------------------------------------ */
#auth {
  position: fixed; inset: 0; z-index: 80;
  background: #000;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 32px; padding: var(--pad);
}
#auth-form { display: flex; flex-direction: column; align-items: center; gap: 14px; }
/* the only visible field is the word "Passwort"; no box, dim -> white */
.auth-field {
  background: transparent; border: none; outline: none;
  color: var(--dim); text-align: center; width: 240px; padding: 0;
  transition: color 0.2s var(--ease);
}
.auth-field::placeholder { color: var(--dim); }
.auth-field:hover, .auth-field:focus { color: var(--fg); }
#auth-msg { color: var(--dim); min-height: 1.4em; text-align: center; }
#auth-code { display: flex; flex-direction: column; align-items: center; gap: 18px; max-width: 360px; }
.auth-note { color: var(--dim); text-align: center; }
#auth-code-value { color: var(--fg); letter-spacing: 3px; font-size: 14px; }
/* secondary actions: stacked, pinned to the bottom of the viewport (less important) */
#auth-links {
  position: absolute; left: 0; right: 0; bottom: var(--pad);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}

/* without a session the portfolio is view-only: hide the edit panel */
body:not(.authed) #detail .panel { display: none; }
/* logout lives in the filter panel, only when logged in */
#btn-logout { color: var(--dim); cursor: pointer; transition: color 0.2s var(--ease); }
#btn-logout:hover { color: var(--fg); }
body:not(.authed) #btn-logout { display: none; }

/* ---- misc ------------------------------------------------------------- */
.hidden { display: none !important; }

#drop-hint {
  position: fixed; inset: 0; z-index: 60;
  display: none; align-items: center; justify-content: center;
  background: rgba(0,0,0,.8); color: var(--fg);
  pointer-events: none;
}
body.dragging #drop-hint { display: flex; }

::selection { background: #fff; color: #000; }
::-webkit-scrollbar { width: 0; height: 0; }

/* ---- mobile ----------------------------------------------------------- */
@media (max-width: 640px) {
  :root { --pad: 14px; --gap: 12px; }

  #logo, #logo svg { height: 24px; }
  #bar { gap: 12px; }

  /* filter button stays pinned to the right (no flex spacer when bar search is hidden) */
  #actions { margin-left: auto; }

  /* search moves into the filter panel on mobile, right-aligned, full width */
  #searchwrap { display: none; }
  #search-m { display: block; text-align: right; }

  /* filter panel; search pushed a bit further down from the filter button */
  #filter-row { column-gap: 16px; row-gap: 12px; padding-top: 10px; }
  #filters { width: 100%; }
  /* tags keep their own line below the projects (base .frow-break = flex-basis:100%) */

  /* mobile column options: only 2 / 1 (2 is default) */
  #cols .deskcol { display: none; }
  #cols .mobcol { display: inline-flex; }

  /* items capped at 80% of the viewport height */
  .cell .media { max-height: 80vh; overflow: hidden; }

  /* detail view becomes a vertical scroll: media + fields, delete below the fold */
  #detail { overflow-y: auto; -webkit-overflow-scrolling: touch; }
  #detail .nav { display: none; } /* swipe to navigate instead */
  #detail .stage {
    position: static; bottom: auto;
    min-height: calc(100vh - 38px);
    padding: 52px var(--pad) 0;
  }
  #detail .stage img, #detail .stage video { max-width: 100%; max-height: 80vh; }

  /* grid: project (left) + tags (right) on row 1, delete alone on row 2 */
  .panel {
    position: static; left: auto; right: auto; bottom: auto;
    display: grid; grid-template-columns: auto minmax(0, 1fr);
    column-gap: 16px; row-gap: 28px; align-items: baseline;
    padding: 8px var(--pad) 0;
  }
  .panel > .field:first-child { grid-column: 1; }          /* project: left */
  .field.tags { grid-column: 2; min-width: 0; justify-content: flex-end; } /* tags: right */
  .field { gap: 8px; }
  /* tags on a single right-aligned line; overflow fades out on the left when too many */
  .tags-edit {
    flex-wrap: nowrap; min-width: 0; overflow: hidden; justify-content: flex-end;
    -webkit-mask-image: linear-gradient(to right, transparent 0, #000 28px);
    mask-image: linear-gradient(to right, transparent 0, #000 28px);
  }
  #tag-chips { flex-wrap: nowrap; }
  .field.tags .combo { display: none; } /* hide the add-field on mobile for a clean truncated row */
  /* delete on its own line below the fold (revealed on scroll), right-aligned */
  #f-delete { grid-column: 1 / -1; justify-self: end; margin-bottom: var(--pad); }

  /* tapping the tags expands them: hide project, show every tag (wrapping) */
  .panel.tags-expanded > .field:first-child { display: none; }
  .panel.tags-expanded .field.tags { grid-column: 1 / -1; justify-content: flex-start; }
  .panel.tags-expanded .tags-edit {
    flex-wrap: wrap; overflow: visible; justify-content: flex-start;
    -webkit-mask-image: none; mask-image: none;
  }
  .panel.tags-expanded #tag-chips { flex-wrap: wrap; }
}
