/* ===== MODAL OVERLAY (full-screen backdrop) ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;

  /*
   * Graceful degradation for backdrop-filter:
   * 1. Solid semi-transparent bg (always works)
   * 2. backdrop-filter blur where supported
   */
  background: rgba(13, 13, 13, 0.80);
}
@supports (backdrop-filter: blur(1px)) {
  .modal-overlay {
    background: rgba(13, 13, 13, 0.60);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
  }
}

/* Hidden state */
.modal-overlay {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
}

.modal-overlay.is-open {
  opacity: 1;
  pointer-events: all;
}

/* ===== MODAL BOX ===== */
.modal {
  position: relative;
  width: 100%;
  max-width: 740px;
  height: min(82dvh, 640px);
  background: var(--paper);
  border: var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;

  /* Entry animation: slide up + slight scale */
  transform: translateY(28px) scale(0.97);
  transition: transform 0.36s cubic-bezier(0.34, 1.15, 0.64, 1);
}

.modal-overlay.is-open .modal {
  transform: none;
}

/* ===== READ PROGRESS BAR ===== */
.modal__progress {
  position: absolute;
  top: 0;
  left: 0;
  height: 2px;
  width: 0%;
  background: var(--accent);
  z-index: 10;
  pointer-events: none;
  transition: width 0.12s linear;
}

/* ===== MODAL HEADER ===== */
.modal__header {
  height: 56px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
  border-bottom: var(--border);
  background: var(--black);
  color: var(--white);
}

.modal__header-num {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--gray-2);
  letter-spacing: 0.12em;
  flex-shrink: 0;
}

.modal__header-title {
  font-family: var(--font-serif);
  font-size: clamp(14px, 2vw, 20px);
  font-weight: normal;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal__header-tags {
  font-size: 8px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--gray-2);
  flex-shrink: 0;
}

@media (max-width: 540px) {
  .modal__header-tags { display: none; }
}

.modal__close {
  flex-shrink: 0;
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: var(--white);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.modal__close:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.55);
}

.modal__close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ===== ARTICLE FEED (snap-scroll) ===== */
.modal__feed {
  flex: 1;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  /* Hide scrollbar visually; keep it functional */
  scrollbar-width: none;
}
.modal__feed::-webkit-scrollbar { display: none; }

/* Graceful degradation: if snap not supported, content is still scrollable */
@supports not (scroll-snap-type: y mandatory) {
  .modal__feed {
    scroll-snap-type: none;
    overflow-y: auto;
  }
}

/* ===== ARTICLE ===== */
.modal__article {
  scroll-snap-align: start;
  scroll-snap-stop: always;
  min-height: 100%;
  padding: clamp(20px, 4vw, 40px) clamp(20px, 5vw, 48px);
  display: flex;
  flex-direction: column;
  border-bottom: var(--border);
  position: relative;
  box-sizing: border-box;
}

.modal__article:last-child { border-bottom: none; }

/* Counter badge */
.modal__article-num {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.1em;
  color: var(--gray-1);
  margin-bottom: 18px;
}

/* Title */
.modal__article-title {
  font-family: var(--font-serif);
  font-size: clamp(20px, 3.2vw, 34px);
  line-height: 1.1;
  letter-spacing: -0.015em;
  margin-bottom: 14px;
  word-break: break-word;
  hyphens: auto;
}

/* Meta row: date + read time */
.modal__article-meta {
  display: flex;
  align-items: center;
  gap: 18px;
  font-family: var(--font-mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gray-1);
  padding-bottom: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--gray-2);
}

.modal__article-meta::before {
  content: '';
  display: inline-block;
  width: 20px;
  height: 1px;
  background: var(--accent);
  flex-shrink: 0;
}

/* Body */
.modal__article-body {
  font-size: clamp(13px, 1.2vw, 15px);
  line-height: 1.72;
  color: #2a2a2a;
  flex: 1;
}

.modal__article-body p + p { margin-top: 1em; }

/* Tags */
.modal__article-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 24px;
}

.modal__article-tag {
  font-family: var(--font-mono);
  font-size: 8px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  border: 1px solid var(--gray-2);
  padding: 3px 8px;
  color: var(--gray-1);
}

/* Animated "next" hint */
.modal__scroll-hint {
  position: absolute;
  bottom: 14px;
  right: 18px;
  font-family: var(--font-mono);
  font-size: 8px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--gray-1);
  animation: hintBounce 2s ease-in-out infinite;
}

.modal__article:last-child .modal__scroll-hint { display: none; }

@keyframes hintBounce {
  0%, 100% { transform: translateY(0);   opacity: 0.5; }
  50%       { transform: translateY(5px); opacity: 1;   }
}

/* Decorative background letter */
.modal__article-bg {
  position: absolute;
  bottom: -18px;
  right: 12px;
  font-family: var(--font-serif);
  font-size: clamp(80px, 14vw, 180px);
  line-height: 1;
  color: var(--black);
  opacity: 0.03;
  pointer-events: none;
  user-select: none;
}

/* Empty state */
.modal__empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-family: var(--font-serif);
  font-size: 18px;
  color: var(--gray-1);
  font-style: italic;
}

/* Navigation dots */
.modal__dots {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 5px;
  pointer-events: none;
  z-index: 5;
}

.modal__dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--gray-2);
  transition: background 0.2s, transform 0.2s;
}

.modal__dot.is-active {
  background: var(--black);
  transform: scale(1.6);
}

/* ===== MOBILE (≤ 600px): full-screen, slides from bottom ===== */
@media (max-width: 600px) {
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .modal {
    width: 100%;
    max-width: 100%;
    height: 92dvh;
    border-left: none;
    border-right: none;
    border-bottom: none;
    border-radius: 0;
    /* Override desktop entry animation for mobile */
    transform: translateY(100%);
    transition: transform 0.38s cubic-bezier(0.32, 0.72, 0, 1);
  }

  .modal-overlay.is-open .modal { transform: none; }

  .modal__article { padding: 22px 18px; }

  .modal__dots { display: none; }
}

/* Reduced motion: instant transitions */
@media (prefers-reduced-motion: reduce) {
  .modal-overlay,
  .modal {
    transition: none;
  }
  .modal__scroll-hint { animation: none; }
}
