/* ============================================================
   Random Art — gallery wall aesthetic
   Theme colours are injected per-artwork via CSS custom props
   ============================================================ */

:root {
  --bg: #14110d;
  --bg2: #1c1813;
  --ink: #efe9dd;
  --ink-dim: #b3a890;
  --accent: #a9803e;
  --accent-soft: rgba(255, 255, 255, 0.14);
  --serif: "Georgia", "Iowan Old Style", "Times New Roman", serif;
  --sans: "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
  --ease: cubic-bezier(.22,.61,.36,1);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--serif);
  color: var(--ink);
  background:
    radial-gradient(120% 90% at 18% 8%, var(--bg2) 0%, transparent 60%),
    var(--bg);
  overflow: hidden;
  transition: background 1.2s var(--ease);
}

#app { height: 100dvh; display: flex; flex-direction: column; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 1.2rem;
  padding: .8rem 1.4rem;
  background: linear-gradient(to bottom, rgba(0,0,0,.42), transparent);
  position: relative; z-index: 30;
}
.brand { display: flex; align-items: center; gap: .55rem; text-decoration: none; color: var(--ink); }
.brand-mark {
  width: 13px; height: 13px; border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(255,255,255,.07);
  transform: rotate(45deg);
}
.brand-name { font-family: var(--serif); letter-spacing: .04em; font-size: 1.02rem; }
.brand-name em { font-style: italic; opacity: .75; }
.brand:hover .brand-mark { transform: rotate(0deg); }
.brand-mark { transition: transform .5s var(--ease); }

.catnav { display: flex; gap: .1rem; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
.catnav button {
  background: none; border: 0; color: var(--ink-dim);
  font-family: var(--sans); font-size: .74rem; letter-spacing: .14em; text-transform: uppercase;
  padding: .42rem .6rem; cursor: pointer; border-radius: 99px;
  transition: color .25s, background .25s;
}
.catnav button:hover { color: var(--ink); background: rgba(255,255,255,.06); }
.catnav button.active { color: var(--ink); background: rgba(255,255,255,.1); }

.btn-refresh, .btn-refine {
  display: inline-flex; align-items: center; gap: .45rem;
  background: rgba(255,255,255,.08); color: var(--ink);
  border: 1px solid rgba(255,255,255,.16);
  font-family: var(--sans); font-size: .76rem; letter-spacing: .1em; text-transform: uppercase;
  padding: .5rem .9rem; border-radius: 99px; cursor: pointer;
  transition: background .25s, transform .25s var(--ease), border-color .25s;
  backdrop-filter: blur(6px);
}
.btn-refresh { margin-left: auto; }
.catnav + .btn-refresh { margin-left: .6rem; }
.btn-refresh:hover, .btn-refine:hover { background: rgba(255,255,255,.16); transform: translateY(-1px); }
.btn-refresh:active, .btn-refine:active { transform: translateY(0); }
.btn-refresh[disabled], .btn-refine[disabled] { opacity: .45; pointer-events: none; }

/* ---------- stage / wall ---------- */
.stage { flex: 1; min-height: 0; position: relative; }
.wall {
  position: absolute; inset: 0;
  display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(300px, 460px);
  gap: 0;
}
.figure-wrap {
  display: flex; align-items: center; justify-content: center;
  padding: clamp(1rem, 3.4vh, 2.6rem) clamp(1rem, 3vw, 3rem);
  min-height: 0; min-width: 0;
  position: relative;                 /* anchors the refine dock */
}
.figure {
  margin: 0; max-height: 100%; display: flex; flex-direction: column; align-items: center;
  max-width: 100%;
  animation: rise .9s var(--ease) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(26px) scale(.985); } }

.frame {
  position: relative; max-height: calc(100dvh - 220px); max-width: 100%;
  background: #fff; padding: clamp(10px, 1.4vw, 18px);
  border-radius: 2px;
  box-shadow:
    0 1px 2px rgba(0,0,0,.4),
    0 12px 32px rgba(0,0,0,.5),
    0 40px 90px -20px rgba(0,0,0,.65),
    inset 0 0 0 1px rgba(0,0,0,.08);
  transition: box-shadow .8s;
}
.frame::before {  /* subtle bezel */
  content: ""; position: absolute; inset: 0; border-radius: 2px; pointer-events: none;
  background: linear-gradient(135deg, rgba(255,255,255,.5), rgba(255,255,255,0) 40%, rgba(0,0,0,.12));
  mix-blend-mode: overlay; opacity: .5;
}
.frame img {
  display: block; max-height: calc(100dvh - 250px); max-width: 100%;
  width: auto; height: auto;
  filter: saturate(1.04) contrast(1.03);
}
.sheen {
  position: absolute; inset: 0; pointer-events: none; opacity: .5;
  background: linear-gradient(115deg, rgba(255,255,255,.1) 0%, rgba(255,255,255,0) 28%, rgba(0,0,0,.06) 88%);
}
.plate {
  margin-top: .85rem; text-align: center;
  font-family: var(--sans); font-size: .68rem; letter-spacing: .16em; text-transform: uppercase;
  color: var(--ink-dim);
}
.plate b { color: var(--ink); font-weight: 500; }

