
  :root {
    --bg: #faf9f7;        --surface: #ffffff;    --surface-2: #f4f2ee;
    --border: #e6e2db;    --border-strong: #d4cec3;
    --text: #1c1b19;      --muted: #6f6a61;      --faint: #9b958a;
    --accent: #6d4aff;    --accent-soft: #efeaff; --accent-ink: #4326c9;
    --gold: #b7791f;      --danger: #b4443a;     --danger-soft: #fdf1ef;
    --ok: #2f7a4d;
    --astrosage: #2563eb; --astrotheme: #059669;
    --astrodatabank: #7c3aed; --lunarastro: #b45309;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(20,18,15,.04), 0 8px 24px rgba(20,18,15,.06);
    --font: ui-sans-serif, -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
    --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace;
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --bg: #14131a;       --surface: #1c1b24;    --surface-2: #232230;
      --border: #2e2c3a;   --border-strong: #3d3a4d;
      --text: #ece9f3;     --muted: #a29cb4;      --faint: #726c85;
      --accent: #9b7bff;   --accent-soft: #272040; --accent-ink: #c4b1ff;
      --gold: #d9a441;     --danger: #ef7d72;     --danger-soft: #2d1d1c;
      --ok: #62c68d;
      --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.28);
    }
  }
  * { box-sizing: border-box; }
  html, body { height: 100%; }
  body {
    margin: 0; font-family: var(--font); background: var(--bg); color: var(--text);
    display: flex; flex-direction: column; overflow: hidden;
    -webkit-font-smoothing: antialiased;
  }
  button, input, select, textarea { font: inherit; color: inherit; }
  a { color: var(--accent-ink); }

  /* ---------- top bar + tabs ---------- */
  .topbar {
    display: flex; align-items: center; gap: 14px; padding: 0 16px;
    height: 52px; flex: 0 0 auto; border-bottom: 1px solid var(--border);
    background: var(--surface);
  }
  .brand { display: flex; align-items: center; gap: 9px; font-weight: 650;
           font-size: 14.5px; letter-spacing: -.01em; cursor: pointer; }
  .brand .mark { width: 22px; height: 22px; }
  .tabs { display: flex; gap: 4px; overflow-x: auto; flex: 1; min-width: 0;
          scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab {
    display: flex; align-items: center; gap: 8px; padding: 5px 9px 5px 12px;
    border-radius: 9px; background: transparent; border: 1px solid transparent;
    font-size: 12.5px; white-space: nowrap; cursor: pointer; color: var(--muted);
    max-width: 210px;
  }
  .tab:hover { background: var(--surface-2); }
  .tab.active { background: var(--accent-soft); color: var(--accent-ink);
                border-color: color-mix(in srgb, var(--accent) 25%, transparent); font-weight: 600; }
  .tab .label { overflow: hidden; text-overflow: ellipsis; }
  .tab .x { opacity: .45; font-size: 15px; line-height: 1; padding: 0 2px; border-radius: 4px; }
  .tab .x:hover { opacity: 1; background: color-mix(in srgb, var(--text) 10%, transparent); }
  .who { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted);
         flex: 0 0 auto; cursor: pointer; padding: 5px 10px; border-radius: 20px;
         border: 1px solid var(--border); }
  .who:hover { border-color: var(--border-strong); }
  .who .dot { width: 20px; height: 20px; border-radius: 50%; background: var(--accent);
              color: #fff; display: grid; place-items: center; font-size: 10px; font-weight: 700; }

  /* ---------- panes ---------- */
  .pane { flex: 1 1 auto; min-height: 0; overflow: hidden; display: none; }
  .pane.show { display: flex; }

  /* ---------- home ---------- */
  #home { flex-direction: column; align-items: center; overflow-y: auto; }
  .home-inner { width: 100%; max-width: 720px; padding: 0 24px 64px;
                margin-top: min(13vh, 110px); }
  .home-title { font-size: 30px; font-weight: 640; letter-spacing: -.025em;
                text-align: center; margin: 0 0 8px; }
  .home-sub { text-align: center; color: var(--muted); font-size: 14px;
              margin: 0 0 30px; line-height: 1.55; }
  .composer {
    background: var(--surface); border: 1px solid var(--border-strong);
    border-radius: 16px; box-shadow: var(--shadow); padding: 14px 14px 10px;
    transition: border-color .15s;
  }
  .composer:focus-within { border-color: var(--accent); }
  .composer textarea {
    width: 100%; border: 0; outline: 0; resize: none; background: transparent;
    font-size: 15px; line-height: 1.5; min-height: 26px; max-height: 190px;
  }
  .composer-row { display: flex; align-items: center; justify-content: space-between;
                  gap: 10px; margin-top: 8px; }
  .btn {
    border: 1px solid var(--border-strong); background: var(--surface);
    border-radius: 9px; padding: 7px 13px; font-size: 13px; cursor: pointer;
    display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
  }
  .btn:hover { background: var(--surface-2); }
  .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 550; }
  .btn.primary:hover { filter: brightness(1.08); }
  .btn:disabled { opacity: .45; cursor: default; }
  .btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
  .btn.ghost:hover { background: var(--surface-2); }
  .chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 18px; justify-content: center; }
  .chip {
    font-size: 12.5px; padding: 6px 12px; border-radius: 20px; cursor: pointer;
    background: var(--surface); border: 1px solid var(--border); color: var(--muted);
  }
  .chip:hover { border-color: var(--accent); color: var(--accent-ink); background: var(--accent-soft); }
  .chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
  .statbar { display: flex; gap: 22px; justify-content: center; margin-top: 34px;
             flex-wrap: wrap; font-size: 12px; color: var(--muted); }
  .statbar b { display: block; font-size: 19px; color: var(--text); font-weight: 640;
               font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
  .statbar div { text-align: center; }

  /* ---------- results ---------- */
  .interpreted { font-size: 12.5px; color: var(--muted); margin: 22px 0 10px;
                 display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
  .pill { background: var(--surface-2); border: 1px solid var(--border);
          border-radius: 6px; padding: 2px 8px; font-size: 11.5px; color: var(--text); }
  .results { display: grid; gap: 8px; }
  .rescard {
    display: flex; align-items: center; gap: 12px; padding: 11px 14px; cursor: pointer;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  }
  .rescard:hover { border-color: var(--accent); box-shadow: var(--shadow); }
  .rescard .nm { font-weight: 600; font-size: 13.5px; }
  .rescard .sub { font-size: 11.5px; color: var(--muted); margin-top: 2px;
                  display: flex; gap: 7px; flex-wrap: wrap; align-items: center; }
  .rescard .grow { flex: 1; min-width: 0; }
  .badge { font-size: 9.5px; padding: 1.5px 6px; border-radius: 20px; color: #fff;
           font-weight: 700; letter-spacing: .02em; text-transform: uppercase; }
  .badge.astrosage { background: var(--astrosage); }
  .badge.astrotheme { background: var(--astrotheme); }
  .badge.astrodatabank { background: var(--astrodatabank); }
  .badge.lunarastro { background: var(--lunarastro); }
  .rodden { font-size: 10px; font-weight: 700; padding: 1.5px 5px; border-radius: 4px;
            background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
  .warnmark { color: var(--danger); font-weight: 700; }

  /* ---------- browse drawer ---------- */
  .drawer { position: fixed; inset: 0; background: rgba(12,10,16,.4); z-index: 50;
            display: none; backdrop-filter: blur(2px); }
  .drawer.show { display: block; }
  .drawer-panel {
    position: absolute; top: 0; right: 0; bottom: 0; width: min(440px, 92vw);
    background: var(--surface); border-left: 1px solid var(--border);
    display: flex; flex-direction: column; box-shadow: -8px 0 40px rgba(0,0,0,.18);
  }
  .drawer-head { padding: 16px 18px; border-bottom: 1px solid var(--border);
                 display: flex; justify-content: space-between; align-items: center; }
  .drawer-body { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 18px; }
  .field-row { display: grid; gap: 7px; margin-bottom: 14px; }
  .field-row label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
                     color: var(--muted); font-weight: 600; }
  .field-row input, .field-row select {
    padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg); outline: 0;
  }
  .field-row input:focus, .field-row select:focus { border-color: var(--accent); }
  .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

  /* ---------- chart pane ---------- */
  .chartpane { display: grid; grid-template-columns: minmax(0,1fr) minmax(340px, 420px);
               width: 100%; min-height: 0; }
  .chartmain { min-width: 0; min-height: 0; overflow-y: auto; padding: 26px 30px 60px; }
  .chartside { min-width: 0; min-height: 0; border-left: 1px solid var(--border);
               background: var(--surface); display: flex; flex-direction: column; }
  @media (max-width: 1040px) {
    .chartpane { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
    .chartside { border-left: 0; border-top: 1px solid var(--border); max-height: 52vh; }
  }
  .ph1 { font-size: 25px; font-weight: 650; letter-spacing: -.024em; margin: 0 0 6px; }
  .pmeta { display: flex; gap: 9px; flex-wrap: wrap; align-items: center;
           color: var(--muted); font-size: 12.5px; margin-bottom: 18px; }
  .section { margin-bottom: 26px; }
  .sec-title { font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
               color: var(--faint); font-weight: 700; margin-bottom: 11px;
               display: flex; align-items: center; gap: 8px; }
  .sec-title::after { content: ''; flex: 1; height: 1px; background: var(--border); }
  .card { background: var(--surface); border: 1px solid var(--border);
          border-radius: var(--radius); padding: 14px 16px; }
  .grid-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px,1fr)); gap: 10px; }
  .fld { background: var(--surface); border: 1px solid var(--border);
         border-radius: 10px; padding: 9px 12px; }
  .fld .k { font-size: 10px; text-transform: uppercase; letter-spacing: .05em;
            color: var(--faint); font-weight: 650; margin-bottom: 3px; }
  .fld .v { font-size: 13.5px; font-weight: 520; word-break: break-word; }
  .prose { font-size: 13.5px; line-height: 1.65; color: var(--muted); }
  .prose b { color: var(--text); }
  .banner { border-radius: 10px; padding: 11px 14px; font-size: 12.5px; line-height: 1.55;
            margin-bottom: 18px; border: 1px solid; }
  .banner.warn { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
  .banner.info { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 25%, transparent); }

  .timeline { border-left: 2px solid var(--border); margin-left: 5px; padding-left: 16px; }
  .ev { position: relative; padding: 7px 0; display: flex; gap: 12px; font-size: 13px; }
  .ev::before { content: ''; position: absolute; left: -21px; top: 13px; width: 8px; height: 8px;
                border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); }
  .ev .when { color: var(--muted); min-width: 96px; font-variant-numeric: tabular-nums; }
  .ev .approx { font-size: 9.5px; color: var(--faint); }

  table.data { border-collapse: collapse; width: 100%; font-size: 12.5px; }
  table.data th { text-align: left; font-size: 10px; text-transform: uppercase;
                  letter-spacing: .05em; color: var(--faint); font-weight: 700;
                  padding: 7px 10px; border-bottom: 1px solid var(--border); }
  table.data td { padding: 6px 10px; border-bottom: 1px solid var(--border); }
  table.data tr:last-child td { border-bottom: 0; }
  table.data .mono { font-family: var(--mono); font-size: 11.5px; }
  .scroll-x { overflow-x: auto; }
  .retro { color: var(--danger); font-weight: 700; font-size: 10px; }

  .chartwrap { display: flex; gap: 20px; flex-wrap: wrap; align-items: flex-start; }
  .chartsvg { background: var(--surface); border: 1px solid var(--border);
              border-radius: var(--radius); padding: 10px; }

  /* calculator tabs */
  .calcbar { display: flex; gap: 4px; border-bottom: 1px solid var(--border);
             margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
  .calcbar::-webkit-scrollbar { display: none; }
  .calctab { padding: 8px 13px; font-size: 12.5px; cursor: pointer; white-space: nowrap;
             color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
  .calctab:hover { color: var(--text); }
  .calctab.on { color: var(--accent-ink); border-bottom-color: var(--accent); font-weight: 620; }
  .doctrinebar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
                 margin-bottom: 14px; font-size: 12px; }
  .doctrinebar select { padding: 5px 8px; border: 1px solid var(--border);
      border-radius: 7px; background: var(--surface); outline: 0; font-size: 12px; }
  .doctrinebar select:focus { border-color: var(--accent); }
  .doctrinebar label { color: var(--faint); font-size: 10.5px; text-transform: uppercase;
                       letter-spacing: .05em; font-weight: 650; }
  .kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); gap: 8px; }
  .kv .fld .v { font-size: 13px; }
  .cite { font-size: 11.5px; color: var(--muted); font-style: italic; margin-top: 8px; }
  .heat { display: inline-block; min-width: 22px; text-align: center; border-radius: 4px;
          padding: 1px 4px; font-variant-numeric: tabular-nums; }
  .dasha-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px;
               padding: 3px 0; font-variant-numeric: tabular-nums; }
  .dasha-row.lvl2 { padding-left: 22px; color: var(--muted); font-size: 12px; }
  .dasha-row.lvl3 { padding-left: 44px; color: var(--faint); font-size: 11.5px; }
  .dasha-row.now { background: var(--accent-soft); border-radius: 6px; padding-left: 6px;
                   color: var(--accent-ink); font-weight: 600; }
  .dasha-row.lvl2.now { padding-left: 22px; } .dasha-row.lvl3.now { padding-left: 44px; }
  .lordtag { font-weight: 650; min-width: 74px; }

  /* ---------- chat ---------- */
  .chat-head { padding: 12px 16px; border-bottom: 1px solid var(--border);
               display: grid; gap: 8px; flex: 0 0 auto; }
  .chat-head .row { display: flex; gap: 8px; align-items: center; }
  .chat-head select, .chat-head input { flex: 1; min-width: 0; padding: 6px 9px;
      border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
      outline: 0; font-size: 12.5px; }
  .chatlog { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 16px;
             display: flex; flex-direction: column; gap: 14px; }
  .msg { font-size: 13.2px; line-height: 1.62; }
  .msg .role { font-size: 10px; font-weight: 700; text-transform: uppercase;
               letter-spacing: .06em; color: var(--faint); margin-bottom: 5px; }
  .msg.user .body { background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 20%, transparent);
                    padding: 9px 12px; border-radius: 10px; }
  .msg .body { white-space: pre-wrap; word-wrap: break-word; }
  .chat-compose { flex: 0 0 auto; border-top: 1px solid var(--border); padding: 12px 14px; }
  .chat-compose textarea { width: 100%; border: 1px solid var(--border); border-radius: 10px;
      background: var(--bg); padding: 9px 11px; resize: none; outline: 0; font-size: 13px;
      min-height: 40px; max-height: 140px; }
  .chat-compose textarea:focus { border-color: var(--accent); }
  .hint { font-size: 11px; color: var(--faint); line-height: 1.5; }
  .empty { color: var(--muted); font-size: 13px; text-align: center; padding: 34px 20px;
           line-height: 1.6; }
  .spinner { width: 13px; height: 13px; border: 2px solid var(--border-strong);
             border-top-color: var(--accent); border-radius: 50%;
             animation: spin .7s linear infinite; display: inline-block; }
  @keyframes spin { to { transform: rotate(360deg); } }

  /* ---------- name modal ---------- */
  .modal { position: fixed; inset: 0; background: rgba(12,10,16,.45); z-index: 80;
           display: none; place-items: center; backdrop-filter: blur(3px); }
  .modal.show { display: grid; }
  .modal-box { background: var(--surface); border: 1px solid var(--border);
               border-radius: 16px; padding: 24px; width: min(400px, 92vw);
               box-shadow: 0 20px 60px rgba(0,0,0,.28); }
  .modal-box h3 { margin: 0 0 6px; font-size: 17px; font-weight: 640; }
  .modal-box p { margin: 0 0 16px; font-size: 13px; color: var(--muted); line-height: 1.55; }
  .modal-box input { width: 100%; padding: 10px 12px; border: 1px solid var(--border-strong);
                     border-radius: 9px; background: var(--bg); outline: 0; margin-bottom: 14px; }
  .modal-box input:focus { border-color: var(--accent); }
