/* 밤하늘 — 별자리 */

:root {
  --ink: rgba(226, 234, 255, 0.92);
  /* 알파는 대비에서 역산했다. 이 글자들은 캔버스 위에 떠 있어 배경이 고정이
     아니다 — 밤하늘 최암부 rgb(3,7,20)부터 은하수가 지날 때의 rgb(26,33,54)까지
     변한다. 가장 밝은 쪽을 기준으로 잡아야 1년 내내 AA 를 지킨다.
       dim   0.62 → 0.78   (은하수 위 4.32:1 이던 것이 6.01:1)
       faint 0.38 → 0.75   (2.29:1 → 4.96:1)
     알파 위계(dim > faint)와 기본색 밝기 차이는 그대로 둔다. */
  --ink-dim: rgba(178, 194, 232, 0.78);
  --ink-faint: rgba(160, 180, 225, 0.75);
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

* { box-sizing: border-box; }

html {
  background: #000106;
  scroll-behavior: auto;
  /* 화면에 별 말고는 아무것도 보이지 않아야 한다. 스크롤 힌트가 있으므로
     막대를 숨겨도 스크롤할 수 있다는 사실은 전달된다. */
  scrollbar-width: none;
  -ms-overflow-style: none;
}
html::-webkit-scrollbar,
body::-webkit-scrollbar { width: 0; height: 0; display: none; }

body {
  margin: 0;
  /* 스크롤 한 바퀴가 1년이다. 이 값이 곧 계절이 흐르는 속도이고,
     키울수록 하늘이 천천히 돈다. */
  min-height: 4200vh;
  background: #000106;
  color: var(--ink);
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

/* --- 로딩 ---------------------------------------------------------------- */

#loader {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000106;
  transition: opacity 0.7s var(--ease), visibility 0.7s;
}
#loader.is-done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

#loader-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  /* 최소 노출 시간을 따로 보장하므로 여기서는 짧게만 지연한다.
     첫 프레임부터 튀어나오면 그것대로 거칠어 보인다. */
  opacity: 0;
  animation: loader-in 0.4s var(--ease) 0.08s forwards;
}

#loader-title {
  margin: 0;
  font-size: 15px;
  font-weight: 300;
  letter-spacing: 0.42em;
  text-indent: 0.42em;
  color: rgba(206, 220, 250, 0.78);
}

#loader-track {
  width: clamp(140px, 22vw, 220px);
  height: 1px;
  background: rgba(140, 170, 230, 0.16);
  overflow: hidden;
}

#loader-bar {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg,
    rgba(150, 185, 255, 0.5), rgba(226, 236, 255, 0.95));
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.25s var(--ease);
}

#loader-pct {
  margin: 0;
  font-size: 10.5px;
  letter-spacing: 0.2em;
  color: rgba(150, 175, 220, 0.5);
  font-variant-numeric: tabular-nums;
}

@keyframes loader-in {
  to { opacity: 1; }
}

/* 데이터가 준비되기 전의 깜빡임을 막는다 */
#sky {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0;
  transition: opacity 1.1s var(--ease);
}
body.is-ready #sky { opacity: 1; }

/* --- UI ------------------------------------------------------------------ */

#ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

#date-readout {
  position: absolute;
  top: clamp(20px, 4vh, 40px);
  left: clamp(20px, 4vw, 44px);
  display: flex;
  flex-direction: column;
  gap: 4px;
  opacity: 0;
  animation: fade-in 1.4s var(--ease) 0.6s forwards;
}

#date-month {
  font-size: clamp(19px, 2.4vw, 26px);
  font-weight: 300;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

#date-season {
  font-size: clamp(11px, 1.2vw, 13px);
  color: var(--ink-faint);
  letter-spacing: 0.14em;
}

#scroll-hint {
  position: absolute;
  left: 50%;
  bottom: clamp(28px, 6vh, 54px);
  transform: translateX(-50%);
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--ink-faint);
  white-space: nowrap;
  opacity: 0;
  animation: hint-in 1.6s var(--ease) 1.6s forwards;
  transition: opacity 0.6s var(--ease);
}
#scroll-hint.is-hidden { opacity: 0 !important; }

#debug {
  position: absolute;
  right: 12px;
  bottom: 12px;
  font: 11px/1.5 ui-monospace, "SFMono-Regular", Consolas, monospace;
  color: rgba(140, 255, 190, 0.85);
  background: rgba(0, 0, 0, 0.55);
  padding: 5px 9px;
  border-radius: 4px;
  display: none;
  white-space: pre;
}
#debug.is-on { display: block; }

