:root {
  --ink: #e9edf5;
  --dim: rgba(233, 237, 245, 0.62);
  --faint: rgba(233, 237, 245, 0.34);
  --line: rgba(233, 237, 245, 0.16);
  --panel: rgba(8, 11, 20, 0.58);
  --gold: #f3d9a4;
  --pad: clamp(14px, 2.4vw, 28px);
  --serif: "Noto Serif KR", "Nanum Myeongjo", "AppleMyungjo", "Batang", serif;
  --sans: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #04060c; color: var(--ink); font-family: var(--sans); overflow: hidden; }
body { -webkit-font-smoothing: antialiased; touch-action: none; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.hidden { opacity: 0 !important; pointer-events: none !important; visibility: hidden; }

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#vignette { position: fixed; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 52%, rgba(2, 3, 8, 0.62) 100%); }
#fade { position: fixed; inset: 0; background: #04060c; opacity: 0; pointer-events: none; }

/* body markers */
#markers { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.marker { position: absolute; left: 0; top: 0; will-change: transform; transition: opacity 0.6s; }
.marker i { position: absolute; left: -3px; top: -3px; width: 6px; height: 6px; border-radius: 50%;
  background: var(--c, #fff); box-shadow: 0 0 10px 2px var(--c, #fff); }
.marker span { position: absolute; left: 10px; top: -9px; font-size: 12px; letter-spacing: 0.08em;
  color: var(--dim); white-space: nowrap; text-shadow: 0 0 6px #000; }
.marker.craft i { left: -4px; top: -4px; width: 8px; height: 8px; }
.marker.craft span { color: var(--gold); }
.marker.up span { top: -25px; }
.marker.nodot i { display: none; }

/* HUD */
#hud { position: fixed; left: var(--pad); top: calc(var(--pad) + env(safe-area-inset-top)); transition: opacity 1.2s; pointer-events: none; }
#craft { font-size: 12px; letter-spacing: 0.32em; color: var(--gold); }
#date { font-family: var(--serif); font-size: clamp(24px, 3.6vw, 40px); font-weight: 300; margin: 4px 0 10px; font-variant-numeric: tabular-nums; }
#stats { margin: 0; display: grid; gap: 4px; font-size: 13px; }
#stats div { display: flex; gap: 10px; align-items: baseline; }
#stats dt { color: var(--faint); min-width: 7.5em; }
#stats dd { margin: 0; color: var(--dim); font-variant-numeric: tabular-nums; }

/* chapter caption */
#caption { position: fixed; left: 50%; bottom: calc(132px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(640px, calc(100vw - 2 * var(--pad))); text-align: center; transition: opacity 1.4s; pointer-events: none; }
#caption h2 { font-family: var(--serif); font-weight: 300; font-size: clamp(22px, 3vw, 32px); letter-spacing: 0.2em; margin: 0 0 6px; }
#caption p { margin: 0; color: var(--dim); font-size: 14px; line-height: 1.7; text-shadow: 0 0 8px #000; }
#cap-facts { margin-top: 4px !important; color: var(--gold) !important; font-size: 12.5px !important; font-variant-numeric: tabular-nums; }
body.has-gallery #caption { bottom: calc(238px + env(safe-area-inset-bottom)); }

/* gallery strip */
#gallery { position: fixed; left: 0; right: 0; bottom: calc(118px + env(safe-area-inset-bottom)); transition: opacity 1.2s;
  display: flex; flex-direction: column; align-items: center; gap: 6px; }
#gallery-head { font-size: 11px; letter-spacing: 0.24em; color: var(--faint); }
#thumbs { display: flex; gap: 10px; max-width: 100vw; overflow-x: auto; padding: 2px var(--pad) 6px; scrollbar-width: none; touch-action: pan-x; }
#thumbs::-webkit-scrollbar { display: none; }
.thumb { flex: 0 0 auto; width: 104px; padding: 0; border: 1px solid var(--line); border-radius: 6px; overflow: hidden;
  background: rgba(0, 0, 0, 0.5); text-align: left; transition: border-color 0.3s, transform 0.3s; }
.thumb:hover, .thumb:focus-visible { border-color: var(--gold); transform: translateY(-2px); outline: none; }
.thumb img { display: block; width: 100%; height: 68px; object-fit: cover; }
.thumb span { display: block; padding: 4px 6px 5px; font-size: 10.5px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* controls */
#controls { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px var(--pad) calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(4, 6, 12, 0.92), rgba(4, 6, 12, 0)); transition: opacity 1.2s; }
#chapters { display: flex; gap: 6px; justify-content: center; overflow-x: auto; padding: 4px 0 10px; scrollbar-width: none; touch-action: pan-x; }
#chapters::-webkit-scrollbar { display: none; }
#chapters button { flex: 0 0 auto; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; font-size: 12px;
  color: var(--dim); letter-spacing: 0.06em; transition: color 0.3s, border-color 0.3s, background 0.3s; }
#chapters button.on { color: #0a0d16; background: var(--gold); border-color: var(--gold); }
#transport { display: flex; align-items: center; gap: 10px; max-width: 900px; margin: 0 auto; }
#transport button { flex: 0 0 auto; width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 50%; font-size: 13px; color: var(--ink); }
#transport button.off { color: var(--faint); text-decoration: line-through; }
#scrubwrap { position: relative; flex: 1 1 auto; min-width: 0; display: flex; }
#scrub { flex: 1 1 auto; min-width: 0; width: 100%; height: 28px; appearance: none; -webkit-appearance: none; background: transparent; touch-action: pan-x; }
#scrub::-webkit-slider-runnable-track { height: 2px; background: var(--line); }
#scrub::-moz-range-track { height: 2px; background: var(--line); }
#scrub::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -6px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 10px var(--gold); }
#scrub::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%; background: var(--gold); }

/* end card */
#endcard { position: fixed; right: var(--pad); top: 46%; transform: translateY(-50%); width: min(320px, calc(100vw - 2 * var(--pad)));
  max-height: calc(100vh - 260px); overflow-y: auto; padding: 20px 22px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); transition: opacity 2s; touch-action: pan-y; }
#endcard h2 { font-family: var(--serif); font-weight: 300; letter-spacing: 0.16em; margin: 0 0 4px; font-size: 21px; }
#end-asof { margin: 0 0 14px; font-size: 12px; color: var(--faint); }
#end-grid { display: grid; gap: 16px; }
#end-grid h3 { margin: 0 0 6px; font-size: 13px; letter-spacing: 0.2em; color: var(--gold); font-weight: 500; }
#end-grid dl { margin: 0; font-size: 13px; display: grid; gap: 5px; }
#end-grid dt { color: var(--faint); font-size: 11px; }
#end-grid dd { margin: 0; color: var(--ink); font-variant-numeric: tabular-nums; }
#end-grid small { color: var(--dim); }
#restart { margin-top: 16px; padding: 8px 18px; border: 1px solid var(--line); border-radius: 999px; font-size: 13px; color: var(--dim); }

/* lightbox */
#lightbox { position: fixed; inset: 0; z-index: 30; background: rgba(2, 3, 8, 0.94); display: flex; align-items: center; justify-content: center;
  transition: opacity 0.5s; padding: 18px; touch-action: pan-y; }
#lightbox figure { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 14px; max-width: 980px; max-height: 100%; overflow-y: auto; }
#lb-img { max-width: 100%; max-height: 62vh; object-fit: contain; border-radius: 4px; background: #000; }
#lightbox figcaption { max-width: 640px; text-align: center; user-select: text; -webkit-user-select: text; }
#lb-title { font-family: var(--serif); font-weight: 400; font-size: 20px; margin: 0 0 6px; }
#lb-meta { margin: 0 0 8px; font-size: 12px; color: var(--gold); letter-spacing: 0.04em; }
#lb-caption { margin: 0 0 10px; font-size: 14px; line-height: 1.7; color: var(--dim); }
#lb-link { font-size: 12px; color: var(--faint); }
#lb-close, #about-close { position: absolute; top: 12px; right: 14px; width: 40px; height: 40px; font-size: 26px; color: var(--dim); z-index: 2; }
#lb-prev, #lb-next { position: absolute; top: 40%; width: 44px; height: 64px; font-size: 34px; color: var(--dim); z-index: 2; }
#lb-prev { left: 4px; } #lb-next { right: 4px; }

/* about sheet */
#about { position: fixed; inset: 0; z-index: 30; background: rgba(2, 3, 8, 0.8); display: flex; align-items: center; justify-content: center; padding: 16px; transition: opacity 0.5s; }
#about .sheet { position: relative; width: min(640px, 100%); max-height: 100%; overflow-y: auto; padding: 26px 26px 20px; background: #0a0e1a;
  border: 1px solid var(--line); border-radius: 14px; touch-action: pan-y; user-select: text; -webkit-user-select: text; }
