:root {
  --paper: #fbf9f4; --ink: #221c18; --muted: #6d625a; --rule: #8a2432; --rule-soft: #e7d6d0;
  --mark: #d99a1e; --mark-ink: #5a3b00; --field: #ffffff; --focus: #1f5fa8;
  color-scheme: light dark; box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "Spectral", "Noto Serif Tamil", Georgia, "Times New Roman", serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #15172b; --ink: #ebe5d5; --muted: #a3a3bd; --rule: #c9a24a; --rule-soft: #34375c;
    --mark: #e2685a; --mark-ink: #ffe3de; --field: #1d2040; --focus: #9cc2ff;
  }
}
:root[data-theme="dark"] {
  --paper: #15172b; --ink: #ebe5d5; --muted: #a3a3bd; --rule: #c9a24a; --rule-soft: #34375c;
  --mark: #e2685a; --mark-ink: #ffe3de; --field: #1d2040; --focus: #9cc2ff;
}
*, *::before, *::after { box-sizing: inherit; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
body { margin: 0; background: var(--paper); color: var(--ink); font-size: 17px; line-height: 1.5; padding: 0 clamp(16px, 4vw, 48px) 48px; }
:lang(ta), [lang="ta"] { font-family: "Noto Serif Tamil", "Spectral", serif; }

.masthead { max-width: 1200px; margin: 0 auto; padding: 32px 0 8px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 20px; }
.masthead h1 { margin: 0; font-size: 2.5rem; font-weight: 500; letter-spacing: -0.01em; color: var(--rule); }
.lede { margin: 0; color: var(--muted); font-style: italic; }

/* form */
.birth { max-width: 1200px; margin: 16px auto 28px; display: grid; gap: 14px 16px;
  grid-template-columns: repeat(12, 1fr); padding: 18px 0; border-block: 1px solid var(--rule-soft); }
.f { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.f-name { grid-column: span 3; } .f-date { grid-column: span 2; } .f-time { grid-column: span 2; }
.f-place { grid-column: span 5; } .f-ay { grid-column: span 3; } .f-node { grid-column: span 2; }
.f-geo { grid-column: 1 / -1; border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 16px; }
.f-geo legend { padding: 0; margin-bottom: 6px; font-size: 0.8rem; font-style: italic; }
.f-geo label { display: flex; flex-direction: column; gap: 4px; }
.f-geo .hint { grid-column: 1 / -1; margin: 0; }
.actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
input, select, button { font: inherit; font-size: 1rem; color: var(--ink); }
input, select { background: var(--field); border: 1px solid var(--rule-soft); border-radius: 4px; padding: 7px 9px; width: 100%; min-width: 0; }
input:focus-visible, select:focus-visible, button:focus-visible, summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.combo { position: relative; }
#place-list { position: absolute; z-index: 5; inset: calc(100% + 2px) 0 auto; margin: 0; padding: 4px 0; list-style: none;
  background: var(--field); border: 1px solid var(--rule-soft); border-radius: 4px; max-height: 280px; overflow-y: auto; box-shadow: 0 8px 24px rgb(0 0 0 / 0.18); }
#place-list li { padding: 6px 10px; cursor: pointer; color: var(--ink); display: flex; justify-content: space-between; gap: 12px; }
#place-list li small { color: var(--muted); }
#place-list li.notice { cursor: default; color: var(--muted); font-size: 0.85rem; white-space: normal; }
#place-list li[aria-selected="true"] { background: var(--rule-soft); }
.hint { font-size: 0.8rem; max-width: 70ch; }
button[type="submit"] { background: var(--rule); color: var(--paper); border: 0; border-radius: 4px; padding: 9px 22px; cursor: pointer; font-weight: 600; }
.buttons { display: flex; gap: 10px; flex-wrap: wrap; }
button.secondary { background: none; color: var(--rule); border: 1px solid var(--rule); border-radius: 4px; padding: 8px 18px; cursor: pointer; font-weight: 600; }
button.secondary:disabled { opacity: 0.45; cursor: not-allowed; }
button[type="submit"]:disabled { opacity: 0.6; cursor: progress; }
.lang { display: inline-flex; border: 1px solid var(--rule-soft); border-radius: 4px; overflow: hidden; }
.lang button { background: none; border: 0; padding: 6px 12px; cursor: pointer; color: var(--muted); }
.lang button[aria-pressed="true"] { background: var(--rule-soft); color: var(--ink); }
.error { grid-column: 1 / -1; margin: 0; color: var(--rule); font-weight: 500; }

/* reading */
.reading { max-width: 1200px; margin: 0 auto; display: grid; grid-template-columns: minmax(300px, 460px) minmax(0, 1fr); gap: 36px; align-items: start; }

/* South Indian chart: signs fixed, Pisces top-left, running clockwise */
.chart { display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); aspect-ratio: 1;
  border: 2px solid var(--rule); background: var(--rule); gap: 1px; }
