:root {
  --bg: #ffffff;
  /* white background */
  --fg: #000000;
  /* black text */
  --muted: #666666;
  /* muted grey */
  --card: #ffffff;
  /* cards blend with background */
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100dvh;
  /* keep your dvh fix */
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: "Noto Sans KR", system-ui, -apple-system,
    "Apple SD Gothic Neo", "Malgun Gothic",
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

/* Layout: fixed sidebar (25%), scrollable gallery */
.layout {
  display: flex;
  height: 100dvh;
  /* instead of 100vh */
  overflow: hidden;
}

.sidebar {
  width: 25vw;
  min-width: 260px;
  max-width: 520px;
  padding: 1.25rem 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  border-right: 1px solid #ddd;
  /* lighter divider for white theme */
}

.brand {
  font-weight: 700;
  letter-spacing: .2px;
  font-size: 1.1rem;
  margin: 0;
}

.brand a {
  color: inherit;
  text-decoration: none;
}

.brand a:hover {
  text-decoration: underline;
}

.asset-list {
  display: flex;
  flex-direction: column;
  gap: .4rem;
}

.asset-link {
  color: var(--fg);
  text-decoration: none;
  opacity: .85;
  padding: .35rem .25rem;
  border-radius: .5rem;
  font-weight: 500;
}

.asset-link:hover {
  opacity: 1;
  background: #f2f2f2;
}

.sidebar-footer {
  margin-top: auto;
  color: var(--muted);
  font-size: .9rem;
  opacity: .8;
}

/* Only the grid scrolls */
.gallery {
  flex: 1;
  height: 100dvh;
  /* instead of 100vh */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.gallery::-webkit-scrollbar {
  width: 10px;
}

.gallery::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 10px;
}

/* === Masonry (columns) — prevents same-height rows === */
.masonry {
  column-count: 3;
  /* desktop: 3 columns */
  column-gap: 1rem;
  padding: 1.25rem;
  margin: 0;
}

/* responsive downsizing */
@media (max-width:1100px) {
  .sidebar {
    width: 28vw;
  }

  .masonry {
    column-count: 2;
  }
}

@media (max-width:720px) {
  .layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid #ddd;
  }

  .gallery {
    height: calc(100vh - 140px);
  }

  /* mobile: 2 columns instead of 1 */
  .masonry {
    column-count: 2;
    padding: 1rem;
  }

  /* hide the asset list on mobile */
  .asset-list {
    display: none;
  }
}

@media (max-width:480px) {

  /* very narrow phones: fallback to 1 column */
  .masonry {
    column-count: 1;
  }
}

/* Cards inside columns */
.card {
  display: inline-block;
  /* critical for column layouts */
  width: 100%;
  margin: 0 0 1rem;
  /* vertical spacing between cards */
  background: transparent;
  /* only media shows */
  border-radius: 16px;
  color: inherit;
  text-decoration: none;
  break-inside: avoid;
  /* don't split across columns */
  page-break-inside: avoid;
  -webkit-column-break-inside: avoid;
  box-shadow: none;
  /* no shadow for clean gallery look */
}

/* Media wrapper preserves rounded corners without clipping card height */
.card-media-wrap {
  border-radius: 16px;
  overflow: hidden;
  position: relative;
  /* <-- added to allow overlay video on iOS press&hold */
}

.card-media {
  display: block;
  width: 100%;
  height: auto;
  /* let intrinsic size drive height */
  object-fit: cover;
  /* use 'contain' if you never want cropping */
  background: #fff;
  /* fallback for transparency */
}

/* Overlay video for iOS press&hold preview */
.ios-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* keep iOS long-press overlay transparent over the thumbnail */
.ios-preview {
  background: transparent;
}

/* was inheriting white */
.card {
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.preview-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 16px;
  background: #000;
  pointer-events: none;
  /* don’t steal taps */
}

/* avoid link preview on long-press */

/* Meta (hidden now) */
.card-meta {
  display: none;
}

/* iOS Safari fallback: use grid instead of columns */
@supports (-webkit-touch-callout: none) {
  .masonry {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    grid-gap: 1rem;
    padding: 1.25rem;
  }

  .card {
    display: block;
    margin: 0;
  }
}

/* ----- Detail view (replaces grid when an item is opened) ----- */
.detail {
  padding: 1.25rem;
  max-width: 1200px;
  margin: 0 auto;
}

.detail-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1rem;
}

.detail-back {
  appearance: none;
  border: 0;
  background: #eee;
  color: #000;
  padding: .45rem .7rem;
  border-radius: .5rem;
  cursor: pointer;
  font-weight: 600;
}

.detail-back:hover {
  background: #e5e5e5;
}

.detail-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
}

.detail-meta {
  margin: 0;
  color: #666;
  font-size: .95rem;
}

.detail-media {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* detail page media sizing */
.detail-media .frame {
  background: transparent;
}

/* nice letterboxing */
.detail-media video,
.detail-media img {
  display: block;
  /* removes the thin line */
  width: 100%;
  height: auto;
  max-height: 82dvh;
  /* keep your viewport fit */
  object-fit: contain;
  /* no cropping */
  background: transparent;
  /* no black behind video */
}

@media (max-width:720px) {

  .detail-media video,
  .detail-media img {
    max-height: 88dvh;
  }
}

.preview-btn {
  position: absolute;
  right: .5rem;
  bottom: .5rem;
  padding: .35rem .55rem;
  font: 600 12px/1 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: #000;
  background: rgba(255, 255, 255, .9);
  border: 1px solid #e4e4e4;
  border-radius: .5rem;
  cursor: pointer;
}

.preview-btn:active {
  transform: translateY(1px);
}