:root {
  --bg: #12100e;
  --bg-2: #1a1714;
  --ink: #e8dcc4;
  --muted: #8a7f70;
  --line: rgba(232, 220, 196, 0.12);
  --rust: #c45c26;
  --sage: #7d9a6f;
  --danger: #b54a3c;
  --serif: "Instrument Serif", "Times New Roman", serif;
  --sans: "IBM Plex Sans", "PingFang SC", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--sans);
  background: radial-gradient(1200px 600px at 10% -10%, #2a221c 0%, var(--bg) 55%);
  color: var(--ink);
}

.grain {
  pointer-events: none;
  position: fixed;
  inset: 0;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.9'/%3E%3C/svg%3E");
  z-index: 8;
}

.top {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  padding: 28px 36px 8px;
}
.brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}
.mark {
  width: 44px; height: 44px;
  border: 1px solid var(--line);
  display: grid; place-items: center;
  font-family: var(--serif);
  font-size: 18px;
  color: var(--rust);
}
h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 28px;
}
.layout {
  display: grid;
  grid-template-columns: minmax(260px, 440px) minmax(0, 1fr);
  gap: 28px;
  padding: 12px 36px 24px;
  align-items: start;
}
.viewfinder { max-width: 440px; }

.frame {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--bg-2);
  border: 1px solid var(--line);
  overflow: hidden;
}
.frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.frame img[hidden],
.frame img:not([src]) {
  display: none !important;
}
.placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--muted);
  gap: 6px;
}
.placeholder p {
  margin: 0;
  font-family: var(--serif);
  font-size: 20px;
  color: var(--ink);
  font-style: italic;
}
.frame-meta {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: space-between;
  padding: 12px 14px;
  background: linear-gradient(transparent, rgba(0,0,0,.72));
  font-size: 12px;
  letter-spacing: 0.04em;
}

.scoreboard {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 14px;
  margin-top: 14px;
  align-items: start;
}
.score-ring {
  width: 84px; height: 84px;
  border-radius: 50%;
  border: 1px solid var(--line);
  display: grid;
  place-content: center;
  text-align: center;
  background: conic-gradient(var(--rust) calc(var(--p, 0) * 1%), transparent 0);
}
.score-ring strong {
  font-family: var(--serif);
  font-size: 26px;
  line-height: 1;
}
.score-ring span {
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--muted);
}
.action {
  margin: 0 0 8px;
  letter-spacing: 0.28em;
  font-size: 13px;
  color: var(--rust);
}
.reason {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}
.eval-bits {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}
.eval-bits[hidden] { display: none !important; }
.eval-bits li { margin-top: 3px; }
.eval-bits em {
  font-style: normal;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-right: 8px;
  color: var(--ink);
  font-size: 10px;
}

.console {
  border-left: 1px solid var(--line);
  padding-left: 28px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.controls label {
  display: grid;
  gap: 6px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.controls input, .controls select {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 8px 10px;
  min-width: 88px;
  font: inherit;
  color-scheme: dark;
}
.grow { flex: 1; min-width: 180px; }
.grow select, .grow input { width: 100%; }
button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  align-self: end;
}
button[hidden] { display: none !important; }
#stopBtn {
  background: transparent;
  color: var(--ink);
}
.meters {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 22px 0 16px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}
.meters em {
  display: block;
  font-family: var(--serif);
  font-style: normal;
  font-size: 28px;
}
.meters span { color: var(--muted); font-size: 12px; }