/* ---------- info panel ---------- */
.panel {
  display: flex; flex-direction: column; min-height: 0;
  background: linear-gradient(to left, rgba(8,6,4,.55), rgba(8,6,4,.28));
  backdrop-filter: blur(18px) saturate(1.1);
  border-left: 1px solid rgba(255,255,255,.08);
  animation: slidein .9s var(--ease) both;
}
@keyframes slidein { from { opacity: 0; transform: translateX(34px); } }
.panel-scroll { overflow-y: auto; padding: 2.2rem 2rem 1.4rem; flex: 1; scrollbar-width: thin; }
.kicker {
  font-family: var(--sans); font-size: .68rem; letter-spacing: .32em; text-transform: uppercase;
  color: var(--accent); margin: 0 0 1rem;
}
.artwork-title {
  font-size: clamp(1.5rem, 2.6vw, 2.15rem); line-height: 1.16; font-weight: 500;
  margin: 0 0 .35rem; font-style: italic; letter-spacing: .005em;
}
.byline { margin: 0; color: var(--ink-dim); font-size: .98rem; }
.byline span { color: var(--ink); }
.divider { height: 1px; background: linear-gradient(to right, var(--accent), transparent 78%); margin: 1.5rem 0 1.3rem; opacity: .55; }
.artist-head { font-size: 1.02rem; margin: 0 0 .5rem; letter-spacing: .01em; }
.artist-bio { margin: 0; font-size: .93rem; line-height: 1.68; color: color-mix(in srgb, var(--ink) 84%, transparent); }

.meta { display: flex; flex-wrap: wrap; gap: .45rem; margin: 1.4rem 0 1.1rem; }
.meta span {
  font-family: var(--sans); font-size: .67rem; letter-spacing: .12em; text-transform: uppercase;
  padding: .3rem .62rem; border: 1px solid rgba(255,255,255,.18); border-radius: 99px; color: var(--ink-dim);
}
.meta span b { color: var(--ink); font-weight: 500; }

.work-info { font-size: .88rem; line-height: 1.62; color: color-mix(in srgb, var(--ink) 78%, transparent); }
.work-info dt {
  font-family: var(--sans); font-size: .63rem; letter-spacing: .22em; text-transform: uppercase;
  color: var(--accent); opacity: .85; margin: .95rem 0 .18rem;
}
.work-info dd { margin: 0; }

.panel-foot {
  display: flex; align-items: center; gap: 1rem;
  padding: .85rem 2rem; border-top: 1px solid rgba(255,255,255,.08);
  font-family: var(--sans); font-size: .7rem; letter-spacing: .08em;
}
.swatches { display: flex; gap: .3rem; }
.swatches i {
  width: 13px; height: 13px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,.25);
  transition: transform .25s var(--ease);
}
.swatches i:hover { transform: scale(1.35); }
.museum-link { margin-left: auto; color: var(--ink-dim); text-decoration: none; letter-spacing: .08em; }
.museum-link:hover { color: var(--accent); }

/* ---------- refine dock ---------- */
/* lives on the artwork wall, bottom-left of the figure — subtle */
.refine { position: absolute; left: 1.6rem; bottom: 1.25rem; z-index: 40; }
.btn-refine {
  padding: .4rem .8rem;
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  border-color: rgba(255,255,255,.14);
  color: var(--ink-dim);
  font-weight: 500;
}
.btn-refine:hover {
  background: color-mix(in srgb, var(--accent) 78%, transparent);
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  color: #100d09;
}
.btn-refine svg { width: 12px; height: 12px; }
.refine-hint { opacity: .55; font-size: .6rem; letter-spacing: .12em; margin-left: .25rem; }

/* ---------- loading ---------- */
/* Slim top progress rail — visible on every load/refine, tinted by the
   current artwork theme via --accent. Phases: indeterminate sweep while
   fetching, then completes as metadata+image arrive. */
