:root {
  --bg: #efece4;
  --paper: #f7f3ea;
  --paper-light: #fdfcf8;
  --ink: #111;
  --ink-soft: #444;
  --ink-mute: #777;
  --rule: rgba(0,0,0,0.15);
  --accent: #b85420;
  --veil: rgba(20,15,10,0.7);
  --chip-bg: #fff;
  --tile-placeholder: #d9d4c4;
  --gutter: 3px;
}

:root.dark {
  --bg: #16110d;
  --paper: #1f1a14;
  --paper-light: #2a221c;
  --ink: #efece4;
  --ink-soft: #c8c0b3;
  --ink-mute: #8a8175;
  --rule: rgba(255,255,255,0.13);
  --accent: #e07a40;
  --veil: rgba(0,0,0,0.82);
  --chip-bg: #2a221c;
  --tile-placeholder: #2a221c;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.4;
}

a { color: var(--accent); }
a:hover { text-decoration: underline; }

/* ---------- header ---------- */

/* Header + filter bar share one sticky parent so they always move as a unit. */
.site-top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
}

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 14px 20px;
  border-bottom: 1px solid var(--ink);
}

.site-title {
  margin: 0;
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 900;
  font-size: 22px;
  letter-spacing: -0.01em;
}

.site-count {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-mute);
}

.site-header-right {
  display: flex;
  align-items: baseline;
  gap: 14px;
}

.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 4px 8px;
  color: var(--ink);
  border-radius: 3px;
}
.theme-toggle:hover { background: var(--paper-light); }

/* ---------- filter bar ---------- */

.filter-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 20px;
  background: var(--paper-light);
  border-bottom: 1px solid var(--rule);
}

/* Sits in the same sticky slot as .filter-bar but only when viewing an artist page.
   Filter controls don't apply to a single-artist view, so we swap them for the
   back-to-gallery action instead. */
.artist-bar {
  display: flex;
  align-items: center;
  padding: 10px 20px;
  background: var(--paper-light);
  border-bottom: 1px solid var(--rule);
}

.artist-bar-back {
  display: inline-block;
  padding: 6px 14px;
  font-size: 12px;
  color: var(--ink);
  text-decoration: none;
  border: 1px solid var(--rule);
  border-radius: 3px;
}
.artist-bar-back:hover { border-color: var(--ink); text-decoration: none; }

.filter-search {
  flex: 0 1 280px;
  background: var(--chip-bg);
  color: var(--ink);
  border: 1px solid var(--rule);
  padding: 6px 10px;
  font: inherit;
  border-radius: 3px;
}

.filter-search:focus { outline: 1.5px solid var(--accent); border-color: var(--accent); }

.filter-chips {
  display: flex;
  gap: 6px;
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;  /* prevent horizontal-scrollbar from also enabling vertical scroll & clipping chips */
  scrollbar-width: thin;
  padding-bottom: 2px;  /* breathing room so horizontal scrollbar doesn't crowd chips */
}

/* ---------- footer ---------- */

.site-footer {
  margin-top: 60px;
  padding: 20px;
  border-top: 1px solid var(--rule);
  font-size: 11px;
  color: var(--ink-mute);
}

.site-footer em { font-style: italic; }

/* ---------- grid (masonry) ---------- */

.grid {
  column-count: 5;
  column-gap: var(--gutter);
  padding: var(--gutter);
}

@media (max-width: 1099px) { .grid { column-count: 3; } }
@media (max-width: 699px)  { .grid { column-count: 2; } }

.tile {
  position: relative;
  display: block;
  break-inside: avoid;
  margin-bottom: var(--gutter);
  overflow: hidden;
  cursor: pointer;
  background: var(--tile-placeholder);  /* placeholder color until image loads */
}

.tile img {
  display: block;
  width: 100%;
  height: auto;
}