#about h2 { font-family: var(--serif); font-weight: 400; font-size: 19px; margin: 0 30px 12px 0; }
#about h3 { font-size: 12px; letter-spacing: 0.24em; color: var(--gold); margin: 16px 0 6px; font-weight: 500; }
#about ul { margin: 0; padding-left: 18px; font-size: 13.5px; line-height: 1.75; color: var(--dim); }
.fine { font-size: 11.5px; color: var(--faint); line-height: 1.6; }

/* intro */
#intro { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; text-align: center;
  background: radial-gradient(ellipse at 50% 60%, rgba(10, 16, 34, 0.55), rgba(4, 6, 12, 0.9)); transition: opacity 2.4s; padding: var(--pad); }
#intro.gone { opacity: 0; pointer-events: none; }
#intro .kicker { letter-spacing: 0.5em; font-size: 12px; color: var(--gold); margin: 0 0 10px; }
#intro h1 { font-family: var(--serif); font-weight: 200; font-size: clamp(40px, 8vw, 84px); letter-spacing: 0.24em; margin: 0 0 18px; text-indent: 0.24em; }
#intro .lead { color: var(--dim); font-size: 15px; line-height: 1.9; margin: 0 0 30px; }
#start { padding: 12px 34px; border: 1px solid var(--gold); border-radius: 999px; color: var(--gold); font-size: 15px; letter-spacing: 0.2em; transition: background 0.4s, color 0.4s; }
#start:not(:disabled):hover { background: var(--gold); color: #0a0d16; }
#start:disabled { border-color: var(--line); color: var(--faint); cursor: default; }
.soundopt { display: block; margin: 16px 0 26px; font-size: 12.5px; color: var(--dim); }

