/* 대문의 역사 (/gate-history). 본문 HTML · 대문 목록은 DB(site_page 'gate-history'), 그리기는 js/gate-history.js
   어두운 전시실: 가운데 작품은 앞으로 크게 · 양옆은 비스듬히 뒤로 물러나 흐릿하게(3D) → 위에서 부드러운 빛줄기와 먼지
   → 작품 대표색(JSON tint)으로 벽 · 바닥이 은은하게 물듦 → 왼쪽 아래 전시 포스터식 설명 → 아래 연도 눈금
   무대는 테두리 · 단색 상자 없이 가장자리를 사이트 바탕으로 녹임 (색은 dnd2.css :root 의 --gate-*) */
.gh { --gh-ease: cubic-bezier(.22, .8, .2, 1); display: flex; flex-direction: column; gap: var(--sp-6); }

/* ── 머리 ── */
.gh-head { display: grid; justify-items: center; gap: var(--sp-3); text-align: center; }
.gh-head__k { font-size: var(--fs-sm); letter-spacing: var(--ls-caps); }
.gh-head__t { font-size: var(--fs-hero); font-weight: var(--fw-black); letter-spacing: var(--ls-display); line-height: var(--lh-display); color: var(--text-strong); }
.gh-head__d { max-width: 520px; font-size: var(--fs-base); line-height: var(--lh-reading); color: var(--text-sub); }
.gh-source { text-align: center; font-size: var(--fs-xs); color: var(--muted); }
.gh-empty { padding: var(--sp-10) 0; text-align: center; font-size: var(--fs-base); color: var(--text-sub); }

