/* Commons Wall — Pinterest-like styling. */
:root {
  --bg: #ffffff;
  --fg: #211922;
  --muted: #767676;
  --pill: #f1f1f1;
  --pill-focus: #e9e9e9;
  --card-radius: 16px;
  --accent: #006699; /* Wikimedia blue-ish */
  --overlay: rgba(0, 0, 0, 0.6);
  --panel: #ffffff;
  --border: #e2e2e2;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --fg: #efefef;
    --muted: #9a9a9a;
    --pill: #2a2a2a;
    --pill-focus: #333333;
    --overlay: rgba(0, 0, 0, 0.75);
    --panel: #1e1e1e;
    --border: #3a3a3a;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ---- Header -------------------------------------------------------------- */
#topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  background: var(--bg);
}
#brand {
  font-size: 19px;
  font-weight: 800;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}
#brand span { color: var(--fg); }

#searchbox { position: relative; flex: 1; }
#search-input {
  width: 100%;
  padding: 11px 18px;
  border: none;
  border-radius: 24px;
  background: var(--pill);
  color: var(--fg);
  font: inherit;
  outline: none;
}
#search-input:focus { background: var(--pill-focus); box-shadow: 0 0 0 3px rgba(0, 102, 153, 0.35); }

/* ---- Hamburger menu ------------------------------------------------------- */
#menu { position: relative; }
#menu-btn {
  padding: 10px 14px;
  border: none;
  border-radius: 22px;
  background: var(--pill);
  color: var(--fg);
  font: inherit;
  font-size: 17px;
  line-height: 1.2;
  cursor: pointer;
}
#menu-btn:hover { background: var(--pill-focus); }
#menu-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 236px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  z-index: 30;
}

#auth-btn {
  padding: 10px 16px;
  border: none;
  border-radius: 22px;
  background: var(--pill);
  color: var(--fg);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
#auth-btn:hover:not(:disabled) { background: var(--pill-focus); }
#auth-btn:disabled { cursor: default; opacity: 0.8; }

#menu-qr {
  display: block;
  padding: 8px;
  border: none;
  border-radius: 10px;
  background: var(--pill);
  color: var(--muted);
  font: inherit;
  cursor: zoom-in;
}
#menu-qr:hover { background: var(--pill-focus); }
#menu-qr-code svg { display: block; width: 100%; height: auto; border-radius: 6px; }
#menu-qr-hint {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  text-align: center;
}

#menu-about {
  padding: 10px 16px;
  border: none;
  border-radius: 22px;
  background: var(--pill);
  color: var(--fg);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
#menu-about:hover { background: var(--pill-focus); }

#qr-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: var(--overlay);
  cursor: zoom-out;
}
#qr-overlay-code svg {
  display: block;
  width: min(82vmin, 560px);
  height: auto;
  border-radius: 14px;
}
#qr-overlay-url {
  max-width: 84vw;
  color: #fff;
  font-size: 13px;
  text-align: center;
  overflow-wrap: anywhere;
}

/* ---- About overlay -------------------------------------------------------- */
#about-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--overlay);
}
#about-card {
  position: relative;
  max-width: 440px;
  max-height: 84vh;
  overflow-y: auto;
  padding: 22px 26px;
  background: var(--panel);
  border-radius: 16px;
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.3);
}
#about-card h2 { margin: 0 24px 10px 0; font-size: 20px; }
#about-beta {
  vertical-align: 2px;
  margin-left: 2px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
#about-card h3 {
  margin: 16px 0 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
#about-card p { margin: 8px 0; }
#about-card a { color: var(--accent); }
.about-links { margin: 0; padding-left: 20px; }
.about-links li { margin: 4px 0; }
#about-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: var(--pill);
  color: var(--fg);
  font: inherit;
  cursor: pointer;
}
#about-close:hover { background: var(--pill-focus); }

/* ---- Suggestion dropdown ------------------------------------------------- */
#suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  padding: 6px;
}
.sug-section {
  padding: 8px 12px 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.sug-row {
  padding: 9px 12px;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sug-row:hover, .sug-row.active { background: var(--pill); }
.sug-desc { color: var(--muted); font-size: 13px; }

/* ---- Chip (active feed) + sort toggle ------------------------------------ */
#chipbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 2px 16px 8px;
}
#sort-toggle {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: 18px;
  background: var(--pill);
}
.sort-pill {
  border: none;
  padding: 5px 12px;
  border-radius: 15px;
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.sort-pill:hover { background: var(--pill-focus); }
.sort-pill.active { background: var(--accent); color: #fff; }
#chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px 7px 14px;
  border-radius: 18px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
}
#chip-link {
  color: #fff;
  opacity: 0.75;
  text-decoration: none;
  font-size: 13px;
  line-height: 1;
}
#chip-link:hover { opacity: 1; }
#chip-clear {
  border: none;
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
}
#chip-clear:hover { background: rgba(255, 255, 255, 0.4); }

/* ---- Wall ---------------------------------------------------------------- */
main { padding: 4px 16px 40px; }
#wall { position: relative; width: 100%; }
.card {
  position: absolute;
  top: 0;
  left: 0;
  border-radius: var(--card-radius);
  overflow: hidden;
  cursor: zoom-in;
  background: var(--pill);
}
.card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;               /* placeholder shows until the queue loads it */
  transition: opacity 0.25s;
}
.card img.img-loaded { opacity: 1; }
.card.img-failed { cursor: default; }
.card-title {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 18px 10px 8px;
  font-size: 12px;
  color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.65));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transition: opacity 0.15s;
}
.card:hover .card-title { opacity: 1; }

