:root {
  --color-bg: #07080f;
  --color-surface: #12141d;
  --color-surface-raised: #1b1e2a;
  --color-text: #f1f2f6;
  --color-text-muted: #9a9fb2;
  --color-primary: #7c9cff;
  --color-border: #2a2e3d;
  --color-warn-bg: #2a2314;
  --color-warn-border: #6b5523;
  --color-warn-text: #ffd27a;
  --color-danger-bg: #2a1414;
  --color-danger-border: #6b2323;
  --color-danger-text: #ff8a8a;
  --tier-best: #3ddc97;
  --tier-good: #9bd94f;
  --tier-fair: #f5b942;
  --tier-low: #ff8a4c;
  --tier-poor: #ff5a5a;
  --tier-none: #6b6f80;
  --radius-lg: 20px;
  --radius-md: 12px;
  --shadow-elevated: 0 4px 24px rgba(0, 0, 0, 0.55);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --sheet-height: 44vh;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Malgun Gothic", sans-serif;
  color: var(--color-text);
  background: var(--color-bg);
  overscroll-behavior: none;
}

.muted { color: var(--color-text-muted); }

.map-sky {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  visibility: hidden;
  background: #02030a;
}

#map {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  background: transparent;
}

.map-config-notice {
  position: fixed;
  top: calc(120px + var(--safe-top));
  left: 16px;
  right: 16px;
  z-index: 30;
  background: var(--color-danger-bg);
  border: 1px solid var(--color-danger-border);
  color: var(--color-danger-text);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  line-height: 1.5;
}

/* ---------- 상단 바 ---------- */

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: linear-gradient(to bottom, rgba(7, 8, 15, 0.92), rgba(7, 8, 15, 0));
  pointer-events: none;
}

.topbar > * { pointer-events: auto; }

.topbar-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.chip {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
}

.date-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 4px;
  box-shadow: var(--shadow-elevated);
}

.date-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--color-surface-raised);
  color: var(--color-text);
  font-size: 12px;
  cursor: pointer;
}

.date-btn:disabled { opacity: 0.35; cursor: default; }

#date-input {
  background: transparent;
  border: none;
  color: var(--color-text);
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  padding: 6px 4px;
  color-scheme: dark;
}

.status-banner {
  margin: 8px 0 0;
  padding: 8px 12px;
  max-width: 460px;
  background: var(--color-warn-bg);
  border: 1px solid var(--color-warn-border);
  color: var(--color-warn-text);
  border-radius: var(--radius-md);
  font-size: 12.5px;
  line-height: 1.5;
}

/* ---------- 3D 버튼 ---------- */

.fab {
  position: fixed;
  right: 16px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-elevated);
  z-index: 20;
  cursor: pointer;
}

.fab-3d {
  bottom: calc(var(--sheet-height) + 16px + var(--safe-bottom));
  background: var(--color-surface-raised);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  transition: background 150ms ease, color 150ms ease, border-color 150ms ease;
}

.fab-3d.is-active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #0b0d18;
}

/* ---------- 지도 하늘 도크 ---------- */

.sky-dock {
  position: fixed;
  left: 16px;
  bottom: calc(var(--sheet-height) + 16px + var(--safe-bottom));
  z-index: 21;
  max-width: calc(100vw - 100px);
  padding: 8px 10px;
  background: rgba(18, 20, 29, 0.88);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-elevated);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.sky-dock[hidden] { display: none; }

.dock-row { display: flex; align-items: center; gap: 6px; }

.dock-step {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: var(--color-surface-raised);
  color: var(--color-text);
  font-size: 11px;
  cursor: pointer;
}

.dock-step:disabled { opacity: 0.35; cursor: default; }

.dock-time {
  min-width: 46px;
  text-align: center;
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.dock-gc {
  margin-left: 4px;
  height: 32px;
  padding: 0 12px;
  border-radius: 16px;
  border: none;
  background: linear-gradient(135deg, #7c9cff, #a78bff);
  color: #0b0d18;
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.dock-sub {
  margin: 6px 2px 0;
  font-size: 11px;
  line-height: 1.4;
  color: var(--color-text-muted);
}

/* ---------- 하단 시트 ---------- */

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--sheet-height);
  z-index: 25;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-elevated);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: height 220ms ease;
}

