:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1c1c1e;
  --muted: #6e6e73;
  --line: #e3e1dc;
  --accent: #0a66d8;
  --accent-text: #ffffff;
  --danger: #c62828;
  --tile: #ecebe7;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121214;
    --surface: #1c1c1f;
    --text: #f2f2f4;
    --muted: #9a9aa1;
    --line: #2c2c31;
    --accent: #4a9bff;
    --accent-text: #0b1220;
    --danger: #ff6b6b;
    --tile: #232327;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input { font: inherit; color: inherit; }

/* ---------- topp ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 1100px; margin: 0 auto; padding: 20px 16px 8px;
}
.top h1 { margin: 0; font-size: 1.6rem; letter-spacing: -0.02em; }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 4px; }
.link:hover { color: var(--text); }

main, .uploader { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

/* ---------- opplasting ---------- */
.uploader form {
  display: grid; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 8px 0 8px;
}
.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 110px; padding: 16px; text-align: center;
  border: 2px dashed var(--line); border-radius: var(--radius); cursor: pointer;
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, transparent); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.drop-title { font-weight: 600; }
.drop-hint { color: var(--muted); font-size: .92rem; overflow-wrap: anywhere; }
#caption {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg);
}
.ttl { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ttl legend { float: left; margin-right: 4px; color: var(--muted); font-size: .92rem; }
.ttl label { cursor: pointer; }
.ttl input { position: absolute; opacity: 0; pointer-events: none; }
.ttl span {
  display: inline-block; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line); font-size: .92rem;
}
.ttl input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.ttl input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.primary {
  justify-self: start; padding: 10px 20px; border-radius: 10px; border: 0;
  background: var(--accent); color: var(--accent-text); font-weight: 600; cursor: pointer;
}
.primary:disabled { opacity: .45; cursor: default; }
progress { width: 100%; height: 6px; accent-color: var(--accent); }
.status { margin: 0; color: var(--muted); font-size: .92rem; min-height: 1.2em; }
.status.error { color: var(--danger); }

/* ---------- dager ---------- */
.day h2 {
  position: sticky; top: 0; z-index: 2;
  margin: 0; padding: 18px 0 10px;
  background: var(--bg); font-size: 1.15rem; letter-spacing: -0.01em;
}
.batch { margin-bottom: 22px; }
.caption { margin: 0 0 8px; font-size: 1.02rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.meta { margin: 6px 0 0; color: var(--muted); font-size: .85rem; }
.grid {
  display: grid; gap: 12px 6px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
@media (max-width: 480px) {
  .grid { grid-template-columns: repeat(3, 1fr); gap: 8px 3px; }
  .grid .kind-video, .grid .kind-file, .grid .kind-pdf, .grid .kind-audio { grid-column: span 3; }
}
.tile { position: relative; min-width: 0; }
.tile a.open-image {
  display: block; aspect-ratio: 1; overflow: hidden;
  border-radius: 8px; background: var(--tile);
}
.tile img { display: block; width: 100%; height: 100%; object-fit: cover; }
.tile-name {
  margin: 4px 2px 0; font-size: .8rem; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kind-video { grid-column: span 2; }
.tile video {
  display: block; width: 100%; aspect-ratio: 16 / 10; object-fit: contain;
  border-radius: 8px; background: #000;
}
.kind-file, .kind-pdf, .kind-audio {
  min-height: 150px; display: flex; flex-direction: column;
  overflow: hidden; border-radius: 8px; background: var(--tile);
}
.filecard {
  flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 4px;
  padding: 14px; color: inherit; text-decoration: none;
}
.filecard:hover .fname { text-decoration: underline; }
.ext {
  align-self: flex-start; padding: 2px 8px; border-radius: 6px;
  background: var(--accent); color: var(--accent-text); font-size: .75rem; font-weight: 700; letter-spacing: .04em;
}
.fname { font-weight: 600; overflow-wrap: anywhere; line-height: 1.3; }
.fsize { color: var(--muted); font-size: .85rem; }
.tile audio { width: calc(100% - 16px); margin: 0 8px 10px; }

.del {
  position: absolute; top: 6px; right: 6px; z-index: 1;
  width: 30px; height: 30px; border-radius: 50%; border: 0;
  background: rgba(0, 0, 0, .55); color: #fff; font-size: 20px; line-height: 30px; cursor: pointer;
  opacity: .85;
}
.del:hover { background: var(--danger); opacity: 1; }

.empty { color: var(--muted); text-align: center; padding: 60px 0; }
footer { max-width: 1100px; margin: 0 auto; padding: 30px 16px 40px; text-align: center; }
footer a { color: var(--muted); font-size: .85rem; }

/* ---------- lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .94); touch-action: pan-y;
}
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100vw; max-height: 100dvh; object-fit: contain; user-select: none; }
.lb-btn {
  position: absolute; border: 0; background: rgba(255, 255, 255, .12); color: #fff;
  width: 46px; height: 46px; border-radius: 50%; font-size: 28px; line-height: 46px; cursor: pointer;
}
.lb-btn:hover { background: rgba(255, 255, 255, .25); }
.lb-close { top: max(12px, env(safe-area-inset-top)); right: 12px; }
.lb-prev { left: 12px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 12px; top: 50%; transform: translateY(-50%); }
.lb-bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px 14px;
  padding: 28px 16px max(16px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, .7));
}
.lb-name {
  color: #fff; font-size: .95rem; text-align: center;
  max-width: 100%; overflow-wrap: anywhere;
}
.lb-download {
  color: #fff; background: rgba(255, 255, 255, .14); padding: 7px 14px; border-radius: 999px;
  text-decoration: none; font-size: .88rem; white-space: nowrap;
}
.lb-download:hover { background: rgba(255, 255, 255, .25); }
@media (hover: none) { .lb-prev, .lb-next { display: none; } }

/* ---------- innlogging ---------- */
.login-page { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login {
  width: 100%; max-width: 340px; display: grid; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px;
}
.login h1 { margin: 0 0 4px; font-size: 1.4rem; }
.login input { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
.login .primary { justify-self: stretch; }
.login .error { margin: 0; color: var(--danger); }
.login .back { color: var(--muted); font-size: .9rem; text-align: center; }
