:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c1f24;
  --muted: #667085;
  --border: #e3e6ea;
  --primary: #2563eb;
  --primary-text: #ffffff;
  --danger: #dc2626;
  --notice: #ecfdf3;
  --notice-border: #a6f4c5;
  --radius: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1a1d23;
    --text: #e8eaed;
    --muted: #9aa3af;
    --border: #2c313a;
    --primary: #3b82f6;
    --danger: #ef4444;
    --notice: #0f2a1d;
    --notice-border: #1f6f46;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--primary); }
h1 { font-size: 1.75rem; line-height: 1.2; margin: 0 0 .5rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .5rem; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-bottom: 48px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.lead { font-size: 1.1rem; }
.center { text-align: center; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; }
.brand { font-weight: 700; }
.who { display: flex; gap: 10px; align-items: center; font-size: .95rem; margin: 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; margin-bottom: 20px; }
.card.narrow { max-width: 460px; margin: 40px auto; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }

.form { display: grid; gap: 14px; margin-top: 16px; }
label { display: grid; gap: 6px; font-weight: 600; font-size: .95rem; }
input[type=text], input[type=email], input[type=password] {
  width: 100%; font: inherit; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
input[readonly] { opacity: .8; }
input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 10px 0; }
.inline-form input[type=text] { flex: 1 1 240px; width: auto; }
/* "https://host/f/" prefix glued to the custom-link box. */
.slug-input { display: flex; align-items: stretch; flex: 1 1 320px; min-width: 0; margin-top: 6px; }
.inline-form .slug-input { margin-top: 0; }
.slug-prefix {
  display: flex; align-items: center; padding: 0 10px; border: 1px solid var(--border); border-right: 0;
  border-radius: 10px 0 0 10px; background: var(--surface); color: var(--muted); font-size: .9em;
  max-width: 50%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.slug-input input[type=text] { border-radius: 0 10px 10px 0; flex: 1 1 auto; min-width: 120px; width: auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; padding: 10px 16px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none;
  white-space: nowrap;
}
.btn:hover { filter: brightness(.97); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-lg { padding: 14px 22px; font-size: 1.05rem; }
.btn-sm { padding: 6px 12px; font-size: .875rem; }
.btn[hidden] { display: none; }
.linkish { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; cursor: pointer; text-decoration: underline; }
.alert { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); padding: 10px 14px; border-radius: 10px; }
.pill { padding: 6px 12px; border-radius: 999px; background: var(--border); font-size: .9rem; }

.notice { background: var(--notice); border: 1px solid var(--notice-border); border-radius: var(--radius); padding: 16px; margin-bottom: 20px; }
.copy-row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.copy-row input { flex: 1 1 260px; width: auto; font-family: ui-monospace, monospace; font-size: .9rem; }

.folder-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.folder-head h1 { overflow-wrap: anywhere; }
.folder-head #summary { margin: 0; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 8px 0 16px; flex-wrap: wrap; }
.tabs { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.tab { font: inherit; border: 0; background: none; padding: 7px 14px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.tab.active { background: var(--primary); color: #fff; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
@media (max-width: 520px) {
  .grid { grid-template-columns: repeat(3, 1fr); gap: 4px; }
  .tile .by { display: none; }
  .btn-lg { width: 100%; }
  .actions { width: 100%; }
}
.tile {
  position: relative; aspect-ratio: 1; border: 0; padding: 0; overflow: hidden; cursor: pointer;
  background: var(--border); border-radius: 8px; color: var(--text); font: inherit;
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s; }
.tile:hover img { transform: scale(1.03); }
.placeholder { display: grid; place-content: center; justify-items: center; gap: 6px; height: 100%; padding: 8px; font-size: .8rem; color: var(--muted); overflow-wrap: anywhere; text-align: center; }
.ext { font-weight: 800; font-size: 1.1rem; color: var(--text); }
.badge { position: absolute; top: 6px; font-size: .72rem; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: rgba(0,0,0,.65); color: #fff; }
.badge.play { left: 6px; }
.badge.mine { right: 6px; background: var(--primary); }
.by { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 8px 6px; font-size: .75rem; color: #fff; text-align: left;
  background: linear-gradient(transparent, rgba(0,0,0,.6)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--muted); border-top-color: transparent; border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

.lightbox { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: #000; color: #fff; }
.lightbox::backdrop { background: rgba(0,0,0,.9); }
/* minmax(0, 1fr): the media row never grows past the screen, so tall (portrait) photos shrink to fit. */
.lightbox[open] { display: grid; grid-template-rows: minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr); }
.lb-media { display: flex; align-items: center; justify-content: center; min-height: 0; overflow: hidden;
  padding: clamp(20px, 4vw, 48px) clamp(20px, 6vw, 96px); box-sizing: border-box; }
/* A faint outline so the edge of a dark photo is still visible against the black background. */
.lb-media img, .lb-media video { display: block; max-width: 100%; max-height: 100%; width: auto; height: auto;
  object-fit: contain; border-radius: 8px; box-shadow: 0 0 0 1px rgba(255,255,255,.14), 0 8px 40px rgba(0,0,0,.6); }
.lb-file { text-align: center; padding: 24px; }
.lb-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: #111; flex-wrap: wrap;
  padding: 12px max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.lb-info { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.lb-info .muted { color: #aaa; }
.lb-actions { display: flex; gap: 8px; }
.lb-nav { position: absolute; top: 45%; font-size: 2.5rem; line-height: 1; background: rgba(0,0,0,.45); color: #fff; border: 0; width: 48px; height: 64px; cursor: pointer; border-radius: 8px; }
.lb-prev { left: 8px; } .lb-next { right: 8px; }
.lb-nav[hidden] { display: none; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }

/* ---------- Toolbar: sort + view ---------- */
.toolbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sort { display: inline-flex; flex-direction: row; align-items: center; gap: 6px; font-weight: 500; font-size: .9rem; color: var(--muted); }
.sort select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 8px;
}
#sort-dir { min-width: 34px; }
[hidden] { display: none !important; }

/* ---------- List view ---------- */
.list-table tbody tr { cursor: pointer; }
.list-table tbody tr:hover, .list-table tbody tr:focus { background: color-mix(in srgb, var(--primary) 7%, transparent); outline: none; }
.list-table td { vertical-align: middle; padding-top: 6px; padding-bottom: 6px; }
.list-table th[data-sort] { cursor: pointer; user-select: none; }
.list-table th[data-sort]:hover { color: var(--text); }
.list-table th.sorted { color: var(--text); }
.list-table th.sorted::after { content: ' ↓'; }
.list-table th.sorted[data-dir="asc"]::after { content: ' ↑'; }
.c-thumb { width: 52px; padding-right: 0 !important; }
.mini { width: 44px; height: 44px; border-radius: 6px; overflow: hidden; background: var(--border); display: grid; place-items: center; }
.mini img { width: 100%; height: 100%; object-fit: cover; display: block; }
.mini-ext { font-size: .6rem; font-weight: 800; color: var(--muted); }
.c-name { white-space: normal !important; min-width: 180px; max-width: 360px; }
.fname { overflow-wrap: anywhere; }
.c-name .sub { display: none; font-size: .8rem; color: var(--muted); }
.badge-inline { margin-left: 6px; font-size: .7rem; font-weight: 700; padding: 1px 6px; border-radius: 5px; background: var(--primary); color: #fff; vertical-align: 1px; }
.c-num { text-align: right !important; }
.c-act { width: 1%; }
@media (max-width: 720px) {
  .c-hide-sm, .c-person { display: none; }
  .c-name .sub { display: block; }
  .c-name { min-width: 0; }
  .toolbar-right { width: 100%; }
}

/* ---------- Admin tracking tables ---------- */
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.section-head h2 { margin: 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; }
.wrap-cell { white-space: normal !important; overflow-wrap: anywhere; min-width: 160px; }
.act-delete td, .act-delete_denied td { color: var(--danger); }
.privacy { margin-top: 18px; }
.admin-nav { display: flex; align-items: center; gap: 16px; }
.admin-nav form { margin: 0; }
.chip { display: inline-block; margin: 2px 4px 2px 0; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); text-decoration: none; font-size: .85rem; white-space: nowrap; }
.chip:hover { border-color: var(--primary); }
textarea { width: 100%; font: inherit; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9rem;
  padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); resize: vertical; }
textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.pill-warn { margin-left: 6px; font-size: .72rem; padding: 2px 8px; background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.act-login_denied td { color: var(--danger); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }

/* ---------- Tags ---------- */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; font-size: .85rem;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; line-height: 1.2; font: inherit; }
.chip.active { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.chip-count { font-size: .75rem; opacity: .7; }
.chip-sm { padding: 1px 8px; font-size: .75rem; cursor: default; }
.chip-x { border: 0; background: none; color: inherit; font-size: 1.1rem; line-height: 1; padding: 0 0 0 2px; cursor: pointer; opacity: .7; }
.chip-x:hover { opacity: 1; }
.tag-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 14px; }
.tag-bar-label { font-size: .9rem; }
.tag-prompt label { display: block; }
.tag-prompt .copy-row input { font-family: inherit; font-size: 1rem; }
.badge.tags { top: auto; bottom: 6px; right: 6px; z-index: 1; }
.row-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.lb-tags-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; white-space: normal; }
.lb-tags { display: contents; }
.lb-tags .chip { background: #222; border-color: #444; color: #eee; cursor: default; padding: 3px 10px; }
.lb-tag-form { display: inline-flex; gap: 6px; }
.lb-tag-form input { width: 150px; padding: 5px 10px; font-size: 16px; /* 16px stops iOS zooming in */ background: #222; color: #eee; border-color: #444; }
.flash { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #111; color: #fff; padding: 10px 16px;
  border-radius: 10px; box-shadow: 0 4px 20px rgba(0,0,0,.3); z-index: 50; max-width: calc(100% - 32px); }
.tile:has(.badge.tags) .by { padding-right: 56px; }
#lb-name { cursor: pointer; }
.lb-info.full { white-space: normal; overflow-wrap: anywhere; }
.fname, .tile .placeholder { overflow-wrap: anywhere; }
.lightbox:focus { outline: none; }
