/* ── 역사 오버레이 (1080px 기준 — --ui-scale 비례) ── */
.history-overlay {
  position: absolute;
  top: var(--top-height);
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  display: none;
  flex-direction: column;
  color: #fff;
  overflow: hidden;
}

.history-overlay--open {
  display: flex;
  flex-direction: column;
  z-index: 130;
}

.history-overlay__inner {
  position: relative;
  z-index: 1;
  flex: 1;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding:
    calc(var(--home-panel-gap) * 2 + 52 * var(--ui-scale) * 1px)
    calc(48 * var(--ui-scale) * 1px)
    calc(32 * var(--ui-scale) * 1px);
}

.history-overlay__bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  transition: background-image 0.45s ease, filter 0.45s ease;
}

.history-overlay__bg::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  transition: background 0.45s ease;
}

/* 타임라인: 흑백 + 비네팅 */
.history-overlay--timeline .history-overlay__bg {
  filter: grayscale(1) brightness(0.42) contrast(1.05);
  transform: none;
}

.history-overlay--timeline .history-overlay__bg::after {
  background:
    radial-gradient(
      ellipse 85% 75% at 50% 45%,
      rgba(0, 0, 0, 0) 0%,
      rgba(0, 0, 0, 0.35) 55%,
      rgba(0, 0, 0, 0.82) 100%
    ),
    radial-gradient(
      ellipse 100% 100% at 50% 50%,
      transparent 40%,
      rgba(0, 0, 0, 0.55) 100%
    );
}

/* 상세: 사진 색감 + 블러 */
.history-overlay--detail .history-overlay__bg {
  filter: blur(calc(32 * var(--ui-scale) * 1px)) saturate(1.25) brightness(1.08);
  transform: scale(1.15);
}

.history-overlay--detail .history-overlay__bg::after {
  background: rgba(
    var(--detail-tint-r, 200),
    var(--detail-tint-g, 210),
    var(--detail-tint-b, 220),
    0.38
  );
}

/* 허브: 첨부 배경 + 블러 (어두운 오버레이 없음) */
.history-overlay--hub .history-overlay__bg {
  filter: blur(calc(28 * var(--ui-scale) * 1px));
  transform: scale(1.1);
}

.history-overlay--hub .history-overlay__bg::after {
  background: transparent;
}