@keyframes fade-in {
  to { opacity: 1; }
}

@keyframes hint-in {
  0% { opacity: 0; transform: translateX(-50%) translateY(6px); }
  100% { opacity: 1; transform: translateX(-50%) translateY(0); }
}

#credits-btn {
  position: absolute;
  right: clamp(16px, 2.5vw, 28px);
  bottom: clamp(16px, 2.5vh, 28px);
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink-faint);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
  transition: background 0.3s var(--ease), color 0.3s var(--ease);
}
#credits-btn:hover,
#credits-btn:focus-visible {
  background: rgba(255, 255, 255, 0.13);
  color: var(--ink);
  outline: none;
}

/* --- 별자리 레이어 -------------------------------------------------------- */

#constellation-layer {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
}

.con-path {
  fill: none;
  stroke: rgba(163, 202, 255, 0.68);
  stroke-width: 1.15;
  stroke-linecap: round;
  stroke-linejoin: round;
  /* drop-shadow 로 번지게 하면 좌표가 바뀔 때마다 필터를 다시 계산해야 해서
     커서를 올리는 순간 프레임이 무거워진다. 선을 조금 밝게 올려 대신한다. */
}

#con-label {
  fill: rgba(213, 228, 255, 0.9);
  font-size: 14px;
  letter-spacing: 0.22em;
  opacity: 0;
  paint-order: stroke;
  stroke: rgba(0, 4, 14, 0.75);
  stroke-width: 3.5;
}

/* --- 공통 다이얼로그 ------------------------------------------------------ */

#modal, #credits {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(16px, 4vw, 48px);
  opacity: 0;
  visibility: hidden;
  /* visibility 를 duration 으로 전환하면 전환이 시작되는 순간에는 아직
     hidden 이라 focus() 가 먹지 않는다. 키보드로 모달을 열었을 때 포커스가
     바깥에 남는 문제가 생기므로, 열 때는 지연 없이 즉시 visible 로 바꾸고
     닫을 때만 페이드가 끝난 뒤 hidden 이 되도록 지연을 준다. */
  transition: opacity 0.32s var(--ease), visibility 0s linear 0.32s;
}
#modal.is-open, #credits.is-open {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.32s var(--ease), visibility 0s linear 0s;
}

#modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 2, 8, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

#modal-panel, #credits-panel {
  position: relative;
  background: linear-gradient(160deg, rgba(14, 20, 38, 0.97), rgba(7, 11, 24, 0.98));
  border: 1px solid rgba(120, 150, 220, 0.16);
  border-radius: 14px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  max-height: 100%;
  overflow-y: auto;
  transform: translateY(10px) scale(0.99);
  transition: transform 0.36s var(--ease);
  scrollbar-width: thin;
  scrollbar-color: rgba(120, 150, 220, 0.3) transparent;
}
#modal-panel::-webkit-scrollbar,
#credits-panel::-webkit-scrollbar { width: 9px; }
#modal-panel::-webkit-scrollbar-track,
#credits-panel::-webkit-scrollbar-track { background: transparent; }
#modal-panel::-webkit-scrollbar-thumb,
#credits-panel::-webkit-scrollbar-thumb {
  background: rgba(120, 150, 220, 0.28);
  border-radius: 5px;
  border: 2px solid transparent;
  background-clip: content-box;
}
#modal.is-open #modal-panel,
#credits.is-open #credits-panel { transform: none; }

#modal-panel {
  width: min(940px, 100%);
  padding: clamp(24px, 3.4vw, 40px);
}

#modal-close, #credits-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink-dim);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.25s var(--ease), color 0.25s var(--ease);
}
#modal-close:hover, #credits-close:hover,
#modal-close:focus-visible, #credits-close:focus-visible {
  background: rgba(255, 255, 255, 0.14);
  color: var(--ink);
  outline: none;
}

/* --- 모달 내용 ------------------------------------------------------------ */

#modal-head { margin-bottom: 22px; }

#modal-ko {
  margin: 0;
  font-size: clamp(24px, 3vw, 33px);
  font-weight: 300;
  letter-spacing: 0.03em;
}

#modal-la {
  margin: 5px 0 0;
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--ink-faint);
  text-transform: uppercase;
}

#modal-body {
  display: grid;
  grid-template-columns: minmax(0, 460px) minmax(0, 1fr);
  gap: clamp(20px, 3vw, 40px);
  align-items: start;
}

