/* Bindu — light and dark themes, element-coded signs, printable chart.
 *
 * Two rules from the plan are structural, not decorative:
 *  - meaning is never carried by colour alone: every tinted cell also has its
 *    sign written out, and retrograde or warning states carry a mark or a word;
 *  - colours are declared in pairs and checked for contrast in both themes.
 */

:root {
  --el-fire: #C62828;
  --el-earth: #2E7D32;
  --el-air: #E0A800;
  --el-water: #1565C0;
}

html.theme-light {
  --bg: #FFFFFF;
  --surface: #F5F5F7;
  --text: #1A1A2E;
  --muted: #6B7280;
  --border: #E3E3E8;
  --accent: #6200EE;
  --accent-soft: rgba(98, 0, 238, 0.12);
  --warning: #B26A00;
  --error: #C62828;
  --tint: 0.14;
  --cell-bg: #FFFFFF;
}

html.theme-dark {
  --bg: #14141C;
  --surface: #1D1D28;
  --text: #E8E8EF;
  --muted: #9A9AA8;
  --border: #2C2C3A;
  --accent: #9D6BFF;
  --accent-soft: rgba(157, 107, 255, 0.18);
  --warning: #E0A800;
  --error: #FF6B6B;
  --tint: 0.30;
  --cell-bg: #1D1D28;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  line-height: 1.55;
}

a { color: var(--accent); }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---- chrome ---- */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  font-weight: 700;
  font-size: 18px;
  color: var(--text);
  text-decoration: none;
  letter-spacing: 0.5px;
}

.nav { display: flex; gap: 14px; margin-left: auto; }
.nav a { text-decoration: none; font-weight: 600; }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  font-size: 18px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
}

.footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  max-width: 900px;
  margin: 40px auto 24px;
  padding: 0 20px;
  color: var(--muted);
  font-size: 12px;
}

/* ---- panels and forms ---- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
}

.panel h1, .panel h2 { margin-top: 0; font-size: 18px; }
.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.birth-form, .settings-form { display: block; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }

input[type="text"], input[type="number"], input[type="search"], select {
  width: 100%;
  padding: 10px;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

input:focus, select:focus, button:focus, a:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1 1 0; min-width: 0; }

.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.check input { width: auto; }

.advanced { margin: 10px 0 4px; border-top: 1px solid var(--border); padding-top: 10px; }
.advanced summary { cursor: pointer; font-weight: 600; }

button, .button {
  display: inline-block;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  width: 100%;
  margin-top: 8px;
  letter-spacing: 0.5px;
}

button.danger { color: var(--error); border-color: var(--error); }
.inline { display: inline; }
.actions { display: flex; gap: 8px; align-items: center; }

.logout-form { display: inline; margin: 0; }
button.link {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: inherit;
  cursor: pointer;
}
.account { color: var(--muted); font-weight: 600; }
.login-form { display: grid; gap: 12px; max-width: 320px; }
.login-form label { display: grid; gap: 4px; font-size: 14px; }

.hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.flash { background: var(--accent-soft); border-radius: 8px; padding: 10px 14px; }
.warning { color: var(--warning); border-left: 3px solid var(--warning); padding-left: 10px; margin: 12px 0; }
.error { color: var(--error); font-weight: 600; }
.empty { color: var(--muted); }
.muted { color: var(--muted); }

/* ---- autocomplete ---- */

.suggestions {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  overflow: hidden;
}

.suggestions li { padding: 8px 12px; cursor: pointer; }
.suggestions li[aria-selected="true"], .suggestions li:hover { background: var(--accent-soft); }
.suggestions .suggestion-details { display: block; font-size: 12px; color: var(--muted); }

/* ---- recent and chart lists ---- */

.recent { list-style: none; margin: 0; padding: 0; }
.recent a {
  display: flex;
  gap: 10px;
  align-items: baseline;
  flex-wrap: wrap;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
}
.recent-name { font-weight: 600; }
.recent-meta { color: var(--muted); font-size: 13px; }
.pill {
  margin-left: auto;
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
}

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
th { font-size: 12px; text-transform: uppercase; color: var(--muted); }
.positions td, .charts td { font-size: 14px; }

.search { display: flex; gap: 8px; align-items: center; }
.search input { min-width: 180px; }

/* ---- facts list ---- */

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px 18px; margin: 12px 0 0; }
.facts dt { font-size: 12px; color: var(--muted); }
.facts dd { margin: 0 0 6px; }

/* ---- chart ---- */

.chart-wrap { display: flex; justify-content: center; padding: 10px 0; }
svg.chart { width: 100%; max-width: 460px; height: auto; }
svg.chart text { text-anchor: middle; fill: var(--text); font-family: inherit; }
svg.chart .chart-sign { font-size: 11px; font-weight: 600; }
/* No font-size here on purpose: the renderer shrinks the labels of a crowded
   cell, and a CSS rule would override the inline size the layout computed. */
