/* =====================================================================
   NASA Renewal · Shared Components
   Loaded after tokens.css by every app screen.

   Scope: only patterns that should be IDENTICAL across today / explore /
   live / library. Page-specific layout (padding around topbar, tabbar
   positioning, etc.) stays in each page's own <style> as a small
   override on top of these defaults.
   ===================================================================== */

/* ---------- Reset & base ---------- */
* { margin: 0; padding: 0; box-sizing: border-box; }
button { border: 0; background: transparent; font: inherit; color: inherit; cursor: pointer; padding: 0; }

html, body {
  background: var(--bg-frame);
  color: var(--text-primary);
  font-family: 'Pretendard Variable', 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}
body { margin: 0; }

.mono { font-family: 'Space Mono', 'Pretendard', ui-monospace, monospace; letter-spacing: 0; }

/* ---------- Scroll container (today/explore) ----------
   Full-height vertical scroll inside .device, hidden scrollbar.
   live/library scroll on .device itself and do not need this. */
.scroll {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
.scroll::-webkit-scrollbar { display: none; }

/* ---------- Material Symbols Rounded (FILL 0 default) ---------- */
.msi {
  font-family: 'Material Symbols Rounded';
  font-weight: normal;
  font-style: normal;
  font-size: 24px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -webkit-font-smoothing: antialiased;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  flex-shrink: 0;
  vertical-align: middle;
  user-select: none;
}

/* ---------- Page topbar (NASA worm + tab title + actions) ---------- */
.page-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.page-topbar-brand {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.page-topbar-brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.nasa-worm {
  height: 22px;
  width: auto;
  display: block;
  flex-shrink: 0;
}
.page-topbar-divider {
  width: 1px;
  height: 18px;
  background: rgba(255, 255, 255, 0.22);
  flex-shrink: 0;
}
.page-topbar-eyebrow {
  font-family: 'Space Mono', 'Pretendard', monospace;
  font-size: var(--fs-10);
  letter-spacing: 2.2px;
  color: var(--accent);
  text-transform: uppercase;
  font-weight: 700;
}
.page-topbar-title {
  font-family: 'Space Mono', 'Pretendard', ui-monospace, monospace;
  font-size: var(--fs-22);
  font-weight: 700;
  letter-spacing: 3px;
  line-height: 1;
  color: var(--text-primary);
  text-transform: uppercase;
  margin: 0;
}
.page-topbar-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ---------- Icon button (40px circle on neutral surface) ---------- */
.icon-btn {
  width: 40px; height: 40px;
  border-radius: var(--radius-pill);
  background: var(--bg-ui);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--motion-fast), transform var(--motion-press);
  text-decoration: none;
}
.icon-btn:active {
  background: var(--bg-ui-active);
  transform: scale(0.94);
}
.icon-btn .msi {
  font-size: 18px;
  color: var(--text-primary);
}

/* ---------- Section head (canonical "Memories" pattern) ----------
   One pattern, aliased for backwards compat with page-specific class names:
   - today: .rail-head/.rail-title/.rail-link (+ .poster-* alias)
   - explore: .section-head/.section-title/.section-link/.section-meta
   - live: .sheet-section-head/.sheet-section-title/.sheet-section-meta
   - library: .vD-all-header/.vD-all-title/.vD-all-link
*/
.rail-head, .poster-head,
.section-head,
.sheet-section-head,
.vD-all-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  padding: 0;
}
.rail-title, .poster-title,
.section-title,
.sheet-section-title,
.vD-all-title {
  font-size: var(--fs-22);
  font-weight: 800;
  letter-spacing: -0.5px;
  line-height: 1.1;
  color: var(--text-primary);
  margin: 0;
  font-family: inherit;
  text-transform: none;
}
.rail-link, .poster-link,
.section-link, .section-meta,
.sheet-section-meta,
.vD-all-link {
  color: var(--text-subtle);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1;
  cursor: pointer;
}
/* 헤더 우측 링크 — 전 페이지 한글 카피("전체보기" 등)라 Pretendard.
   모노 자간(1.6px)이 한글에서 벌어지는 문제 함께 해결 */