.sheet-bar {
  flex: none;
  width: 100%;
  display: block;
  padding: 8px 16px 8px;
  background: transparent;
  border: none;
  color: inherit;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.sheet-grip {
  display: block;
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--color-border);
  margin: 0 auto 8px;
}

.sheet-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  font-size: 15px;
}

.sheet-bar-row strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sheet-chevron {
  margin-left: auto;
  width: 10px;
  height: 10px;
  border-right: 2px solid var(--color-text-muted);
  border-bottom: 2px solid var(--color-text-muted);
  transform: rotate(45deg) translateY(-3px);
  transition: transform 220ms ease;
}

.sheet.is-collapsed .sheet-chevron { transform: rotate(-135deg) translate(-2px, -2px); }

.sheet-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 16px calc(14px + var(--safe-bottom));
  -webkit-overflow-scrolling: touch;
}

.sheet.is-collapsed .sheet-scroll { visibility: hidden; }

body.sheet-collapsed { --sheet-height: calc(76px + var(--safe-bottom)); }

.spot-list { list-style: none; margin: 0; padding: 0; }

.spot-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
}

.spot-item:last-child { border-bottom: none; }

.spot-rank { width: 20px; text-align: center; color: var(--color-text-muted); font-size: 13px; }

.spot-info { flex: 1; min-width: 0; }

.spot-name {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.spot-sub { font-size: 12px; color: var(--color-text-muted); margin-top: 2px; }

.score-badge {
  min-width: 52px;
  text-align: center;
  padding: 6px 8px;
  border-radius: var(--radius-md);
  font-weight: 800;
  font-size: 16px;
  color: #0b0d18;
  background: var(--tier-none);
}

.score-badge small { display: block; font-size: 10.5px; font-weight: 700; opacity: 0.85; }

.tier-best { background: var(--tier-best); }
.tier-good { background: var(--tier-good); }
.tier-fair { background: var(--tier-fair); }
.tier-low { background: var(--tier-low); }
.tier-poor { background: var(--tier-poor); }
.tier-none { background: var(--tier-none); color: #fff; }

.attribution {
  margin: 12px 0 0;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--color-text-muted);
}

.attribution a { color: var(--color-primary); }

/* ---------- 지도 마커 ---------- */

.spot-marker {
  width: 40px;
  height: 40px;
  cursor: pointer;
}

.spot-marker-body {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  color: #0b0d18;
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
  transition: transform 120ms ease;
}

.spot-marker.is-selected {
  z-index: 5;
}

.spot-marker.is-selected .spot-marker-body {
  transform: scale(1.25);
  border-color: #fff;
}

.spot-marker.is-unverified .spot-marker-body {
  border-style: dashed;
}

/* ---------- 상세 ---------- */

.back-btn {
  background: none;
  border: none;
  color: var(--color-primary);
  font-family: inherit;
  font-size: 14px;
  padding: 0 0 8px;
  cursor: pointer;
}

.detail-head { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.detail-head h2 { margin: 0; font-size: 18px; }
.detail-head .score-badge { font-size: 22px; min-width: 68px; }

.detail-meta { font-size: 13px; color: var(--color-text-muted); line-height: 1.6; margin: 0 0 10px; }

.warn-box {
  margin: 8px 0;
  padding: 8px 12px;
  background: var(--color-warn-bg);
  border: 1px solid var(--color-warn-border);
  color: var(--color-warn-text);
  border-radius: var(--radius-md);
  font-size: 12.5px;
  line-height: 1.5;
}

.factor-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 12px 0;
}

.factor {
  background: var(--color-surface-raised);
  border-radius: var(--radius-md);
  padding: 8px 10px;
}

.factor span { display: block; font-size: 11.5px; color: var(--color-text-muted); }
.factor b { font-size: 15px; }

.tips { margin: 8px 0; padding-left: 18px; font-size: 13px; line-height: 1.6; }

.timeline { display: flex; align-items: flex-end; gap: 3px; height: 70px; margin: 12px 0 4px; }

.timeline-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; }

.timeline-bar { width: 100%; border-radius: 3px 3px 0 0; min-height: 2px; background: var(--tier-none); }

.timeline-label { font-size: 9.5px; color: var(--color-text-muted); margin-top: 3px; }

.link-row { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }

.link-btn {
  padding: 8px 12px;
  border-radius: var(--radius-md);
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  font-size: 13px;
  text-decoration: none;
}

