/* ---------------------------------------------------------------- tokens */
:root {
  --bg-0: #05060d;
  --bg-1: #0a0c1a;
  --bg-2: #101427;
  --panel: rgba(18, 22, 42, 0.62);
  --panel-solid: #12162a;
  --line: rgba(150, 165, 220, 0.16);
  --line-strong: rgba(160, 180, 240, 0.34);
  --ink: #e7ebfb;
  --ink-dim: #a3abcd;
  --ink-faint: #6d759b;
  --gold: #e8c47a;
  --gold-soft: rgba(232, 196, 122, 0.16);
  --violet: #9b8cf0;
  --cyan: #6fd8e0;
  --rose: #ff8a9c;
  --good: #6fe0b0;
  --warn: #ffb86b;
  --bad: #ff7a6b;
  --fire: #ff8a63;
  --earth: #8fd6a8;
  --air: #8fc2f0;
  --water: #9b9ff0;
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --serif: "Cormorant Garamond", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --glyph: "Noto Sans Symbols 2", "Segoe UI Symbol", "Apple Symbols", "DejaVu Sans", var(--sans);
}

* { box-sizing: border-box; }

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

/* Deep-space backdrop: two nebular pools over a near-black field. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(900px 700px at 18% 12%, rgba(96, 78, 190, 0.20), transparent 62%),
    radial-gradient(1000px 800px at 86% 88%, rgba(28, 108, 140, 0.18), transparent 66%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0) 60%);
  z-index: -2;
}

#starfield { position: fixed; inset: 0; z-index: -1; opacity: 0.55; }

/* ---------------------------------------------------------------- layout */
.app {
  display: grid;
  grid-template-columns: 296px minmax(0, 1fr) 360px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "head head head" "left stage right";
  gap: 16px;
  height: 100%;
  padding: 16px;
}

header.masthead {
  grid-area: head;
  display: flex;
  align-items: baseline;
  gap: 18px;
  flex-wrap: wrap;
  padding: 0 4px;
}

.wordmark {
  font-family: var(--serif);
  font-size: 27px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  background: linear-gradient(96deg, var(--gold), #fff3d4 40%, var(--violet));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin: 0;
  font-weight: 500;
}

.tagline { color: var(--ink-faint); font-size: 12px; letter-spacing: 0.06em; }

.masthead .spacer { flex: 1; }

.clock {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink-dim);
  display: flex;
  gap: 14px;
  align-items: center;
}
.clock b { color: var(--ink); font-weight: 500; }

.rail {
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 4px;
}
.rail.left { grid-area: left; }
.rail.right { grid-area: right; }

.stage {
  grid-area: stage;
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
}

/* ---------------------------------------------------------------- cards */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  backdrop-filter: blur(14px) saturate(120%);
  -webkit-backdrop-filter: blur(14px) saturate(120%);
}

.card > h2 {
  margin: 0 0 12px;
  font-size: 10.5px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card > h2::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 11px; }
.field:last-child { margin-bottom: 0; }
.field > label { font-size: 10.5px; letter-spacing: 0.11em; text-transform: uppercase; color: var(--ink-faint); }
.field .row { display: flex; gap: 7px; }
.field .row > * { min-width: 0; }

