:root {
  --bg: #171C1B;
  --charcoal: #292D2B;
  --charcoal-2: #1F2423;
  --gold: #D9BC85;
  --gold-deep: #B48E4E;
  --ivory: #F4EBDD;
  --muted: #B8B0A3;
  --line: rgba(217, 188, 133, 0.28);
  --serif: ui-serif, "New York", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Noto Serif", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 14px;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ivory);
  font-family: var(--sans);
  font-size: 1.125rem;
  line-height: 1.6;
  overflow-x: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

img { max-width: 100%; height: auto; display: block; }

button { font: inherit; color: inherit; }

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
  border-radius: 6px;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -100px;
  background: var(--gold);
  color: var(--bg);
  padding: 12px 18px;
  border-radius: 10px;
  font-weight: 600;
  z-index: 10;
  text-decoration: none;
}
.skip-link:focus { top: 12px; }

/* Header */
.site-header {
  text-align: center;
  padding: 44px 20px 8px;
  max-width: 900px;
  margin: 0 auto;
}
.site-header .emblem { width: 76px; height: 76px; margin: 0 auto 14px; }
.site-header h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(2.1rem, 8.2vw, 3.6rem);
  line-height: 1.12;
  letter-spacing: -0.005em;
  margin: 0;
  text-wrap: balance;
}
.subtitle {
  font-family: var(--serif);
  font-style: italic;
  color: var(--gold);
  font-size: clamp(1.2rem, 4.6vw, 1.6rem);
  margin: 10px 0 0;
  text-wrap: balance;
}

/* Intro + portrait */
.intro {
  text-align: center;
  padding: 28px 20px 8px;
  max-width: 640px;
  margin: 0 auto;
}
.gilded {
  display: inline-block;
  margin: 0 auto;
  padding: 7px;
  background: linear-gradient(135deg, #7A5A2A 0%, #C9A45F 22%, #F0DCA6 42%, #B8914C 62%, #6E5024 82%, #B48E4E 100%);
  border: 1px solid #5A4220;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.55), 0 2px 6px rgba(0, 0, 0, 0.4);
}
.gilded img {
  width: min(62vw, 260px);
  padding: 3px;
  background: linear-gradient(135deg, #F3E2B3, #A8864A 55%, #E6CC8F);
  outline: 0.5px solid rgba(0, 0, 0, 0.35);
}
.intro-text {
  font-family: var(--serif);
  font-size: clamp(1.15rem, 4.2vw, 1.35rem);
  line-height: 1.6;
  color: var(--ivory);
  margin: 30px auto 0;
  max-width: 34ch;
  text-wrap: pretty;
}

.divider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 40px auto 8px;
  max-width: 420px;
  padding: 0 20px;
}
.divider span { flex: 1; height: 1px; background: linear-gradient(90deg, transparent, var(--line), transparent); }
.divider img { opacity: 0.85; }

/* Gallery */
.gallery {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}
.gallery:focus { outline: none; }
.gallery h2 {
  font-family: var(--serif);
  font-weight: 600;
  text-align: center;
  font-size: clamp(1.55rem, 6vw, 2.3rem);
  line-height: 1.25;
  margin: 0 0 24px;
  text-wrap: balance;
}

.gallery h2 span { display: inline-block; }

.gallery-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  margin: 0 4px 18px;
}
.gallery-bar[hidden] { display: none; }
.gallery-count { margin: 0; color: var(--muted); font-size: 1rem; }
.sort {
  display: inline-flex;
  background: var(--charcoal-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px;
}
.sort-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 10px 16px;
  min-height: 44px;
  border-radius: 999px;
  font-size: 0.98rem;
  cursor: pointer;
}
.sort-btn[aria-pressed="true"] { background: var(--gold); color: var(--bg); font-weight: 600; }

.gallery-status { text-align: center; }
.gallery-status:empty { display: none; }
.loading, .empty, .error {
  padding: 36px 20px 28px;
  max-width: 520px;
  margin: 0 auto;
  background: var(--charcoal-2);
  border: 1px solid var(--line);
  border-radius: 18px;
}
.loading img, .empty img { margin: 0 auto 14px; }
.loading p { color: var(--muted); margin: 0; }
.empty p, .error p { font-family: var(--serif); font-size: 1.2rem; line-height: 1.6; margin: 0; }
.error .retry {
  margin-top: 18px;
  background: var(--gold);
  color: var(--bg);
  border: 0;
  border-radius: 12px;
  padding: 12px 26px;
  min-height: 48px;
  font-weight: 600;
  cursor: pointer;
}
.notice { text-align: center; color: var(--muted); }

