/* =============================================================
   Kurs-Collection – ruhige Galerie im Stil einer Mac-App:
   weißer Grund, keine Beschriftungen, nur die Arbeiten.
   ============================================================= */

/* Farben, Abstände und Schrift an einer Stelle */
:root {
  --page: #ffffff;
  --ink: #1d1d1f;
  --muted: #86868b;
  --pill: rgb(236 236 238 / 0.82);
  --pill-strong: #e6e6e9;
  --tile-bg: #f2f2f4;
  --gap: 16px;
  --row-height: 190px; /* wird vom Größen-Slider verändert */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--page);
  color: var(--ink);
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Pillen (Grundform für Kopfzeile und Leiste) ---------- */

.pill {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 40px;
  padding: 4px;
  background: var(--pill);
  border-radius: 999px;
  backdrop-filter: blur(20px) saturate(1.6);
  -webkit-backdrop-filter: blur(20px) saturate(1.6);
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 32px;
  height: 32px;
  padding: 0 7px;
  background: none;
  border: none;
  border-radius: 999px;
  cursor: pointer;
}

.icon-button:hover {
  background: rgb(0 0 0 / 0.06);
}

:focus-visible {
  outline: 2px solid #0a84ff;
  outline-offset: 2px;
}

/* ---------- Kopfzeile ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  /* weicher Übergang nach unten, damit Bilder darunter "verschwinden" */
  background: linear-gradient(var(--page) 60%, rgb(255 255 255 / 0));
}

.title-pill {
  gap: 10px;
  padding: 4px 18px;
  font-size: 15px;
}

#count {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.segments {
  display: flex;
}

.segments button {
  height: 32px;
  padding: 0 13px;
  background: none;
  border: none;
  border-radius: 999px;
  color: #555;
  cursor: pointer;
}

.segments button:hover {
  color: var(--ink);
}

.segments button.active {
  color: #fff;
  background: var(--ink);
}

#search {
  width: 180px;
  height: 32px;
  padding: 0 12px;
  font: inherit;
  border: none;
  border-radius: 999px;
  background: #fff;
  outline-offset: 0;
}

/* ---------- Das Raster ---------- */
/* Trick für gleich hohe Zeilen über die volle Breite:
   Jede Kachel wächst im Verhältnis zu ihrem Seitenverhältnis (--ratio).
   Breite Bilder wachsen mehr, hohe weniger – so bleiben alle Zeilen
   gleich hoch. Das unsichtbare ::after verhindert, dass die letzte,
   halb leere Zeile riesig aufgebläht wird. */

.grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
  padding: 4px 20px 120px;
}

.grid::after {
  content: "";
  flex-grow: 1000000;
}

.tile {
  --ratio: 1.5; /* Standard, bis das echte Verhältnis bekannt ist */
  position: relative;
  flex-grow: var(--ratio);
  flex-basis: calc(var(--ratio) * var(--row-height));
  /* Zeilen dürfen nicht kleiner als 1/3 der Wunschhöhe werden */
  min-width: calc(var(--ratio) * var(--row-height) / 3);
  max-width: calc(var(--ratio) * var(--row-height) * 1.6);
  padding: 0;
  overflow: hidden;
  background: var(--tile-bg);
  border: none;
  cursor: zoom-in;
  animation: tile-in 500ms var(--ease-out) both;
  /* beim Scrollen per Tastatur nicht unter Kopfzeile oder Leiste verschwinden */
  scroll-margin: 72px 0 88px;
}

.tile img,
.tile video {
  display: block;
  width: 100%;
  aspect-ratio: var(--ratio);
  object-fit: cover;
}

/* zuletzt angesehene Arbeit: schwarzer Rahmen wie in der Referenz.
   Der Tastatur-Fokus sieht genauso aus. */
.tile.is-selected,
.tile:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

/* kleines Play-Symbol unten links bei Videos */
.play-badge {
  position: absolute;
  left: 8px;
  bottom: 8px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgb(255 255 255 / 0.9);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.2);
}

.play-badge svg {
  width: 10px;
  height: 10px;
  fill: var(--ink);
  stroke: none;
  margin-left: 2px;
}

@keyframes tile-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.empty {
  margin: 120px 20px;
  text-align: center;
  line-height: 1.6;
  color: var(--muted);
}

/* ---------- Schwebende Leiste unten rechts ---------- */

.dock {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 10;
  gap: 2px;
  padding: 4px 16px 4px 6px;
  box-shadow: 0 4px 24px rgb(0 0 0 / 0.08);
}

.chevron {
  width: 12px;
  height: 12px;
  transition: transform 200ms var(--ease-out);
}

