/* Palette: https://rendata.nl/color-picker/?p=ren — teal primary, coral accent */
:root {
  --bg: #f9f9f9;
  --surface: #ebf3f1;
  --text: #191919;
  --muted: #5c6b68;
  --primary: #1c6758;
  --border: #d6e7e4;
  --accent: #ff9779;
  --accent-hover: #ffac94;
  --on-accent: #191919;
  --header-h: 56px;
  --gap: 6px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a1b18;
    --surface: #143630;
    --text: #ebf3f1;
    --muted: #85b8ad;
    --primary: #85b8ad;
    --border: #1f5247;
    --accent-hover: #ffc1af;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0a1b18;
  --surface: #143630;
  --text: #ebf3f1;
  --muted: #85b8ad;
  --primary: #85b8ad;
  --border: #1f5247;
  --accent-hover: #ffc1af;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  transition: background-color .2s, color .2s;
}

a { color: var(--primary); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.logo {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--primary);
  text-decoration: none;
}
.logo span { color: var(--accent); }

.site-nav { display: flex; align-items: center; gap: 4px; }

.site-nav a {
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
}
.site-nav a:hover { color: var(--primary); }
.site-nav a[aria-current="page"] {
  color: var(--primary);
  font-weight: 600;
  box-shadow: inset 0 -2px 0 var(--accent);
  border-radius: 0;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface); color: var(--primary); }
.icon-btn svg { width: 20px; height: 20px; }

.theme-toggle .moon { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .moon { display: block; }
}

main { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.empty { margin: auto; padding: 2rem 16px; color: var(--muted); text-align: center; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  min-height: 44px;
  padding: 0 22px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background-color .15s, transform .1s;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: transparent; color: var(--primary); box-shadow: inset 0 0 0 1.5px var(--primary); }
.btn.secondary:hover { background: var(--surface); }

/* Random page */
.random {
  align-items: center;
  gap: 16px;
  padding: 16px 16px 24px;
  height: calc(100dvh - var(--header-h));
}

.random-frame {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
}

.random-frame img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity .35s ease;
}
.random-frame img.loaded { opacity: 1; }

/* Gallery: justified rows. Each tile grows in proportion to its aspect ratio (--r),
   so all tiles in a row end up the same height. */
.gallery {
  --row: clamp(110px, 22vw, 260px);
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
  padding: var(--gap);
}
.gallery::after { content: ""; flex-grow: 1e9; } /* keep the last row from stretching */

.tile {
  flex-grow: var(--r);
  flex-basis: calc(var(--r) * var(--row));
  aspect-ratio: var(--r);
  max-height: calc(var(--row) * 2);
  display: block;
  overflow: hidden;
  background: var(--surface);
  border-radius: 2px;
  cursor: zoom-in;
}
.tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform .3s ease, opacity .3s;
}
.tile:hover img { transform: scale(1.03); }

/* Lightbox */
.lightbox {
  width: 100vw;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
.lightbox::backdrop { background: var(--bg); }
.lightbox[open] { display: grid; place-items: center; }

.lightbox img {
  max-width: 100vw;
  max-height: 100dvh;
  object-fit: contain;
  touch-action: pan-y pinch-zoom;
  user-select: none;
  -webkit-user-drag: none;
}

.lightbox .icon-btn {
  position: absolute;
  width: 48px;
  height: 48px;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
}
.lightbox .icon-btn:hover { background: var(--surface); }
.lb-close { top: 12px; right: 12px; }
.lb-prev, .lb-next { top: 50%; transform: translateY(-50%); }
.lb-prev { left: 12px; }
.lb-next { right: 12px; }

@media (hover: none) {
  .lb-prev, .lb-next { display: none; } /* swipe instead */
}

/* Upload page */
.upload {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  gap: 24px;
}
.upload h1 { margin: 0; font-size: 1.5rem; color: var(--primary); }
.upload section { display: flex; flex-direction: column; gap: 12px; }
.upload label { font-weight: 600; }
.upload input[type="password"], .upload input[type="text"] {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.upload .row { display: flex; flex-wrap: wrap; gap: 8px; }
.hint { margin: 0; font-size: .875rem; color: var(--muted); }
.status { margin: 0; min-height: 1.5em; }
.status.error { color: #bc3c4c; }
:root[data-theme="dark"] .status.error { color: #e4b1b7; }

.picker {
  display: grid;
  place-items: center;
  min-height: 120px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  color: var(--muted);
  cursor: pointer;
  text-align: center;
  padding: 16px;
}
.picker:hover { border-color: var(--primary); color: var(--primary); }
.picker input { position: absolute; opacity: 0; pointer-events: none; }

.previews {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.previews li { position: relative; aspect-ratio: 1; border-radius: 6px; overflow: hidden; background: var(--surface); }
.previews img { width: 100%; height: 100%; object-fit: cover; display: block; }
.previews .badge {
  position: absolute;
  inset: auto 4px 4px auto;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--bg);
  font-size: .75rem;
}

@media (max-width: 480px) {
  :root { --header-h: 52px; --gap: 4px; }
  .site-nav a { padding: 6px 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
