:root {
  --bg: #0b1026;
  --bg2: #131a3a;
  --card: #1a2246;
  --card-edge: #2a3466;
  --text: #eef1ff;
  --dim: #9aa3cf;
  --accent: #ffd76a;
  --good: #6ee7a0;
  --radius: 16px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
  min-height: 100vh;
  color: var(--text);
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 14px calc(20px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 2px 10px;
}
.brand { font-size: 1.35rem; font-weight: 800; letter-spacing: -0.02em; }
.brand-star { color: var(--accent); }

.loc-chip {
  background: var(--card);
  border: 1px solid var(--card-edge);
  color: var(--dim);
  border-radius: 14px;
  padding: 5px 12px;
  font-size: 0.78rem;
  line-height: 1.3;
  cursor: pointer;
  max-width: 100%;
  text-align: left;
  white-space: normal;    /* 길면 2줄로 */
  word-break: keep-all;
}
.topbar-right { max-width: 64%; }
.loc-chip:active { opacity: 0.7; }

.datenav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.datenav button {
  background: var(--card);
  border: 1px solid var(--card-edge);
  color: var(--text);
  border-radius: 12px;
  width: 44px;
  height: 44px;
  font-size: 1rem;
  cursor: pointer;
}
.datenav-center { text-align: center; }
.date-label { font-size: 1.08rem; font-weight: 700; }
.btn-today {
  width: auto !important;
  height: auto !important;
  padding: 3px 12px;
  font-size: 0.8rem !important;
  color: var(--accent) !important;
  margin-top: 3px;
}
.hidden { display: none !important; }

.card {
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card-title {
  font-size: 0.85rem;
  color: var(--dim);
  font-weight: 600;
  margin-bottom: 8px;
}
.card-title .sub { font-weight: 400; font-size: 0.78rem; opacity: 0.8; }

.card-hero { text-align: center; padding: 20px 16px; }
.hero-time { font-size: 1.7rem; font-weight: 800; letter-spacing: -0.01em; }
.hero-sub { color: var(--dim); margin-top: 6px; font-size: 0.95rem; }

.badge {
  display: inline-block;
  margin-top: 10px;
  padding: 5px 14px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 700;
  background: rgba(110, 231, 160, 0.12);
  color: var(--good);
  border: 1px solid rgba(110, 231, 160, 0.35);
}
.badge.warn {
  background: rgba(255, 215, 106, 0.10);
  color: var(--accent);
  border-color: rgba(255, 215, 106, 0.35);
}

.card-moon { display: flex; align-items: center; gap: 16px; }
#moon-canvas { flex: 0 0 auto; width: 110px; height: 110px; }
.moon-info { flex: 1; min-width: 0; }
.big { font-size: 1.35rem; font-weight: 800; margin-bottom: 4px; }
.detail { color: var(--dim); font-size: 0.92rem; line-height: 1.55; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid2 .card { margin-bottom: 12px; }

.row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 5px 0;
  font-size: 0.95rem;
}
.row span { color: var(--dim); font-size: 0.85rem; }
.row b { font-variant-numeric: tabular-nums; font-weight: 700; }

.week-list { font-size: 0.8rem; }
.week-row {
  display: flex;
  justify-content: space-between;
  gap: 4px;
  padding: 3px 0;
  color: var(--dim);
  white-space: nowrap;
}
.week-row b { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 600; }
.week-row .wk-moon { width: 3.2em; text-align: right; }

footer {
  text-align: center;
  color: var(--dim);
  font-size: 0.78rem;
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.coords { opacity: 0.7; }

/* ---------- 하단 탭 ---------- */
body { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }

.tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 560px;
  display: flex;
  background: rgba(15, 21, 48, 0.96);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--card-edge);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  gap: 8px;
  z-index: 10;
}
.tabbar button {
  flex: 1;
  background: none;
  border: none;
  color: var(--dim);
  font-size: 1rem;
  font-weight: 700;
  padding: 11px 0;
  border-radius: 12px;
  cursor: pointer;
  font-family: inherit;
}
.tabbar button.active { background: var(--card); color: var(--accent); }

/* ---------- 촬영 시간 설정 ---------- */
.hours-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 10px;
}
.hours-label { color: var(--dim); font-size: 0.85rem; font-weight: 600; white-space: nowrap; }
.hours-sep { color: var(--dim); }
.hours-bar select {
  flex: 1;
  background: var(--bg2);
  border: 1px solid var(--card-edge);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 8px;
  font-size: 0.95rem;
  font-family: inherit;
}