/* "älteste zuerst": Pfeil zeigt nach oben */
.sort-button.is-reversed .chevron {
  transform: rotate(180deg);
}

#shuffle.is-active {
  color: #fff;
  background: var(--ink);
}

/* Slider: schwarze Spur links vom Knopf, graue rechts */
#size {
  -webkit-appearance: none;
  appearance: none;
  width: 150px;
  height: 20px;
  margin-left: 10px;
  background: transparent;
  cursor: pointer;
}

#size::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--ink) var(--fill, 30%), rgb(0 0 0 / 0.15) var(--fill, 30%));
}

#size::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: rgb(0 0 0 / 0.15);
}

#size::-moz-range-progress {
  height: 4px;
  border-radius: 2px;
  background: var(--ink);
}

#size::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px;
  height: 18px;
  margin-top: -7px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.3);
}

#size::-moz-range-thumb {
  width: 28px;
  height: 18px;
  border: none;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.3);
}

/* ---------- Großansicht ---------- */

.viewer {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  overflow: hidden;
}

.viewer::backdrop {
  background: transparent;
}

/* weiße Fläche hinter dem großen Bild – wird beim Öffnen eingeblendet */
.viewer-backdrop {
  position: absolute;
  inset: 0;
  background: var(--page);
}

.viewer-stage:focus {
  outline: none;
}

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

.viewer-stage img,
.viewer-stage video {
  display: block;
  background: var(--tile-bg);
  transform-origin: top left; /* wichtig für die Zoom-Animation */
}

.viewer-close {
  position: absolute;
  top: 16px;
  right: 20px;
  width: 40px;
  height: 40px;
  background: var(--pill);
}

.viewer-nav {
  position: absolute;
  top: 50%;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-top: -22px;
  color: #fff;
  background: rgb(29 29 31 / 0.72);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.viewer-nav:hover {
  background: var(--ink);
}

.viewer-nav.prev {
  left: 20px;
}

.viewer-nav.next {
  right: 20px;
}

.viewer-caption {
  position: absolute;
  left: 50%;
  bottom: 20px;
  width: max-content;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-width: calc(100vw - 40px);
  transform: translateX(-50%);
}

.caption-pill {
  gap: 12px;
  max-width: 100%;
  padding: 4px 6px 4px 18px;
  white-space: nowrap;
}

/* Name und Buttons bleiben ganz, nur der Meta-Text wird gekürzt */
.caption-pill > strong,
.caption-pill > .text-button {
  flex-shrink: 0;
}

#viewer-meta {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted);
}

.text-button {
  height: 32px;
  padding: 0 12px;
  line-height: 32px;
  font-size: 13px;
  color: var(--ink);
  text-decoration: none;
  background: rgb(255 255 255 / 0.7);
  border: none;
  border-radius: 999px;
  cursor: pointer;
}

.text-button:hover {
  background: #fff;
}

/* Einstellungen als kleine Tabelle über der Pille */
.settings {
  display: grid;
  grid-template-columns: repeat(4, auto auto);
  gap: 4px 10px;
  margin: 0;
  padding: 12px 16px;
  font-size: 12px;
  background: var(--pill);
  border-radius: 16px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  order: -1; /* über der Pille anzeigen */
}

.settings[hidden] {
  display: none;
}

.settings dt {
  color: var(--muted);
}

.settings dd {
  margin: 0 8px 0 0;
  font-variant-numeric: tabular-nums;
}

/* Formel: Beschriftung in der ersten Spalte, Formel im Rest der Zeile */
.settings dt.formula-label {
  grid-column: 1;
}

.settings dd.formula {
  grid-column: 2 / -1;
  max-width: 560px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  overflow-wrap: anywhere;
}

/* Bedienelemente der Großansicht erscheinen erst nach dem Zoomen */
.viewer .viewer-close,
.viewer .viewer-nav,
.viewer .viewer-caption {
  transition: opacity 200ms ease;
}

.viewer.is-animating .viewer-close,
.viewer.is-animating .viewer-nav,
.viewer.is-animating .viewer-caption {
  opacity: 0;
}

/* ---------- Schmale Bildschirme ---------- */

@media (max-width: 700px) {
  .topbar {
    flex-wrap: wrap;
    padding: 10px 12px;
  }

  .segments button {
    padding: 0 9px;
  }

  .grid {
    --gap: 8px;
    padding: 4px 12px 100px;
  }

  .dock {
    right: 12px;
    bottom: 12px;
  }

  #size {
    width: 100px;
  }

  .viewer-nav {
    top: auto;
    bottom: 76px;
  }

  .settings {
    grid-template-columns: repeat(2, auto auto);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tile {
    animation: none;
  }
}