.tile-num {
  position: absolute;
  top: 5px;
  left: 7px;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  mix-blend-mode: difference;
  z-index: 2;
  pointer-events: none;
}

.tile-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 10px 12px;
  background: linear-gradient(180deg, rgba(0,0,0,0) 40%, rgba(0,0,0,0.85) 100%);
  color: #fff;
  opacity: 0;
  transition: opacity 150ms ease-out;
  pointer-events: none;
}

.tile:hover .tile-overlay { opacity: 1; }

.tile-overlay b { display: block; font-size: 12px; margin-bottom: 2px; }
.tile-overlay span { font-size: 10px; opacity: 0.85; }

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

.lightbox {
  position: fixed;
  inset: 0;
  background: var(--veil);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  z-index: 100;
  animation: lb-fade 200ms ease-out;
}

@keyframes lb-fade { from { opacity: 0; } to { opacity: 1; } }

.lb-box {
  background: var(--paper);
  width: min(1100px, 100%);
  height: 100%;
  max-height: 80vh;
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  grid-template-rows: 1fr;
  border-radius: 4px;
  overflow: hidden;
  position: relative;
  box-shadow: 0 12px 50px rgba(0,0,0,0.5);
}

.lb-close {
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  background: none;
  border: none;
  color: var(--ink);
  z-index: 5;
}

.lb-img {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--paper);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.lb-img img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.lb-meta {
  padding: 24px 26px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
}

.lb-num   { font-size: 11px; letter-spacing: 0.12em; color: var(--ink-mute); text-transform: uppercase; }
.lb-title { font-family: 'Playfair Display', Georgia, serif; font-size: 22px; font-weight: 700; font-style: italic; line-height: 1.15; }
.lb-artist { display: flex; align-items: center; gap: 10px; }
.lb-artist-text { min-width: 0; }
.lb-artist a { font-size: 14px; font-weight: 700; color: var(--ink); }
.lb-artist a:hover { color: var(--accent); }
.lb-artist-photo-link { flex-shrink: 0; line-height: 0; }
.lb-artist-photo {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg);
  border: 1px solid var(--rule);
  display: block;
}
.lb-rule  { border-top: 1px solid var(--rule); margin: 4px 0; }
/* Two-column grid: fixed-width label, value flows left-aligned next to it.
   Avoids both the no-gap crowding and the giant gap that space-between produced. */
.lb-row   { display: grid; grid-template-columns: 70px 1fr; column-gap: 12px; font-size: 12px; align-items: baseline; }
.lb-row span:first-child { color: var(--ink-mute); text-transform: uppercase; letter-spacing: 0.06em; }
.lb-price { font-size: 18px; font-weight: 700; color: var(--accent); }
.lb-nfs   { font-size: 14px; font-style: italic; color: var(--ink-mute); }
.lb-link  { font-size: 12px; color: var(--accent); }
.lb-nav   { margin-top: auto; padding-top: 12px; display: flex; gap: 14px; align-items: center; font-size: 13px; }
.lb-nav button { background: none; border: 1px solid var(--rule); padding: 6px 12px; cursor: pointer; font: inherit; border-radius: 3px; color: var(--ink); }
.lb-nav button:hover { border-color: var(--ink); }
.lb-nav button:disabled { opacity: 0.4; cursor: not-allowed; }
.lb-share { margin-left: auto; }