svg.chart .chart-body { fill: var(--text); }
svg.chart .chart-lagna { font-size: 10px; font-weight: 700; fill: var(--accent); }
svg.chart .chart-frame, svg.chart .chart-line { fill: none; stroke: var(--border); stroke-width: 1.5; }
svg.chart .chart-center { font-size: 12px; font-weight: 600; fill: var(--muted); }
svg.chart .chart-center-sub { font-size: 11px; fill: var(--muted); }
svg.chart .cell { stroke: var(--border); stroke-width: 1; }
svg.chart .cell-lagna { stroke: var(--accent); stroke-width: 3; }
svg.chart .cell-fire { fill: var(--el-fire); fill-opacity: var(--tint); }
svg.chart .cell-earth { fill: var(--el-earth); fill-opacity: var(--tint); }
svg.chart .cell-air { fill: var(--el-air); fill-opacity: var(--tint); }
svg.chart .cell-water { fill: var(--el-water); fill-opacity: var(--tint); }

/* The first house: an accent tint over the element tint, an accent frame and
   the «Лагна» label. The layers do not compete — the element stays readable
   underneath, and the name is always written out. */
svg.chart .lagna-fill {
  fill: var(--accent);
  fill-opacity: 0.16;
  stroke: var(--accent);
  stroke-width: 3;
}

/* A faint element mark in the position table, with the sign name always
   present, so the colour is never the only carrier of meaning. */
td[class^="element-"] { border-left: 3px solid transparent; }
td.element-sign-aries, td.element-sign-leo, td.element-sign-sagittarius { border-left-color: var(--el-fire); }
td.element-sign-taurus, td.element-sign-virgo, td.element-sign-capricorn { border-left-color: var(--el-earth); }
td.element-sign-gemini, td.element-sign-libra, td.element-sign-aquarius { border-left-color: var(--el-air); }
td.element-sign-cancer, td.element-sign-scorpio, td.element-sign-pisces { border-left-color: var(--el-water); }

.back, .save-form { margin-top: 12px; }

/* ---- divisional charts ---- */

.varga-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.varga-card { margin-bottom: 0; }
.varga-card h2 { font-size: 15px; margin-bottom: 4px; }
.varga-card svg.chart { max-width: 100%; }

.warning-row { background: var(--accent-soft); }

/* A name with a description available on hover says so, without relying on
   the cursor alone. */
[title] { text-decoration: underline dotted; text-underline-offset: 3px; cursor: help; }

/* ---- responsive: astrologers work from a phone ---- */

@media (max-width: 640px) {
  .container { padding: 12px; }
  .topbar { padding: 10px 12px; }
  .nav { gap: 10px; font-size: 14px; }
  .panel { padding: 14px; }
  .panel-head { flex-direction: column; align-items: flex-start; }
  .search { width: 100%; }
  .search input { min-width: 0; }
  .facts { grid-template-columns: 1fr; }
  .positions th:nth-child(4), .positions td:nth-child(4),
  .positions th:nth-child(5), .positions td:nth-child(5) { display: none; }
  svg.chart { max-width: 100%; }
}

/* ---- print: the chart page without any interface ---- */

@media print {
  .topbar, .footer, .no-print, .save-form, .back, .panel-actions { display: none !important; }
  body { background: #fff; color: #000; }
  .panel { border: none; padding: 0; break-inside: avoid; }
  svg.chart { max-width: 420px; }
  a { color: #000; text-decoration: none; }
}

/* ---- reading screen: sphere and stage chips, facts, interpretation ---- */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 8px 0;
}

.chips-label {
  font-size: 12px;
  color: var(--muted);
}

.chip {
  display: inline-block;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  text-decoration: none;
  color: var(--text);
  font-size: 13px;
}

.chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.facts-list {
  margin: 6px 0 12px;
  padding-left: 18px;
  font-size: 14px;
}

.factor {
  border-left: 3px solid var(--border);
  padding-left: 12px;
  margin: 10px 0;
}

.factor p { margin: 4px 0; }

.factor details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
}

.factor details .muted { font-size: 12px; }

/* The reading itself: a thread of lines. Facts and sources sit behind the
   disclosures, so the screen shows the interpretation first and the evidence
   on demand. */
.thread p {
  margin: 0 0 8px;
  font-size: 15px;
  line-height: 1.5;
}

.facts-block {
  margin-top: 10px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.facts-block > summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
}

.facts-block h4 {
  margin: 10px 0 4px;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.factor-why {
  border-left: 3px solid var(--border);
  padding-left: 10px;
  margin: 8px 0;
}

/* The balance line: what the fired rules add up to, before the thread. */
.balance {
  margin: 0 0 10px;
  padding: 8px 10px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
  font-size: 14px;
}

/* One graha's compensation: a short prescription, set apart from the thread. */
.remedy {
  border-left: 3px solid var(--border);
  padding-left: 10px;
  margin: 10px 0;
}
.remedy p {
  margin: 4px 0;
}

/* The chart-wide compensation ranking: the most repeated graha comes first. */
.compensation-summary { margin-bottom: 14px; }
.compensation-rank { padding-left: 18px; }
.compensation-rank .rank-head { font-weight: 600; margin: 0 0 4px; }

/* Ayurvedic constitution: food, routine and weight, three columns on wide. */
.constitution-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.constitution h4 { margin: 8px 0 4px; }
@media (max-width: 640px) { .constitution-grid { grid-template-columns: 1fr; } }
