/* Stargaze-AR — UX/PWA 스타일시트
 * 다크 야간 테마 + 적색광(암순응 보호) 모드. 이모지 미사용, 아이콘은 SVG/도형.
 * 색상은 CSS 변수로 관리하고 body.redlight 에서 적색 팔레트로 치환한다.
 */

:root {
  --bg-sheet: rgba(8, 12, 22, 0.94);
  --bg-panel: rgba(14, 20, 34, 0.92);
  --bg-chip: rgba(40, 54, 84, 0.55);
  --fg: #d8e2f4;
  --fg-dim: #8ea0c2;
  --fg-strong: #ffffff;
  --accent: #6ea8ff;
  --accent-soft: rgba(110, 168, 255, 0.18);
  --border: rgba(120, 150, 200, 0.22);
  --danger: #ff8a7a;
  --ok: #7ad6a0;
  --shadow: 0 -8px 30px rgba(0, 0, 0, 0.55);
  --touch: 48px; /* 최소 터치 타깃 */
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);

  /* ----- 천체 종류 시각 언어(색표). --sky-<cat>=톤(마커/글리프), -t=텍스트(라벨).
     js/ui/types.js 가 var(--sky-*) 로만 참조 → 적색광에서 같은 변수만 치환하면
     칩/카드/범례 글리프가 일괄 redlight 톤으로 바뀐다(형태는 불변). ----- */
  --sky-sun: #ffd24a;          --sky-sun-t: #ffe08a;
  --sky-moon: #dfe3ea;         --sky-moon-t: #e7ecf4;
  --sky-planet: #ffc56a;       --sky-planet-t: #ffd98a;
  --sky-star: #f4ead8;         --sky-star-t: #c7d0e0;
  --sky-constellation: #43c7d6; --sky-constellation-t: #79d2dd;
  --sky-dso: #c77dff;          --sky-dso-t: #d6a8ff;
  --sky-satellite: #46e08a;    --sky-satellite-t: #7bf0b0;
  --sky-event: #ff9a3c;        --sky-event-t: #ffb866;
}

/* 적색광 모드: 야간 암순응 보호용 붉은 단색 팔레트 */
body.redlight {
  --bg-sheet: rgba(20, 4, 4, 0.95);
  --bg-panel: rgba(28, 6, 6, 0.93);
  --bg-chip: rgba(80, 18, 18, 0.55);
  --fg: #ff9a86;
  --fg-dim: #c5705f;
  --fg-strong: #ffb9a6;
  --accent: #ff6a4d;
  --accent-soft: rgba(255, 106, 77, 0.18);
  --border: rgba(255, 120, 90, 0.28);
  --danger: #ffb0a0;
  --ok: #ff8f70;

  /* 적색광: 채도를 죽인 redlight 톤으로 종류색을 치환(밝기·형태 단서는 글리프가 유지).
     색만으로 구분 불가한 적색광에서도 형태(점/선/고리/빛살/반달/점선원/다이아/십자)로 읽힌다. */
  --sky-sun: #ff9d6a;          --sky-sun-t: #ffb892;
  --sky-moon: #e7b6a6;         --sky-moon-t: #f0c8bb;
  --sky-planet: #ff9d7a;       --sky-planet-t: #ffb398;
  --sky-star: #c98a78;         --sky-star-t: #b9776a;
  --sky-constellation: #c2554a; --sky-constellation-t: #cf6f5f;
  --sky-dso: #cf7d92;          --sky-dso-t: #dd9aaa;
  --sky-satellite: #d98a6a;    --sky-satellite-t: #e6a488;
  --sky-event: #ff8a5c;        --sky-event-t: #ffa078;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: #05070f;
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo",
    "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

/* ----- 레이어: 카메라 영상 / three.js 캔버스 / DOM 오버레이 ----- */
#cam {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #05070f;
  z-index: 0;
}
#cam[hidden] { display: none; }

#sky {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
  touch-action: none;
}

#overlay {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none; /* 빈 영역은 캔버스로 패스스루 */
}
#overlay > * { pointer-events: auto; }

/* 적색광 야간 보호 베일(은은한 붉은 막) — 카메라/캔버스 위, UI 아래 */
#nightveil {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(120, 0, 0, 0.10), rgba(90, 0, 0, 0.22));
  opacity: 0;
  transition: opacity 0.3s ease;
}
body.redlight #nightveil { opacity: 1; }