@media (max-width: 640px) {
  #stats { font-size: 12px; }
  #stats dt { min-width: 6.6em; }
  #caption { bottom: calc(126px + env(safe-area-inset-bottom)); }
  #caption p { font-size: 13px; }
  body.has-gallery #caption { bottom: calc(226px + env(safe-area-inset-bottom)); }
  #gallery { bottom: calc(112px + env(safe-area-inset-bottom)); }
  .thumb { width: 88px; } .thumb img { height: 58px; }
  #chapters { justify-content: flex-start; }
  #endcard { left: var(--pad); right: var(--pad); top: auto; bottom: calc(112px + env(safe-area-inset-bottom)); transform: none; width: auto; max-height: 42vh; padding: 14px 16px; }
  #end-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  #end-grid small { display: block; }
  .marker span { font-size: 11px; }
}
@media (max-height: 520px) {
  #caption p#cap-body { display: none; }
  #gallery-head { display: none; }
}

/* places where photos were taken */
#ticks { position: absolute; left: 0; right: 0; top: 0; height: 100%; pointer-events: none; }
#transport .tick { position: absolute; top: 0; flex: none; width: 14px; height: 100%; margin-left: -7px; padding: 0; border: 0; border-radius: 0; pointer-events: auto; }
.tick::before { content: ""; position: absolute; left: 6px; top: 3px; width: 2px; height: 7px; background: var(--gold); opacity: 0.75; border-radius: 1px; }
.tick:hover::before, .tick:focus-visible::before { opacity: 1; height: 10px; top: 1px; box-shadow: 0 0 6px var(--gold); }
.spot { position: absolute; left: -16px; top: -16px; width: 32px; height: 32px; padding: 0; pointer-events: auto; display: none; }
.spot.on { display: block; }
.spot::before { content: ""; position: absolute; left: 11px; top: 11px; width: 9px; height: 9px; transform: rotate(45deg);
  border: 1.5px solid var(--gold); background: rgba(243, 217, 164, 0.18); box-shadow: 0 0 8px rgba(243, 217, 164, 0.6); transition: transform 0.2s, background 0.2s; }
