
  :root {
    --paper: #ffffff;
    --ink: #333333;
    --ink-soft: rgba(51, 51, 51, 0.5);
    --hair: rgba(10, 10, 10, 0.16);
    --rule: 1px solid var(--ink);
    --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  }

  * { margin: 0; padding: 0; box-sizing: border-box; }

  [hidden] { display: none !important; }

  body {
    background: var(--paper);
    color: var(--ink);
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: 10px;
    letter-spacing: 0.06em;
    -webkit-font-smoothing: antialiased;
    text-transform: uppercase;
  }

  ::selection { background: var(--ink); color: var(--paper); }

  /* ---------- header ---------- */

  .top {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    height: 40px; /* panel sits at exactly 40px — no gap */
    padding: 0 16px;
    background: var(--paper);
    font-size: 10px;
    letter-spacing: 0.1em;
  }

  .top .mid {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    letter-spacing: 0.14em;
  }

  .top button {
    all: unset;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    cursor: pointer;
  }

  .top .cnt { color: var(--ink); }

  .top .right {
    display: flex;
    align-items: center;
    gap: 20px;
  }

  .top .hbtn {
    color: var(--ink);
    transition: transform 160ms var(--ease-out);
  }

  .top .hbtn:hover { text-decoration: underline; text-underline-offset: 3px; }
  .top .hbtn:active { transform: scale(0.95); }

  /* ---------- filter panel (hidden dropdown) ---------- */

  .fpanel {
    position: fixed;
    top: 40px;
    left: 0; right: 0;
    z-index: 39;
    background: var(--paper);
    overflow: hidden;
    max-height: 0;
    transition: max-height 220ms var(--ease-out);
  }

  .fpanel.open { max-height: min(480px, calc(100vh - 40px)); }

  .fpanel .finner {
    border-top: var(--rule);
    border-bottom: var(--rule);
  }

  .filter-primary {
    display: flex;
    align-items: center;
    gap: 18px;
    min-height: 40px;
    padding: 0 16px;
    border-bottom: var(--rule);
  }

  .filter-primary .f {
    all: unset;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    cursor: pointer;
    color: var(--ink-soft);
    transition: color 160ms var(--ease-out), transform 160ms var(--ease-out);
  }

  .filter-primary .f:hover,
  .filter-primary .f.on { color: var(--ink); }
  .filter-primary .f:active { transform: scale(0.95); }

  .fcols {
    display: grid;
    grid-template-columns: minmax(190px, 27%) minmax(190px, 27%) 1fr;
  }

  .fcol { border-right: var(--rule); }
  .fcol:last-child { border-right: 0; }

  .fhead {
    display: flex;
    align-items: center;
    height: 24px;
    padding: 0 16px;
    border-bottom: var(--rule);
    color: var(--ink);
  }

  .fopts { padding: 8px 16px 16px; }

  .fcol .f {
    all: unset;
    display: block;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    cursor: pointer;
    color: var(--ink-soft);
    line-height: 1.7;
    transition: color 200ms var(--ease-out);
  }

  .fcol .f:hover,
  .fcol .f.on { color: var(--ink); }

  .fclose {
    all: unset;
    margin-left: auto;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    cursor: pointer;
    color: var(--ink);
  }

  .fclose:hover { text-decoration: underline; text-underline-offset: 3px; }

  /* ---------- canvas + grid ---------- */

  .canvas {
    margin: 0 auto;
  }

  .masonry {
    width: 100%;
    padding-top: 40px;
    columns: 4;
    column-gap: 0;
    transform-origin: 0 0;
  }

  .item {
    position: relative;
    break-inside: avoid;
    cursor: pointer;
    overflow: hidden;
  }

  .frame { display: block; overflow: hidden; }

  /* modular vertical rhythm — 6 / 12 / 24, repeating */
  .sp-a { margin-bottom: 6vh; }
  .sp-b { margin-bottom: 12vh; }
  .sp-c { margin-bottom: 24vh; }

  .item img {
    display: block;
    width: 100%;
    height: auto;
    background: transparent;
    filter: saturate(0.72) contrast(0.97);
    transform: none;
  }

  .item figcaption {
    display: block;
    position: relative;
    z-index: 1;
    background: var(--paper);
    padding: 8px 10px 0;
    height: 26px;
    line-height: 1;
    font-size: 9.5px;
    letter-spacing: 0.1em;
    color: var(--ink);
  }

  /* Photographs stay visible even while scripts or images are still loading. */
  .frame { background: #f1f0ed; }
  .item.has-error figcaption::after { content: ' · 다시 시도'; }

  /* ---------- lightbox ---------- */

  .lightbox {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.88);
    opacity: 0;
    pointer-events: none;
    transition: opacity 260ms var(--ease-out);
  }

  .lightbox.open {
    opacity: 1;
    pointer-events: auto;
  }

  .lightbox .lb-media > img {
    max-width: min(88vw, 1240px);
    max-height: 80vh;
    display: block;
    transform: scale(0.97);
    filter: saturate(0.72) contrast(0.97);
    opacity: 0;
    transition:
      transform 400ms var(--ease-out),
      opacity 300ms var(--ease-out);
  }

  .lightbox.open .lb-media > img.ready {
    transform: scale(1);
    opacity: 1;
  }

  .lightbox .lb-media {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: fit-content;
    max-width: min(88vw, 1240px);
    max-height: 80vh;
    margin: 0;
  }

  .lightbox .lb-media > img {
    max-width: 100%;
    max-height: calc(80vh - 28px);
  }

  .lightbox .lb-meta {
    display: flex;
    align-items: center;
    align-self: stretch;
    justify-content: flex-start;
    width: 100%;
    min-height: 28px;
    padding-top: 10px;
    color: var(--ink);
    font-size: 10px;
    line-height: 1;
    letter-spacing: 0.12em;
    white-space: nowrap;
  }

  .lightbox .lb-bar {
    position: absolute;
    top: 0; left: 0; right: 0;
    display: flex;
    justify-content: space-between;
    padding: 14px 16px;
    font-size: 10px;
    letter-spacing: 0.12em;
  }

  .lightbox button {
    all: unset;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    cursor: pointer;
    color: var(--ink);
    transition: transform 160ms var(--ease-out);
  }

  .lightbox button:active { transform: scale(0.95); }

  .lb-zone {
    position: absolute;
    top: 0; bottom: 0;
    width: 50%;
    z-index: -1;
  }
  .lb-zone--prev { left: 0; cursor: w-resize; }
  .lb-zone--next { right: 0; cursor: e-resize; }

  body.locked { overflow: hidden; }

  /* ---------- mobile ---------- */

  @media (max-width: 900px) {
    .masonry { columns: 3; }
    .sp-a { margin-bottom: 4vh; }
    .sp-b { margin-bottom: 8vh; }
    .sp-c { margin-bottom: 16vh; }
  }

  @media (max-width: 600px) {
    .masonry { columns: 2 !important; } /* fixed — no manual control on mobile */
    .item figcaption { font-size: 8.5px; }
    .top { padding: 0 12px; }
    .top .mid { display: none; }
    .top .right { gap: 12px; }
    .filter-primary { gap: 14px; padding: 0 12px; }
    .fcols { grid-template-columns: 1fr 1fr minmax(44px, auto); }
    .fhead { padding: 0 12px; }
    .fopts { padding: 8px 12px 14px; }
  }

  @media (prefers-reduced-motion: reduce) {
    .item { transition: opacity 200ms ease; }
    .item .frame {
      transform: none;
      transition: none;
    }
    .fpanel,
    .lightbox { transition: none; }
    .lightbox .lb-media > img {
      transform: none;
      transition: opacity 200ms ease;
    }
  }