/* ----- 조준점(중앙 십자선) ----- */
#crosshair {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  z-index: 2;
  pointer-events: none;
  opacity: 0.85;
}
#crosshair::before, #crosshair::after {
  content: "";
  position: absolute;
  background: var(--accent);
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.8);
}
#crosshair::before { left: 50%; top: 0; width: 2px; height: 100%; margin-left: -1px; }
#crosshair::after  { top: 50%; left: 0; height: 2px; width: 100%; margin-top: -1px; }
#crosshair .ring {
  position: absolute;
  inset: 12px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  opacity: 0.7;
}

/* ----- 상단 바 ----- */
#topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(8px + var(--safe-t)) 12px 8px;
  z-index: 3;
}
.brand {
  font-weight: 700;
  font-size: 15px;
  color: var(--fg-strong);
  letter-spacing: 0.5px;
  margin-right: auto;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.7);
}
.brand small { display: block; font-weight: 400; font-size: 11px; color: var(--fg-dim); }

/* ----- 둥근 아이콘 버튼 ----- */
.iconbtn {
  min-width: var(--touch);
  min-height: var(--touch);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 10px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--fg);
  border-radius: 14px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}
.iconbtn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.iconbtn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--fg-strong); }
.iconbtn .lbl { font-size: 12px; }

/* ----- 하단 내비게이션 ----- */
#bottomnav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-around;
  gap: 6px;
  padding: 8px 10px calc(8px + var(--safe-b));
  background: linear-gradient(to top, rgba(5, 7, 15, 0.92), rgba(5, 7, 15, 0));
  z-index: 3;
}
#bottomnav .iconbtn {
  flex: 1;
  flex-direction: column;
  gap: 2px;
  padding: 6px 4px;
  border-radius: 16px;
}

/* ----- 배너(권한/폴백 안내) ----- */
#banners {
  position: fixed;
  left: 10px;
  right: 10px;
  top: calc(58px + var(--safe-t));
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.banner {
  pointer-events: auto;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--fg);
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}
.banner.warn { border-left-color: var(--danger); }
.banner .grow { flex: 1; }
.banner button {
  flex: none;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-chip);
  color: var(--fg-strong);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}
.banner .x {
  border: none;
  background: none;
  color: var(--fg-dim);
  font-size: 18px;
  min-width: 32px;
  padding: 0;
}

/* ----- 바텀시트 공통 ----- */
#sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 4;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease;
}
#sheet-backdrop.show { opacity: 1; visibility: visible; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-sheet);
  border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow);
  transform: translateY(102%);
  transition: transform 0.26s cubic-bezier(0.2, 0.7, 0.3, 1);
  padding-bottom: var(--safe-b);
  backdrop-filter: blur(8px);
}
.sheet.open { transform: translateY(0); }

.sheet-handle {
  width: 42px;
  height: 4px;
  background: var(--fg-dim);
  border-radius: 3px;
  margin: 8px auto 4px;
  opacity: 0.6;
  flex: none;
}
.sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 16px 10px;
  flex: none;
}
.sheet-head h2 { margin: 0; font-size: 18px; color: var(--fg-strong); flex: 1; }
.sheet-close {
  border: none;
  background: var(--bg-chip);
  color: var(--fg);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
}
.sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 16px 20px;
}

/* ----- 정보 카드 ----- */
.card-sub { color: var(--fg-dim); font-size: 13px; margin: -4px 0 12px; }
.card-summary { font-size: 15px; line-height: 1.55; margin: 0 0 14px; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 16px; }
.fact {
  background: var(--bg-chip);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px;
}
.fact .l { font-size: 11px; color: var(--fg-dim); }
.fact .v { font-size: 15px; color: var(--fg-strong); font-weight: 600; }
.card-body { font-size: 14px; line-height: 1.65; }
.card-body h3 { font-size: 15px; color: var(--fg-strong); margin: 16px 0 6px; }
.card-body p { margin: 0 0 10px; }
.card-body ul { margin: 0 0 10px; padding-left: 20px; }
.card-body strong { color: var(--fg-strong); }
.card-sources { margin-top: 16px; font-size: 11px; color: var(--fg-dim); }
.card-sources li { margin-bottom: 2px; word-break: break-all; }
.card-actions { display: flex; gap: 8px; margin: 4px 0 14px; }
.btn-primary {
  flex: 1;
  min-height: var(--touch);
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--fg-strong);
  border-radius: 12px;
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
}

