:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --text: #e7e9ee;
  --muted: #99a0ad;
  --accent: #6c8cff;
  --accent-press: #5577f0;
  --danger: #e25555;
  --line: #2a2f3a;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
a.plain, a.plain:hover { color: inherit; text-decoration: none; }

h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .25rem; }

.muted { color: var(--muted); }

/* ---- layout ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1rem clamp(1rem, 4vw, 2rem);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: rgba(15, 17, 21, .9);
  backdrop-filter: blur(8px);
  z-index: 5;
}
.topbar .actions { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }

main { padding: clamp(1rem, 4vw, 2rem); max-width: 1200px; margin: 0 auto; }
.home { text-align: center; padding-top: 18vh; }

/* ---- branding ---- */
.brand-logo {
  display: block;
  width: 120px;
  height: 120px;
  margin: 0 auto 1.1rem;
  border-radius: 22px;
}
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  flex: none;
}
.topbar h1 { display: inline-flex; align-items: center; gap: .5rem; }
.topbar h1 a.plain { display: inline-flex; align-items: center; gap: .5rem; }

/* ---- buttons / chips ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: .55rem .9rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--accent-press); text-decoration: none; }
.btn.ghost { background: var(--panel-2); color: var(--text); }
.btn.ghost:hover { background: #2a2f3a; }
.btn.danger { background: transparent; color: var(--danger); box-shadow: inset 0 0 0 1px var(--danger); }
.btn.danger:hover { background: rgba(226, 85, 85, .12); }
.btn.discord { background: #5865f2; }
.btn.discord:hover { background: #4853d8; }

.chip {
  display: inline-flex;
  align-items: center;
  padding: .25rem .6rem;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: .85rem;
}

/* ---- forms ---- */
input[type="text"] {
  flex: 1 1 260px;
  min-width: 0;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: .55rem .75rem;
  font: inherit;
}
input[type="text"]:focus { outline: 2px solid var(--accent); border-color: transparent; }

.row { display: flex; gap: .6rem; align-items: center; }
.row.wrap { flex-wrap: wrap; }

