/* ===========================================================================
   Solsystemet – stil (mörkt rymdtema, glasiga paneler)
   =========================================================================== */
:root {
  --bg: #05070d;
  --panel: rgba(16, 22, 38, 0.72);
  --panel-solid: #0d1224;
  --border: rgba(120, 160, 220, 0.16);
  --text: #dfe6f2;
  --muted: #8b98b3;
  --accent: #6cc5ff;
  --accent2: #ffcf6b;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

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

#scene { position: fixed; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; }

/* --- Etiketter ovanpå canvas ------------------------------------------- */
#labels { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.label {
  position: absolute; top: 0; left: 0;
  pointer-events: auto; cursor: pointer;
  font: 600 12px/1 var(--font); letter-spacing: 0.02em;
  color: #eaf1ff; background: rgba(8, 12, 24, 0.55);
  border: 1px solid var(--border); border-radius: 20px;
  padding: 3px 9px; white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(4px);
  transition: color .15s, border-color .15s, background .15s;
}
.label:hover { color: var(--accent); border-color: var(--accent); }
.label-star { color: var(--accent2); font-size: 13px; }
.label-dwarf { color: #d8b6ff; }
.label-moon { font-size: 11px; opacity: 0.85; padding: 2px 7px; }
.label-station { color: #7ee6d0; font-size: 11px; padding: 2px 7px; }
.label-exostar { color: #ffd27e; font-size: 12px; }
.label-exoplanet { color: #c8b6ff; font-size: 11px; padding: 2px 7px; }
.label.sel { border-color: var(--accent); color: var(--accent); background: rgba(20, 40, 70, 0.7); }

/* --- Sidopanel ---------------------------------------------------------- */
#sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: 288px; z-index: 10;
  display: flex; flex-direction: column;
  background: var(--panel); backdrop-filter: blur(16px);
  border-right: 1px solid var(--border); box-shadow: var(--shadow);
  transition: transform .3s ease;
}
#sidebar header { padding: 18px 20px 12px; border-bottom: 1px solid var(--border); }
#sidebar h1 {
  margin: 0; font-size: 20px; font-weight: 700; letter-spacing: 0.04em;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
#sidebar header p { margin: 4px 0 0; font-size: 12px; color: var(--muted); }

#body-list { flex: 1; overflow-y: auto; padding: 8px 10px 16px; }
#body-list::-webkit-scrollbar { width: 8px; }
#body-list::-webkit-scrollbar-thumb { background: rgba(120,160,220,.2); border-radius: 8px; }

.group { border-bottom: 1px solid rgba(120, 160, 220, 0.08); }
.group-head {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: none; border: none; cursor: pointer; text-align: left;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--accent); font-weight: 700; padding: 12px 8px 7px;
}
.group-head:hover { color: #fff; }
.group-head .chev { font-size: 9px; color: var(--muted); transition: transform .15s; flex: 0 0 auto; }
.group.collapsed .group-head { color: var(--muted); }
.group.collapsed .group-head .chev { transform: rotate(-90deg); }
.group.collapsed > .group-body { display: none; }
#body-list.searching .group-body { display: block; }
.group-body { padding-bottom: 4px; }
.sub-head { font-size: 11px; color: var(--muted); margin: 6px 10px 2px 12px; font-weight: 600; }

.body-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: none; border: 1px solid transparent; border-radius: 10px;
  padding: 7px 10px; margin: 1px 0; cursor: pointer; color: var(--text);
  font-size: 14px; text-align: left; transition: background .12s, border-color .12s;
}
.body-item:hover { background: rgba(108, 197, 255, 0.08); }
.body-item.active { background: rgba(108, 197, 255, 0.16); border-color: var(--accent); }
.body-item.indent { padding-left: 18px; font-size: 13px; }
.body-item .dot {
  width: 22px; height: 22px; border-radius: 50%; flex: 0 0 auto;
  background-size: cover; background-position: center;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.12), 0 0 8px rgba(0,0,0,.5);
}
.body-item.indent .dot { width: 16px; height: 16px; }
.body-item .nm { flex: 1; }
.body-item .cnt { font-size: 11px; color: var(--muted); }

.credits {
  padding: 10px 16px; font-size: 10.5px; line-height: 1.5; color: var(--muted);
  border-top: 1px solid var(--border);
}
.credits a { color: var(--accent); text-decoration: none; }
.credits a:hover { text-decoration: underline; }
.credits .updated { display: block; margin-top: 6px; opacity: 0.8; font-style: italic; }

/* --- Faktapanel --------------------------------------------------------- */
/* Fullhöjds panel längs högerkanten – spegling av sidopanelen till vänster. */
#info {
  position: fixed; top: 0; right: 0; bottom: 0; width: 352px; max-width: 100vw; z-index: 10;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--panel); backdrop-filter: blur(16px);
  border-left: 1px solid var(--border); box-shadow: var(--shadow);
  transform: translateX(100%); opacity: 0;
  transition: transform .35s cubic-bezier(.2,.8,.2,1), opacity .35s;
}
#info.open { transform: translateX(0); opacity: 1; }
/* Scrollande innehåll med samma scrollbar som sidopanelen (#body-list). */
.info-scroll { flex: 1; overflow-y: auto; padding: 18px; }
.info-scroll::-webkit-scrollbar { width: 8px; }
.info-scroll::-webkit-scrollbar-thumb { background: rgba(120, 160, 220, .2); border-radius: 8px; }
#info .close {
  position: absolute; top: 12px; right: 14px; width: 30px; height: 30px; z-index: 2;
  border-radius: 50%; border: 1px solid var(--border); background: rgba(20, 26, 42, 0.9);
  color: var(--text); font-size: 18px; line-height: 1; cursor: pointer;
}
#info .close:hover { background: rgba(255,255,255,.12); }
.info-head { display: flex; gap: 14px; align-items: center; margin-bottom: 12px; padding-right: 30px; }
.preview {
  width: 66px; height: 66px; border-radius: 50%; flex: 0 0 auto;
  background-size: cover; background-position: center;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.15), 0 0 18px rgba(108,197,255,.25);
}
#info h2 { margin: 0; font-size: 22px; }
#info .type { font-size: 12px; color: var(--accent); margin-top: 3px; }
#info .desc { font-size: 13.5px; line-height: 1.55; color: #cdd6e6; margin: 0 0 14px; }