/* ---------- 대상 검색 ---------- */
.search-wrap { margin-bottom: 12px; }
#target-search {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1.05rem;
  padding: 14px 16px;
  font-family: inherit;
  outline: none;
}
#target-search:focus { border-color: var(--accent); }
#target-search::placeholder { color: var(--dim); opacity: 0.7; }

.type-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 10px;
  scrollbar-width: none;
}
.type-chips::-webkit-scrollbar { display: none; }
.type-chips button {
  background: var(--card);
  border: 1px solid var(--card-edge);
  color: var(--dim);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  flex: none;
}
.type-chips button.active {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(255, 215, 106, 0.08);
}

.t-head { color: var(--dim); font-size: 0.85rem; font-weight: 600; margin: 4px 2px 8px; }
.t-row {
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: var(--radius);
  padding: 13px 16px;
  margin-bottom: 8px;
  cursor: pointer;
}
.t-row:active { opacity: 0.75; }
.t-row { display: flex; align-items: center; gap: 12px; }
.t-thumb {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  object-fit: cover;
  flex: none;
  /* 실측 서베이 사진이 어두워서 밝기 보정 */
  filter: brightness(1.7) contrast(1.12) saturate(1.4);
  background: linear-gradient(110deg, #131a3a 40%, #232c5c 50%, #131a3a 60%);
  background-size: 250% 100%;
  animation: thumb-loading 1.4s linear infinite;
}
.t-info { flex: 1; min-width: 0; }
.d-head { display: flex; align-items: flex-start; gap: 14px; justify-content: space-between; }
.d-thumb {
  width: 96px;
  height: 96px;
  border-radius: 12px;
  object-fit: cover;
  flex: none;
  margin-top: 8px;
  filter: brightness(1.7) contrast(1.12) saturate(1.4);
  background: linear-gradient(110deg, #131a3a 40%, #232c5c 50%, #131a3a 60%);
  background-size: 250% 100%;
  animation: thumb-loading 1.4s linear infinite;
}
@keyframes thumb-loading {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}

#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 18, 0.92);
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 20px;
  cursor: pointer;
}
#lightbox-img {
  max-width: min(92vw, 620px);
  max-height: 72vh;
  border-radius: 16px;
  filter: brightness(1.7) contrast(1.12) saturate(1.4);
  background: linear-gradient(110deg, #131a3a 40%, #232c5c 50%, #131a3a 60%);
  background-size: 250% 100%;
  animation: thumb-loading 1.4s linear infinite;
  min-width: 240px;
  min-height: 240px;
  object-fit: contain;
}
#lightbox-cap { font-size: 1.1rem; font-weight: 700; }
.lightbox-hint { color: var(--dim); font-size: 0.8rem; }

/* ---------- 은하수 탭 ---------- */
.mw-day {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(42, 52, 102, 0.5);
  font-size: 0.9rem;
  color: var(--dim);
}
.mw-day:last-child { border-bottom: none; }
.mw-day b { color: var(--text); min-width: 5.5em; }
.mw-day.today b { color: var(--accent); }
.mw-day span { font-variant-numeric: tabular-nums; }
.mw-dur { color: var(--good); margin-left: auto; }
.mw-moon { min-width: 3.4em; text-align: right; }

.mw-hour {
  padding: 8px 0 8px 10px;
  border-left: 3px solid var(--card-edge);
  margin-bottom: 8px;
}
.mw-hour.best { border-left-color: var(--accent); }
.mw-hour.good { border-left-color: var(--good); }
.mw-hour.warn { border-left-color: #e07b5a; }
.mw-hour-top {
  display: flex;
  gap: 10px;
  align-items: baseline;
  font-size: 0.92rem;
}
.mw-hour-top b { min-width: 2.6em; }
.mw-hour-top span { color: var(--dim); font-size: 0.85rem; }
.mw-verdict { margin-left: auto; font-weight: 700; }
.mw-hour.best .mw-verdict { color: var(--accent); }
.mw-hour.good .mw-verdict { color: var(--good); }
.mw-hour.warn .mw-verdict { color: #e07b5a; }
.mw-hour.dim .mw-verdict { color: var(--dim); font-weight: 400; }
.mw-band { color: var(--dim); font-size: 0.8rem; margin-top: 3px; line-height: 1.5; }
.mw-cloud-some { color: var(--accent); }
.mw-cloudcol { min-width: 4.2em; text-align: right; font-size: 0.82rem; }

/* ---------- 적색 모드 (암적응 보호) ---------- */
html.red-mode body,
html.red-mode .tabbar,
html.red-mode #lightbox {
  filter: sepia(1) saturate(5) hue-rotate(-50deg) brightness(0.72) contrast(1.05);
}
html.red-mode { background: #000; }
.topbar-right { display: flex; align-items: center; gap: 8px; max-width: 60%; }
.red-toggle {
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: 999px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 0.9rem;
  flex: none;
}
html.red-mode .red-toggle { border-color: #f66; }

/* ---------- 행성·유성우·ISS 카드 ---------- */
.pl-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 5px 0;
  font-size: 0.92rem;
}
.pl-name { color: var(--dim); font-size: 0.88rem; }
.pl-no { color: var(--dim); opacity: 0.6; font-size: 0.85rem; }
.pl-row b { font-variant-numeric: tabular-nums; }

.mt-row {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 6px 0;
  font-size: 0.85rem;
  color: var(--dim);
  flex-wrap: wrap;
}
.mt-row b { color: var(--text); font-size: 0.92rem; }
.mt-row.now b { color: var(--accent); }
.mt-zhr { margin-left: auto; }
.mt-moon.good { color: var(--good); }
.mt-moon.ok { color: var(--accent); }
.mt-moon.bad { color: #e07b5a; }

#planet-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-top: 8px;
  font-size: 0.82rem;
  color: var(--dim);
}
.pl-leg { display: flex; align-items: center; gap: 5px; }
.pl-leg i {
  width: 10px;
  height: 3px;
  border-radius: 2px;
  display: inline-block;
}
.pl-leg b { color: var(--text); font-variant-numeric: tabular-nums; }

.at-good { color: var(--good); }
.at-ok { color: var(--accent); }
.at-bad { color: #e07b5a; }

.shot-mark { color: var(--good); font-weight: 800; }
.shot-btn {
  width: 100%;
  margin-top: 12px;
  background: var(--bg2);
  border: 1px solid var(--card-edge);
  color: var(--text);
  border-radius: 12px;
  padding: 12px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.shot-btn.done { border-color: var(--good); color: var(--good); background: rgba(110, 231, 160, 0.08); }
.dw-best { color: var(--good); }
.dw-warn { color: var(--accent); }

/* 자동 스트레칭 적용된 사진은 CSS 밝기 보정 해제 */
.t-thumb.enhanced, .d-thumb.enhanced, #lightbox-img.enhanced {
  filter: saturate(1.2);
  animation: none;
  background: #0b1026;
}
.t-name { font-size: 1.02rem; }
.t-name b { color: var(--accent); }
.t-type { color: var(--dim); font-size: 0.8rem; }
.t-when { color: var(--dim); font-size: 0.86rem; margin-top: 3px; }
.t-when.ok { color: var(--good); }

.btn-back {
  background: none;
  border: none;
  color: var(--dim);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
}
.chart-legend {
  color: var(--dim);
  font-size: 0.75rem;
  margin: 6px 0 10px;
}
.chart-legend .lg-obj { color: var(--accent); }

/* ---------- 관측지 지도 ---------- */
#map-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--card-edge);
  height: calc(100vh - 210px);
  min-height: 360px;
}
#map { width: 100%; height: 100%; background: #0b1026; }

.map-btns {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 5;
}
.map-btns button {
  background: rgba(15, 21, 48, 0.92);
  border: 1px solid var(--card-edge);
  color: var(--text);
  border-radius: 10px;
  min-width: 44px;
  height: 40px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  padding: 0 10px;
}
.map-btns button.on { color: var(--accent); border-color: var(--accent); }

#spot-card {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  background: rgba(15, 21, 48, 0.95);
  backdrop-filter: blur(6px);
  border: 1px solid var(--card-edge);
  border-radius: var(--radius);
  padding: 14px 16px;
  z-index: 6;
}
.spot-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.1rem;
  margin-bottom: 4px;
}
.spot-head b { color: var(--accent); }
.spot-approx { font-size: 0.72rem; color: var(--dim); font-weight: 400; margin-left: 2px; }
.spot-stars { color: var(--accent); letter-spacing: 2px; font-size: 0.9rem; }
.spot-head .btn-back { margin-left: auto; font-size: 1rem; }
.spot-meta { color: var(--dim); font-size: 0.82rem; margin-top: 6px; }

.map-hint { color: var(--dim); font-size: 0.82rem; text-align: center; margin-top: 10px; }

.search-wrap { position: relative; }
#spot-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: rgba(15, 21, 48, 0.97);
  border: 1px solid var(--card-edge);
  border-radius: 12px;
  z-index: 20;
  overflow: hidden;
}
.sr-item {
  padding: 11px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-bottom: 1px solid rgba(42, 52, 102, 0.5);
}
.sr-item:last-child { border-bottom: none; }
.sr-item:active { background: var(--card); }
.sr-item b { font-size: 0.95rem; }
.sr-item span { color: var(--dim); font-size: 0.78rem; }
.sr-empty { padding: 12px 14px; color: var(--dim); font-size: 0.85rem; line-height: 1.5; }