@media (max-width: 699px) {
  .lightbox { padding: 0; }
  .lb-box { max-height: 100vh; grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  /* Cap the image to ~70% of the viewport so a tall artwork can't squeeze the
     info panel down to a sliver, especially on landscape phones. The meta panel
     gets a guaranteed floor and scrolls internally if content overflows. */
  .lb-img { padding: 8px; max-height: 70vh; }
  .lb-meta { padding: 14px 16px; min-height: 25vh; }
}

/* ---------- filter chips ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--chip-bg);
  color: var(--ink);
  border: 1px solid var(--ink);
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  white-space: nowrap;
  cursor: pointer;
  position: relative;
}

.chip:hover { background: var(--paper-light); }

.chip.active { background: var(--ink); color: var(--bg); }
.chip.active:hover { background: var(--ink-soft); }

.chip-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 2px;
  padding: 4px 6px;
  font-size: 14px;
  line-height: 1;
  border-radius: 50%;
}
.chip-x:hover { background: rgba(0,0,0,0.12); }
.chip.active .chip-x:hover { background: rgba(255,255,255,0.2); }

.chip-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 180px;
  background: var(--chip-bg);
  color: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  padding: 6px 0;
  z-index: 20;
}

.chip-menu label, .chip-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  background: none;
  border: none;
  font: inherit;
  color: var(--ink);
}
.chip-menu label:hover, .chip-menu button:hover { background: var(--paper-light); }

.chip-menu input[type="checkbox"] { margin-right: 6px; }
.chip-menu .chip-menu-clear { color: var(--accent); border-top: 1px solid var(--rule); margin-top: 4px; padding-top: 8px; }

.chip-reset {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
  margin-left: 4px;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  white-space: nowrap;
}
.chip-reset:hover { color: var(--ink); }

/* ---------- artist page ---------- */

.artist-view {
  padding: 0 0 40px;
}

.artist-header {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 24px 20px;
  border-bottom: 1px solid var(--ink);
  background: var(--paper-light);
}

.artist-photo {
  width: 110px;
  height: 110px;
  object-fit: cover;
  background: var(--bg);
  flex-shrink: 0;
}

.artist-photo-placeholder {
  width: 110px;
  height: 110px;
  background: var(--bg);
  border: 1px dashed var(--rule);
}

.artist-info { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.artist-name { font-family: 'Playfair Display', Georgia, serif; font-size: 28px; font-weight: 900; line-height: 1.1; }
.artist-org  { font-size: 13px; color: var(--ink-mute); }
.artist-meta { display: flex; gap: 14px; font-size: 12px; align-items: center; }

/* ---------- about overlay ---------- */

.about-overlay {
  position: fixed;
  inset: 0;
  background: var(--veil);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  z-index: 100;
}

.about-box {
  background: var(--paper);
  max-width: 640px;
  width: 100%;
  padding: 28px 32px;
  border-radius: 4px;
  position: relative;
  font-size: 14px;
  line-height: 1.55;
}

.about-box h2 { font-family: 'Playfair Display', Georgia, serif; margin: 0 0 12px; }
.about-box p  { margin: 0 0 12px; }
.about-box .about-close { position: absolute; top: 8px; right: 12px; font-size: 22px; cursor: pointer; background: none; border: none; color: var(--ink); }

/* ---------- mobile ---------- */

@media (max-width: 699px) {
  .site-header { padding: 10px 14px; }
  .site-title  { font-size: 18px; }
  .site-count  { font-size: 10px; }

  .filter-bar { padding: 8px 14px; gap: 6px; }
  .filter-search { flex: 0 1 140px; padding: 5px 8px; font-size: 12px; }

  /* On mobile, wrap chips onto multiple rows instead of a horizontal scroll —
     all filter options should be visible at a glance on a small screen. */
  .filter-chips {
    flex-wrap: wrap;
    overflow: visible;
    padding-bottom: 0;
  }
  .filter-bar { align-items: flex-start; }
  .chip { font-size: 10px; padding: 4px 8px; }
}

/* Touch devices: show tile overlay on tap (first tap), then a second tap opens. */
@media (pointer: coarse) {
  .tile.touched .tile-overlay { opacity: 1; }
  /* Fullscreen API on a plain <img> doesn't work on iOS Safari and is unreliable
     on Android — hide the button on touch to avoid a non-functional control. */
  .lb-nav button[data-nav="fullscreen"] { display: none; }
}

/* Lightbox nav button disabled state (cleanup from Task 11 review) */
.lb-nav button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