input, select, button, textarea {
  font: inherit;
  color: var(--ink);
  background: rgba(8, 11, 24, 0.72);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 9px;
  width: 100%;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
input:focus, select:focus { outline: none; border-color: var(--violet); box-shadow: 0 0 0 3px rgba(155, 140, 240, 0.16); }
select { appearance: none; cursor: pointer; background-image: linear-gradient(45deg, transparent 50%, var(--ink-faint) 50%), linear-gradient(135deg, var(--ink-faint) 50%, transparent 50%); background-position: right 12px center, right 7px center; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 26px; }
input[type="range"] { padding: 0; background: none; border: none; accent-color: var(--violet); }

button {
  cursor: pointer;
  background: rgba(155, 140, 240, 0.10);
  border-color: rgba(155, 140, 240, 0.30);
  white-space: nowrap;
}
button:hover { background: rgba(155, 140, 240, 0.20); border-color: var(--violet); }
button.ghost { background: rgba(255, 255, 255, 0.03); border-color: var(--line); }
button.ghost:hover { background: rgba(255, 255, 255, 0.08); }
button.primary { background: linear-gradient(180deg, rgba(232, 196, 122, 0.24), rgba(232, 196, 122, 0.12)); border-color: rgba(232, 196, 122, 0.45); color: #ffeec4; }
button.primary:hover { background: rgba(232, 196, 122, 0.30); }
button[aria-pressed="true"] { background: rgba(111, 224, 176, 0.16); border-color: rgba(111, 224, 176, 0.48); color: #cffbe8; }

.btn-row { display: flex; gap: 7px; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { border: none; border-radius: 0; background: transparent; font-size: 12px; padding: 7px 4px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: rgba(155, 140, 240, 0.22); color: #ede9ff; }

/* ---------------------------------------------------------------- wheel */
.wheel-wrap { position: relative; width: min(100%, calc(100vh - 130px)); aspect-ratio: 1; }
#wheel { width: 100%; height: 100%; overflow: visible; }
#wheel text { font-family: var(--glyph); user-select: none; }

.sign-sector { transition: opacity 0.2s; }
.tick-minor { stroke: rgba(160, 175, 225, 0.22); stroke-width: 1; }
.tick-major { stroke: rgba(180, 195, 245, 0.45); stroke-width: 1.2; }
.tick-ten { stroke: rgba(232, 196, 122, 0.55); stroke-width: 1.5; }
.ring { fill: none; stroke: var(--line); }
.ring-strong { fill: none; stroke: var(--line-strong); }

.house-cusp { stroke: rgba(150, 165, 220, 0.28); stroke-width: 1; stroke-dasharray: 3 4; }
.house-angle { stroke: rgba(232, 196, 122, 0.66); stroke-width: 1.8; }
.house-num { fill: var(--ink-faint); font-size: 12px; font-family: var(--mono); text-anchor: middle; dominant-baseline: central; }

.aspect-line { stroke-linecap: round; transition: opacity 0.18s, stroke-width 0.18s; }
.body-node { cursor: pointer; }
.body-glyph { text-anchor: middle; dominant-baseline: central; font-size: 21px; paint-order: stroke; stroke: rgba(5, 6, 13, 0.85); stroke-width: 3px; }
.body-degree { text-anchor: middle; dominant-baseline: central; font-size: 9.5px; font-family: var(--mono); fill: var(--ink-dim); }
.body-retro { text-anchor: middle; dominant-baseline: central; font-size: 9px; font-family: var(--mono); fill: var(--bad); }
.leader { stroke-width: 1; opacity: 0.5; }

.dimmed { opacity: 0.13 !important; }
.body-node.active .body-glyph { font-size: 25px; }

.hub-title { text-anchor: middle; font-family: var(--serif); fill: var(--ink); }
.hub-sub { text-anchor: middle; font-family: var(--mono); fill: var(--ink-faint); font-size: 10px; letter-spacing: 0.08em; }

/* ---------------------------------------------------------------- tables */
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { text-align: left; font-weight: 600; font-size: 9.5px; letter-spacing: 0.13em; text-transform: uppercase; color: var(--ink-faint); padding: 0 6px 7px 0; border-bottom: 1px solid var(--line); }
td { padding: 5px 6px 5px 0; border-bottom: 1px solid rgba(150, 165, 220, 0.07); vertical-align: middle; }
tbody tr { cursor: pointer; transition: background 0.12s; }
tbody tr:hover, tbody tr.active { background: rgba(155, 140, 240, 0.11); }
.num { font-family: var(--mono); text-align: right; }
.glyph-cell { font-family: var(--glyph); font-size: 16px; width: 22px; text-align: center; }
.retro { color: var(--bad); font-family: var(--mono); font-size: 10px; }
.dignity { font-size: 9px; letter-spacing: 0.08em; text-transform: uppercase; padding: 1px 5px; border-radius: 5px; }
.dignity.rulership { background: rgba(111, 224, 176, 0.16); color: var(--good); }
.dignity.exaltation { background: rgba(232, 196, 122, 0.16); color: var(--gold); }
.dignity.detriment { background: rgba(255, 122, 107, 0.14); color: var(--bad); }
.dignity.fall { background: rgba(155, 140, 240, 0.16); color: var(--violet); }

.aspect-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; border-bottom: 1px solid rgba(150, 165, 220, 0.07); cursor: pointer; font-size: 12px; }
.aspect-row:hover { background: rgba(155, 140, 240, 0.10); }
.aspect-row .g { font-family: var(--glyph); font-size: 15px; width: 18px; text-align: center; }
.aspect-row .orb { margin-left: auto; font-family: var(--mono); font-size: 10.5px; color: var(--ink-faint); }
.aspect-bar { height: 3px; border-radius: 2px; width: 34px; background: rgba(255,255,255,0.08); overflow: hidden; }
.aspect-bar > i { display: block; height: 100%; border-radius: 2px; }

/* ---------------------------------------------------------------- status */
.src { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 12px; border-bottom: 1px solid rgba(150, 165, 220, 0.07); }
.src:last-child { border-bottom: none; }
.src .name { flex: 1; }
.src a { color: var(--ink-dim); text-decoration: none; border-bottom: 1px dotted var(--line-strong); }
.src a:hover { color: var(--gold); }
.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; box-shadow: 0 0 8px currentColor; }
.dot.ok { background: var(--good); color: var(--good); }
.dot.blocked, .dot.unparsed { background: var(--warn); color: var(--warn); }
.dot.error { background: var(--bad); color: var(--bad); }
.dot.skipped, .dot.idle { background: var(--ink-faint); color: transparent; box-shadow: none; }
.dot.pending { background: var(--cyan); color: var(--cyan); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.25; } }

.note { font-size: 11px; line-height: 1.55; color: var(--ink-faint); }
.note a { color: var(--ink-dim); }

.agree {
  display: flex; align-items: baseline; gap: 8px;
  font-family: var(--mono); font-size: 11px; color: var(--ink-dim);
  padding: 8px 10px; border-radius: 9px;
  background: rgba(111, 224, 176, 0.07); border: 1px solid rgba(111, 224, 176, 0.20);
  margin-bottom: 10px;
}
.agree b { font-size: 17px; color: var(--good); font-weight: 500; }

.delta-good { color: var(--good); }
.delta-mid { color: var(--warn); }
.delta-bad { color: var(--bad); }
.delta-na { color: var(--ink-faint); }

/* ---------------------------------------------------------------- detail */
#detail { min-height: 96px; }
.detail-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.detail-head .g { font-family: var(--glyph); font-size: 28px; }
.detail-head .n { font-family: var(--serif); font-size: 20px; letter-spacing: 0.02em; }
.detail-head .z { margin-left: auto; font-family: var(--mono); font-size: 13px; color: var(--gold); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 11.5px; }
.kv dt { color: var(--ink-faint); }
.kv dd { margin: 0; font-family: var(--mono); text-align: right; }

.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
.chip { font-size: 10.5px; padding: 2px 8px; border-radius: 20px; border: 1px solid var(--line); color: var(--ink-dim); text-decoration: none; }
.chip:hover { border-color: var(--gold); color: var(--gold); }

.bal { display: flex; gap: 4px; margin-top: 4px; }
.bal > div { flex: 1; text-align: center; padding: 5px 0; border-radius: 7px; font-family: var(--mono); font-size: 11px; }
.bal .fire { background: rgba(255,138,99,0.13); color: var(--fire); }
.bal .earth { background: rgba(143,214,168,0.13); color: var(--earth); }
.bal .air { background: rgba(143,194,240,0.13); color: var(--air); }
.bal .water { background: rgba(155,159,240,0.13); color: var(--water); }
.bal .cardinal, .bal .fixed, .bal .mutable { background: rgba(255,255,255,0.05); color: var(--ink-dim); }

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--panel-solid); border: 1px solid var(--line-strong); color: var(--ink);
  padding: 9px 16px; border-radius: 10px; font-size: 12.5px;
  opacity: 0; pointer-events: none; transition: opacity 0.25s, transform 0.25s; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* --------------------------------------------------------- responsive */
@media (max-width: 1400px) {
  .app { grid-template-columns: 264px minmax(0, 1fr) 320px; }
}
@media (max-width: 1100px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto auto;
    grid-template-areas: "head" "stage" "left" "right";
    height: auto;
  }
  .rail { overflow: visible; }
  .wheel-wrap { width: min(100%, 92vw); }
  body, html { height: auto; }
}

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(150, 165, 220, 0.18); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: rgba(150, 165, 220, 0.34); }