.spot:hover::before, .spot:focus-visible::before { transform: rotate(45deg) scale(1.35); background: var(--gold); }
.thumb.placed { position: relative; }
.thumb.placed::after { content: ""; position: absolute; right: 6px; top: 6px; width: 7px; height: 7px; transform: rotate(45deg); border: 1.5px solid var(--gold); background: rgba(8, 11, 20, 0.6); }
#lb-go { display: block; margin: 0 auto 12px; padding: 8px 18px; border: 1px solid var(--gold); border-radius: 999px; color: var(--gold); font-size: 13px; letter-spacing: 0.08em; }
#lb-go:hover { background: var(--gold); color: #0a0d16; }
#lb-place { margin: 0 0 10px; font-size: 12px; color: var(--faint); }
#lb-place:empty { display: none; }

#shot { position: fixed; right: var(--pad); top: 46%; transform: translateY(-50%); width: min(330px, calc(100vw - 2 * var(--pad)));
  max-height: calc(100vh - 240px); overflow-y: auto; padding: 16px 18px 18px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); transition: opacity 0.8s; touch-action: pan-y; z-index: 5; }
#shot .kicker { margin: 0 0 10px; font-size: 11px; letter-spacing: 0.24em; color: var(--gold); }
#shot-img { display: block; width: 100%; max-height: 34vh; object-fit: contain; background: #000; border-radius: 6px; }
#shot h3 { font-family: var(--serif); font-weight: 400; font-size: 17px; margin: 12px 0 6px; }
#shot p { margin: 0 0 5px; font-size: 12.5px; line-height: 1.6; color: var(--dim); font-variant-numeric: tabular-nums; }
#shot p a { color: var(--gold); }
#shot-src { color: var(--faint) !important; font-size: 11.5px !important; }
#shot-close { position: absolute; top: 4px; right: 6px; width: 36px; height: 36px; font-size: 22px; color: var(--dim); }
#shot-open { margin-top: 8px; padding: 7px 16px; border: 1px solid var(--line); border-radius: 999px; font-size: 12.5px; color: var(--dim); }
body.has-shot #gallery, body.has-shot #caption { opacity: 0 !important; pointer-events: none; }
@media (max-width: 640px) {
  #shot { left: var(--pad); right: var(--pad); top: auto; bottom: calc(112px + env(safe-area-inset-bottom)); transform: none; width: auto; max-height: 44vh;
    display: grid; grid-template-columns: 104px 1fr; column-gap: 12px; padding: 12px 14px; }
  #shot .kicker { grid-column: 1 / -1; margin-bottom: 6px; }
  #shot-img { grid-row: 2 / span 5; max-height: 150px; }
  #shot h3 { margin: 0 0 4px; font-size: 15px; }
  #shot p { font-size: 11.5px; }
  #shot-open { justify-self: start; margin-top: 4px; }
}
