:root {
  --navy-deepest: #030614;
  --navy-deep: #060a1c;
  --navy: #0a1330;
  --navy-mid: #101d47;
  --navy-line: rgba(226, 189, 104, 0.18);
  --gold-1: #fbe8ab;
  --gold-2: #e6c164;
  --gold-3: #c99a3e;
  --gold-4: #8a6420;
  --parchment: #f3e6c4;
  --ink: #eef1fa;
  --ink-dim: #9aa3c4;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--navy-deepest);
}

body {
  margin: 0;
  font-family: "Cormorant Garamond", serif;
  color: var(--ink);
  background:
    radial-gradient(ellipse 80% 60% at 50% 38%, var(--navy-mid) 0%, var(--navy-deep) 62%, var(--navy-deepest) 100%);
  min-height: 100dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.viewer-shell {
  width: 100%;
  margin: auto 0;
  display: flex;
  flex-direction: column;
}

.grain {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.05;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='120'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

button { font-family: inherit; }

/* ===== Header ===== */
.viewer-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem clamp(1rem, 3vw, 2.25rem);
  border-bottom: 1px solid var(--navy-line);
  animation: dropIn 0.7s cubic-bezier(.2,.7,.3,1) both;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: var(--parchment);
}

.brand-mark {
  width: clamp(1.6rem, 3vw, 2.1rem);
  height: clamp(1.6rem, 3vw, 2.1rem);
  border-radius: 22%;
  box-shadow: 0 0 0 1px var(--navy-line);
}

.brand-text {
  font-family: "Cinzel", serif;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: clamp(0.72rem, 1.6vw, 0.95rem);
  background: linear-gradient(180deg, var(--gold-1), var(--gold-3));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-text em { font-style: normal; color: var(--ink-dim); background: none; -webkit-text-fill-color: var(--ink-dim); }

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.text-link {
  font-family: "Cinzel", serif;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  padding-bottom: 2px;
  transition: color 0.2s, border-color 0.2s;
  white-space: nowrap;
}
.text-link:hover { color: var(--gold-2); border-color: var(--gold-3); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(10, 19, 48, 0.5);
  border: 1px solid var(--navy-line);
  color: var(--gold-2);
  border-radius: 999px;
  padding: 0.5rem 0.85rem;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.15s, color 0.2s;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-family: "Cinzel", serif;
}
.icon-btn svg { stroke: currentColor; fill: none; stroke-width: 1.6; flex-shrink: 0; }
.icon-btn:hover { background: rgba(230, 193, 100, 0.12); border-color: var(--gold-3); color: var(--gold-1); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn--square { padding: 0.5rem; }
.icon-btn--square span { display: none; }
@media (max-width: 640px) { .icon-btn span { display: none; } }

/* ===== Stage ===== */
.stage {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(0.5rem, 2vw, 2rem);
  padding: clamp(0.75rem, 2vh, 1.75rem) clamp(0.5rem, 3vw, 2.5rem);
  position: relative;
}

.nav-arrow {
  flex: 0 0 auto;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  background: rgba(10, 19, 48, 0.55);
  border: 1px solid var(--navy-line);
  color: var(--gold-2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.15s, color 0.2s;
  animation: fadeIn 0.9s 0.15s cubic-bezier(.2,.7,.3,1) both;
}
.nav-arrow svg { stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-arrow:hover { background: rgba(230, 193, 100, 0.14); border-color: var(--gold-3); color: var(--gold-1); transform: scale(1.06); }
.nav-arrow:active { transform: scale(0.95); }
.nav-arrow:disabled { opacity: 0.25; cursor: default; transform: none; }

@media (max-width: 720px) {
  .nav-arrow { display: none; }
}

.plate-frame {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: riseIn 0.8s cubic-bezier(.2,.7,.3,1) both;
  filter: drop-shadow(0 25px 60px rgba(0, 0, 0, 0.55));
}

#plateImg {
  display: block;
  max-width: min(90vw, 1400px);
  max-height: 62dvh;
  width: auto;
  height: auto;
  aspect-ratio: 1376 / 768;
  object-fit: contain;
  border: 1px solid rgba(230, 193, 100, 0.35);
  background: var(--navy);
  opacity: 1;
  transform: scale(1);
  filter: blur(0);
  transition: opacity 0.28s ease, transform 0.32s ease, filter 0.32s ease;
}
#plateImg.is-changing {
  opacity: 0;
  transform: scale(0.985);
  filter: blur(6px);
}

.frame-corner {
  position: absolute;
  width: 30px;
  height: 30px;
  pointer-events: none;
  z-index: 2;
}
.corner--tl { top: -9px; left: -9px; border-top: 2px solid var(--gold-2); border-left: 2px solid var(--gold-2); }
.corner--tr { top: -9px; right: -9px; border-top: 2px solid var(--gold-2); border-right: 2px solid var(--gold-2); }
.corner--bl { bottom: -9px; left: -9px; border-bottom: 2px solid var(--gold-2); border-left: 2px solid var(--gold-2); }
.corner--br { bottom: -9px; right: -9px; border-bottom: 2px solid var(--gold-2); border-right: 2px solid var(--gold-2); }

/* ===== Caption bar ===== */
.caption-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: clamp(1rem, 3vw, 2.5rem);
  padding: 1rem clamp(1rem, 3vw, 2.25rem);
  border-top: 1px solid var(--navy-line);
  animation: fadeIn 0.9s 0.2s cubic-bezier(.2,.7,.3,1) both;
}

.folio {
  flex: 0 0 auto;
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  border-right: 1px solid var(--navy-line);
  padding-right: clamp(1rem, 3vw, 2rem);
}
.folio-label {
  font-family: "Cinzel", serif;
  font-size: 0.6rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-dim);
  align-self: flex-start;
  margin-top: 0.3rem;
  display: none;
}
.folio-number {
  font-family: "Cinzel Decorative", serif;
  font-weight: 900;
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  background: linear-gradient(180deg, var(--gold-1), var(--gold-3));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  line-height: 1;
}
.folio-total {
  font-family: "Cinzel", serif;
  font-size: 0.75rem;
  color: var(--ink-dim);
  letter-spacing: 0.05em;
}
@media (min-width: 900px) { .folio-label { display: block; } }

.caption-text { min-width: 0; flex: 1 1 auto; }
.era-tag {
  margin: 0 0 0.15rem;
  font-family: "Cinzel", serif;
  font-size: 0.68rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--gold-2);
  min-height: 1em;
}
#captionTitle {
  margin: 0;
  font-weight: 500;
  font-style: italic;
  font-size: clamp(0.95rem, 2.4vw, 1.55rem);
  color: var(--parchment);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.mobile-nav { display: none; flex: 0 0 auto; gap: 0.5rem; }