table.stats { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.stats tr { border-bottom: 1px solid rgba(120,160,220,.1); }
table.stats th { text-align: left; color: var(--muted); font-weight: 500; padding: 7px 8px 7px 0; width: 44%; vertical-align: top; }
table.stats td { text-align: right; padding: 7px 0; color: #eaf1ff; }

.sizecmp {
  margin: 16px 0 0; padding: 14px 12px 12px; border-radius: 12px;
  background: rgba(108, 197, 255, 0.06); border: 1px solid var(--border);
}
.sizecmp-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--accent); font-weight: 700; margin-bottom: 12px;
}
.sizecmp-row { display: flex; align-items: flex-end; justify-content: center; gap: 30px; min-height: 132px; }
.cmp-item { display: flex; flex-direction: column; align-items: center; gap: 7px; }
.cmp-ball {
  border-radius: 50%; background-size: cover; background-position: center; flex: 0 0 auto;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18), 0 0 12px rgba(0, 0, 0, 0.5);
}
.cmp-item span { font-size: 11px; color: var(--muted); max-width: 130px; text-align: center; }
.sizecmp-ratio { margin-top: 12px; font-size: 12.5px; text-align: center; color: #eaf1ff; }
.sizecmp-ratio .dia { color: var(--muted); }
.sizecmp-ratio b { color: var(--accent); }

/* Fotografi i faktarutan (t.ex. månbilen som saknar 3D-modell). */
.bodyfig {
  margin: 16px 0 0; padding: 8px; border-radius: 12px;
  background: rgba(108, 197, 255, 0.06); border: 1px solid var(--border);
}
.bodyfig img { display: block; width: 100%; height: auto; border-radius: 8px; }
.bodyfig figcaption {
  margin-top: 8px; font-size: 11.5px; line-height: 1.45; color: var(--muted); text-align: center;
}
.bodyfig .figcred { display: block; margin-top: 3px; font-size: 10.5px; opacity: 0.75; }
.bodyfig figcaption a { color: var(--accent); text-decoration: none; }
.bodyfig figcaption a:hover { text-decoration: underline; }
/* Renderad 3D-modell (dataURL som bakgrund, hela modellen synlig mot mörk botten). */
.modelfig .modelview {
  width: 100%; aspect-ratio: 3 / 2; min-height: 150px; border-radius: 8px;
  background-color: #0a0f1c;
  background-size: contain; background-position: center; background-repeat: no-repeat;
}
/* Interaktiv 3D-vy (egen WebGL-canvas som roteras/zoomas). */
.viewer-slot { width: 100%; line-height: 0; }
.model-viewer-canvas {
  width: 100%; height: 240px; display: block; border-radius: 8px;
  background: #0a0f1c; cursor: grab; touch-action: none;
}
.model-viewer-canvas:active { cursor: grabbing; }

.fun {
  margin: 14px 0 0; font-size: 12.5px; line-height: 1.5; color: #e7dcc2;
  background: rgba(255, 207, 107, 0.08); border-left: 3px solid var(--accent2);
  border-radius: 8px; padding: 10px 12px;
}
.fun span { color: var(--accent2); font-weight: 700; }

/* --- Kontrollrad -------------------------------------------------------- */
/* Dockad längst ner, mellan sidopanelen (vänster) och faktarutan (höger). */
#controls {
  position: fixed; left: 288px; right: 0; bottom: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: var(--panel); backdrop-filter: blur(16px);
  border-top: 1px solid var(--border); box-shadow: var(--shadow);
  padding: 12px 18px;
  transition: right .35s cubic-bezier(.2, .8, .2, 1);
}
/* Krymper så raden hålls mellan panelerna när faktarutan är öppen. */
body:has(#info.open) #controls { right: 352px; }
/* Fast tvåradslayout som inte radbryts (oberoende av webbläsarzoom). */
.controls-row { display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: nowrap; }
.ctrl-group { display: flex; flex-direction: column; gap: 6px; }
.ctrl-group > label { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.slider-row { display: flex; align-items: center; gap: 8px; }
.mini { font-size: 11px; color: var(--muted); white-space: nowrap; }
.badge {
  font-size: 11px; text-transform: none; letter-spacing: 0; color: var(--accent);
  background: rgba(108,197,255,.12); border-radius: 20px; padding: 2px 8px;
}

input[type="range"] {
  -webkit-appearance: none; appearance: none; height: 4px; width: 150px;
  background: rgba(160,190,230,.25); border-radius: 4px; outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 15px; height: 15px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 10px rgba(108,197,255,.7); cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 15px; height: 15px; border: none; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 10px rgba(108,197,255,.7); cursor: pointer;
}

.ctrl-btn {
  background: rgba(108,197,255,.12); border: 1px solid var(--border); color: var(--text);
  border-radius: 12px; padding: 10px 14px; font-size: 13px; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.ctrl-btn:hover { background: rgba(108,197,255,.22); border-color: var(--accent); }

.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; flex: 0 0 auto;
  background: rgba(108,197,255,.16); border: 1px solid var(--border); color: var(--text);
  cursor: pointer; font-size: 12px; display: grid; place-items: center;
}
.icon-btn:hover { background: rgba(108,197,255,.28); }

.toggles { flex-direction: row; gap: 14px; flex-wrap: nowrap; }
.chk { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text); text-transform: none; letter-spacing: 0; cursor: pointer; }
.chk input { accent-color: var(--accent); width: 15px; height: 15px; }

/* --- Hint & menyknapp --------------------------------------------------- */
#hint {
  position: fixed; right: 18px; bottom: 120px; z-index: 8;
  font-size: 11px; color: var(--muted); pointer-events: none;
  text-shadow: 0 1px 3px #000;
}
#menu-toggle {
  position: fixed; top: 12px; left: 12px; z-index: 20; display: none;
  width: 42px; height: 42px; border-radius: 12px; font-size: 18px;
  background: var(--panel); backdrop-filter: blur(12px);
  border: 1px solid var(--border); color: var(--text); cursor: pointer;
}