/* ---------- 좌표 확인 도구 (?edit=1) ---------- */

.coord-tool {
  position: fixed;
  right: 16px;
  top: calc(70px + var(--safe-top));
  z-index: 30;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.6;
  max-width: 260px;
}

.coord-tool code { color: var(--color-primary); user-select: all; }

/* ---------- 3D 밤하늘 ---------- */

body.sky-open { overflow: hidden; }

.sky-view {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: #000;
  color: var(--color-text);
  user-select: none;
  -webkit-user-select: none;
}

.sky-view[hidden] { display: none; }

#sky-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

#sky-canvas:active { cursor: grabbing; }

.sky-labels {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.sky-label {
  position: absolute;
  left: 0;
  top: 0;
  white-space: nowrap;
  font-size: 11.5px;
  line-height: 1;
  text-shadow: 0 0 4px #000, 0 0 8px #000;
  will-change: transform;
}

.sky-label[hidden] { display: none; }
.sky-label-con { color: rgba(150, 180, 255, 0.78); letter-spacing: 0.02em; }
.sky-label-star { color: rgba(235, 240, 255, 0.85); margin-top: 7px; }
.sky-label-gc { color: rgba(255, 214, 140, 0.95); font-weight: 700; margin-top: 12px; }
.sky-label-planet { color: rgba(255, 236, 190, 0.95); font-weight: 700; margin-top: 8px; }
.sky-label-moon { color: rgba(255, 244, 214, 0.95); font-weight: 700; margin-top: 17px; }
.sky-label-cardinal { color: rgba(255, 255, 255, 0.8); font-size: 15px; font-weight: 800; }

.sky-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + var(--safe-top)) 14px 24px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0));
  pointer-events: none;
}

.sky-top > * { pointer-events: auto; }

.sky-close {
  flex: none;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: rgba(18, 20, 29, 0.85);
  color: var(--color-text);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
}

.sky-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; text-shadow: 0 0 6px #000; }
.sky-title strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sky-title span { font-size: 12px; color: var(--color-text-muted); }

.sky-loading {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  background: rgba(18, 20, 29, 0.9);
  font-size: 14px;
}

.sky-loading[hidden] { display: none; }

.sky-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 28px 14px calc(12px + var(--safe-bottom));
  background: linear-gradient(to top, rgba(0, 0, 0, 0.88) 55%, rgba(0, 0, 0, 0));
  pointer-events: none;
}

.sky-panel > * { pointer-events: auto; }

.sky-info {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  margin-bottom: 10px;
  font-size: 12.5px;
}

.sky-info span { color: var(--color-text-muted); margin-right: 6px; }

.sky-time-row { display: flex; align-items: center; gap: 10px; }

.sky-play {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: rgba(27, 30, 42, 0.95);
  color: var(--color-text);
  font-size: 13px;
  cursor: pointer;
}

#sky-time { flex: 1; accent-color: var(--color-primary); height: 30px; }

.sky-time-label { flex: none; min-width: 48px; text-align: right; font-weight: 800; font-size: 16px; font-variant-numeric: tabular-nums; }

.sky-toggles { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.sky-chip {
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: rgba(27, 30, 42, 0.9);
  color: var(--color-text-muted);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}

.sky-chip[aria-pressed="true"] {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #0b0d18;
  font-weight: 700;
}

.sky-credit { margin: 10px 0 0; font-size: 10.5px; line-height: 1.55; color: var(--color-text-muted); }
.sky-credit a { color: var(--color-primary); }

.sky-open-btn {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: none;
  background: linear-gradient(135deg, #7c9cff, #a78bff);
  color: #0b0d18;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}

@media (min-width: 900px) {
  :root { --sheet-height: 100vh; }
  .sheet {
    left: 16px;
    top: 200px;
    bottom: 16px;
    right: auto;
    width: 380px;
    height: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
  }
  .fab-3d { bottom: 24px; }
  .sky-dock { left: 412px; bottom: 24px; max-width: none; }
  .sheet-grip, .sheet-chevron { display: none; }
  .sheet-bar { cursor: default; padding-top: 14px; pointer-events: none; }
  .sheet.is-collapsed .sheet-scroll { visibility: visible; }
  body.sheet-collapsed { --sheet-height: 100vh; }
}