#modal-chart-wrap {
  background: radial-gradient(ellipse at 50% 45%, #060b1c 0%, #01030a 100%);
  border: 1px solid rgba(120, 150, 220, 0.12);
  border-radius: 10px;
  padding: 8px;
}

#modal-chart {
  display: block;
  width: 100%;
  height: auto;
}

.chart-line {
  fill: none;
  stroke: rgba(140, 180, 250, 0.4);
  stroke-width: 1;
  stroke-linecap: round;
}

.chart-star { filter: drop-shadow(0 0 3px rgba(190, 215, 255, 0.75)); }

.chart-name {
  fill: rgba(198, 214, 248, 0.78);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  /* 별 위에 글자가 놓여도 읽히도록 뒤에 얇은 외곽선을 깐다 */
  paint-order: stroke;
  stroke: rgba(4, 8, 20, 0.85);
  stroke-width: 2.6;
}

/* 실루엣 이미지를 넣었을 때만 쓰인다 */
.chart-illustration { opacity: 0.17; }

#modal-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 30px;
  margin: 0 0 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(120, 150, 220, 0.13);
}
#modal-meta dt {
  font-size: 10.5px;
  letter-spacing: 0.14em;
  color: var(--ink-faint);
  margin-bottom: 3px;
}
#modal-meta dd {
  margin: 0;
  font-size: 14px;
  color: var(--ink);
}

#modal-text p {
  margin: 0 0 14px;
  font-size: 14.5px;
  line-height: 1.85;
  color: rgba(210, 222, 248, 0.88);
  word-break: keep-all;
}

#modal-summary {
  font-size: 15.5px !important;
  color: var(--ink) !important;
}

#modal-text h3 {
  margin: 24px 0 9px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.18em;
  color: rgba(150, 185, 255, 0.68);
}

#modal-stars {
  margin: 0;
  padding: 0;
  list-style: none;
}
#modal-stars li {
  padding: 9px 0;
  border-top: 1px solid rgba(120, 150, 220, 0.1);
  font-size: 13.5px;
  line-height: 1.75;
  word-break: keep-all;
}
#modal-stars li:first-child { border-top: none; }
#modal-stars b {
  display: block;
  font-weight: 500;
  color: rgba(185, 210, 255, 0.95);
  margin-bottom: 2px;
}
#modal-stars span { color: rgba(198, 212, 240, 0.74); }

/* --- 크레딧 --------------------------------------------------------------- */

#credits-panel {
  width: min(430px, 100%);
  padding: 32px;
}
#credits-title {
  margin: 0 0 20px;
  font-size: 17px;
  font-weight: 400;
  letter-spacing: 0.06em;
}
#credits dl { margin: 0; font-size: 12.5px; line-height: 1.75; }
#credits dt {
  font-size: 10px;
  letter-spacing: 0.15em;
  color: rgba(150, 185, 255, 0.62);
  margin-top: 16px;
}
#credits dt:first-child { margin-top: 0; }
#credits dd {
  margin: 4px 0 0;
  color: rgba(200, 214, 244, 0.82);
}
#credits dd span { color: var(--ink-faint); font-size: 11px; }
#credits a { color: rgba(150, 190, 255, 0.9); text-decoration: none; }
#credits a:hover { text-decoration: underline; }

/* --- 접근성 --------------------------------------------------------------- */

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
/* 키보드로 옮겨 오면 보이게 해서, 지금 어디에 있는지 알 수 있게 한다 */
.visually-hidden button:focus-visible {
  position: fixed;
  left: 50%;
  top: 24px;
  transform: translateX(-50%);
  width: auto; height: auto;
  margin: 0; padding: 9px 18px;
  clip: auto;
  clip-path: none;
  z-index: 200;
  background: rgba(12, 18, 34, 0.96);
  border: 1px solid rgba(140, 175, 245, 0.5);
  border-radius: 7px;
  color: var(--ink);
  font-size: 13px;
}

body.is-modal-open { cursor: default !important; }

/* --- 반응형 --------------------------------------------------------------- */

@media (max-width: 780px) {
  #modal-body { grid-template-columns: 1fr; }
  #modal-panel { padding: 22px 18px 26px; }
  #modal-chart-wrap { max-width: 460px; margin: 0 auto; }
}

@media (prefers-reduced-motion: reduce) {
  #sky { transition: none; }
  #date-readout, #scroll-hint, #loader-inner {
    animation-duration: 0.01ms;
    animation-delay: 0ms;
  }
  #modal, #credits, #modal-panel, #credits-panel, #loader {
    transition-duration: 0.01ms;
  }
  #loader-bar { transition: none; }
}
