:root {
  --bg: #0d0d0e;
  --bg2: #151517;
  --card: #18181b;
  --line: #2a2a2e;
  --text: #f1efea;
  --muted: #9a978f;
  --accent: #e9d3a6;
  --accent-ink: #1a1408;
  --bad: #ff7a6b;
  --ok: #8fd6a2;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
body.noscroll { overflow: hidden; }
a { color: var(--accent); }
h1, h2, h3 { font-family: ui-serif, "Iowan Old Style", "Palatino Linotype", Georgia, serif; font-weight: 500; letter-spacing: -0.01em; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
[hidden] { display: none !important; }

.boot { display: grid; place-items: center; min-height: 60vh; }
.spinner { width: 28px; height: 28px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4em;
  font: inherit; font-weight: 600; font-size: 0.95rem; text-decoration: none;
  padding: 0.7em 1.15em; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg2); color: var(--text);
  transition: background 0.15s, border-color 0.15s, opacity 0.15s, transform 0.05s;
}
.btn:hover { border-color: #444; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #f3e1bb; }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; border-color: #5a2a25; color: var(--bad); }
.btn.small { padding: 0.45em 0.9em; font-size: 0.85rem; }
.btn.wide { width: 100%; }
.btn.on { border-color: var(--accent); color: var(--accent); }
input {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 0.7em 0.9em; width: 100%;
}
input:focus-visible, .btn:focus-visible, .drop:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.brand { font-weight: 600; letter-spacing: 0.02em; margin: 0; color: var(--text); text-decoration: none; display: inline-flex; align-items: center; gap: 0.35em; }
.brand-mark { color: var(--accent); font-size: 1.1em; }
.brand small { color: var(--muted); font-weight: 500; }

/* ---------- home ---------- */
.home {
  min-height: 100vh; display: grid; place-items: center; padding: 32px 20px;
  background: radial-gradient(1200px 600px at 50% -10%, #221d14 0%, transparent 60%), var(--bg);
}
.home-inner { width: 100%; max-width: 440px; text-align: center; }
.home h1 { font-size: clamp(2rem, 6vw, 2.8rem); margin: 18px 0 8px; }
.lede { color: var(--muted); margin: 0 0 28px; }
.code-form { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; display: grid; gap: 14px; text-align: left; }
.code-label { font-size: 0.85rem; color: var(--muted); }
.code-input {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 1.9rem; letter-spacing: 0.4em;
  text-align: center; text-transform: uppercase; padding: 0.45em 0.3em 0.45em 0.7em; background: var(--bg);
}
.code-input::placeholder { color: #3a3a3f; letter-spacing: 0.2em; }
.form-err { color: var(--bad); min-height: 1.3em; margin: 0; font-size: 0.9rem; }
.approved { display: grid; justify-items: center; gap: 6px; padding: 18px 0; text-align: center; animation: pop 0.35s ease-out; }
.approved .check { width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; font-size: 1.6rem; background: var(--ok); color: #0b2412; }
.approved p { margin: 0; }
@keyframes pop { from { transform: scale(0.9); opacity: 0; } }
.disclaimer { margin-top: 22px; padding: 18px 20px; border-left: 2px solid var(--accent); background: rgba(233, 211, 166, 0.05); border-radius: 0 var(--radius) var(--radius) 0; text-align: left; font-size: 0.92rem; }
.disclaimer p { margin: 0 0 8px; }
.disclaimer p:last-child { margin: 0; }
.disc-title { font-weight: 600; }

/* ---------- gallery ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px clamp(16px, 3vw, 40px); background: rgba(13, 13, 14, 0.85); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.topbar-right { display: flex; gap: 8px; align-items: center; }
.gallery-head { padding: 34px clamp(16px, 3vw, 40px) 8px; max-width: 980px; }
.gallery-head h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); }
.meta { color: var(--muted); margin: 4px 0 14px; }
.note { color: #c9c6be; margin: 0 0 8px; font-size: 0.93rem; max-width: 760px; }
.note.tagline { color: var(--muted); font-size: 0.86rem; }
.toolbar {
  position: sticky; top: 57px; z-index: 4; display: flex; flex-wrap: wrap; gap: 8px;
  padding: 12px clamp(16px, 3vw, 40px); background: rgba(13, 13, 14, 0.9); backdrop-filter: blur(10px);
}
.bar { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar-fill { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
.bar-fill.warn { background: var(--bad); }

/* justified grid: each tile grows by its aspect ratio */
.grid { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px clamp(10px, 2vw, 34px) 60px; }
.grid::after { content: ""; flex-grow: 999; }
.tile { position: relative; margin: 0; overflow: hidden; border-radius: 6px; background: var(--bg2); cursor: zoom-in; min-width: 120px; }
.tile .pad { display: block; }
.tile img, .tile .noprev { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transition: transform 0.3s, opacity 0.2s; }
.tile:hover img { transform: scale(1.02); }
.tile figcaption {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 10px 6px; font-size: 0.75rem; color: #ddd;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.65)); opacity: 0; transition: opacity 0.2s; pointer-events: none;
}
.tile:hover figcaption { opacity: 1; }
.tick {
  position: absolute; top: 8px; left: 8px; width: 28px; height: 28px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.85);
  background: rgba(0, 0, 0, 0.35); color: transparent; font-weight: 700; cursor: pointer; display: grid; place-items: center; padding: 0;
  opacity: 0; transition: opacity 0.15s, background 0.15s;
}
.tile:hover .tick, body.selecting .tick { opacity: 1; }
@media (hover: none) { .tick { opacity: 1; } }
.tile.sel .tick { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tile.sel img { opacity: 0.75; }
.tile.sel { outline: 3px solid var(--accent); outline-offset: -3px; }
body.selecting .tile { cursor: pointer; }
.noprev { display: grid; place-items: center; align-content: center; gap: 4px; color: var(--muted); font-size: 0.8rem; }
.noprev span { font-weight: 700; letter-spacing: 0.2em; color: var(--accent); }
.empty { color: var(--muted); padding: 40px clamp(16px, 3vw, 40px); }

/* lightbox */
.lightbox { position: fixed; inset: 0; z-index: 20; background: #050506; display: grid; grid-template-rows: auto 1fr auto; }
.lb-top { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; color: var(--muted); font-size: 0.9rem; }
.lb-x { background: none; border: 0; color: var(--text); font-size: 1.4rem; cursor: pointer; padding: 6px 10px; }
.lb-stage { position: relative; display: grid; place-items: center; min-height: 0; padding: 0 56px; }
.lb-img { max-width: 100%; max-height: calc(100vh - 140px); object-fit: contain; border-radius: 2px; user-select: none; }
.lb-noprev { color: var(--muted); }
.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 46px; height: 64px; border: 0; border-radius: 10px;
  background: rgba(255, 255, 255, 0.06); color: var(--text); font-size: 2rem; cursor: pointer;
}
.lb-nav:hover { background: rgba(255, 255, 255, 0.12); }
.lb-nav.prev { left: 6px; }
.lb-nav.next { right: 6px; }
.lb-bar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
.lb-name { color: #cfccc4; font-size: 0.9rem; word-break: break-all; }
.lb-actions { display: flex; gap: 8px; }
@media (max-width: 640px) {
  .lb-stage { padding: 0; }
  .lb-nav { display: none; }
  .toolbar { top: 53px; }
  .toolbar .btn { flex: 1 1 auto; }
  .grid { gap: 4px; }
  .tile { min-width: 90px; }
}

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; z-index: 40;
  background: #26262a; color: var(--text); border: 1px solid var(--line); padding: 10px 16px; border-radius: 999px;
  transition: opacity 0.2s, transform 0.2s; pointer-events: none; font-size: 0.9rem; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { border-color: var(--bad); color: var(--bad); }

/* ---------- admin ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.login { max-width: 380px; margin: 0 auto; display: grid; gap: 12px; text-align: center; }
.login h2 { font-size: 1.5rem; }
.login-err { color: var(--bad); margin: 0; min-height: 1.2em; }
.login-left { color: var(--muted); font-size: 0.85rem; margin: 0; }
.login-left.warn { color: var(--bad); }
.lock-box { display: grid; gap: 6px; padding: 12px; border: 1px solid #5a2a25; border-radius: 10px; }
.lock-bar { height: 4px; background: var(--line); border-radius: 9px; overflow: hidden; }
.lock-fill { display: block; height: 100%; background: var(--bad); }
.admin-wrap { max-width: 1100px; margin: 0 auto; padding: 24px clamp(14px, 3vw, 32px) 80px; display: grid; gap: 18px; }
.new-album h2 { font-size: 1.3rem; margin-bottom: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > input { flex: 1 1 240px; }
.code-wrap { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.85rem; }
.code-small { width: 9ch; font-family: ui-monospace, Consolas, monospace; text-transform: uppercase; letter-spacing: 0.15em; }
.usage p { margin: 0 0 8px; }
.section-title { font-size: 1.3rem; margin-top: 6px; }
.album-list { display: grid; gap: 10px; }
.album-card { display: flex; justify-content: space-between; align-items: center; gap: 12px; text-decoration: none; color: var(--text); }
.album-card:hover { border-color: #444; }
.album-card h3 { font-size: 1.15rem; }
.album-card p { margin: 2px 0 0; }
.code-pill { font-family: ui-monospace, Consolas, monospace; letter-spacing: 0.2em; padding: 6px 12px; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); color: var(--accent); }
.album-head { display: flex; gap: 12px; align-items: center; }
.title-edit { font-family: ui-serif, Georgia, serif; font-size: 1.6rem; background: transparent; border-color: transparent; padding-left: 4px; }
.title-edit:hover, .title-edit:focus { border-color: var(--line); }
.code-card { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 14px; }
.code-card p { margin: 0 0 2px; }
.code-big { font-family: ui-monospace, Consolas, monospace; font-size: 2rem; letter-spacing: 0.3em; color: var(--accent); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.drop {
  display: grid; place-items: center; gap: 4px; text-align: center; padding: 34px 16px; border: 2px dashed var(--line); border-radius: var(--radius);
  color: var(--muted); cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.drop b { color: var(--text); font-size: 1.1rem; }
.drop:hover, .drop.over { border-color: var(--accent); background: rgba(233, 211, 166, 0.04); }
.queue { display: grid; gap: 6px; }
.queue:empty { display: none; }
.q-row { display: grid; grid-template-columns: 1fr auto auto; gap: 4px 12px; align-items: center; padding: 10px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; font-size: 0.88rem; }
.q-row .bar { grid-column: 1 / -1; }
.q-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-size, .q-status { color: var(--muted); }
.q-row.ok .q-status { color: var(--ok); }
.q-row.bad .q-status { color: var(--bad); }
.admin-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.admin-tile { position: relative; margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.admin-tile img, .admin-tile .noprev { display: block; width: 100%; aspect-ratio: 3 / 2; object-fit: cover; background: var(--bg2); }
.admin-tile figcaption { display: flex; justify-content: space-between; gap: 6px; padding: 6px 8px; font-size: 0.75rem; }
.admin-tile figcaption span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-tile small { color: var(--muted); white-space: nowrap; }
.del { position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, 0.6); color: #fff; cursor: pointer; opacity: 0; transition: opacity 0.15s; }
.admin-tile:hover .del { opacity: 1; }
@media (hover: none) { .del { opacity: 1; } }

/* ---------- download tray (floats above everything, incl. the photo viewer) ---------- */
.dlpanel {
  position: fixed; right: 16px; bottom: 16px; z-index: 30; width: min(420px, calc(100vw - 32px));
  max-height: min(70vh, 560px); display: flex; flex-direction: column; gap: 10px;
  padding: 14px 16px; background: #1b1b1f; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
}
.dl-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.dl-title { margin: 0; font-weight: 600; }
.dl-sub { margin: 2px 0 0; color: var(--muted); font-size: 0.82rem; }
.dl-actions { display: flex; gap: 6px; }
.dl-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; display: grid; gap: 6px; min-height: 0; }
.dl-row { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; font-size: 0.82rem; padding: 6px 2px; border-top: 1px solid var(--line); }
.dl-row:first-child { border-top: 0; }
.dl-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-size { color: var(--muted); text-align: right; }
.dl-state { grid-column: 1; color: var(--muted); }
.dl-row .bar { grid-column: 1 / -1; }
.bar.thin { height: 3px; }
.dl-row.waiting .bar { opacity: 0.35; }
.dl-row.active .dl-state { color: var(--accent); }
.dl-row.done .dl-state { color: var(--ok); }
.dl-row.done .bar-fill { background: var(--ok); }
.dl-row.failed .dl-state { color: var(--bad); }
@media (max-width: 640px) {
  .dlpanel { right: 8px; left: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); width: auto; max-height: 55vh; }
}

/* ---------- pull to refresh (phones) ---------- */
#ptr {
  position: fixed; top: 0; left: 50%; z-index: 50; transform: translate(-50%, -60px); opacity: 0;
  display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px;
  background: #222226; border: 1px solid var(--line); color: var(--text); font-size: 0.85rem; pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.ptr-ic { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: rgba(233, 211, 166, 0.15); color: var(--accent); transition: transform 0.2s; }
#ptr.ready .ptr-ic { transform: rotate(180deg); }
#ptr.busy .ptr-ic { animation: spin 0.8s linear infinite; }