@media (max-width: 720px) {
  .mobile-nav { display: flex; }
  .folio-total { display: none; }
}

/* ===== Progress track ===== */
.progress-track {
  flex: 0 0 auto;
  height: 2px;
  background: var(--navy-line);
  position: relative;
}
.progress-fill {
  position: absolute;
  inset: 0;
  width: 7.14%;
  background: linear-gradient(90deg, var(--gold-3), var(--gold-1));
  transition: width 0.35s cubic-bezier(.3,.7,.2,1);
}

/* ===== Filmstrip ===== */
.filmstrip {
  flex: 0 0 auto;
  display: flex;
  gap: 0.6rem;
  align-items: center;
  padding: 0.6rem clamp(1rem, 3vw, 2.25rem) 1rem;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--gold-4) transparent;
  animation: fadeIn 1s 0.3s cubic-bezier(.2,.7,.3,1) both;
}
.filmstrip::-webkit-scrollbar { height: 5px; }
.filmstrip::-webkit-scrollbar-thumb { background: var(--gold-4); border-radius: 4px; }

.thumb-btn {
  flex: 0 0 auto;
  width: clamp(3.4rem, 7vw, 4.8rem);
  aspect-ratio: 1376 / 768;
  border-radius: 3px;
  border: 1px solid var(--navy-line);
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.2s, border-color 0.2s, transform 0.2s;
  background: var(--navy);
}
.thumb-btn img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-btn:hover { opacity: 0.85; transform: translateY(-2px); }
.thumb-btn.is-active { opacity: 1; border-color: var(--gold-2); box-shadow: 0 0 0 1px var(--gold-2); }

/* ===== Grid overlay (index) ===== */
.grid-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(4, 7, 20, 0.92);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  padding: clamp(1.25rem, 3vw, 3rem);
  animation: fadeIn 0.25s ease both;
}
.grid-overlay[hidden] { display: none; }

.grid-overlay__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}
.grid-overlay__header h2 {
  font-family: "Cinzel Decorative", serif;
  font-weight: 700;
  color: var(--parchment);
  font-size: clamp(1.2rem, 3vw, 1.8rem);
  margin: 0;
}

.grid-overlay__inner {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.5rem;
  padding-bottom: 1rem;
}

.grid-item {
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  text-align: left;
  color: inherit;
  animation: riseIn 0.5s both;
}
.grid-item img {
  width: 100%;
  aspect-ratio: 1376 / 768;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--navy-line);
  transition: border-color 0.2s, transform 0.2s;
}
.grid-item:hover img { border-color: var(--gold-3); transform: translateY(-3px); }
.grid-item .grid-item-folio {
  font-family: "Cinzel", serif;
  color: var(--gold-2);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  margin: 0.5rem 0 0.15rem;
}
.grid-item .grid-item-title {
  font-family: "Cormorant Garamond", serif;
  font-style: italic;
  font-size: 0.95rem;
  color: var(--ink);
  margin: 0;
}

/* ===== Keyframes ===== */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes dropIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes riseIn { from { opacity: 0; transform: translateY(14px) scale(0.99); } to { opacity: 1; transform: translateY(0) scale(1); } }

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