.rail-link, .poster-link,
.section-link,
.vD-all-link {
  font-family: inherit;
  font-size: var(--fs-13);
  letter-spacing: -0.1px;
  font-weight: 600;
  text-transform: none;
}
/* 헤더 우측 메타 — 영문 데이터("5 QUEUED · UPD 2m" 등)라 모노 유지 */
.section-meta,
.sheet-section-meta {
  font-family: 'Space Mono', 'Pretendard', monospace;
  font-size: var(--fs-11);
  letter-spacing: 1.6px;
  text-transform: uppercase;
  font-weight: 700;
}
.rail-link .msi, .poster-link .msi,
.section-link .msi, .section-meta .msi,
.vD-all-link .msi {
  font-size: 14px;
  color: var(--text-subtle);
}

/* ---------- Live dot + pulse (shared by every "now" indicator) ---------- */
.live-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--live);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.45; transform: scale(0.82); }
}

/* ---------- Bottom tab bar ----------
   Position (absolute vs fixed) is set per page — today/explore use
   absolute inside .device, live/library use fixed because their root
   container itself scrolls. */
.tabbar {
  bottom: 0; left: 0; right: 0;
  width: 100vw;
  max-width: 100vw;
  /* 브라우저에서는 기존과 동일한 84px, PWA에서는 홈 인디케이터만큼 확장 */
  height: calc(60px + max(24px, env(safe-area-inset-bottom, 24px)));
  background: var(--bg-primary);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  align-items: center;
  padding-bottom: max(24px, env(safe-area-inset-bottom, 24px));
  z-index: 50;
  view-transition-name: tabbar; /* 페이지 전환 중에도 탭바는 제자리 고정 */
}
.tab-item {
  position: relative;
  text-decoration: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  align-self: stretch;
  min-height: 60px;
  color: var(--text-subtle);
  font-size: var(--fs-10);
  font-weight: 500;
  letter-spacing: 0.2px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: color var(--motion-fast);
}
.tab-item { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.tab-item:active { opacity: 0.7; }
.tab-item.active { color: var(--accent); }
.tab-icon {
  font-size: 22px;
  transition: transform 0.16s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.tab-item:active .tab-icon { transform: scale(0.85); }
@media (prefers-reduced-motion: reduce) {
  .tab-icon { transition: none; }
  .tab-item:active .tab-icon { transform: none; }
}

/* ---------- Cross-document 페이지 전환 (프로그레시브 인핸스먼트) ----------
   같은 오리진 탭 이동을 하드 리로드 플래시 대신 짧은 크로스페이드로 처리.
   탭바는 view-transition-name으로 분리되어 전환 중에도 그 자리에 남는다.
   미지원 브라우저는 규칙 전체를 무시 — 기존 내비게이션 그대로. */
@view-transition { navigation: auto; }
::view-transition-old(root),
::view-transition-new(root) { animation-duration: 0.22s; }

/* 탭 순서 기반 방향성 슬라이드 — pwa-nav.js가 html[data-nav-dir]를 세팅.
   fwd = 오른쪽 탭으로 이동(콘텐츠는 왼쪽으로 밀림), back = 반대.
   미지원 브라우저/일반 내비게이션은 위의 기본 크로스페이드. */
html[data-nav-dir='fwd']::view-transition-old(root) { animation: vtOutFwd 0.25s ease both; }
html[data-nav-dir='fwd']::view-transition-new(root) { animation: vtInFwd 0.25s ease both; }
html[data-nav-dir='back']::view-transition-old(root) { animation: vtOutBack 0.25s ease both; }
html[data-nav-dir='back']::view-transition-new(root) { animation: vtInBack 0.25s ease both; }
@keyframes vtOutFwd  { to { opacity: 0; transform: translateX(-24px); } }
@keyframes vtInFwd   { from { opacity: 0; transform: translateX(24px); } }
@keyframes vtOutBack { to { opacity: 0; transform: translateX(24px); } }
@keyframes vtInBack  { from { opacity: 0; transform: translateX(-24px); } }

@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
}
/* 페이지 로드 사이 흰 플래시 방지 */
html { background: var(--bg-frame, #000); }

/* ---------- 모션 민감 사용자 보호 — 전역 킬스위치 ----------
   Ken Burns, 펄스, 리빌 등 페이지별 장식 애니메이션 일괄 정지.
   (기능적 상태 변화는 클래스 토글이라 영향 없음) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  html { scroll-behavior: auto; }
}

/* ---------- 카드 프레스 피드백 + 스크롤 진입 리빌 (pwa-nav.js가 클래스 부여) ----------
   프레스: 탭바 아이콘과 같은 촉감 언어(스프링 스케일)를 카드로 확장.
   리빌: 로드 시 뷰포트 아래에 있던 섹션만 대상 — 첫 화면 플래시 없음. */
.pmc-press { transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1); }
.pmc-press:active { transform: scale(0.98); }
.pmc-reveal { opacity: 0; transform: translateY(12px); }
.pmc-reveal-in {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.55s ease, transform 0.55s ease;
}
@media (prefers-reduced-motion: reduce) {
  .pmc-press, .pmc-press:active { transition: none; transform: none; }
  .pmc-reveal { opacity: 1; transform: none; }
}

/* ---------- Empty state (shared "no data" card) ---------- */
.empty-state {
  background: var(--bg-card);
  border-radius: var(--radius-card);
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
}
.empty-state-eyebrow {
  font-family: 'Space Mono', 'Pretendard', monospace;
  font-size: var(--fs-10);
  letter-spacing: 2.2px;
  color: var(--text-faint);
  text-transform: uppercase;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.empty-state-eyebrow::before {
  content: '';
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--text-faint);
}
.empty-state-title {
  font-size: var(--fs-18);
  font-weight: 700;
  letter-spacing: -0.3px;
  line-height: 1.3;
  color: var(--text-primary);
}
.empty-state-sub {
  font-size: var(--fs-13);
  color: var(--text-muted);
  line-height: 1.5;
}
.empty-state-meta {
  font-family: 'Space Mono', 'Pretendard', monospace;
  font-size: var(--fs-11);
  letter-spacing: 1.4px;
  color: var(--text-faint);
  text-transform: uppercase;
  font-weight: 700;
  margin-top: 4px;
}

/* ---------- Focus + reduced motion (accessibility baseline) ---------- */
*:focus { outline: none; }
a:focus-visible,
button:focus-visible,
.icon-btn:focus-visible,
.tab-item:focus-visible,
[role="button"]:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

@media (prefers-reduced-motion: reduce) {
  .live-dot { animation: none !important; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Smooth cross-page transitions (View Transitions API, 2026-06-11) ----------
   Enabled app-wide: every navigation between tabs and detail pages cross-fades with a
   subtle rise. Cross-document (MPA) — both pages opt in via this shared stylesheet.
   Gracefully no-ops on browsers without support; respects reduced-motion. */
@view-transition { navigation: auto; }
::view-transition-old(root) { animation: vt-out 0.20s ease both; }
::view-transition-new(root) { animation: vt-in 0.30s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
@keyframes vt-out { to { opacity: 0; } }
@keyframes vt-in { from { opacity: 0; transform: translateY(8px); } }
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
}

/* ---------- Hide native scrollbar app-wide (clean inside iPhone iframe + standalone) ---------- */
html, body { scrollbar-width: none; -ms-overflow-style: none; }
html::-webkit-scrollbar, body::-webkit-scrollbar { display: none; width: 0; height: 0; }