.log {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  max-height: min(520px, calc(100vh - 280px));
  font-size: 13px;
  line-height: 1.55;
  color: var(--muted);
}
.log li {
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.log .tag {
  color: var(--ink);
  margin-right: 8px;
  letter-spacing: 0.08em;
  font-size: 11px;
}

.gallery-wrap { padding: 8px 36px 48px; }
.gallery-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  border-top: 1px solid var(--line);
  padding-top: 22px;
  margin-bottom: 18px;
}
.gallery-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 26px;
}
.gallery-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.abstract-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.06em;
}
.abstract-progress[hidden] { display: none !important; }
.abstract-progress em {
  font-style: normal;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.abstract-progress__track {
  width: 92px;
  height: 3px;
  background: var(--line);
  overflow: hidden;
}
.abstract-progress__bar {
  height: 100%;
  width: 0;
  background: var(--ink);
  transition: width 0.45s ease;
}
.card .thumb .gen-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: rgba(232, 220, 196, 0.16);
  z-index: 3;
  overflow: hidden;
  pointer-events: none;
}
.card .thumb:not(.is-generating) .gen-bar {
  display: none;
}
.card .thumb .gen-bar i {
  display: block;
  height: 100%;
  width: 38%;
  background: var(--ink);
  animation: gen-slide 1.15s ease-in-out infinite;
}
@keyframes gen-slide {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}
.filters {
  display: flex;
  border: 1px solid var(--line);
}
.filters button {
  background: transparent;
  color: var(--muted);
  border: 0;
  border-right: 1px solid var(--line);
  padding: 7px 14px;
  align-self: auto;
}
.filters button:last-child { border-right: 0; }
.filters button.is-on {
  background: var(--ink);
  color: var(--bg);
}
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px;
}
.card {
  border: 1px solid var(--line);
  background: var(--bg-2);
}
.card .thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #1a1714;
  cursor: zoom-in;
}
.card .thumb .photo-stack {
  position: absolute;
  inset: 0;
}
.card .thumb img.photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.card .thumb img.abstract {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
  filter: none;
}
.card .thumb:hover img.abstract {
  opacity: 0.9;
  z-index: 2;
}
.card .thumb img[hidden],
.card .thumb img:not([src]) {
  display: none !important;
}
.card.discarded .thumb img.photo {
  filter: grayscale(1) brightness(0.55);
}
.card.discarded .veil {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: rgba(12, 11, 10, 0.42);
  display: grid;
  place-items: center;
  letter-spacing: 0.32em;
  font-size: 12px;
  color: rgba(232, 220, 196, 0.72);
  pointer-events: none;
  text-transform: uppercase;
}
.card .cap { padding: 12px 14px 14px; }
.card .cap .row-top {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.card .cap strong {
  font-family: var(--serif);
  font-size: 22px;
  line-height: 1;
  flex: 0 0 auto;
}
.card.discarded .cap strong { color: var(--muted); }
.card .cap .place {
  margin: 0;
  min-width: 0;
  flex: 1;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.02em;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card .cap .icons {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
  flex: 0 0 auto;
}
.card .cap .icon-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  margin: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  align-self: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.card .cap .icon-btn svg {
  width: 16px;
  height: 16px;
  display: block;
}
.card .cap .icon-btn:hover {
  color: var(--ink);
}
.card .cap .geo {
  margin: 6px 0 0;
  color: rgba(232, 220, 196, 0.38);
  font-size: 11px;
  letter-spacing: 0.02em;
  line-height: 1.4;
}
.card .cap .critique {
  margin: 8px 0 0;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.55;
}
.empty-gallery { color: var(--muted); }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: #1c1a17;
  display: grid;
  grid-template-rows: 1fr auto;
  cursor: zoom-out;
}
.lightbox[hidden] { display: none !important; }
.lightbox-stage {
  display: grid;
  place-items: center;
  padding: 56px 28px 16px;
  min-height: 0;
  cursor: zoom-out;
}
.exhibit {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: min(88vw, 920px);
  cursor: default;
}
.gilt-frame {
  padding: 3px;
  background: linear-gradient(135deg, #d7c39a 0%, #8a7048 28%, #efe3c4 50%, #6e5634 72%, #cbb489 100%);
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(0, 0, 0, 0.35);
}
.gilt-frame__wood {
  background:
    linear-gradient(160deg, #4a3b2c 0%, #2a211a 45%, #1a1511 100%);
  padding: 9px;
}
.gilt-frame__fillet {
  padding: 4px;
  background: linear-gradient(180deg, #ead9b0, #b08a4e 48%, #7a5c32);
}
.gilt-frame__mat {
  background: #f4efe6;
  padding: 16px;
  box-shadow: inset 0 0 0 1px rgba(62, 48, 28, 0.14);
}
.gilt-frame__mat .photo-stack {
  position: relative;
  aspect-ratio: 16 / 9;
  width: min(78vw, 860px, calc((100vh - 250px) * 16 / 9));
  background: #ddd6c8;
  cursor: default;
}
.gilt-frame__mat .photo-stack img.photo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: auto;
}
.gilt-frame__mat .photo-stack img.abstract {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
}
.gilt-frame__mat .photo-stack.has-abstract:hover img.abstract {
  opacity: 0.9;
}
.gilt-frame__mat img[hidden],
.gilt-frame__mat img:not([src]) {
  display: none !important;
}
.exhibit-caption {
  margin: 20px 12px 0;
  max-width: 28em;
  color: #f7f2e8;
  font-family: "Cormorant Garamond", "Noto Serif SC", "Songti SC", serif;
  font-style: italic;
  font-weight: 400;
  font-size: 20px;
  letter-spacing: 0.14em;
  line-height: 1.7;
  text-align: center;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
}
.exhibit-caption:empty {
  display: none;
}
.lightbox-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 28px 18px;
  border-top: 1px solid var(--line);
  background: #12100e;
  cursor: default;
}
.lightbox-stats {
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.04em;
  line-height: 1.5;
}
.lightbox-stats strong {
  color: var(--ink);
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 400;
  margin-right: 10px;
}
.lightbox-maps {
  color: var(--bg);
  background: var(--ink);
  text-decoration: none;
  padding: 8px 14px;
  font-size: 13px;
  border: 1px solid var(--ink);
}
.lightbox-maps[hidden] { display: none !important; }
.lightbox-close {
  position: absolute;
  top: 16px;
  right: 20px;
  width: 40px;
  height: 40px;
  padding: 0;
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
  font-size: 24px;
  line-height: 1;
  z-index: 2;
}

@media (hover: none) {
  .card .thumb:active img.abstract,
  .gilt-frame__mat .photo-stack.has-abstract:active img.abstract {
    opacity: 0.9;
    z-index: 2;
  }
}

@media (max-width: 960px) {
  .layout, .top, .gallery-wrap { padding-left: 18px; padding-right: 18px; }
  .layout { grid-template-columns: 1fr; gap: 20px; }
  .viewfinder { max-width: none; }
  .console { border-left: 0; padding-left: 0; border-top: 1px solid var(--line); padding-top: 18px; }
  .log { max-height: min(240px, 32vh); }
}

@media (max-width: 640px) {
  .top {
    padding: max(14px, env(safe-area-inset-top)) 16px 4px;
  }
  .brand { gap: 6px; }
  .mark { width: 32px; height: 32px; font-size: 14px; }
  h1 { font-size: 22px; }

  .layout {
    padding: 8px 16px 16px;
    gap: 16px;
  }
  .gallery-wrap {
    padding: 4px 16px max(28px, env(safe-area-inset-bottom));
  }

  .placeholder { padding: 0 12px; }
  .placeholder p { font-size: 17px; }
  .placeholder span { font-size: 12px; line-height: 1.45; }
  .frame-meta {
    font-size: 11px;
    padding: 8px 10px;
    gap: 10px;
  }
  .frame-meta span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .scoreboard {
    grid-template-columns: 64px 1fr;
    gap: 12px;
    margin-top: 12px;
  }
  .score-ring { width: 64px; height: 64px; }
  .score-ring strong { font-size: 20px; }
  .action { letter-spacing: 0.16em; font-size: 12px; }
  .reason { font-size: 13px; }

  .controls { gap: 8px; }
  .controls label {
    flex: 1 1 calc(33.33% - 6px);
    min-width: 0;
  }
  .controls .grow {
    flex: 1 1 100%;
    min-width: 0;
  }
  .controls input,
  .controls select {
    min-width: 0;
    width: 100%;
    font-size: 16px;
    padding: 10px;
  }
  .controls button {
    flex: 1 1 100%;
    width: 100%;
    align-self: stretch;
    min-height: 44px;
    margin-top: 4px;
  }

  .meters { margin: 16px 0 12px; gap: 8px; }
  .meters em { font-size: 22px; }
  .log { max-height: 160px; font-size: 12px; }

  .gallery-head {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding-top: 18px;
  }
  .gallery-head h2 { font-size: 22px; }
  .gallery-tools {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }
  .abstract-progress { width: 100%; }
  .abstract-progress__track { flex: 1; width: auto; min-width: 0; }
  .filters { width: 100%; }
  .filters button {
    flex: 1;
    padding: 10px 8px;
    min-height: 40px;
  }
  .gallery {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .card .cap .icon-btn {
    width: 40px;
    height: 40px;
  }
  .card .cap .icon-btn svg {
    width: 18px;
    height: 18px;
  }
  .card .cap .place { white-space: normal; }

  .lightbox-stage {
    padding: max(48px, calc(env(safe-area-inset-top) + 36px)) 12px 12px;
  }
  .exhibit { max-width: 100%; }
  .gilt-frame { padding: 2px; }
  .gilt-frame__wood { padding: 5px; }
  .gilt-frame__fillet { padding: 2px; }
  .gilt-frame__mat { padding: 8px; }
  .gilt-frame__mat .photo-stack {
    width: min(100%, calc((100dvh - 220px) * 16 / 9));
  }
  .exhibit-caption {
    font-size: 16px;
    letter-spacing: 0.06em;
    line-height: 1.55;
    margin: 12px 8px 0;
  }
  .lightbox-bar {
    padding: 12px 16px max(16px, env(safe-area-inset-bottom));
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .lightbox-maps { text-align: center; }
  .lightbox-close {
    top: max(8px, env(safe-area-inset-top));
    right: 8px;
    width: 44px;
    height: 44px;
  }
}