/* ── 전시실 ── */
.gh-room { display: flex; flex-direction: column; gap: var(--sp-5); margin-inline: calc(var(--gutter) * -1); }
.gh-stage { --gh-tint: var(--focus-rgb); --h: clamp(600px, 80vh, 820px); --horizon: 76%;
  --gh-fade: radial-gradient(ellipse 56% 54% at 50% 50%, #000 42%, transparent 100%);   /* 가장자리를 사이트 바탕으로 녹이는 마스크 */
  position: relative; height: var(--h); overflow: hidden; perspective: 1800px; perspective-origin: 50% 40%; isolation: isolate; outline: none; touch-action: pan-y; }
.gh-stage:focus-visible { box-shadow: inset 0 0 0 3px rgba(var(--focus-rgb), .8); }
/* 벽 · 바닥: 경계선 없이 위아래로 이어지고 바깥쪽은 사이트 바탕으로 사라짐 */
.gh-stage::before { content: ""; position: absolute; inset: 0; z-index: -2; pointer-events: none;
  background: linear-gradient(var(--gate-black), var(--gate-wall) 32%, var(--gate-wall) calc(var(--horizon) - 4%), var(--gate-floor) calc(var(--horizon) + 4%));
  -webkit-mask-image: var(--gh-fade); mask-image: var(--gh-fade); }
/* 작품 대표색으로 물드는 빛: 벽 뒤 빛 웅덩이 + 바닥 빛 */
.gh-ambient { position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(ellipse 34% 42% at 50% 42%, rgba(var(--gh-tint), .22), transparent 70%),
    radial-gradient(ellipse 40% 14% at 50% calc(var(--horizon) + 4%), rgba(var(--gh-tint), .2), transparent 70%),
    radial-gradient(ellipse 30% 40% at 50% 40%, rgba(var(--gate-light-rgb), .09), transparent 70%);
  -webkit-mask-image: var(--gh-fade); mask-image: var(--gh-fade); }
/* 벽 질감 (잔 알갱이) */
.gh-texture { position: absolute; inset: 0; z-index: -1; pointer-events: none; opacity: .07; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .9 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  -webkit-mask-image: var(--gh-fade); mask-image: var(--gh-fade); }
/* 바닥 광택: 가운데만 은은하게 */
.gh-floor { position: absolute; left: 0; right: 0; top: calc(var(--horizon) - 6%); bottom: 0; z-index: 0; pointer-events: none;
  background: radial-gradient(ellipse 40% 34% at 50% 26%, rgba(var(--gate-light-rgb), .07), transparent 75%); }
/* 천장 조명 기구 + 빛줄기 + 먼지 */
.gh-fixture { position: absolute; z-index: 3; top: 0; left: 50%; width: 64px; height: 18px; transform: translateX(-50%); border-radius: 0 0 32px 32px; background: linear-gradient(var(--surface-2), var(--gate-black)); box-shadow: 0 6px 16px rgba(var(--gate-shade-rgb), .7); }
.gh-fixture::after { content: ""; position: absolute; left: 14px; right: 14px; bottom: -3px; height: 6px; border-radius: 50%; background: rgba(var(--gate-light-rgb), .95); box-shadow: 0 0 18px 4px rgba(var(--gate-light-rgb), .55); }
.gh-cone { position: absolute; z-index: 1; top: 10px; left: 50%; width: min(1100px, 120%); height: calc(var(--horizon) + 14%); transform: translateX(-50%); pointer-events: none; mix-blend-mode: screen;
  background: radial-gradient(ellipse 30% 100% at 50% 0%, rgba(var(--gate-light-rgb), .15), rgba(var(--gate-light-rgb), .05) 50%, transparent 78%);
  -webkit-mask-image: linear-gradient(transparent, #000 10%); mask-image: linear-gradient(transparent, #000 10%); }   /* 위 끝도 일자로 끊기지 않게 */
.gh-dust { position: absolute; z-index: 3; top: 10px; left: 50%; width: min(700px, 80%); height: var(--horizon); transform: translateX(-50%); pointer-events: none; clip-path: polygon(44% 0, 56% 0, 84% 100%, 16% 100%); }
.gh-dust i { position: absolute; width: 3px; height: 3px; border-radius: 50%; background: rgba(var(--gate-light-rgb), .7); opacity: 0; animation: gh-dust 14s linear infinite; }
.gh-dust i:nth-child(1)  { left: 46%; top: 20%; animation-delay: 0s; }
.gh-dust i:nth-child(2)  { left: 52%; top: 35%; animation-delay: -2s; animation-duration: 18s; }
.gh-dust i:nth-child(3)  { left: 40%; top: 50%; animation-delay: -5s; }
.gh-dust i:nth-child(4)  { left: 58%; top: 28%; animation-delay: -7s; animation-duration: 20s; }
.gh-dust i:nth-child(5)  { left: 49%; top: 62%; animation-delay: -9s; }
.gh-dust i:nth-child(6)  { left: 36%; top: 72%; animation-delay: -11s; animation-duration: 16s; }
.gh-dust i:nth-child(7)  { left: 63%; top: 55%; animation-delay: -3s; }
.gh-dust i:nth-child(8)  { left: 44%; top: 82%; animation-delay: -12s; animation-duration: 22s; }
.gh-dust i:nth-child(9)  { left: 55%; top: 75%; animation-delay: -6s; }
.gh-dust i:nth-child(10) { left: 60%; top: 15%; animation-delay: -10s; animation-duration: 17s; }
.gh-dust i:nth-child(11) { left: 38%; top: 40%; animation-delay: -4s; }
.gh-dust i:nth-child(12) { left: 66%; top: 80%; animation-delay: -8s; animation-duration: 19s; }
@keyframes gh-dust {
  0%   { transform: translate(0, 0); opacity: 0; }
  15%  { opacity: .8; }
  85%  { opacity: .5; }
  100% { transform: translate(24px, 60px); opacity: 0; }
}

/* 작품들: 가운데 기준 원근 배치 (JS 가 --d 거리 · --ad 절댓값 · --side 방향을 줌) */
.gh-works { position: absolute; inset: 0; z-index: 2; margin: 0; padding: 0; list-style: none; transform-style: preserve-3d; }
.gh-work { --d: 0; --ad: 0; --side: 0; --step: clamp(260px, 34vw, 520px); position: absolute; left: 50%; top: 37%; transform-style: preserve-3d;
  transform: translate(-50%, -50%) translateX(calc(var(--d) * var(--step))) translateZ(calc(var(--ad) * -260px)) rotateY(calc(var(--side) * -32deg)) scale(calc(1 - var(--ad) * .08));
  filter: brightness(calc(1 - min(var(--ad), 1.5) * .4)) saturate(calc(1 - min(var(--ad), 1.5) * .3)) blur(calc(min(var(--ad), 2) * 1.5px));
  transition: transform 1s var(--gh-ease), opacity .8s var(--gh-ease), visibility .8s; }
.gh-work.is-far { opacity: 0; visibility: hidden; pointer-events: none; }
/* 양옆 작품은 바깥쪽 절반이 서서히 사라짐 (무대 끝에서 일자로 잘리지 않게). .gh-works 에 마스크를 걸면 3D 원근이 납작해져서 작품마다 검 */
.gh-work.is-left { -webkit-mask-image: linear-gradient(90deg, transparent 5%, #000 60%); mask-image: linear-gradient(90deg, transparent 5%, #000 60%); }
.gh-work.is-right { -webkit-mask-image: linear-gradient(270deg, transparent 5%, #000 60%); mask-image: linear-gradient(270deg, transparent 5%, #000 60%); }
/* 액자: 깎인 나무 테 + 베벨 매트 */
.gh-frame { position: relative; display: block; padding: var(--sp-3); border: 0; border-radius: 1px; cursor: zoom-in;
  background: linear-gradient(135deg, var(--gate-wood-hi), var(--gate-wood) 22%, var(--gate-wood) 70%, var(--gate-wood-lo));
  box-shadow:
    inset 1px 1px 0 rgba(var(--gate-hi-rgb), .12), inset -1px -1px 0 rgba(var(--gate-shade-rgb), .7),
    inset 0 0 0 4px rgba(var(--gate-shade-rgb), .25),
    0 2px 2px rgba(var(--gate-shade-rgb), .5), 0 30px 60px -10px rgba(var(--gate-shade-rgb), .85), 0 60px 120px -20px rgba(var(--gate-shade-rgb), .7); }
.gh-work:not(.is-on) .gh-frame { cursor: pointer; }
.gh-mat { display: block; padding: clamp(14px, 2.4vw, 30px); background: var(--gate-mat);
  box-shadow: inset 2px 2px 3px rgba(var(--gate-shade-rgb), .35), inset -1px -1px 0 rgba(var(--gate-hi-rgb), .7); }   /* 테 안쪽 그늘 */
.gh-mat img { display: block; height: clamp(200px, 38vh, 360px); width: auto; max-width: 52vw; object-fit: contain;
  box-shadow: 0 0 0 1px rgba(var(--gate-shade-rgb), .12), -1px -1px 0 1px rgba(var(--gate-hi-rgb), .8), 1px 1px 0 1px rgba(var(--gate-shade-rgb), .1); }   /* 매트 안쪽 깎인 면 */
/* 위에서 떨어지는 빛이 액자에 닿는 느낌 */
.gh-frame::after { content: ""; position: absolute; inset: 0; pointer-events: none; mix-blend-mode: soft-light;
  background: radial-gradient(ellipse 90% 70% at 50% -10%, rgba(var(--gate-light-rgb), .55), transparent 60%), linear-gradient(transparent 55%, rgba(var(--gate-shade-rgb), .35)); }
.gh-work.is-long .gh-frame { background: var(--gate-gold); }
.gh-frame:focus-visible { outline: 3px solid rgba(var(--focus-rgb), .8); outline-offset: 6px; }
/* 바닥에 비친 색 (그림을 뒤집어 흐리게) */
.gh-refl { position: absolute; left: 6%; right: 6%; top: calc(100% + var(--sp-16)); height: 46%; pointer-events: none; transform: scaleY(-.6); transform-origin: top; opacity: .22; filter: blur(22px) saturate(1.4);
  -webkit-mask-image: radial-gradient(ellipse 50% 50% at 50% 70%, #000, transparent 100%); mask-image: radial-gradient(ellipse 50% 50% at 50% 70%, #000, transparent 100%); }
.gh-refl img { width: 100%; height: 100%; object-fit: cover; }
.gh-work:not(.is-on) .gh-refl { opacity: .1; }

/* 설명 (전시 포스터식) · 넘김 */
.gh-cap { position: absolute; z-index: 5; left: max(var(--gutter), calc(50% - 600px)); bottom: var(--sp-8); display: grid; gap: var(--sp-1); max-width: 460px; pointer-events: none; }
.gh-cap.is-anim > * { animation: gh-in .7s var(--gh-ease) both; }   /* 넘길 때만 (처음 그릴 때는 바로 보임) */
.gh-cap__no { font-family: var(--font-display); font-size: var(--gate-no-size); font-weight: var(--fw-bold); line-height: var(--lh-none); color: transparent; -webkit-text-stroke: 1px rgba(var(--gh-tint), .9); }
.gh-cap h2 { font-size: var(--fs-3xl); font-weight: var(--fw-black); line-height: var(--lh-tight); color: var(--text-strong); text-shadow: 0 2px 12px rgba(var(--gate-shade-rgb), .8); animation-delay: .06s; }
.gh-cap__meta { font-size: var(--fs-sm); color: var(--text-sub); animation-delay: .12s; }
.gh-cap__meta b { color: var(--text-strong); font-weight: var(--fw-semibold); }
.gh-cap p { margin-top: var(--sp-1); font-size: var(--fs-md); line-height: var(--lh-loose); color: var(--text-sub); text-shadow: 0 1px 8px rgba(var(--gate-shade-rgb), .9); animation-delay: .18s; }
.gh-cap .gh-dur { justify-self: start; animation-delay: .14s; }
@keyframes gh-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
/* 걸린 기간 딱지 (가장 오래 걸린 작품은 금빛) */
.gh-dur { display: inline-flex; align-items: center; min-height: 24px; padding: 0 var(--sp-2); border-radius: 999px; font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--accent); background: color-mix(in srgb, var(--primary) 16%, transparent); }
.gh-dur.is-long { color: var(--medal-gold-ink); background: var(--medal-gold); }
.gh-ctrl { position: absolute; z-index: 5; right: max(var(--gutter), calc(50% - 600px)); bottom: var(--sp-8); display: flex; align-items: center; gap: var(--sp-2); }
.gh-count { margin-right: var(--sp-2); font-family: var(--font-display); font-size: var(--fs-sm); letter-spacing: var(--ls-caps); color: var(--muted); }
.gh-count b { font-size: var(--fs-xl); color: var(--text-strong); }
/* 공통 .btn-icon 을 둥글게 · 어두운 무대 위에서 보이게 */
.gh-ctrl .btn-icon { border-radius: 50%; background: rgba(var(--gate-shade-rgb), .45); color: var(--text-strong); cursor: pointer; }
.gh-ctrl .btn-icon:hover:not(:disabled) { background: var(--surface-2); border-color: var(--accent-line); }   /* 어두운 바탕을 덮은 만큼 hover 도 여기서 */
.gh-ctrl .btn-icon:disabled { opacity: .35; cursor: default; }   /* 꺼진 단추는 확실히 흐리게 (아이콘 단추) */
.gh-ctrl .btn-icon:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(var(--focus-rgb), .8); }

/* 연도 눈금 */
.gh-scrub { padding-inline: max(var(--gutter), calc(50% - 600px)); }
.gh-scrub__track { --fill: 0%; position: relative; height: 64px; }
.gh-scrub__track::before { content: ""; position: absolute; left: 22px; right: 22px; top: 22px; height: 1px; background: linear-gradient(90deg, var(--line-strong) var(--fill), var(--line) var(--fill)); }
.gh-year { position: absolute; top: 40px; transform: translateX(-50%); font-family: var(--font-display); font-size: var(--fs-xs); color: var(--muted); white-space: nowrap; pointer-events: none; }
.gh-dot { position: absolute; top: 0; width: 44px; height: 44px; margin-left: -22px; padding: 0; border: 0; background: none; cursor: pointer; }
.gh-dot::before { content: ""; position: absolute; left: 50%; top: 50%; width: 10px; height: 10px; transform: translate(-50%, -50%); border-radius: 50%; background: var(--surface-solid); box-shadow: 0 0 0 2px var(--line-strong); transition: transform .3s var(--gh-ease), background .3s, box-shadow .3s; }
.gh-dot:hover::before { box-shadow: 0 0 0 2px var(--accent); }
.gh-dot[aria-current="true"]::before { transform: translate(-50%, -50%) scale(1.4); background: var(--accent); box-shadow: 0 0 0 3px rgba(var(--focus-rgb), .35), 0 0 16px rgba(var(--focus-rgb), .8); }
.gh-dot.is-long::before { box-shadow: 0 0 0 2px var(--gold); }
.gh-dot:focus-visible { outline: none; } .gh-dot:focus-visible::before { box-shadow: 0 0 0 3px rgba(var(--focus-rgb), .8); }
.gh-dot span { position: absolute; left: 50%; bottom: calc(100% - 4px); transform: translateX(-50%); padding: 2px var(--sp-2); border-radius: var(--radius-sm); background: var(--surface-solid); border: 1px solid var(--line); font-size: var(--fs-xs); color: var(--text-strong); white-space: nowrap; opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .2s, visibility .2s; }
.gh-dot:hover span, .gh-dot:focus-visible span { opacity: 1; visibility: visible; }
.gh-dot:first-of-type span { left: 0; transform: none; } .gh-dot:last-of-type span { left: auto; right: 0; transform: none; }

/* 크게 보기 창 (<dialog>) */
.gh-lb { width: 100vw; max-width: none; height: 100dvh; max-height: none; margin: 0; padding: 0; border: 0; background: rgba(var(--scrim-rgb), .94); color: var(--text); z-index: var(--z-lightbox); }
.gh-lb::backdrop { background: transparent; }
.gh-lb[open] { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.gh-lb__top { display: flex; justify-content: flex-end; padding: var(--sp-3); }
.gh-lb__stage { display: grid; place-items: center; min-height: 0; padding: 0 var(--sp-6); }
.gh-lb__stage img { max-width: 100%; max-height: 100%; object-fit: contain; padding: var(--sp-3); background: var(--gate-mat); }
.gh-lb__bar { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; align-items: center; gap: var(--sp-3); width: min(720px, 100%); margin: 0 auto; padding: var(--sp-4) var(--sp-4) var(--sp-6); }
.gh-lb__cap { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--sp-1) var(--sp-3); text-align: center; font-size: var(--fs-sm); color: var(--text-sub); }
.gh-lb__cap strong { font-size: var(--fs-lg); color: var(--text-strong); }
.gh-lb .btn-icon { border-radius: 50%; color: var(--text-strong); cursor: pointer; }
.gh-lb .btn-icon:disabled { opacity: .35; cursor: default; }
body.gh-lb-open { overflow: hidden; }

/* 처음 그릴 때는 움직임 없이 바로 제자리 (넘길 때만 움직임) */
.gh-stage:not(.is-ready) .gh-work { transition: none; }
@media (prefers-reduced-motion: reduce) {
  .gh-work, .gh-cap > *, .gh-dot::before { transition: none; animation: none; }
  .gh-dust { display: none; }
}
@media (max-width: 768px) {
  .gh-stage { --h: 600px; --horizon: 62%; perspective: 1000px; }
  .gh-work { top: 32%; --step: 66vw; }
  .gh-mat { padding: var(--sp-3); }
  .gh-mat img { height: auto; max-height: 220px; max-width: 62vw; }
  .gh-frame { padding: var(--sp-2); }
  .gh-refl { top: calc(100% + var(--sp-8)); }
  .gh-cap { left: var(--sp-4); right: var(--sp-4); bottom: calc(var(--sp-4) + 52px); max-width: none; }
  .gh-cap__no { font-size: var(--fs-4xl); }
  .gh-cap h2 { font-size: var(--fs-2xl); }
  .gh-cap p { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .gh-ctrl { left: var(--sp-4); right: var(--sp-4); bottom: var(--sp-4); }
  .gh-count { margin-right: auto; }
  .gh-scrub { display: none; }   /* 폰은 점 간격이 44px 보다 좁아져서 ‹ › 와 07 / 09 만 */
  .gh-lb__stage { padding: 0 var(--sp-4); }
}