#cloud-bar {
  position: absolute;
  left: 10px;
  right: 10px;
  top: 10px;
  margin-left: 64px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(15, 21, 48, 0.92);
  border: 1px solid var(--card-edge);
  border-radius: 12px;
  padding: 8px 12px;
  z-index: 5;
}
#cloud-bar button {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 1rem;
  cursor: pointer;
  padding: 0 4px;
}
#cloud-bar input[type="range"] { flex: 1; accent-color: var(--accent); }
#cloud-time { font-size: 0.82rem; color: var(--dim); font-variant-numeric: tabular-nums; min-width: 3.2em; }

.star-marker {
  font-size: 17px;
  cursor: pointer;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.8));
}

.spot-actions { display: flex; gap: 8px; margin-top: 10px; }
.spot-actions button {
  background: var(--bg2);
  border: 1px solid var(--card-edge);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.spot-actions button:first-child { flex: 1; border-color: var(--accent); color: var(--accent); }
.toilet-row { align-items: center; margin-top: 8px; }
.toilet-label { color: var(--dim); font-size: 0.85rem; font-weight: 600; white-space: nowrap; }
.toilet-row button { flex: 1; border-color: var(--card-edge) !important; color: var(--text) !important; }

.maplibregl-ctrl-attrib { font-size: 10px; }

@media (min-width: 900px) {
  body { max-width: 640px; }
  .tabbar { max-width: 640px; }
}
