:root {
  --bg: #f6f6f4;
  --panel: #ffffff;
  --panel-2: #fbfbfa;
  --ink: #1b1b19;
  --ink-soft: #6b6b64;
  --line: #e2e2dd;
  --accent: #2f6f4f;
  --accent-ink: #ffffff;
  --danger: #a03030;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 8px 24px rgba(0, 0, 0, .06);
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --panel: #1e2024;
    --panel-2: #23262b;
    --ink: #ececea;
    --ink-soft: #9a9a94;
    --line: #31343a;
    --accent: #6cba8e;
    --accent-ink: #10241a;
    --danger: #e08585;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

/* An author `display` beats the UA rule for [hidden], and several classes here
   set one (.btn, .check-row, .center-box). Without this, anything toggled with
   `el.hidden = true` stays on screen. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

button, input, select {
  font: inherit;
  color: inherit;
}

input[type=checkbox] { accent-color: var(--accent); }

/* ------------------------------- chrome ---------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar .sub {
  color: var(--ink-soft);
  font-size: 13px;
  white-space: nowrap;
}

.spacer { flex: 1 1 auto; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: background .12s, border-color .12s, transform .06s;
}

.btn:hover:not(:disabled) { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 13px; }

/* -------------------------------- grid ----------------------------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(clamp(120px, 22vw, 200px), 1fr));
  gap: 6px;
  padding: 14px;
}

.tile {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel-2);
  cursor: pointer;
  border: 2px solid transparent;
}

.tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity .25s ease;
}

.tile img.loaded { opacity: 1; }

.tile.selected {
  border-color: var(--accent);
}

.tile.selected .check {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.tile .check {
  position: absolute;
  top: 7px;
  left: 7px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .9);
  background: rgba(0, 0, 0, .32);
  display: grid;
  place-items: center;
  font-size: 13px;
  line-height: 1;
  color: transparent;
  opacity: 0;
  transition: opacity .12s;
  backdrop-filter: blur(2px);
}

.tile:hover .check,
.tile.selected .check,
body.selecting .tile .check { opacity: 1; }

.tile .badge {
  position: absolute;
  bottom: 7px;
  right: 7px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
}

.tile .fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  gap: 4px;
  color: var(--ink-soft);
  font-size: 26px;
}

.tile .fallback small {
  font-size: 10px;
  max-width: 90%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Only shown in the admin preview, while the thumbnail cache is being filled. */
.warmstrip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 16px;
  font-size: 13px;
  color: var(--ink-soft);
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
}

.warmstrip #warmText { flex: 1 1 auto; }

/* ------------------------------ actionbar -------------------------- */

.actionbar {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translate(-50%, 140%);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 10px 16px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  transition: transform .22s cubic-bezier(.2, .8, .3, 1);
}

.actionbar.show { transform: translate(-50%, 0); }
.actionbar .count { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ------------------------------ lightbox --------------------------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  /* Fully opaque: at 94% the page's own header bled through behind the photo. */
  background: #0b0b0d;
}

.lightbox.open { display: block; }

/* Flex, not grid: a percentage max-height on a grid item resolves against an
   auto-sized row, so the photo used to overflow past the bars. Flex gives the
   image a definite height to measure against. */
.lightbox .stage {
  position: absolute;
  inset: 56px 0 56px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  min-height: 0;
}

.lightbox img,
.lightbox video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
}

/* The cached tile, blown up while the original is on its way. It has to fill
   the same box the original will occupy - max-width alone only caps a 400px
   thumbnail, leaving it postage-stamp sized and causing a jump on arrival.
   Blurred so it reads as "not ready yet" rather than as a bad photo. */
.lightbox img.placeholder {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: blur(12px);
  transform: scale(1.01);
}

.lightbox .lb-top,
.lightbox .lb-bottom {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: #f2f2f0;
  z-index: 2;
}

/* Scrims keep the filename and buttons readable over a bright photo. */
.lightbox .lb-top {
  top: 0;
  background: linear-gradient(to bottom, rgba(0, 0, 0, .75), transparent);
}

.lightbox .lb-bottom {
  bottom: 0;
  justify-content: center;
  background: linear-gradient(to top, rgba(0, 0, 0, .75), transparent);
}

.lightbox .name {
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lightbox .meta { font-size: 12px; color: #d8d8d2; }

.lightbox .nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .2);
  background: rgba(0, 0, 0, .4);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: grid;
  place-items: center;
  z-index: 2;
}

.lightbox .nav.prev { left: 14px; }
.lightbox .nav.next { right: 14px; }
.lightbox .nav:disabled { opacity: .25; cursor: default; }

.lightbox .spin {
  position: absolute;
  color: #999;
  font-size: 13px;
}

/* ------------------------------- panels ---------------------------- */

.wrap { max-width: 1080px; margin: 0 auto; padding: 20px 18px 60px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 600;
}

.card .hint {
  margin: 0 0 14px;
  color: var(--ink-soft);
  font-size: 13px;
}

.field { margin-bottom: 12px; }

.field label {
  display: block;
  margin-bottom: 5px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
}

.field input[type=text],
.field input[type=password],
.field input[type=number],
.field input[type=search],
.field select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.field input:focus,
.field select:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent);
  outline-offset: 1px;
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-bottom: 10px;
  font-size: 14px;
}

.check-row input { margin-top: 3px; }
.check-row .note { display: block; color: var(--ink-soft); font-size: 12px; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.folder-list {
  max-height: 340px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.folder-list button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  font-size: 14px;
}

.folder-list button:last-child { border-bottom: 0; }
.folder-list button:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.folder-list button.active { background: color-mix(in srgb, var(--accent) 18%, transparent); font-weight: 600; }
.folder-list .year { color: var(--ink-soft); font-variant-numeric: tabular-nums; margin-right: 8px; }

.share {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
  background: var(--panel-2);
}

.share.inactive { opacity: .55; }
.share .title { font-weight: 600; margin-bottom: 2px; }
.share .folder { color: var(--ink-soft); font-size: 12px; margin-bottom: 8px; }

.share .link {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.share .link code {
  flex: 1 1 auto;
  padding: 6px 9px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
  overflow-x: auto;
  white-space: nowrap;
}

.tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }

.tag {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: color-mix(in srgb, var(--accent) 80%, var(--ink));
}

.tag.warn { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.tag.mute { background: var(--line); color: var(--ink-soft); }

/* ------------------------------- misc ------------------------------ */

.center-box {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.center-box .card { width: min(400px, 100%); margin: 0; }

.msg {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--danger);
  min-height: 18px;
}

.msg.ok { color: var(--accent); }

.empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--ink-soft);
}

.sentinel { height: 40px; }

.progress {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  place-items: center;
  background: rgba(8, 8, 10, .7);
  backdrop-filter: blur(3px);
}

.progress.open { display: grid; }

.progress .box {
  width: min(420px, 92vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.progress h3 { margin: 0 0 6px; font-size: 15px; }
.progress .detail { color: var(--ink-soft); font-size: 13px; margin-bottom: 12px; min-height: 19px; }

.bar {
  height: 8px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.bar > i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width .2s;
}

.stats { color: var(--ink-soft); font-size: 12px; }
.stats b { color: var(--ink); font-weight: 600; }

@media (max-width: 560px) {
  .topbar { gap: 8px; padding: 10px 12px; }
  .topbar .sub { display: none; }
  .grid { gap: 4px; padding: 8px; }
}