/* ---- cards ---- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.card.center { text-align: center; max-width: 420px; margin: 12vh auto 0; }

.gallery-card .gc-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: .75rem;
}
.gallery-card .link { font-size: .85rem; word-break: break-all; }
.gallery-card .row.wrap { margin-top: .6rem; }
.gallery-card .gc-meta { font-size: .78rem; margin-top: .15rem; }
.progress { min-height: 1.2em; font-size: .9rem; margin-top: .5rem; }

/* ---- admin cover thumbnails + list / grid views ---- */
.cards.view-list { display: flex; flex-direction: column; }
.cards.view-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}
.cards.view-grid .card { margin-bottom: 0; }
.cards.view-list .gallery-card { display: flex; gap: 1rem; align-items: flex-start; }
.cards.view-grid .gallery-card { display: flex; flex-direction: column; gap: .8rem; }
.gc-body { flex: 1 1 auto; min-width: 0; }
.gc-cover {
  flex: none;
  display: block;
  overflow: hidden;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.cards.view-list .gc-cover { width: 88px; height: 88px; }
.cards.view-grid .gc-cover { width: 100%; aspect-ratio: 4 / 3; }
.gc-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gc-cover.empty { display: flex; align-items: center; justify-content: center; }
.gc-cover-empty { font-size: .72rem; text-align: center; padding: .3rem; }

/* view toggle (segmented) */
.tb-view { display: inline-flex; gap: .35rem; margin-left: auto; }
.btn.ghost.active { border-color: var(--accent); color: var(--text); }

/* ---- admin toolbar (search / sort / tag filter) ---- */
.toolbar { display: flex; flex-direction: column; gap: .6rem; margin-bottom: 1rem; }
.tb-row { display: flex; gap: .6rem; flex-wrap: wrap; }
.tb-search { flex: 1 1 220px; }
select.tb-sort {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: .55rem .75rem;
  font: inherit;
  cursor: pointer;
}
.tb-tags { display: flex; flex-wrap: wrap; gap: .4rem; }

/* ---- tags ---- */
.tag {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .2rem .55rem;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--line);
  font-size: .8rem;
  line-height: 1.4;
}
button.tag { cursor: pointer; font-family: inherit; }
button.tag:hover { color: var(--text); border-color: var(--accent); text-decoration: none; }
.tag.active { background: var(--accent); color: #fff; border-color: transparent; }
.tag.clear { color: var(--danger); border-color: transparent; background: transparent; }
.tag.suggest { border-style: dashed; }
.tag.removable { background: var(--accent); color: #fff; border-color: transparent; }
.tag-x {
  background: none;
  border: 0;
  color: #fff;
  cursor: pointer;
  font-size: .72rem;
  line-height: 1;
  padding: 0 0 0 .1rem;
}
.tag-empty { font-size: .8rem; }
.card-tags { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .7rem; }

/* ---- inline tag editor ---- */
.tag-editor {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .7rem;
  margin-bottom: .7rem;
}
.te-input-row { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .6rem; }
.te-input { flex: 1 1 200px; background: var(--panel); }
.te-chips, .te-suggest { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.te-suggest { margin-top: .5rem; }
.te-label { font-size: .78rem; width: 100%; }

/* ---- gallery grid ---- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: .75rem;
}
@media (min-width: 700px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}
.tile {
  margin: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.tile .thumb {
  display: block;
  aspect-ratio: 1 / 1;
  background: #0b0d11;
}
.tile .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile figcaption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .45rem .6rem;
  font-size: .8rem;
}
.tile .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.tile .dl { font-size: 1rem; }
.empty { padding: 3rem 0; text-align: center; }

/* ---- lightbox ---- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: env(safe-area-inset-top) 1rem 1rem;
}
.lightbox[hidden] { display: none; }
.lb-img { max-width: 96vw; max-height: 82vh; object-fit: contain; border-radius: 6px; }
.lb-btn {
  position: absolute;
  background: rgba(255, 255, 255, .1);
  color: #fff;
  border: 0;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lb-btn:hover { background: rgba(255, 255, 255, .22); }
.lb-close { top: 1rem; right: 1rem; }
.lb-prev { left: 1rem; top: 50%; transform: translateY(-50%); }
.lb-next { right: 1rem; top: 50%; transform: translateY(-50%); }
.lb-dl { position: absolute; bottom: 1.25rem; left: 50%; transform: translateX(-50%); }
@media (max-width: 560px) {
  .lb-prev { left: .25rem; }
  .lb-next { right: .25rem; }
}

/* ---- gallery viewer: in-place admin bar ---- */
.admin-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  padding: .7rem clamp(1rem, 4vw, 2rem);
  background: rgba(31, 35, 44, .96);
  border-bottom: 2px solid var(--accent);
  backdrop-filter: blur(8px);
}
.admin-bar .ga-actions { gap: .5rem; }
.admin-bar .ga-tags { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.admin-bar .ga-tags-label { font-size: .82rem; }
.admin-bar .ga-progress { min-height: 1.1em; font-size: .9rem; }

/* per-image delete button on the viewer tiles */
.tile { position: relative; }
.img-del {
  position: absolute;
  top: .35rem;
  right: .35rem;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 0;
  background: rgba(226, 85, 85, .92);
  color: #fff;
  font-size: .78rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}
.img-del:hover { background: var(--danger); }

/* ---- clickable gallery title + image-count badge ---- */
.gc-title { color: var(--text); }
.gc-title:hover { color: var(--accent); text-decoration: none; }
.count-badge {
  display: inline-flex;
  align-items: baseline;
  gap: .3rem;
  padding: .3rem .6rem;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.count-num { font-size: 1rem; font-weight: 700; color: var(--text); }
.count-unit { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

/* ---- upload progress modal (fixed, blocks the page while uploading) ---- */
.upmodal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, .6);
  backdrop-filter: blur(2px);
}
.upmodal.is-active { display: flex; }
.upmodal-card {
  width: min(92vw, 360px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.3rem;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
.upmodal-card h3 { margin-bottom: .4rem; }
.upbar-track {
  height: 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  overflow: hidden;
  margin: .9rem 0;
}
.upbar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width .18s ease-out;
}
.upmodal-text {
  font-size: .85rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  margin-bottom: 1rem;
}
@media (max-width: 560px) {
  .upmodal-text { font-size: .8rem; }
}