.cell { background: var(--paper); position: relative; padding: 6px 7px 18px; display: flex; flex-direction: column; gap: 1px; overflow: hidden; min-width: 0; }
.cell .sign { position: absolute; right: 6px; bottom: 3px; font-size: 0.68rem; color: var(--muted); }
.cell .house { position: absolute; left: 7px; bottom: 3px; font-size: 0.68rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.cell.lagna { background: linear-gradient(to bottom right, transparent calc(50% - 1px), var(--mark) calc(50% - 1px), var(--mark) calc(50% + 1px), transparent calc(50% + 1px)) top left / 28px 28px no-repeat, var(--paper); }
.gr { display: flex; gap: 5px; align-items: baseline; white-space: nowrap; font-size: clamp(0.8rem, 2.2vw, 0.98rem); line-height: 1.25; }
.gr b { font-weight: 600; }
.gr .deg { font-size: 0.78em; color: var(--muted); font-variant-numeric: tabular-nums; }
.gr .flag { font-size: 0.72em; color: var(--rule); }
.gr.lg b { color: var(--mark-ink); background: color-mix(in srgb, var(--mark) 35%, transparent); padding: 0 3px; border-radius: 2px; }
.cell.lagna .gr:first-child { margin-left: 18px; }
.s0 { grid-row: 1; grid-column: 2; }
.s1 { grid-row: 1; grid-column: 3; }
.s2 { grid-row: 1; grid-column: 4; }
.s3 { grid-row: 2; grid-column: 4; }
.s4 { grid-row: 3; grid-column: 4; }
.s5 { grid-row: 4; grid-column: 4; }
.s6 { grid-row: 4; grid-column: 3; }
.s7 { grid-row: 4; grid-column: 2; }
.s8 { grid-row: 4; grid-column: 1; }
.s9 { grid-row: 3; grid-column: 1; }
.s10 { grid-row: 2; grid-column: 1; }
.s11 { grid-row: 1; grid-column: 1; }
.centre { grid-column: 2 / 4; grid-row: 2 / 4; background: var(--paper); display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 12px; gap: 2px; }
.centre .title { font-size: clamp(1.2rem, 3.6vw, 1.8rem); color: var(--rule); font-weight: 500; }
.centre .who { font-size: 1rem; font-weight: 600; }
.centre .small { font-size: 0.8rem; color: var(--muted); line-height: 1.4; }

.tables, .chart-wrap { min-width: 0; }
.tables h2 { font-size: 1.25rem; font-weight: 500; margin: 0 0 8px; color: var(--rule); }
.tables h2 + .scroll { margin-bottom: 28px; }
.scroll { overflow-x: auto; }
.grid-table { border-collapse: collapse; width: 100%; font-size: 0.92rem; font-variant-numeric: tabular-nums; }
.grid-table th { text-align: left; font-weight: 500; color: var(--muted); font-size: 0.8rem; padding: 6px 8px; border-bottom: 1px solid var(--rule); white-space: nowrap; }
.grid-table td { padding: 7px 8px; border-bottom: 1px solid var(--rule-soft); white-space: nowrap; vertical-align: baseline; }
.grid-table td.num { text-align: right; }
.grid-table tr.lagna-row td { background: color-mix(in srgb, var(--mark) 14%, transparent); }
.tag { font-size: 0.78rem; padding: 1px 6px; border-radius: 3px; border: 1px solid var(--rule-soft); margin-right: 4px; }
.tag.up { border-color: #3c8a4f; color: #2f7a42; } .tag.down { border-color: var(--rule); color: var(--rule); }
.diff { color: var(--rule); font-weight: 600; }
.meta { font-size: 0.82rem; color: var(--muted); max-width: 75ch; }
.empty td { color: var(--muted); font-style: italic; }

@media (max-width: 900px) {
  .reading { grid-template-columns: minmax(0, 1fr); }
  .f-name, .f-place { grid-column: span 12; } .f-geo { grid-template-columns: repeat(2, minmax(0, 1fr)); } .f-date, .f-time { grid-column: span 6; }
  .f-ay, .f-node { grid-column: span 6; }
}
@media (max-width: 520px) { .cell { padding: 4px 4px 15px; } }
@media (prefers-reduced-motion: no-preference) { .chart.cast .gr { animation: settle 0.5s ease-out both; } }
@keyframes settle { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.print-head { display: none; }

/* ---------- PDF / print: one A4 page ---------- */
@page { size: A4 portrait; margin: 12mm; }
@media print {
  /* Same specificity as the dark-theme selectors above, and later in the file, so print is always light. */
  :root:not([data-theme="print"]), :root[data-theme] {
    --paper: #ffffff; --ink: #1a1512; --muted: #5f564f; --rule: #8a2432; --rule-soft: #dccbc5; --mark: #d99a1e; --mark-ink: #4a3000;
    padding: 0;
  }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body { padding: 0; font-size: 9.5pt; background: #fff; }
  .masthead, .birth { display: none; }
  .print-head { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 1.5pt solid var(--rule); padding-bottom: 2mm; margin-bottom: 5mm; }
  .print-title { font-size: 20pt; color: var(--rule); }
  #print-who { font-size: 9pt; color: var(--muted); text-align: right; }
  .reading { max-width: none; display: grid; gap: 5mm 7mm; grid-template-columns: 92mm 1fr;
    grid-template-areas: "chart houses" "planets planets" "meta meta"; }
  .tables { display: contents; }
  .chart-wrap { grid-area: chart; }
  .t-houses { grid-area: houses; }
  .t-planets { grid-area: planets; }
  .meta { grid-area: meta; font-size: 7.5pt; margin: 0; max-width: none; }
  .chart { width: 92mm; }
  .gr { font-size: 8pt; }
  .cell .sign, .cell .house { font-size: 6pt; }
  .centre .title { font-size: 14pt; }
  .centre .small { font-size: 6.5pt; }
  .centre .who { font-size: 8.5pt; }
  .tables h2 { font-size: 11pt; margin-bottom: 1.5mm; }
  .tables h2 + .scroll { margin-bottom: 0; }
  .scroll { overflow: visible; }
  .grid-table { font-size: 8pt; }
  .grid-table th { font-size: 7pt; padding: 1.2mm 1.5mm; }
  .grid-table td { padding: 1.1mm 1.5mm; }
  .tag { font-size: 6.5pt; padding: 0 1mm; }
  .chart, .grid-table, tr { break-inside: avoid; }
  .chart.cast .gr { animation: none; }
}
