:root {
  --bg: #04060f;
  --panel: rgba(10, 14, 30, 0.92);
  --panel-solid: #0a0e1e;
  --line: rgba(160, 175, 230, 0.14);
  --line-strong: rgba(160, 175, 230, 0.28);
  --text: #e6e9f5;
  --muted: #8d95b5;
  --gold: #f2c14e;
  --cyan: #7fe7ff;
  --lore: #d7a7ff;
  --fact: #7fe7ff;
  --warn: #ffab5e;
  --danger: #ff6b6b;
  --radius: 10px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --symbols: "Segoe UI Symbol", "Apple Symbols", "Noto Sans Symbols", "DejaVu Sans", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--cyan); }
h2 { font: 600 15px/1.2 var(--serif); letter-spacing: 0.02em; margin: 0 0 10px; color: #f3eedf; display: inline; }
h3 { font: 600 12px/1.2 var(--sans); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 16px 0 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); font-weight: 400; }
.u { text-decoration: underline dotted; text-underline-offset: 3px; cursor: help; }
.warn { color: var(--warn); }
.only-mobile { display: none; }
code, kbd { font-family: var(--mono); font-size: 12px; background: rgba(255,255,255,0.06); padding: 1px 5px; border-radius: 4px; }

/* ---------- top bar ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: 56px; z-index: 30;
  display: flex; align-items: center; gap: 14px; padding: 0 14px;
  background: linear-gradient(180deg, rgba(6,9,22,0.98), rgba(6,9,22,0.88));
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; cursor: help; }
.brand-mark { width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid var(--gold); position: relative; box-shadow: 0 0 14px rgba(242,193,78,0.35); }
.brand-mark::after { content: ""; position: absolute; inset: 7px; border-radius: 50%; background: var(--gold); }
.brand-name { font: 600 17px/1 var(--serif); letter-spacing: 0.03em; color: #f6efd9; }
.modes { display: flex; gap: 2px; background: rgba(255,255,255,0.04); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.mode-btn { border: 0; background: none; padding: 6px 14px; border-radius: 999px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.mode-btn:hover { color: var(--text); }
.mode-btn.is-active { background: rgba(242,193,78,0.16); color: var(--gold); box-shadow: inset 0 0 0 1px rgba(242,193,78,0.4); }
.chips { display: flex; gap: 6px; flex: 1; min-width: 0; overflow: hidden; }
.chip { font-size: 12px; padding: 3px 9px; border: 1px solid var(--line-strong); border-radius: 999px; color: #c9cfe6; white-space: nowrap; cursor: help; }
.obj-search { position: relative; width: 220px; }
.obj-search input { width: 100%; }
.icon-btn { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line-strong); background: rgba(255,255,255,0.03); cursor: pointer; display: inline-grid; place-items: center; font-size: 15px; }
.icon-btn:hover { border-color: var(--gold); color: var(--gold); }

/* ---------- layout ---------- */
.layout { position: fixed; inset: 56px 0 30px 0; display: grid; grid-template-columns: 320px 1fr 380px; }
.panel { background: var(--panel); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #2a3150 transparent; }
.panel-left { border-right: 1px solid var(--line); padding: 12px; }
.panel-right { border-left: 1px solid var(--line); display: flex; flex-direction: column; overflow: hidden; }
.stage { position: relative; overflow: hidden; background: radial-gradient(ellipse at 50% 40%, #0b1230 0%, #04060f 70%); }
.stage canvas { display: block; }
.label-layer { position: absolute; inset: 0; }

.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; background: rgba(255,255,255,0.015); }
.card details > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 6px; }
.card details > summary::-webkit-details-marker { display: none; }
.card details > summary::after { content: "▸"; margin-left: auto; color: var(--muted); transition: transform .15s; }
.card details[open] > summary::after { transform: rotate(90deg); }
.card details[open] > summary { margin-bottom: 10px; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 9px; position: relative; }
.field > span { font-size: 12px; color: var(--muted); }
.field em { font-style: normal; opacity: 0.7; }
input[type=text], input[type=search], input[type=date], input[type=time], input[type=number], select {
  background: #0d1328; border: 1px solid var(--line-strong); border-radius: 7px; padding: 7px 9px; width: 100%; min-width: 0;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid rgba(242,193,78,0.6); outline-offset: 1px; }
input:disabled { opacity: 0.4; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.check { display: flex; align-items: center; gap: 7px; margin: 6px 0; cursor: pointer; font-size: 13px; }
.check input { accent-color: var(--gold); }
.advanced { margin: 4px 0 10px; }
.advanced summary { cursor: pointer; color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
button.primary { background: linear-gradient(180deg, #f5cd67, #d9a836); color: #1a1405; border: 0; border-radius: 8px; padding: 8px 16px; font-weight: 600; cursor: pointer; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; border: 1px solid var(--line-strong); border-radius: 8px; padding: 7px 12px; cursor: pointer; color: #cfd5ee; }
button.ghost:hover { border-color: var(--gold); color: var(--gold); }
button.ghost.small { padding: 3px 8px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }

.slider { display: grid; grid-template-columns: 1fr 90px 36px; align-items: center; gap: 6px; font-size: 13px; margin: 5px 0; }
.slider > span { display: flex; align-items: center; gap: 5px; cursor: help; }
.slider i { font-style: normal; font-family: var(--symbols); }
.slider input[type=range] { width: 100%; accent-color: var(--gold); }
.slider output { font-family: var(--mono); font-size: 12px; color: var(--muted); text-align: right; }
.layer-grid { display: grid; grid-template-columns: 1fr; }

.info { display: inline-grid; place-items: center; width: 15px; height: 15px; font-size: 11px; border-radius: 50%; color: var(--muted); cursor: help; font-style: normal; vertical-align: 1px; }
.info:hover { color: var(--cyan); }

.resolution { margin-top: 10px; font-size: 12.5px; }
.res-grid { display: grid; grid-template-columns: 62px 1fr; gap: 4px 8px; padding: 9px; background: rgba(127,231,255,0.04); border: 1px solid rgba(127,231,255,0.15); border-radius: 8px; }
.res-grid > span { color: var(--muted); cursor: help; text-decoration: underline dotted rgba(141,149,181,0.5); text-underline-offset: 3px; }
.res-grid > b { font-weight: 500; }
.caution { margin-top: 6px; padding: 6px 8px; border-left: 2px solid var(--warn); background: rgba(255,171,94,0.07); color: #f3d3b3; font-size: 12px; border-radius: 0 6px 6px 0; }
.error { color: var(--danger); padding: 6px 0; }

.dropdown { position: absolute; top: 100%; left: 0; right: 0; z-index: 40; display: none; margin-top: 2px; background: #0e1430; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; box-shadow: 0 12px 30px rgba(0,0,0,0.5); }
.dropdown.show { display: block; }
.dropdown .opt { padding: 7px 10px; cursor: pointer; display: block; }
.dropdown .opt small { display: block; color: var(--muted); font-size: 11px; }
.dropdown .opt:hover, .dropdown .opt.active { background: rgba(242,193,78,0.12); }

.profiles { list-style: none; margin: 8px 0 0; padding: 0; }
.profiles li { display: flex; align-items: center; gap: 6px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.profiles .link { flex: 1; text-align: left; background: none; border: 0; cursor: pointer; padding: 2px 0; }
.profiles .link:hover { color: var(--gold); }
.profiles .del { background: none; border: 0; color: var(--muted); cursor: pointer; }
.credits { font-size: 11px; color: var(--muted); padding: 6px 2px 20px; }

/* ---------- stage overlays ---------- */
.mode-banner { position: absolute; top: 12px; left: 12px; z-index: 5; padding: 6px 12px; border-radius: 999px; background: rgba(6,9,22,0.75); border: 1px solid var(--line); font-size: 12.5px; color: var(--muted); backdrop-filter: blur(6px); max-width: calc(100% - 80px); }
.mode-banner b { color: var(--gold); font-family: var(--serif); font-size: 14px; margin-right: 4px; cursor: help; }
.stage-tools { position: absolute; top: 12px; right: 12px; z-index: 5; display: flex; flex-direction: column; gap: 6px; }
.stage-tools .icon-btn { background: rgba(6,9,22,0.75); backdrop-filter: blur(6px); }
.legend { position: absolute; left: 12px; bottom: 12px; z-index: 5; background: rgba(6,9,22,0.78); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 12px; backdrop-filter: blur(6px); }
.legend summary { cursor: pointer; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.legend-row { display: flex; align-items: center; gap: 8px; padding: 2px 0; cursor: help; font-family: var(--sans); }
.legend-swatch { display: inline-flex; }
.hover-hint { position: absolute; bottom: 12px; right: 12px; z-index: 5; font-size: 11.5px; color: var(--muted); background: rgba(6,9,22,0.6); padding: 4px 10px; border-radius: 999px; pointer-events: none; }

/* 3D labels */
.scene-label { font-size: 12px; white-space: nowrap; pointer-events: auto; cursor: pointer; user-select: none; text-shadow: 0 0 4px #000, 0 0 8px #000; transition: opacity .2s; }
.scene-label .glyph { font-family: var(--symbols); font-size: 17px; line-height: 1; }
.scene-label .deg { font-size: 10.5px; color: #c2c8e2; margin-left: 2px; }
.scene-label.dim { opacity: 0.18; }
.scene-label.selected { outline: 1px solid var(--gold); outline-offset: 3px; border-radius: 4px; background: rgba(242,193,78,0.12); }
.planet-label { display: flex; align-items: center; gap: 1px; }
.planet-label.below .deg { color: #7d86a8; font-style: italic; }
.sign-label .glyph { font-size: 19px; }
.sign-label.small .glyph { font-size: 14px; }
.el-fire { color: #ff9b80; } .el-earth { color: #b8e08f; } .el-air { color: #a6d6ff; } .el-water { color: #b2acff; }
.house-label { font: 600 11px var(--mono); color: #9aa6cc; }
.angle-label { font: 700 12px var(--sans); color: #fff; letter-spacing: 0.05em; background: rgba(255,255,255,0.08); padding: 1px 5px; border-radius: 4px; }
.star-label { font-size: 10.5px; color: #8fb4d8; }
.star-label.contacted { color: var(--cyan); font-weight: 600; font-size: 11.5px; }
.star-label.below { opacity: 0.55; }
.con-label { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: rgba(120,150,210,0.55); cursor: help; }
.cardinal { font: 600 12px var(--sans); color: #8fd18f; cursor: help; }
.cardinal.major { font-size: 15px; }
.net-label { display: flex; align-items: center; gap: 3px; }
.net-label .deg { font-size: 11px; }
.net-label.kind-sign .glyph { font-size: 18px; color: #c9b9ff; }
.net-label.kind-house .glyph { font: 600 11px var(--mono); color: #9aa6cc; }
.net-label.kind-star .glyph { color: var(--cyan); }
.net-label.kind-pattern .glyph { color: #ff9fd2; }
.hide-labels .scene-label:not(.selected):not(.angle-label) { display: none !important; }

/* ---------- right panel ---------- */
.tabs { display: flex; flex: none; border-bottom: 1px solid var(--line); background: var(--panel-solid); overflow-x: auto; scrollbar-width: none; }
.tab { flex: 1; background: none; border: 0; padding: 11px 6px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; font-size: 12.5px; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--gold); border-bottom-color: var(--gold); }
.tab-panel { display: none; padding: 12px 14px 28px; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #2a3150 transparent; }
.tab-panel.is-active { display: block; }
.hint { color: var(--muted); font-size: 12px; }

.list-head, .list-row { display: grid; grid-template-columns: 26px 1fr auto 30px 34px; align-items: center; gap: 6px; }
.list-head { font-size: 11px; color: var(--muted); padding: 0 6px 4px; text-transform: uppercase; letter-spacing: 0.06em; }
.list-head span { cursor: help; }
.list-row { width: 100%; text-align: left; background: none; border: 0; border-radius: 7px; padding: 6px; cursor: pointer; border: 1px solid transparent; }
.list-row:hover { background: rgba(255,255,255,0.04); }
.list-row.is-selected { background: rgba(242,193,78,0.1); border-color: rgba(242,193,78,0.35); }
.list-row .glyph { font-family: var(--symbols); font-size: 17px; text-align: center; }
.list-row .pos { font-family: var(--mono); font-size: 12px; white-space: nowrap; }
.list-row .pos span { font-family: var(--symbols); cursor: help; }
.list-row .house { font-family: var(--mono); font-size: 12px; color: var(--muted); text-align: center; }
.list-row small { color: var(--muted); }
.list-row.conn, .list-row.pattern { grid-template-columns: 26px 1fr auto; }
.star-row, .aspect-row { grid-template-columns: 26px 1fr auto auto; }
.star-row .name, .aspect-row .name { font-size: 12.5px; }
.rx { color: var(--danger); font-weight: 700; cursor: help; }
.badge { font-size: 10px; text-transform: uppercase; padding: 1px 4px; border-radius: 4px; cursor: help; text-align: center; }
.dig-domicile, .dig-exaltation { background: rgba(76,209,138,0.15); color: #7fe0a8; }
.dig-detriment, .dig-fall { background: rgba(255,93,93,0.13); color: #ff9a9a; }

.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 12px 0; }
.facts > div { padding: 8px; border: 1px solid var(--line); border-radius: 8px; cursor: help; }
.facts span { display: block; font-size: 11px; color: var(--muted); }
.facts b { font-weight: 500; text-transform: capitalize; }
.balances { display: grid; gap: 3px; margin-bottom: 8px; }
.bal { display: grid; grid-template-columns: 70px 1fr 18px; align-items: center; gap: 8px; font-size: 12px; cursor: help; }
.bal-bar { height: 6px; background: rgba(255,255,255,0.05); border-radius: 3px; overflow: hidden; }
.bal-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), #e49b4a); }

.aspect-grid { border-collapse: collapse; margin: 8px 0; font-family: var(--symbols); }
.aspect-grid th, .aspect-grid td { width: 27px; height: 27px; text-align: center; border: 1px solid var(--line); font-size: 14px; padding: 0; position: relative; }
.aspect-grid th { color: #c9cfe6; font-weight: 400; cursor: help; border-color: transparent; }
.aspect-grid td[data-edge] { cursor: pointer; }
.aspect-grid td[data-edge]:hover { background: rgba(255,255,255,0.08); }
.aspect-grid td small { position: absolute; right: 1px; bottom: 0; font: 8px var(--mono); color: var(--muted); }
.aspect-grid td.sep { opacity: 0.75; }

.hero { padding: 8px 0 4px; }
.hero-title { font: 600 19px/1.2 var(--serif); color: #f6efd9; }
.big3 { margin-top: 8px; display: grid; gap: 2px; }
.big3 .list-row { grid-template-columns: 30px 1fr auto; }
.detail-head { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.detail-head .glyph.big { font-family: var(--symbols); font-size: 32px; width: 44px; text-align: center; color: var(--gold); }
.detail-head > div { flex: 1; }
.detail-tip { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: rgba(255,255,255,0.02); }
.detail-tip .tip-title { display: none; }

.math-step { border-left: 2px solid rgba(242,193,78,0.4); padding: 4px 0 6px 10px; margin: 10px 0; }
.math-title { font-weight: 600; font-size: 12.5px; color: var(--gold); cursor: help; }
.math-body { font: 12px/1.6 var(--mono); color: #cfd5ee; overflow-wrap: anywhere; }

.wheel2d { width: 100%; height: auto; aspect-ratio: 1; display: block; }
.wheel2d text { font-family: var(--symbols); text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.wheel2d .w-glyph { font-size: 17px; }
.wheel2d .w-house-num { font: 600 9px var(--mono); fill: #8d95b5; }
.wheel2d .w-angle { font: 700 10px var(--sans); fill: #fff; pointer-events: auto; cursor: help; }
.wheel2d .w-pglyph { font-size: 13px; }
.wheel2d .w-pdeg { font: 8px var(--mono); fill: #a9b0cc; }
.wheel2d .w-sign, .wheel2d .w-house, .wheel2d .w-aspect, .wheel2d .w-planet { cursor: help; }
.wheel2d .w-sign:hover path { fill-opacity: 0.3; }
.wheel2d .w-house:hover path { fill-opacity: 0.08; }
.wheel2d .w-planet { cursor: pointer; }
.wheel2d .w-planet:hover circle { stroke-opacity: 1; stroke-width: 2; }
.wheel2d .w-planet.sel circle { stroke: var(--gold); stroke-opacity: 1; stroke-width: 2.5; }
.wheel2d .dim { opacity: 0.15; }
.wheel2d .w-aspect:hover line:last-child { stroke-width: 3; stroke-opacity: 1; }

/* ---------- status ---------- */
.statusbar { position: fixed; inset: auto 0 0 0; height: 30px; z-index: 30; display: flex; align-items: center; gap: 18px; padding: 0 14px; background: #060918; border-top: 1px solid var(--line); font-size: 11.5px; color: var(--muted); overflow: hidden; white-space: nowrap; }
.statusbar span { cursor: help; }
.statusbar b { color: #cfd5ee; font-weight: 500; font-family: var(--mono); }
.statusbar .grow { flex: 1; }

/* ---------- tooltip ---------- */
#tooltip {
  position: fixed; top: 0; left: 0; z-index: 100; max-width: 340px; pointer-events: none;
  background: rgba(12,16,36,0.97); border: 1px solid var(--line-strong); border-radius: 10px; padding: 10px 12px;
  box-shadow: 0 14px 40px rgba(0,0,0,0.55); font-size: 12.5px; opacity: 0; transition: opacity .12s; backdrop-filter: blur(8px);
}
#tooltip.show { opacity: 1; }
.tip-title { font: 600 14px/1.3 var(--serif); color: #f6efd9; margin-bottom: 6px; }
.tip-title .glyph, .tip-title { font-family: var(--serif), var(--symbols); }
.tip-body { color: #cfd5ee; }
.tip-row { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; border-bottom: 1px dashed rgba(160,175,230,0.1); font-size: 12px; }
.tip-row span { color: var(--muted); white-space: nowrap; }
.tip-row b { font-weight: 500; text-align: right; font-family: var(--mono); font-size: 11.5px; }
.tip-fact, .tip-lore { margin-top: 7px; font-size: 12px; line-height: 1.45; }
.tip-fact { color: #bfeef7; }
.tip-lore { color: #e5d3fb; }
.tag { display: inline-block; font: 600 9.5px/1 var(--sans); text-transform: uppercase; letter-spacing: 0.08em; padding: 3px 5px; border-radius: 4px; margin-right: 3px; vertical-align: 1px; }
.tag-fact { background: rgba(127,231,255,0.14); color: var(--fact); }
.tag-lore { background: rgba(215,167,255,0.14); color: var(--lore); }

/* ---------- help + loading ---------- */
.help { max-width: 860px; width: calc(100% - 32px); background: #0a0e1e; color: var(--text); border: 1px solid var(--line-strong); border-radius: 14px; padding: 22px 26px; }
.help::backdrop { background: rgba(2,3,10,0.7); backdrop-filter: blur(3px); }
.help h2 { display: block; font-size: 22px; margin-bottom: 14px; }
.help h3 { text-transform: none; letter-spacing: 0; font-size: 14px; color: #f3eedf; }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 24px; }
.help p, .help li { color: #c9cfe6; font-size: 13px; }
.help ul { padding-left: 18px; }
.help .close { position: absolute; top: 14px; right: 14px; }
.loading { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; background: var(--bg); transition: opacity .5s; text-align: center; color: var(--muted); }
.loading.done { opacity: 0; pointer-events: none; }
.spinner { width: 44px; height: 44px; margin: 0 auto 12px; border-radius: 50%; border: 2px solid rgba(242,193,78,0.2); border-top-color: var(--gold); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- responsive ---------- */
@media (max-width: 1250px) {
  .layout { grid-template-columns: 290px 1fr 340px; }
  .chips { display: none; }
}
@media (max-width: 900px) {
  .only-mobile { display: inline-grid; }
  .brand-name, .obj-search { display: none; }
  .topbar { gap: 8px; padding: 0 10px; }
  .modes { flex: 1; justify-content: center; }
  .mode-btn { padding: 6px 10px; }
  .mode-btn span { display: none; }
  .layout { grid-template-columns: 1fr; }
  .panel { position: fixed; z-index: 25; transition: transform .25s ease; }
  .panel-left { inset: 56px auto 30px 0; width: min(340px, 92vw); transform: translateX(-102%); }
  .panel-right { inset: auto 0 30px 0; height: 62vh; border-left: 0; border-top: 1px solid var(--line-strong); border-radius: 16px 16px 0 0; transform: translateY(102%); }
  .panel.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,0.6); }
  .stage { grid-column: 1; }
  .legend { bottom: 10px; font-size: 11px; }
  .hover-hint { display: none; }
  .statusbar span:not(:first-child):not(:nth-child(2)) { display: none; }
  .help-grid { grid-template-columns: 1fr; }
  .info { width: 22px; height: 22px; font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