/* --- Laddskärm ---------------------------------------------------------- */
#loading {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background: radial-gradient(circle at 50% 40%, #0b1226, #04060c);
  transition: opacity .6s;
}
#loading.hidden { opacity: 0; pointer-events: none; }
.load-inner { text-align: center; }
.load-title {
  font-size: 34px; font-weight: 700; letter-spacing: .06em;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.load-sub { color: var(--muted); font-size: 13px; margin: 8px 0 20px; }
.load-track { width: 240px; height: 4px; background: rgba(160,190,230,.2); border-radius: 4px; margin: 0 auto; overflow: hidden; }
#load-bar { width: 0; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .3s; }

/* --- Sökruta ------------------------------------------------------------ */
.search {
  width: 100%; margin-top: 12px; box-sizing: border-box;
  background: rgba(0, 0, 0, 0.28); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); font-size: 13px; padding: 8px 11px; outline: none;
}
.search:focus { border-color: var(--accent); }
.search::placeholder { color: var(--muted); }

/* --- Verktygsknappar i kontrollraden ------------------------------------ */
.ctrl-group.actions { flex-direction: row; gap: 8px; align-items: center; flex-wrap: nowrap; padding-right: 16px; border-right: 1px solid var(--border); }
.ctrl-btn.sm { padding: 8px 11px; font-size: 12px; border-radius: 10px; }

