/* ============================================================
   StarGazer — refined cosmic UI
   Aesthetic: deep observatory night, editorial serif title,
   restrained accent system (warm amber = observer, cool cyan
   = data lines). No external fonts / no CDN — fully offline.
   ============================================================ */

:root {
  --bg:        #070b14;
  --bg-2:      #0b1120;
  --bg-3:      #0f1729;
  --ink:       #e8edf7;
  --muted:     #8a94ad;
  --faint:     #5b6378;
  --line:      rgba(232, 237, 247, 0.09);
  --line-2:    rgba(232, 237, 247, 0.16);

  --amber:     #f4b860;   /* observer / zenith accent (warm) */
  --cyan:      #6fd6e8;   /* data lines (cool, restrained)   */
  --visible:   #9af0c0;   /* above horizon                   */
  --hidden:    #566079;   /* below horizon                   */

  --panel:     rgba(13, 19, 33, 0.72);
  --panel-br:  rgba(232, 237, 247, 0.10);

  --font-serif: "Iowan Old Style", "Palatino Linotype", "Songti SC", Georgia, "Times New Roman", serif;
  --font-sans:  ui-sans-serif, system-ui, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono:  ui-monospace, "SF Mono", "Cascadia Code", "Consolas", monospace;

  --r: 14px;
  --r-sm: 9px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(1200px 700px at 78% -10%, rgba(111, 214, 232, 0.06), transparent 60%),
    radial-gradient(900px 600px at 10% 110%, rgba(244, 184, 96, 0.05), transparent 55%),
    linear-gradient(180deg, var(--bg-2), var(--bg));
}

.app {
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

/* ── Top bar ─────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(11,17,32,0.85), rgba(11,17,32,0.35));
  backdrop-filter: blur(8px);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-mark {
  width: 34px; height: 34px; border-radius: 50%;
  background:
    radial-gradient(circle at 32% 30%, #fff 0 2px, transparent 3px),
    radial-gradient(circle at 70% 64%, var(--cyan) 0 2px, transparent 3px),
    radial-gradient(circle at 50% 50%, rgba(244,184,96,0.0), rgba(244,184,96,0.35) 60%, transparent 72%),
    conic-gradient(from 210deg, #11203a, #0a1426, #11203a);
  box-shadow: 0 0 0 1px var(--line-2), 0 0 24px rgba(111,214,232,0.18);
}

.brand-text h1 {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 22px;
  letter-spacing: 0.04em;
  margin: 0;
  line-height: 1;
}
.brand-text p {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.14em;
}

.topbar-controls {
  display: flex;
  align-items: flex-end;
  gap: 18px;
  flex-wrap: wrap;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
}

.city-combo { display: flex; gap: 8px; }
#city-search {
  width: 132px;
}
#city-select {
  width: 168px;
}

input[type="text"], select {
  background: var(--bg-3);
  color: var(--ink);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  padding: 9px 11px;
  font-family: var(--font-sans);
  font-size: 13px;
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease;
}
input[type="text"]:focus, select:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(111,214,232,0.14);
}

.time-field { min-width: 320px; }
.time-row { display: flex; align-items: center; gap: 10px; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 4px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--cyan), var(--amber));
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--ink);
  border: 3px solid var(--bg);
  box-shadow: 0 0 0 1px var(--line-2);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--ink); border: 3px solid var(--bg); cursor: pointer;
}

.btn {
  background: var(--ink);
  color: #0a0f1c;
  border: none;
  border-radius: var(--r-sm);
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .12s ease, opacity .12s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line-2);
  padding: 8px 11px;
}
.btn.ghost:hover { border-color: var(--cyan); color: var(--cyan); }
.btn.ghost.active { border-color: var(--cyan); color: var(--cyan); background: rgba(111,214,232,0.10); }

.ws-dot {
  font-size: 13px;
  color: var(--hidden);
  align-self: center;
  margin-left: 2px;
}
.ws-dot.on  { color: var(--visible); text-shadow: 0 0 8px var(--visible); }
.ws-dot.off { color: #e06b6b; }

/* ── Stage ───────────────────────────────────────────────── */
.stage {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 0;
  min-height: 0;
}

.sky-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
}
#sky {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#sky:active { cursor: grabbing; }
.sky-hint {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.06em;
  pointer-events: none;
  white-space: nowrap;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  border-left: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(11,17,32,0.55), rgba(7,11,20,0.2));
  padding: 16px;
  overflow-y: auto;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--panel-br);
  border-radius: var(--r);
  padding: 14px;
}
.panel h2 {
  margin: 0 0 12px;
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

/* ── Catalog (grouped) ───────────────────────────────────── */
.catalog { display: flex; flex-direction: column; gap: 16px; }
.catalog-group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 2px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.04em;
}
.g-icon { color: var(--amber); font-size: 15px; }
.g-count {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--faint);
  background: rgba(232,237,247,0.06);
  border-radius: 99px;
  padding: 1px 8px;
}