/* Category-nav blocks — image-sized cards listing sub/parent categories. */
.card-cat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px;
  background: var(--pill);
  border: 1px solid var(--border);
  cursor: default;
  overflow: hidden;
}
.card-cat-kicker {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 2px 8px 4px;
}
.card-cat-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  border: none;
  background: transparent;
  text-align: left;
  padding: 6px 8px;
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
}
.card-cat-name {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-cat-count {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}
.card-cat-row:hover { background: var(--pill-focus); }
.card-cat-row.card-cat-parent { color: var(--muted); }

/* Inline add-depicts/category editor — a card that steals wall tiles. */
.card-editor {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: var(--panel);
  border: 2px solid var(--accent);
  cursor: default;
  z-index: 2;
}
.card-editor-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 14px;
}
.ed-close {
  border: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--pill);
  color: var(--fg);
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
}
.ed-close:hover { background: var(--pill-focus); }
.card-editor input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--pill);
  color: var(--fg);
  font: inherit;
  font-size: 14px;
}
.ed-sugs {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.ed-row {
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.35;
  cursor: pointer;
}
.ed-row:hover { background: var(--pill-focus); }
.ed-row.ed-disabled { opacity: 0.55; cursor: default; }
.ed-row.ed-disabled:hover { background: transparent; }
.ed-row.ed-saving { opacity: 0.5; pointer-events: none; }
.ed-have { color: var(--muted); font-size: 11px; }
.ed-done { display: flex; flex-wrap: wrap; gap: 4px; }
.ed-added { background: var(--accent); color: #fff; cursor: default; }

.rel-add {
  border: none;
  margin-left: 6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--pill);
  color: var(--fg);
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  vertical-align: text-bottom;
}
.rel-add:hover { background: var(--accent); color: #fff; }

#sentinel { height: 1px; }
#load-more {
  display: block;
  margin: 24px auto;
  padding: 11px 24px;
  border: none;
  border-radius: 22px;
  background: var(--pill);
  color: var(--fg);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
#load-more:hover { background: var(--pill-focus); }
#feed-status {
  text-align: center;
  color: var(--muted);
  padding: 24px 0;
}

/* ---- Status toast -------------------------------------------------------- */
#status {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  padding: 10px 18px;
  border-radius: 20px;
  background: var(--fg);
  color: var(--bg);
  font-size: 14px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.25);
  max-width: 90vw;
}

/* ---- Closeup (Pinterest-style pin page) ---------------------------------- */
/* One big rounded tile at the top of the page; the "More to explore" wall
   below it is the regular feed, restarted on the image's first category. */
#closeup {
  position: relative;
  max-width: 1016px;
  margin: 6px auto 4px;
}
#closeup-back {
  position: absolute;
  left: -60px;
  top: 10px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--fg);
  font-size: 22px;
  cursor: pointer;
}
#closeup-back:hover { background: var(--pill); }
#closeup-card {
  display: flex;
  min-height: 320px;
  background: var(--panel);
  border-radius: 32px;
  overflow: hidden;
  box-shadow: 0 2px 24px rgba(0, 0, 0, 0.18);
  border: 1px solid var(--border);
}
#closeup-figure {
  margin: 0;
  flex: 1 1 60%;
  min-width: 0;
  background: var(--pill);
  display: flex;
  align-items: center;
  justify-content: center;
}
#closeup-img {
  display: block;
  width: 100%;
  max-height: 80vh;
  object-fit: contain;
}
#closeup-meta {
  flex: 0 0 380px;
  padding: 28px 28px 22px;
  max-height: 80vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#closeup-title { margin: 0 0 6px; font-size: 24px; font-weight: 700; line-height: 1.25; }
#closeup-more {
  text-align: center;
  font-size: 17px;
  font-weight: 700;
  margin: 26px 0 2px;
}
.det-field { font-size: 14px; }
.det-label { font-weight: 700; color: var(--muted); margin-right: 4px; }
.det-desc { color: var(--muted); }
.det-loading { color: var(--muted); }
#closeup-related { display: flex; flex-direction: column; gap: 6px; }
.rel-title {
  margin-top: 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.rel-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.rel-chip {
  border: none;
  padding: 6px 12px;
  border-radius: 15px;
  background: var(--pill);
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rel-chip:hover { background: var(--pill-focus); }
.rel-depicts { background: var(--accent); color: #fff; }
.rel-depicts:hover { background: #005580; }
.rel-ext {
  display: inline-block;
  color: var(--muted);
  text-decoration: none;
  border: 1px dashed var(--border);
  background: transparent;
}
.rel-ext:hover { color: var(--fg); }
#closeup-more .more-ext {
  color: var(--muted);
  text-decoration: none;
  font-size: 15px;
}
#closeup-more .more-ext:hover { color: var(--accent); }

#closeup-commons {
  margin-top: auto;
  padding: 10px 16px;
  border-radius: 20px;
  background: var(--accent);
  color: #fff;
  text-align: center;
  text-decoration: none;
  font-weight: 700;
}

@media (max-width: 1160px) {
  #closeup-back { position: static; margin-bottom: 6px; }
}
@media (max-width: 900px) {
  #closeup-card { flex-direction: column; border-radius: 24px; }
  #closeup-figure { flex: 0 1 auto; }
  #closeup-img { max-height: 55vh; }
  #closeup-meta { flex: 1 1 auto; max-height: none; padding: 18px 20px 16px; }
}
@media (max-width: 720px) {
  #brand span { display: none; }
}
