  :root {
    --bg: #fdf8f0; --surface: #ffffff; --ink: #2c1810; --muted: #8a6f5c;
    --accent: #b3541e; --accent-deep: #7a2e0e; --gold: #c99700;
    --line: #e8d9c5; --ok: #2e7d32; --err: #c62828;
    /* The orange from the AstrosevaTalk mark, used for the brand only so it
       stays distinct from --accent, which drives interactive elements. */
    --brand: #f26522;
    --shadow-sm: 0 1px 2px rgba(44, 24, 16, 0.06);
    --shadow-md: 0 4px 16px rgba(44, 24, 16, 0.08);
    --shadow-lg: 0 24px 60px rgba(44, 24, 16, 0.18);
  }
  * { margin: 0; padding: 0; box-sizing: border-box; }
  body {
    font-family: "Segoe UI", system-ui, sans-serif; background: var(--bg);
    color: var(--ink); min-height: 100vh; position: relative;
  }
  /* Watermark. Fixed and behind everything, so it stays put while the page
     scrolls and never intercepts a click. Kept faint enough that chart lines
     and table text still win on contrast. */
  body::before {
    content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
    background-image: url("/static/logo.png");
    background-repeat: no-repeat; background-position: center;
    background-size: min(46vw, 560px);
    opacity: 0.05;
  }
  /* Without this the watermark would sit on top of the panels. */
  header, .layout, .gate { position: relative; z-index: 1; }
  @media print {
    body::before { opacity: 0.08; }
    header .signout, .layout > .panel:first-child { display: none; }
  }
  /* While the gate is up the app must not be readable behind it. */
  body.locked { overflow: hidden; }
  body.locked .layout { filter: blur(6px); pointer-events: none; user-select: none; }

  header {
    background: linear-gradient(135deg, var(--accent-deep), var(--accent));
    color: #fff7ea; padding: 1rem 2rem; border-bottom: 3px solid var(--gold);
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  }
  .brand { display: flex; align-items: center; gap: 0.9rem; min-width: 0; }
  .brand-logo { height: 42px; width: auto; display: block; }
  /* Fallback when logo.png is absent: the wordmark, set in the brand colours. */
  .wordmark {
    font-size: 1.35rem; font-weight: 800; letter-spacing: -0.02em;
    font-style: italic; color: #fff7ea; white-space: nowrap;
  }
  .wordmark span { color: var(--brand); }
  .wordmark-lg { font-size: 1.9rem; color: var(--ink); }
  .wordmark-lg span { color: var(--brand); }
  .brand-text h1 { font-size: 1.15rem; font-weight: 600; line-height: 1.2; }
  .brand-text p { font-size: 0.78rem; opacity: 0.85; margin-top: 0.15rem; }
  .signout {
    flex-shrink: 0; padding: 0.45rem 0.9rem; font-size: 0.78rem; font-weight: 600;
    color: #fff7ea; background: rgba(255, 247, 234, 0.14); cursor: pointer;
    border: 1px solid rgba(255, 247, 234, 0.35); border-radius: 999px;
    transition: background 150ms ease;
  }
  .signout:hover { background: rgba(255, 247, 234, 0.26); }
  @media (max-width: 620px) {
    header { padding: 0.9rem 1rem; }
    .brand-text p { display: none; }
  }

  /* -- Sign-in gate -------------------------------------------------- */
  .gate {
    position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
    padding: 1.5rem; overflow-y: auto;
    background:
      radial-gradient(1200px 600px at 50% -10%, rgba(242, 101, 34, 0.18), transparent 70%),
      rgba(44, 24, 16, 0.55);
    backdrop-filter: blur(4px);
  }
  .gate[hidden] { display: none; }
  .gate-card {
    width: 100%; max-width: 380px; background: var(--surface);
    border: 1px solid var(--line); border-radius: 16px; padding: 2rem 1.75rem 1.5rem;
    box-shadow: var(--shadow-lg); text-align: center;
    animation: gate-in 260ms cubic-bezier(0.16, 1, 0.3, 1);
  }
  @keyframes gate-in {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to { opacity: 1; transform: none; }
  }
  @media (prefers-reduced-motion: reduce) { .gate-card { animation: none; } }
  .gate-brand { margin-bottom: 1.25rem; }
  .gate-logo { height: 52px; width: auto; margin: 0 auto; display: block; }
  .gate-card h1 { font-size: 1.2rem; font-weight: 600; }
  .gate-sub { font-size: 0.85rem; color: var(--muted); margin: 0.3rem 0 1.4rem; }
  .gate-card label {
    display: block; text-align: left; font-size: 0.75rem; font-weight: 600;
    color: var(--muted); margin-bottom: 0.35rem;
  }
  .gate-field { position: relative; display: flex; }
  .gate-field input { padding-right: 4rem; font-family: ui-monospace, monospace; font-size: 0.85rem; }
  .gate-peek {
    position: absolute; right: 0.35rem; top: 50%; transform: translateY(-50%);
    padding: 0.25rem 0.55rem; font-size: 0.72rem; font-weight: 600;
    color: var(--accent); background: none; border: 0; cursor: pointer; border-radius: 4px;
  }
  .gate-peek:hover { background: var(--bg); }
  .gate-error {
    font-size: 0.78rem; color: var(--err); min-height: 1.2em;
    margin-top: 0.5rem; text-align: left;
  }
  .gate-go {
    width: 100%; margin-top: 0.8rem; padding: 0.7rem; font-size: 0.92rem; font-weight: 700;
    color: #fff7ea; background: var(--accent); border: 0; border-radius: 8px; cursor: pointer;
    transition: background 150ms ease, transform 80ms ease;
  }
  .gate-go:hover { background: var(--accent-deep); }
  .gate-go:active { transform: translateY(1px); }
  .gate-go[disabled] { opacity: 0.6; cursor: progress; }
  .gate-note {
    font-size: 0.72rem; color: var(--muted); line-height: 1.5; margin-top: 1rem;
    padding-top: 0.9rem; border-top: 1px solid var(--line);
  }
  .layout {
    display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 1.5rem;
    /* Wide enough for four charts per row on a desktop monitor. The form
       column stays fixed, so every extra pixel goes to the charts. */
    max-width: 1800px; margin: 1.5rem auto; padding: 0 1.5rem;
  }
  /* The form column is sticky so the inputs stay reachable while scrolling a
     long result — otherwise regenerating means scrolling back to the top. */
  .layout > .panel:first-child { align-self: start; position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow-y: auto; }
  @media (max-width: 1000px) {
    .layout { grid-template-columns: 1fr; }
    .layout > .panel:first-child { position: static; max-height: none; }
  }
  .panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 1.25rem; }
  .panel h2 {
    font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--accent-deep);
    margin-bottom: 1rem; padding-bottom: 0.5rem; border-bottom: 2px solid var(--line);
  }
  label { display: block; font-size: 0.78rem; font-weight: 600; color: var(--muted); margin: 0.7rem 0 0.25rem; }
  input {
    width: 100%; padding: 0.5rem 0.6rem; font-size: 0.9rem;
    border: 1px solid var(--line); border-radius: 6px; background: #fffdf9; color: var(--ink);
  }
  input:focus { outline: 2px solid var(--gold); outline-offset: 1px; border-color: var(--gold); }
  .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
  .gender { display: flex; gap: 0.4rem; }
  .gender button {
    flex: 1; padding: 0.5rem 0.6rem; font-size: 0.85rem; font-weight: 600;
    border: 1px solid var(--line); border-radius: 6px; background: #fffdf9;
    color: var(--muted); cursor: pointer;
  }
  .gender button.active { background: var(--gold); color: #fff; border-color: var(--gold); }
  .mode-toggle { display: flex; gap: 0.4rem; margin: 0.7rem 0 0.4rem; }
  .mode-toggle button {
    flex: 1; padding: 0.4rem 0.5rem; font-size: 0.75rem; font-weight: 600;
    border: 1px solid var(--line); border-radius: 999px; background: #fffdf9;
    color: var(--muted); cursor: pointer;
  }
  .mode-toggle button.active { background: var(--accent); color: #fff7ea; border-color: var(--accent); }
  /* Free Report has 7 tabs vs the usual 2-3, so each button sizes to its
     label instead of flex-stretching unevenly across wrapped rows. */
  .mode-toggle.tabbar-wrap { flex-wrap: wrap; }
  .mode-toggle.tabbar-wrap button { flex: 0 0 auto; }
  .coords { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
  .presets { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.5rem; }
  .presets button {
    font-size: 0.72rem; padding: 0.25rem 0.6rem; border: 1px solid var(--line);
    border-radius: 999px; background: var(--bg); color: var(--accent-deep); cursor: pointer;
  }
  .presets button:hover { background: var(--gold); color: #fff; border-color: var(--gold); }
  .place-hint { margin-top: 0.35rem; font-size: 0.75rem; color: var(--muted); min-height: 1.1em; }
  .place-hint.ok { color: var(--ok); }
  .place-hint.err { color: var(--err); }
  .place-wrap { position: relative; }
  .place-dropdown {
    position: absolute; top: calc(100% + 2px); left: 0; right: 0; z-index: 20;
    background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
    box-shadow: 0 8px 20px rgba(44, 24, 16, 0.12); max-height: 220px; overflow-y: auto;
    list-style: none; padding: 0.25rem 0;
  }
  .place-dropdown li {
    padding: 0.5rem 0.7rem; font-size: 0.85rem; cursor: pointer; color: var(--ink);
  }
  .place-dropdown li.active, .place-dropdown li:hover { background: var(--bg); color: var(--accent-deep); }
  .go {
    display: block; width: 100%; margin-top: 1.2rem; padding: 0.75rem; font-size: 0.95rem;
    font-weight: 700; border: none; border-radius: 8px; background: var(--accent);
    color: #fff7ea; cursor: pointer; transition: background 0.15s;
  }
  .go:hover { background: var(--accent-deep); }
  .go:disabled { background: var(--muted); cursor: wait; }
  .go.alt { background: var(--gold); margin-top: 0.6rem; }
  .go.alt:hover { background: #a67d00; }
  #status, #panchang-status, #kp-status, #ashtakvarga-status, #divisional-status {
    margin-top: 0.5rem; font-size: 0.8rem; min-height: 1.2em;
  }
  #status.ok, #panchang-status.ok, #kp-status.ok, #ashtakvarga-status.ok, #divisional-status.ok { color: var(--ok); }
  #status.err, #panchang-status.err, #kp-status.err, #ashtakvarga-status.err, #divisional-status.err { color: var(--err); }
  .placeholder { color: var(--muted); font-size: 0.9rem; padding: 2rem 0; text-align: center; }
  table { width: 100%; border-collapse: collapse; font-size: 0.85rem; margin: 0.6rem 0 1rem; }
  th, td { text-align: left; padding: 0.45rem 0.55rem; border-bottom: 1px solid var(--line); }
  th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); background: var(--bg); }
  tr:hover td { background: #fdf4e3; }
  .retro { color: var(--err); font-weight: 600; }
  .section-title { font-size: 0.95rem; font-weight: 600; color: var(--accent-deep); margin: 1.1rem 0 0.2rem; }
  .kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.6rem; margin: 0.6rem 0; }
  .kv .cell { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 0.55rem 0.7rem; }
  .kv .cell .k { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
  .kv .cell .v { font-size: 0.95rem; font-weight: 600; margin-top: 0.15rem; }
  .charts { display: flex; flex-wrap: wrap; gap: 1.2rem; margin: 0.8rem 0; }
  /* -- Charts --------------------------------------------------------- */
  .chart-grid {
    display: grid; gap: 1.25rem; margin: 1rem 0;
    /* 340px floor: below it the planet abbreviations in a crowded house begin
       to overlap, which is what made the smaller charts hard to read. */
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  }
  .chart-card {
    background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
    padding: 1rem; box-shadow: var(--shadow-sm);
    transition: box-shadow 160ms ease, transform 160ms ease;
  }
  .chart-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
  .chart-card-head { text-align: center; margin-bottom: 0.6rem; }
  .chart-card-title { color: var(--accent-deep); font-size: 0.95rem; font-weight: 700; }
  .chart-card-title span { color: var(--muted); font-weight: 600; }
  .chart-card-sub { color: var(--muted); font-size: 0.73rem; margin-top: 0.1rem; }
  .chart-card svg, .chart-card .si-chart { width: 100%; height: auto; max-width: none; }
  @media (prefers-reduced-motion: reduce) {
    .chart-card, .chart-card:hover { transition: none; transform: none; }
  }

  /* -- Dasha period rows ---------------------------------------------- */
  .dasha-row {
    display: flex; align-items: baseline; justify-content: space-between;
    /* The gap is what stops the date column from running into the lord name
       when a card is narrow; padding keeps both clear of the card edge. */
    gap: 1rem; padding: 0.55rem 0.9rem;
    border-bottom: 1px dashed var(--line); border-left: 3px solid transparent;
  }
  .dasha-row:last-child { border-bottom: 0; }
  .dasha-row.is-active {
    background: rgba(179, 84, 30, 0.08); border-left-color: var(--accent);
  }
  .dasha-row-lord {
    color: var(--accent-deep); font-weight: 700; font-size: 0.86rem;
    letter-spacing: 0.02em; flex-shrink: 0;
  }
  .dasha-row-dates {
    /* Was #DADADA, which is all but invisible on a white card. */
    color: var(--muted); font-size: 0.8rem; text-align: right;
    font-variant-numeric: tabular-nums; white-space: nowrap;
  }
  .dasha-row.is-active .dasha-row-dates { color: var(--ink); }
  /* Narrow cards stack instead of squeezing the date range off the edge. */
  @media (max-width: 400px) {
    .dasha-row { flex-direction: column; align-items: flex-start; gap: 0.15rem; }
    .dasha-row-dates { text-align: left; }
  }

  /* -- Mahadasha prediction cards --------------------------------------- */
  .maha-grid {
    display: grid; gap: 1.2rem; margin: 1rem 0;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  }
  .maha-card {
    background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
    padding: 1rem; box-shadow: var(--shadow-sm);
    transition: box-shadow 160ms ease, transform 160ms ease;
    display: flex; flex-direction: column;
  }
  .maha-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
  .maha-card.is-active { border-color: var(--accent); background: rgba(179, 84, 30, 0.05); }
  .maha-card-head {
    display: flex; align-items: baseline; justify-content: space-between;
    gap: 0.6rem; flex-wrap: wrap; margin-bottom: 0.2rem;
  }
  .maha-card-lord { color: var(--accent-deep); font-weight: 700; font-size: 1rem; letter-spacing: 0.02em; }
  .maha-badge {
    background: var(--ok); color: #fff; padding: 2px 9px; border-radius: 12px;
    font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  }
  .maha-dignity {
    background: var(--bg); color: var(--muted); border: 1px solid var(--line);
    padding: 1px 8px; border-radius: 10px; font-size: 0.68rem; font-weight: 600;
  }
  .maha-card-dates {
    color: var(--muted); font-size: 0.78rem; margin-bottom: 0.6rem;
    font-variant-numeric: tabular-nums;
  }
  .maha-card-body { color: var(--ink); font-size: 0.83rem; line-height: 1.55; }
  .maha-card-body p { margin: 0 0 0.7rem; overflow-wrap: anywhere; }
  .maha-card-body p:last-child { margin-bottom: 0; }
  .maha-drill-btn {
    align-self: flex-start; margin-top: 0.8rem;
    background: transparent; border: 1px solid var(--accent); color: var(--accent-deep);
    padding: 0.35rem 0.8rem; border-radius: 16px; font-size: 0.78rem; font-weight: 700;
    cursor: pointer; transition: background 160ms ease;
  }
  .maha-drill-btn:hover { background: rgba(179, 84, 30, 0.08); }
  @media (prefers-reduced-motion: reduce) {
    .maha-card, .maha-card:hover { transition: none; transform: none; }
  }

  .chart-box { flex: 1 1 320px; max-width: 460px; }
  .chart-box .chart-title { text-align: center; font-size: 0.8rem; font-weight: 600; color: var(--accent-deep); margin-bottom: 0.3rem; }
  .chart-box svg { width: 100%; height: auto; display: block; }
  .si-wrap { max-width: 640px; margin: 0.8rem auto; }
  .si-chart {
    display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, minmax(100px, auto));
    border: 1.5px solid var(--accent-deep); font-size: 0.78rem; background: #fffdf8;
  }
  .si-cell { border: 1px solid var(--line); padding: 0.3rem 0.35rem 1.1rem; position: relative; }
  .si-sign { position: absolute; bottom: 2px; left: 4px; font-size: 0.62rem; color: var(--muted);
    text-transform: uppercase; letter-spacing: 0.03em; }
  .si-line { display: flex; justify-content: space-between; gap: 0.35rem; align-items: baseline; margin-bottom: 1px; }
  .si-line .label { font-weight: 700; color: var(--ink); white-space: nowrap; }
  .si-line .label.planet { color: var(--accent-deep); }
  .si-line .deg { font-weight: 400; color: var(--muted); }
  .si-line .lords { color: var(--muted); font-size: 0.65rem; white-space: nowrap; }
  .si-center {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-align: center; gap: 0.2rem; padding: 0.5rem; background: var(--bg);
  }
  .si-center .si-name { font-weight: 700; font-size: 0.85rem; color: var(--accent-deep); }
  .si-center .si-tags { display: flex; gap: 0.3rem; margin: 0.15rem 0; }
  .si-center .si-tag { font-size: 0.6rem; padding: 0.1rem 0.5rem; border-radius: 999px; font-weight: 600; }
  .si-center .si-tag.birth { background: #fbdce6; color: #a13a5e; }
  .si-center .si-tag.ayan { background: #dcefdc; color: #2e7d32; }
  .si-center .si-meta { font-size: 0.65rem; color: var(--muted); }
  details { margin-top: 1rem; }
  details summary { cursor: pointer; font-size: 0.8rem; color: var(--muted); }
  /* The raw JSON block stays dark: it is code, and a terminal-like panel
     reads correctly there even on a light page. */
  pre { background: #2c1810; color: #f5e6cf; padding: 0.9rem; border-radius: 8px; font-size: 0.75rem; overflow-x: auto; margin-top: 0.5rem; }