.history-hub {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.history-hub--hidden {
  display: none;
}

.history-hub__choices {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: calc(64 * var(--ui-scale) * 1px);
}

.history-hub__choice {
  flex: 0 0 auto;
  width: calc(440 * var(--ui-scale) * 1px);
  height: calc(320 * var(--ui-scale) * 1px);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(18, 20, 28, 0.55);
  border: calc(2 * var(--ui-scale) * 1px) solid rgba(255, 255, 255, 0.45);
  border-radius: calc(12 * var(--ui-scale) * 1px);
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.2s, background 0.2s, transform 0.2s;
}

.history-hub__choice:hover {
  border-color: rgba(255, 255, 255, 0.9);
  background: rgba(18, 20, 28, 0.7);
  transform: translateY(calc(-4 * var(--ui-scale) * 1px));
}

.history-hub__choice-label {
  font-size: calc(32 * var(--ui-scale) * 1px);
  font-weight: 600;
  letter-spacing: 0.04em;
}

.history-timeline {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.history-timeline__header {
  text-align: center;
  flex-shrink: 0;
  margin-bottom: calc(16 * var(--ui-scale) * 1px);
}

.history-timeline__year {
  font-size: calc(56 * var(--ui-scale) * 1px);
  font-weight: 300;
  letter-spacing: 0.04em;
  line-height: 1.1;
}

.history-timeline__note {
  margin-top: calc(8 * var(--ui-scale) * 1px);
  font-size: calc(16 * var(--ui-scale) * 1px);
  color: rgba(255, 255, 255, 0.7);
  letter-spacing: 0.02em;
}

.history-timeline__caption {
  flex-shrink: 0;
  text-align: center;
  margin: 0 0 calc(14 * var(--ui-scale) * 1px);
  min-height: calc(48 * var(--ui-scale) * 1px);
}

.history-carousel {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  column-gap: calc(24 * var(--ui-scale) * 1px);
  min-height: 0;
  padding: calc(8 * var(--ui-scale) * 1px) 0 calc(24 * var(--ui-scale) * 1px);
}

.history-carousel__side {
  flex: 0 0 auto;
  width: calc(200 * var(--ui-scale) * 1px);
  height: calc(200 * var(--ui-scale) * 1px);
  aspect-ratio: 1 / 1;
  border: none;
  padding: 0;
  background-size: cover;
  background-position: center;
  opacity: 0.5;
  cursor: pointer;
  filter: grayscale(0.15);
  transition: opacity 0.25s, transform 0.25s;
}

.history-carousel__side--prev {
  justify-self: end;
  grid-column: 1;
}

.history-carousel__side--next {
  justify-self: start;
  grid-column: 3;
}

.history-carousel__side:hover {
  opacity: 0.72;
  transform: scale(1.03);
}

.history-carousel__main {
  grid-column: 2;
  flex: 0 0 auto;
  width: calc(720 * var(--ui-scale) * 1px);
  max-width: calc(720 * var(--ui-scale) * 1px);
  aspect-ratio: 3 / 2;
  border: none;
  padding: 0;
  background-color: transparent;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
  cursor: pointer;
  box-shadow: 0 calc(12 * var(--ui-scale) * 1px) calc(48 * var(--ui-scale) * 1px) rgba(0, 0, 0, 0.35);
  transition: transform 0.25s;
  justify-self: center;
}

.history-carousel__main:hover {
  transform: scale(1.01);
}

.history-carousel__side--hidden {
  visibility: hidden;
  pointer-events: none;
}

.history-rail {
  flex-shrink: 0;
  position: relative;
  padding-top: calc(8 * var(--ui-scale) * 1px);
}

.history-rail__scroll {
  display: flex;
  justify-content: flex-start;
  align-items: flex-end;
  gap: calc(28 * var(--ui-scale) * 1px);
  overflow-x: auto;
  overflow-y: visible;
  padding: calc(28 * var(--ui-scale) * 1px) 0 calc(8 * var(--ui-scale) * 1px);
  scroll-padding-inline: 50%;
  scrollbar-width: none;
}

.history-rail__scroll::before,
.history-rail__scroll::after {
  content: '';
  flex: 0 0 calc(50% - calc(50 * var(--ui-scale) * 1px));
}

.history-rail__scroll::-webkit-scrollbar {
  display: none;
}

.history-thumb-wrap {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.history-thumb-wrap__year {
  display: block;
  min-height: calc(20 * var(--ui-scale) * 1px);
  margin-bottom: calc(6 * var(--ui-scale) * 1px);
  font-size: calc(13.6 * var(--ui-scale) * 1px);
  color: rgba(255, 255, 255, 0.55);
  white-space: nowrap;
  line-height: 1.2;
}

.history-thumb-wrap__year--placeholder {
  visibility: hidden;
}

.history-thumb {
  width: calc(72 * var(--ui-scale) * 1px);
  height: calc(72 * var(--ui-scale) * 1px);
  aspect-ratio: 1 / 1;
  border: calc(2 * var(--ui-scale) * 1px) solid transparent;
  padding: 0;
  background-size: cover;
  background-position: center;
  cursor: pointer;
  opacity: 0.5;
  filter: grayscale(0.2);
  transition:
    width 0.25s ease,
    height 0.25s ease,
    opacity 0.2s,
    border-color 0.2s,
    filter 0.2s;
}

.history-thumb:hover {
  opacity: 0.8;
  filter: grayscale(0);
}

.history-thumb--active {
  width: calc(100 * var(--ui-scale) * 1px);
  height: calc(100 * var(--ui-scale) * 1px);
  opacity: 1;
  border-color: #fff;
  filter: grayscale(0);
}

.history-rail__title {
  font-size: calc(17.6 * var(--ui-scale) * 1px);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.history-rail__category {
  margin-top: calc(4 * var(--ui-scale) * 1px);
  font-size: calc(13.6 * var(--ui-scale) * 1px);
  color: rgba(255, 255, 255, 0.55);
}

/* ── 상세 뷰 ── */
.history-detail {
  flex: 1;
  display: none;
  flex-direction: column;
  min-height: 0;
}

.history-detail--open {
  display: flex;
}

.history-timeline--hidden {
  display: none;
}

.history-detail__body {
  flex: 1;
  display: flex;
  align-items: center;
  gap: calc(56 * var(--ui-scale) * 1px);
  min-height: 0;
  padding: calc(32 * var(--ui-scale) * 1px) calc(24 * var(--ui-scale) * 1px);
}

.history-detail__image {
  flex: 0 1 auto;
  align-self: center;
  height: 100%;
  max-height: 100%;
  width: auto;
  max-width: 50%;
  aspect-ratio: 3 / 2;
  background-color: transparent;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  box-shadow: none;
}

.history-detail__text {
  flex: 1;
  min-width: 0;
  max-height: 78%;
  overflow-y: auto;
  color: #1a1a1a;
  padding: calc(8 * var(--ui-scale) * 1px) 0;
}

.history-detail__year-row {
  display: flex;
  align-items: flex-end;
  gap: calc(32 * var(--ui-scale) * 1px);
  margin-bottom: 0;
  padding-bottom: calc(12 * var(--ui-scale) * 1px);
  border-bottom: calc(1 * var(--ui-scale) * 1px) solid rgba(0, 0, 0, 0.2);
}

.history-detail__year {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: calc(72 * var(--ui-scale) * 1px);
  font-weight: 400;
  line-height: 1;
  color: #111;
}

.history-detail__category {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: calc(16 * var(--ui-scale) * 1px);
  color: #333;
  padding-bottom: calc(4 * var(--ui-scale) * 1px);
  white-space: nowrap;
}

.history-detail__title {
  font-size: calc(22.4 * var(--ui-scale) * 1px);
  font-weight: 700;
  margin: calc(28 * var(--ui-scale) * 1px) 0 calc(18 * var(--ui-scale) * 1px);
  line-height: 1.4;
  color: #111;
}

.history-detail__desc {
  font-size: calc(15.2 * var(--ui-scale) * 1px);
  line-height: 1.8;
  color: #222;
  max-width: calc(520 * var(--ui-scale) * 1px);
}

.history-detail--dark-bg .history-detail__year,
.history-detail--dark-bg .history-detail__category,
.history-detail--dark-bg .history-detail__title,
.history-detail--dark-bg .history-detail__desc {
  color: #fff;
}

.history-detail--dark-bg .history-detail__year-row {
  border-bottom-color: rgba(255, 255, 255, 0.28);
}

/* ── narrow: History ── */
html[data-mode='narrow'] .history-overlay__inner {
  padding:
    calc(var(--home-panel-gap) * 2 + 52 * var(--ui-scale) * 1px)
    max(12px, calc(14 * var(--ui-scale) * 1px))
    max(16px, calc(env(safe-area-inset-bottom, 0px) + 12px));
}

html[data-mode='narrow'] .history-timeline__year {
  font-size: max(32px, calc(40 * var(--ui-scale) * 1px));
}

html[data-mode='narrow'] .history-timeline__note {
  font-size: max(13px, calc(14 * var(--ui-scale) * 1px));
}

/* 캐러셀: 중앙 정렬, 옆 미리보기는 작게 */
html[data-mode='narrow'] .history-carousel {
  grid-template-columns: minmax(0, 0.55fr) minmax(0, 2.4fr) minmax(0, 0.55fr);
  column-gap: max(8px, calc(10 * var(--ui-scale) * 1px));
  justify-items: center;
  align-items: center;
  width: 100%;
  padding: max(4px, calc(6 * var(--ui-scale) * 1px)) 0
    max(12px, calc(14 * var(--ui-scale) * 1px));
}

html[data-mode='narrow'] .history-carousel__main {
  width: 100%;
  max-width: 100%;
  justify-self: center;
  margin: 0 auto;
}

html[data-mode='narrow'] .history-carousel__side {
  width: 100%;
  max-width: max(64px, calc(88 * var(--ui-scale) * 1px));
  height: auto;
  aspect-ratio: 1 / 1;
}

html[data-mode='narrow'] .history-carousel__side--prev {
  justify-self: end;
}

html[data-mode='narrow'] .history-carousel__side--next {
  justify-self: start;
}

@media (max-width: 480px) {
  html[data-mode='narrow'] .history-carousel {
    grid-template-columns: 1fr;
  }

  html[data-mode='narrow'] .history-carousel__side {
    display: none;
  }

  html[data-mode='narrow'] .history-carousel__main {
    grid-column: 1;
    max-width: min(100%, 520px);
  }
}

html[data-mode='narrow'] .history-rail__scroll {
  gap: max(14px, calc(16 * var(--ui-scale) * 1px));
  padding-top: max(16px, calc(18 * var(--ui-scale) * 1px));
}

html[data-mode='narrow'] .history-rail__scroll::before,
html[data-mode='narrow'] .history-rail__scroll::after {
  flex-basis: max(24px, calc(50% - 40px));
}

html[data-mode='narrow'] .history-thumb {
  width: max(52px, calc(56 * var(--ui-scale) * 1px));
  height: max(52px, calc(56 * var(--ui-scale) * 1px));
}

html[data-mode='narrow'] .history-thumb--active {
  width: max(64px, calc(72 * var(--ui-scale) * 1px));
  height: max(64px, calc(72 * var(--ui-scale) * 1px));
}

/* 상세: 홈 역사 슬라이드와 동일 — 3:4보다 좁을 때 연도→사진→설명 */
@media (max-aspect-ratio: 3 / 4) {
  .history-detail__body {
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: max(10px, calc(12 * var(--ui-scale) * 1px));
    overflow-y: auto;
    padding: max(20px, calc(24 * var(--ui-scale) * 1px))
      max(12px, calc(14 * var(--ui-scale) * 1px))
      max(12px, calc(14 * var(--ui-scale) * 1px));
  }

  .history-detail__text {
    display: contents;
  }

  .history-detail__year-row {
    order: 1;
    justify-content: center;
    align-items: baseline;
    gap: max(10px, calc(12 * var(--ui-scale) * 1px));
    width: 100%;
    margin: 0;
    padding-bottom: max(6px, calc(8 * var(--ui-scale) * 1px));
    border-bottom: none;
  }

  .history-detail__year {
    font-size: max(32px, calc(38 * var(--ui-scale) * 1px));
    text-align: center;
  }

  .history-detail__category {
    font-size: max(12px, calc(13 * var(--ui-scale) * 1px));
    padding-bottom: 0;
  }

  .history-detail__image {
    order: 2;
    flex: 0 0 auto;
    align-self: center;
    width: min(70%, 260px);
    max-width: 100%;
    height: auto;
    max-height: min(20dvh, 148px);
    aspect-ratio: 3 / 2;
    background-size: cover;
    background-position: center;
  }

  .history-detail__title {
    order: 3;
    width: 100%;
    margin: max(4px, calc(6 * var(--ui-scale) * 1px)) 0
      max(6px, calc(8 * var(--ui-scale) * 1px));
    font-size: max(15px, calc(17 * var(--ui-scale) * 1px));
    text-align: center;
  }

  .history-detail__desc {
    order: 4;
    width: 100%;
    font-size: max(12px, calc(13 * var(--ui-scale) * 1px));
    line-height: 1.55;
    max-width: none;
    text-align: center;
  }
}