.progress {
  position: fixed; top: 0; left: 0; right: 0; height: 3px;
  z-index: 60; pointer-events: none;
  background: transparent;
  opacity: 0; transition: opacity .3s var(--ease);
}
.progress.on { opacity: 1; }
.progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(to right, var(--accent), color-mix(in srgb, var(--accent) 55%, white));
  box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 60%, transparent);
  transition: width .25s var(--ease);
}
.progress.indeterminate .progress-fill {
  width: 30% !important;
  animation: rail-slide 1.15s var(--ease) infinite;
}
@keyframes rail-slide {
  0%   { transform: translateX(-100%); }
  55%  { transform: translateX(180%); }
  100% { transform: translateX(290%); }
}
.progress.failed .progress-fill {
  background: #c0392b;
  box-shadow: 0 0 12px rgba(192, 57, 43, .5);
}
/* full-width bar inside the first-load overlay */
.loading-bar {
  width: 220px; height: 2px; overflow: hidden;
  background: color-mix(in srgb, var(--ink) 18%, transparent);
  border-radius: 99px;
}
.loading-bar .js-fill {
  display: block; height: 100%; width: 0%;
  background: var(--accent);
  transition: width .3s var(--ease);
  animation: bar-slide 1.15s var(--ease) infinite; /* always sweeping */
}
.loading-bar.indeterminate .js-fill,
.progress.indeterminate .loading-bar-sync .js-fill {
  width: 30% !important;
  animation: bar-slide 1.15s var(--ease) infinite;
}
@keyframes bar-slide {
  0%   { transform: translateX(-110%); }
  100% { transform: translateX(430%); }
}

/* gallery shimmer: sweeps across the frame while an image is on its way */
.frame-loading {
  position: relative; overflow: hidden;
}
.frame-loading::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(
    105deg,
    transparent 38%,
    color-mix(in srgb, var(--accent) 16%, transparent) 48%,
    color-mix(in srgb, var(--accent) 26%, transparent) 52%,
    transparent 62%
  );
  transform: translateX(-70%);
  animation: sheen-sweep 1.4s var(--ease) infinite;
  pointer-events: none;
}
@keyframes sheen-sweep { to { transform: translateX(70%); } }

@media (prefers-reduced-motion: reduce) {
  .progress-fill,
  .progress.indeterminate .progress-fill,
  .loading-bar .js-fill,
  .frame-loading::after {
    animation: none !important;
  }
  .progress.indeterminate .progress-fill,
  .loading-bar .js-fill { width: 100% !important; opacity: .5; }
  .progress { transition: none; }
}
/* dim existing artwork while the next one is on its way */
.frame-loading #art-img { opacity: .35; transition: opacity .45s var(--ease); }
#art-img { transition: opacity .45s var(--ease); }

.loading {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg); z-index: 60; transition: opacity .7s, visibility .6s;
}
.loading.hidden { opacity: 0; visibility: hidden; }
.loading-inner { display: flex; flex-direction: column; align-items: center; gap: 1rem; }
.loading-ring {
  width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,.14); border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-word { font-family: var(--sans); font-size: .7rem; letter-spacing: .4em; text-transform: uppercase; color: var(--ink-dim); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 1.4rem; transform: translate(-50%, 20px);
  background: rgba(10,8,6,.92); color: var(--ink);
  border: 1px solid rgba(255,255,255,.14);
  font-family: var(--sans); font-size: .74rem; letter-spacing: .12em; text-transform: uppercase;
  padding: .55rem 1.1rem; border-radius: 99px;
  opacity: 0; transition: opacity .35s, transform .35s; pointer-events: none; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- transitions between artworks ---------- */
.swapping .frame, .swapping .panel-scroll { animation: swap .5s var(--ease) both; }

#art-img.crossfade-in { animation: reveal .9s var(--ease) both; }
@keyframes reveal {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes swap { from { opacity: 0; transform: translateY(14px); } }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  /* phones: single scrolling column — artwork first (fully visible, with its
     museum caption), then the info panel as a normal section below. */
  .wall {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    overflow-y: auto;                /* page scrolls, nothing overlaps */
    display: block;                  /* let it flow naturally */
  }
  .figure-wrap {
    min-height: auto;
    padding: 4.2rem 1rem 1rem;       /* room for top progress rail + air */
  }
  .frame { margin: 0 auto; }
  .frame img { max-height: 56dvh; }   /* generous artwork, no overlap */
  .panel {
    border-left: 0;
    border-top: 1px solid rgba(255,255,255,.1);
    max-height: none;                /* grows with content — no clipping */
    background: linear-gradient(to bottom, rgba(8,6,4,.55), rgba(8,6,4,.18));
    backdrop-filter: blur(18px);
  }
  .panel-scroll { overflow: visible; }
  /* dock sits on the artwork (absolute inside figure-wrap) — bottom-left,
     scrolls away with the artwork so it never covers the info panel */
  .refine { left: 1rem; right: auto; bottom: .9rem; z-index: 50; }
  .btn-refine .refine-hint { display: none; }
  .btn-refine { padding: .38rem .62rem; }
}
@media (max-width: 620px) {
  .catnav { display: none; }
  .panel-scroll { padding: 1.4rem 1.2rem; }
  .panel-foot { padding: .8rem 1.2rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}