.body-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.body-list li.body-item {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background .15s ease;
}
.body-list li.body-item:hover { background: rgba(232,237,247,0.05); }
.body-list li.body-item.active { background: rgba(111,214,232,0.10); box-shadow: inset 0 0 0 1px rgba(111,214,232,0.25); }
.dot { width: 11px; height: 11px; border-radius: 50%; box-shadow: 0 0 8px currentColor; }
.body-name { font-size: 14px; }
.body-name small { display: block; color: var(--faint); font-size: 11px; letter-spacing: 0.08em; }
.body-tag { font-size: 11px; color: var(--muted); letter-spacing: 0.05em; }
.empty { color: var(--faint); font-size: 13px; padding: 8px; }

/* ── Detail panel (right sidebar, replaces the old modal) ── */
.detail-panel {
  border-color: var(--line-2);
  animation: panelIn .2s ease;
}
@keyframes panelIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.detail-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.detail-panel-head h2 { margin: 0; }
.detail-close {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: all .15s ease;
}
.detail-close:hover { color: var(--ink); border-color: var(--ink); }

.detail-id { display: flex; align-items: center; gap: 12px; }
.m-dot { width: 16px; height: 16px; border-radius: 50%; flex: none; box-shadow: 0 0 14px currentColor; }
.m-title h3 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 21px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.m-title p { margin: 3px 0 0; color: var(--muted); font-size: 12px; font-family: var(--font-mono); }
.tag {
  margin-left: auto;
  flex: none;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 99px;
  border: 1px solid var(--line-2);
  color: var(--muted);
  letter-spacing: 0.05em;
}
.tag-star { color: #ffcc66; border-color: rgba(255,204,102,0.4); }
.tag-planet, .tag-moon { color: #6fd6e8; border-color: rgba(111,214,232,0.4); }
.tag-dwarf_planet, .tag-black_hole, .tag-neutron_star, .tag-asteroid_belt { color: #e0a0ff; border-color: rgba(224,160,255,0.4); }
.tag-galaxy { color: #9db8ff; border-color: rgba(157,184,255,0.4); }

.detail-desc {
  margin: 14px 0 0;
  font-size: 13.5px;
  line-height: 1.8;
  color: #c4cbd9;
}
.detail-text {
  margin: 0;
  padding: 11px 12px;
  font-size: 13px;
  line-height: 1.8;
  color: #c4cbd9;
  background: rgba(232,237,247,0.03);
  border: 1px solid var(--line);
  border-left: 2px solid var(--cyan);
  border-radius: var(--r-sm);
}
.detail-section { margin-top: 18px; }
.detail-section h4 {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 600;
}
.m-hint { color: var(--muted); text-transform: none; letter-spacing: 0; font-size: 12px; }
.m-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 7px 14px;
  margin: 0;
  font-size: 12.5px;
  background: rgba(232,237,247,0.03);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 11px 13px;
}
.m-grid dt { color: var(--faint); }
.m-grid dd { margin: 0; font-family: var(--font-mono); text-align: right; color: var(--ink); }

/* ── Status bar ──────────────────────────────────────────── */
.statusbar {
  display: flex;
  gap: 26px;
  padding: 8px 22px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--faint);
  letter-spacing: 0.06em;
  background: rgba(7,11,20,0.6);
}

.mono { font-family: var(--font-mono); }

/* ── Responsive ──────────────────────────────────────────── */
/* Medium screens: narrow the sidebar a touch. */
@media (max-width: 1200px) {
  .stage { grid-template-columns: 1fr 300px; }
}

/* Small screens / tablets: stack the 3D scene above the sidebar. */
@media (max-width: 880px) {
  .app { height: auto; min-height: 100vh; overflow: visible; }
  .stage {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(300px, 52vh) auto;
  }
  .sky-wrap { min-height: 300px; }
  .sidebar {
    border-left: none;
    border-top: 1px solid var(--line);
    max-height: none;
    overflow-y: visible;
  }
  .topbar { padding: 12px 16px; gap: 14px; }
  .topbar-controls { gap: 12px; }
  .time-field { min-width: 0; flex: 1; }
  .brand-text p { display: none; }
}

/* Phones: tighter controls, smaller time field. */
@media (max-width: 560px) {
  .topbar { align-items: flex-start; }
  .topbar-controls { width: 100%; }
  .city-field { flex: 1; }
  #city-select { width: 100%; }
  .time-field { min-width: 100%; order: 3; }
  .brand h1 { font-size: 18px; }
  .stage { grid-template-rows: minmax(260px, 46vh) auto; }
  .sky-hint { white-space: normal; text-align: center; width: 90%; }
}