/* Standalone gallery controls and the click-open background blur. */
.top { justify-content: space-between; font-size: 12px; }
.top .mid { color: inherit; text-decoration: none; font-size: 12px; }
.top .hbtn, .lightbox button { min-height: 40px; }
.top .right { margin-left: auto; }
.shuffle-icon { display: block; width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.25; }
.fpanel.open { max-height: calc(100svh - 40px); overflow-y: auto; }
.fcols { grid-template-columns: 1fr 1fr; }
.lightbox { background: rgba(255,255,255,.48); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
.lb-bar { align-items: center; padding: 0 16px; }
.lb-actions { display: flex; gap: 20px; }
.lb-media > img { width: auto; height: auto; object-fit: contain; }
button:focus-visible, a:focus-visible, .item:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }
.empty { padding: 80px 16px; text-align: center; }
@media (max-width: 600px) {
  .top .mid { display: inline; position: static; transform: none; }
  .lb-actions { gap: 16px; }
}

/* Keep the memorial title readable alongside the gallery controls. */
.top .mid { letter-spacing: 0; line-height: 1.4; word-break: keep-all; }
@media (max-width: 600px) {
  .top .mid { max-width: calc(100% - 104px); }
  .top .right { flex-shrink: 0; }
}

/* Loading and retry feedback occupies the viewer only when no preview exists. */
.lb-feedback { position: absolute; left: 24px; right: 24px; top: 50%; display: flex; flex-direction: column; align-items: center; gap: 12px; pointer-events: none; }
.lb-feedback p { font-size: 12px; letter-spacing: 0; }
.lightbox .lb-feedback button { padding: 0 16px; border: 1px solid #333; pointer-events: auto; }
.lightbox .lb-media > img:not([src]) { display: none; }