/* --- Rundturs-rad -------------------------------------------------------- */
#tour-bar {
  position: fixed; left: 50%; bottom: 128px; transform: translate(-50%, 12px); z-index: 11;
  display: none; align-items: center; gap: 12px; max-width: min(680px, calc(100vw - 32px));
  background: var(--panel); backdrop-filter: blur(16px);
  border: 1px solid var(--accent); border-radius: 14px; box-shadow: var(--shadow);
  padding: 10px 12px 10px 14px; opacity: 0; transition: opacity .3s, transform .3s;
}
#tour-bar.show { display: flex; opacity: 1; transform: translate(-50%, 0); }
#tour-text { font-size: 13.5px; color: #eaf1ff; flex: 1; }

/* --- Modaler ------------------------------------------------------------- */
.modal {
  position: fixed; inset: 0; z-index: 150; display: none; place-items: center; padding: 20px;
  background: rgba(4, 6, 12, 0.72); backdrop-filter: blur(5px);
}
.modal.open { display: grid; }
.modal-card {
  position: relative; width: 100%; max-width: 470px; max-height: 86vh; overflow-y: auto;
  background: var(--panel-solid); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); padding: 22px 22px 18px;
}
.modal-card h2 { margin: 0 0 16px; font-size: 20px; }
.modal-close {
  position: absolute; top: 12px; right: 12px; width: 30px; height: 30px; border-radius: 50%;
  border: 1px solid var(--border); background: rgba(255, 255, 255, 0.05); color: var(--text);
  font-size: 18px; line-height: 1; cursor: pointer;
}
.modal-close:hover { background: rgba(255, 255, 255, 0.12); }
.modal-inputs { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.modal-inputs label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); flex: 1; min-width: 150px; }
.modal-inputs input, .modal-inputs select {
  background: rgba(0, 0, 0, 0.3); border: 1px solid var(--border); border-radius: 9px;
  color: var(--text); font-size: 14px; padding: 8px 10px; outline: none;
}
.modal-inputs input:focus, .modal-inputs select:focus { border-color: var(--accent); }
.modal-note { font-size: 11.5px; color: var(--muted); margin: 14px 0 0; }

table.wa { width: 100%; border-collapse: collapse; font-size: 13px; }
table.wa thead th { color: var(--accent); font-weight: 600; text-align: right; padding: 6px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
table.wa thead th:first-child { text-align: left; }
table.wa tbody th { text-align: left; font-weight: 500; color: var(--text); padding: 7px 6px; border-top: 1px solid rgba(120, 160, 220, .1); }
table.wa tbody td { text-align: right; color: #eaf1ff; padding: 7px 6px; border-top: 1px solid rgba(120, 160, 220, .1); }

#cmp-view { min-height: 180px; }

/* --- Felruta ------------------------------------------------------------ */
#err-overlay {
  position: fixed; inset: 0; z-index: 200; display: none; place-items: center;
  background: rgba(4, 6, 12, 0.82); backdrop-filter: blur(4px); padding: 20px;
}
.err-card {
  max-width: 520px; width: 100%; background: var(--panel-solid);
  border: 1px solid #7a3b3b; border-radius: 16px; box-shadow: var(--shadow);
  padding: 22px 24px; text-align: left;
}
.err-card h3 { margin: 0 0 10px; color: #ff8a8a; font-size: 18px; }
.err-card pre {
  white-space: pre-wrap; word-break: break-word; font-size: 12px; line-height: 1.5;
  color: #ffd9d9; background: rgba(0,0,0,.35); border-radius: 8px; padding: 10px 12px; margin: 0 0 12px;
  max-height: 180px; overflow: auto;
}
.err-hint { font-size: 13px; line-height: 1.55; color: var(--muted); margin: 0 0 16px; }
.err-hint code { color: var(--accent); background: rgba(108,197,255,.1); padding: 1px 5px; border-radius: 5px; }
.err-card button {
  background: var(--accent); color: #04101c; border: none; border-radius: 10px;
  padding: 10px 18px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.err-card button:hover { filter: brightness(1.1); }

/* --- Responsivt --------------------------------------------------------- */
@media (max-width: 720px) {
  #sidebar { transform: translateX(-100%); width: 82vw; max-width: 320px; }
  #sidebar.open { transform: translateX(0); }
  #menu-toggle { display: block; }
  #info {
    top: auto; bottom: 116px; left: 50%; right: auto; width: calc(100vw - 24px); max-height: 52vh;
    border: 1px solid var(--border); border-radius: 16px; transform: translate(-50%, 130%);
  }
  #info.open { transform: translate(-50%, 0); }
  #controls { left: 0; right: 0; bottom: 0; gap: 10px; padding: 10px 12px; }
  body:has(#info.open) #controls { right: 0; } /* faktarutan är bottenark på mobil */
  .controls-row { flex-wrap: wrap; gap: 10px 14px; } /* mobil: tillåt radbryt */
  input[type="range"] { width: 110px; }
  #hint { display: none; }
}