/* ----- 검색 ----- */
.search-input {
  width: 100%;
  min-height: var(--touch);
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-chip);
  color: var(--fg-strong);
  font-size: 16px; /* iOS 확대 방지 위해 16px 이상 */
  font-family: inherit;
  margin-bottom: 12px;
}
.result-list, .today-list { list-style: none; margin: 0; padding: 0; }
.result {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--touch);
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.result .name { flex: 1; }
.result .name b { font-size: 15px; color: var(--fg-strong); font-weight: 600; display: block; }
.result .name span { font-size: 12px; color: var(--fg-dim); }
.result .meta { font-size: 12px; color: var(--fg-dim); text-align: right; }
.result .meta .up { color: var(--ok); }
.result .meta .down { color: var(--fg-dim); }
.chip {
  flex: none;
  border: 1px solid var(--border);
  background: var(--bg-chip);
  color: var(--fg);
  border-radius: 10px;
  min-height: 38px;
  padding: 0 12px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}
.muted { color: var(--fg-dim); font-size: 13px; padding: 14px 2px; }
.section-title { font-size: 12px; color: var(--fg-dim); margin: 14px 0 6px; text-transform: none; }

/* ----- 천체 종류 칩/글리프 (검색·오늘밤·카드·범례 공유) -----
 * 색은 인라인 --c(톤)/--ct(텍스트) 변수로 주입(types.js). 배경/테두리는 톤에서 파생
 * (color-mix)해 적색광에서 자동 재틴트. color-mix 미지원 브라우저는 중성 칩으로 폴백. */
.tdot {
  flex: none;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  color: var(--c, var(--fg-dim));
  background: var(--bg-chip);
  background: color-mix(in srgb, var(--c, var(--fg-dim)) 15%, transparent);
  border: 1px solid var(--border);
  border: 1px solid color-mix(in srgb, var(--c, var(--fg-dim)) 40%, transparent);
  pointer-events: none;
}
.tdot svg { width: 18px; height: 18px; display: block; }
.tdot svg, .tchip .g svg { fill: none; }

.tchip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px 2px 6px;
  border-radius: 999px;
  font-size: 11.5px;
  line-height: 1.5;
  white-space: nowrap;
  color: var(--ct, var(--fg));
  background: var(--bg-chip);
  background: color-mix(in srgb, var(--c, var(--fg-dim)) 15%, transparent);
  border: 1px solid var(--border);
  border: 1px solid color-mix(in srgb, var(--c, var(--fg-dim)) 42%, transparent);
}
.tchip .g {
  flex: none;
  width: 15px;
  height: 15px;
  display: inline-flex;
  color: var(--c, var(--fg-dim));
}
.tchip .g svg { width: 100%; height: 100%; display: block; }
.tchip .t { font-weight: 600; }

/* 적색광에서 형태 가독성↑: 글리프 선/테두리를 또렷하게 */
body.redlight .tdot,
body.redlight .tchip { border-color: color-mix(in srgb, var(--c, var(--fg-dim)) 60%, transparent); }

/* ----- 정보 카드 종류 액센트 (data-sky-type + --card-c/--card-t, types/card.js 주입) ----- */
#sheet-card[data-sky-type] { border-top: 2px solid var(--card-c, var(--border)); }
#sheet-card[data-sky-type] .sheet-head {
  border-left: 3px solid var(--card-c, var(--accent));
  padding-left: 13px;
  margin-left: -3px;
}
#sheet-card[data-sky-type] .sheet-head h2 { color: var(--card-t, var(--fg-strong)); }
.card-typebar { margin: 0 0 10px; }

/* ----- 범례(설정 패널 접이식) ----- */
details.legend { display: block; padding: 12px 0; }
details.legend > summary {
  list-style: none;
  display: flex;
  align-items: center;
  cursor: pointer;
  gap: 8px;
}
details.legend > summary::-webkit-details-marker { display: none; }
details.legend > summary::after {
  content: "";
  width: 9px;
  height: 9px;
  flex: none;
  border-right: 2px solid var(--fg-dim);
  border-bottom: 2px solid var(--fg-dim);
  transform: rotate(45deg);
  transition: transform 0.15s;
}
details.legend[open] > summary::after { transform: rotate(-135deg); }
details.legend > summary .t { font-size: 14px; color: var(--fg-strong); display: block; }
details.legend > summary .d { font-size: 12px; color: var(--fg-dim); margin-top: 2px; }
.legend-body { padding: 10px 0 2px; }
.legend-group {
  font-size: 11px;
  color: var(--fg-dim);
  margin: 12px 0 6px;
}
.legend-group:first-child { margin-top: 4px; }
.legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
}
.legend-row .tchip { flex: none; min-width: 74px; }
.legend-desc { font-size: 12.5px; color: var(--fg); }