.pulse { animation: pulse 2.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 0.45; } 50% { opacity: 1; } }

.cards {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.cards[hidden] { display: none; }
@media (max-width: 340px) { .cards { grid-template-columns: 1fr; } }
@media (min-width: 720px) { .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 22px; } }
@media (min-width: 1040px) { .cards { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.card {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  padding: 0;
  text-align: left;
  background: var(--charcoal);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.2s ease;
}
.card:hover { border-color: var(--gold); }
@media (hover: hover) { .card:hover { transform: translateY(-2px); } }
.card:focus-visible { outline-offset: 2px; border-radius: var(--radius); }

.thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  background: radial-gradient(circle at 50% 42%, #2C3230 0%, #1A1F1E 70%);
  overflow: hidden;
}
.thumb img.poster {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 30%;
}
.thumb .fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}
.thumb .fallback img { width: 34%; opacity: 0.55; }
.play {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 64px;
  height: 64px;
  margin: -32px 0 0 -32px;
  border-radius: 50%;
  background: rgba(23, 28, 27, 0.72);
  border: 2px solid var(--gold);
  display: grid;
  place-items: center;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}
.play svg { width: 26px; height: 26px; margin-left: 4px; fill: var(--gold); }
.card:hover .play { background: var(--gold); }
.card:hover .play svg { fill: var(--bg); }

.card-body { padding: 12px 14px 16px; }
.card-number {
  display: block;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.2rem;
  line-height: 1.3;
  color: var(--ivory);
}
.card-title { display: block; color: var(--gold); font-size: 1rem; line-height: 1.35; margin-top: 4px; }
.card-by { display: block; color: var(--muted); font-size: 0.98rem; line-height: 1.4; margin-top: 4px; font-style: italic; }

/* Footer */
.site-footer {
  text-align: center;
  padding: 36px 20px 56px;
  border-top: 1px solid rgba(217, 188, 133, 0.14);
  margin-top: 16px;
}
.site-footer img { margin: 0 auto 12px; opacity: 0.9; }
.site-footer p { font-family: var(--serif); font-style: italic; color: var(--gold); font-size: 1.2rem; margin: 0; }

/* Player dialog */
.player {
  width: min(560px, 100vw);
  max-width: 100vw;
  max-height: 100dvh;
  margin: auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--bg);
  color: var(--ivory);
  overflow: auto;
}
.player::backdrop { background: rgba(8, 10, 10, 0.86); }
@media (max-width: 600px) {
  .player { width: 100vw; height: 100dvh; border-radius: 0; border: 0; }
}
.player-inner {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: max(14px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
  min-height: 100%;
}
.player-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.player-head h2 { font-family: var(--serif); font-weight: 600; font-size: 1.5rem; margin: 0; }
.close-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--charcoal);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 16px;
  min-height: 48px;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
}
.close-btn:hover { border-color: var(--gold); }
.player-frame {
  position: relative;
  width: 100%;
  max-width: calc((100dvh - 250px) * 9 / 16);
  min-width: min(100%, 220px);
  aspect-ratio: 9 / 16;
  margin: 0 auto;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
}
.player-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.player-frame .frame-msg {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  color: var(--muted);
}
.player-meta { text-align: center; }
.player-meta .m-title { font-family: var(--serif); color: var(--gold); font-size: 1.2rem; margin: 0; }
.player-meta .m-by { font-style: italic; color: var(--ivory); margin: 2px 0 0; }
.player-meta .m-date { color: var(--muted); font-size: 0.98rem; margin: 2px 0 0; }
.player-meta .m-desc { margin: 10px auto 0; max-width: 46ch; color: var(--ivory); }
.player-nav { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; margin-top: auto; }
.nav-btn {
  flex: 1 1 0;
  min-height: 48px;
  padding: 10px 14px;
  background: var(--charcoal);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 1rem;
  cursor: pointer;
}
.nav-btn:hover:not(:disabled) { border-color: var(--gold); }
.nav-btn:disabled { opacity: 0.4; cursor: default; }
.share-btn { flex-basis: 100%; order: -1; color: var(--gold); }
.share-btn[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  .card:hover { transform: none; }
}

@media (forced-colors: active) {
  .card, .sort, .nav-btn, .close-btn { border: 1px solid CanvasText; }
}

.home-link { color: var(--gold); font-size: 1.2rem; }