/* ----- 설정 ----- */
.set-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.set-row .grow { flex: 1; }
.set-row label.t { font-size: 14px; color: var(--fg-strong); display: block; }
.set-row .d { font-size: 12px; color: var(--fg-dim); margin-top: 2px; }
.set-row input[type="number"] {
  width: 96px;
  min-height: 40px;
  text-align: right;
  padding: 0 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-chip);
  color: var(--fg-strong);
  font-size: 16px;
  font-family: inherit;
}
.set-row input[type="range"] { width: 130px; }

/* 스위치 토글 */
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute;
  inset: 0;
  background: var(--bg-chip);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background 0.15s;
}
.switch .track::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--fg-dim);
  transition: transform 0.15s, background 0.15s;
}
.switch input:checked + .track { background: var(--accent-soft); border-color: var(--accent); }
.switch input:checked + .track::before { transform: translateX(20px); background: var(--accent); }

/* ----- 방향 안내(검색 결과로 천체 찾기) ----- */
#direction-guide {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 4;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  pointer-events: none;
}
#direction-guide.show { display: flex; }
#direction-guide .arrow {
  width: 96px;
  height: 96px;
  color: var(--accent);
  filter: drop-shadow(0 0 8px rgba(0, 0, 0, 0.7));
  transition: transform 0.12s linear;
}
#direction-guide .arrow svg { width: 100%; height: 100%; fill: currentColor; }
#direction-guide .dg-label {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 14px;
  font-size: 15px;
  color: var(--fg-strong);
  text-align: center;
  pointer-events: auto;
}
#direction-guide .dg-target { font-size: 12px; color: var(--fg-dim); display: block; }
#direction-guide .dg-close {
  pointer-events: auto;
  margin-top: 4px;
  border: 1px solid var(--border);
  background: var(--bg-chip);
  color: var(--fg);
  border-radius: 10px;
  min-height: 40px;
  padding: 0 16px;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}
#direction-guide .arrow.found { color: var(--ok); }

/* ----- 토스트 ----- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(86px + var(--safe-b));
  transform: translateX(-50%) translateY(10px);
  z-index: 6;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--fg-strong);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 13px;
  max-width: 86vw;
  text-align: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0); }

/* ----- 시작 화면(권한 안내 + 관측 시작) ----- */
#start-screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: radial-gradient(ellipse at 50% 30%, #0c1730, #05070f 70%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px 28px calc(32px + var(--safe-b));
}
#start-screen.hide { display: none; }
#start-screen .logo {
  width: 84px;
  height: 84px;
  margin-bottom: 18px;
  color: var(--accent);
}
#start-screen h1 { font-size: 26px; margin: 0 0 6px; color: var(--fg-strong); }
#start-screen .tag { color: var(--fg-dim); font-size: 14px; margin: 0 0 26px; }
.perm-list { list-style: none; margin: 0 0 28px; padding: 0; max-width: 360px; text-align: left; }
.perm-list li {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--fg);
}
.perm-list .pi {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--bg-chip);
  border: 1px solid var(--border);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}
.perm-list .pi svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.perm-list b { color: var(--fg-strong); display: block; font-size: 14px; }
#btn-start {
  min-height: 56px;
  padding: 0 36px;
  border-radius: 16px;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--fg-strong);
  font-size: 18px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}
#start-screen .note { margin-top: 18px; font-size: 11px; color: var(--fg-dim); max-width: 340px; }

/* ----- 설치 배너 ----- */
#install-banner {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: calc(80px + var(--safe-b));
  z-index: 7;
  background: var(--bg-panel);
  border: 1px solid var(--accent);
  border-radius: 14px;
  padding: 12px 14px;
  display: none;
  align-items: center;
  gap: 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
}
#install-banner.show { display: flex; }
#install-banner .grow { flex: 1; font-size: 13px; }
#install-banner b { color: var(--fg-strong); display: block; font-size: 14px; margin-bottom: 2px; }

@media (min-width: 720px) {
  .sheet { left: 50%; right: auto; width: 460px; transform: translate(-50%, 102%); }
  .sheet.open { transform: translate(-50%, 0); }
}
