.rules-main {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}
.rules-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: start;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.12);
}
.rules-hero h1 {
  margin: 4px 0 8px;
  font-size: clamp(28px, 4vw, 44px);
}
.rules-hero p {
  max-width: 850px;
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}
.rules-kicker {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--gold);
  font-weight: 800;
}
.rules-version {
  min-width: 140px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  font-size: 12px;
}
.rules-version span {
  color: var(--muted);
}
.rules-status-key {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 7px 10px;
  align-items: center;
  margin: 14px 0 20px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  font-size: 12px;
  color: var(--muted);
}
.rule-status {
  display: inline-flex;
  width: max-content;
  align-items: center;
  padding: 3px 7px;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border: 1px solid currentColor;
}
.rule-status.source-derived {
  color: var(--status-source-derived);
}
.rule-status.reconstructed {
  color: var(--status-reconstructed);
}
.rule-status.syncrota-model {
  color: var(--status-syncrota-model);
}
.rule-status.protected {
  color: var(--status-protected);
}
.rules-content {
  display: grid;
  gap: 14px;
}
.rules-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}
.rules-card-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
.rules-card h2 {
  margin: 3px 0 0;
  font-size: 19px;
}
.rules-card p {
  color: var(--muted);
  line-height: 1.55;
}
.rules-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.rule-block {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
}
.rule-block h3 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--gold);
}
.rule-block p {
  margin: 6px 0 0;
  font-size: 11px;
}
.rules-table-wrap {
  overflow-x: auto;
}
.rules-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.rules-table th,
.rules-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}
.rules-table th {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.rules-table tr:last-child td {
  border-bottom: 0;
}
.rules-table td:first-child {
  font-weight: 700;
}
.rules-admin-note {
  margin-top: 14px;
}
.rules-admin-note p {
  margin: 0;
}
.rules-footnote {
  margin: 18px 4px 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}
.rules-callout {
  padding: 10px 12px;
  border-left: 3px solid var(--gold);
  background: var(--bg);
  border-radius: 0 8px 8px 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}
.page-link.is-current {
  border-color: var(--gold);
  color: var(--gold);
}
@media (max-width: 700px) {
  .rules-main {
    width: calc(100% - 20px);
    padding-top: 16px;
  }
  .rules-hero {
    grid-template-columns: 1fr;
    padding: 16px;
  }
  .rules-version {
    width: 100%;
  }
  .rules-card {
    padding: 14px;
  }
  .rules-status-key {
    grid-template-columns: 1fr;
    gap: 5px;
  }
  .rules-status-key .rule-status:not(:first-child) {
    margin-top: 5px;
  }
  .header-actions {
    gap: 6px;
  }
  .header-actions .page-link {
    font-size: 10px;
    padding: 6px 7px;
  }
}

/* Calculation Rules is a normal document page, not the fixed-height wheel workspace. */
html {
  height: auto;
  min-height: 100%;
  overflow-y: auto;
}
body {
  height: auto;
  min-height: 100vh;
  display: block;
  overflow-x: hidden;
  overflow-y: auto;
}
main.rules-main {
  display: block;
  height: auto;
  min-height: 0;
  overflow: visible;
  transition: none;
}

/* Keep reference datasets visually distinct from surrounding explanatory rules. */
.rules-table-wrap {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
}
.rules-table {
  border-collapse: separate;
  border-spacing: 0;
}
.rules-table th,
.rules-table td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 9px 11px;
}
.rules-table thead th {
  background: color-mix(in srgb, var(--panel) 78%, var(--gold) 22%);
  color: var(--text);
  font-weight: 800;
}
@media (max-width: 700px) {
  .rules-table th,
  .rules-table td {
    padding: 8px 9px;
  }
}

/* Source-wheel audit / degree-reference controls. */
.degree-reference-controls {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  margin: 12px 0;
}
.degree-reference-controls label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.degree-reference-controls select {
  min-width: 150px;
  padding: 8px 30px 8px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  text-transform: none;
  letter-spacing: normal;
}
.degree-reference-count {
  margin-left: auto;
  padding: 8px 0;
  color: var(--muted);
  font-size: 11px;
}
.rules-table td {
  vertical-align: top;
}
.rules-table td:not(:first-child) {
  font-weight: 400;
}
.rules-table-wrap + .rules-table-wrap {
  margin-top: 10px;
}
@media (max-width: 700px) {
  .degree-reference-controls {
    align-items: stretch;
  }
  .degree-reference-controls label,
  .degree-reference-controls select {
    width: 100%;
  }
  .degree-reference-count {
    margin-left: 0;
  }
}

/* Rules page layout refactor: wide reviewer workspace, collapsible top-level sections and scrollable audit tables. */
:root {
  --rules-bg: #080807;
  --rules-panel: #0d0c0a;
  --rules-panel-2: #17140f;
  --rules-text: #f1eadc;
  --rules-muted: #c4b9a5;
  --rules-line: #5b4a29;
  --rules-line-strong: #806735;
  --rules-gold: #d8b25c;
  /* Rule-provenance badges (.rule-status). These are also the colour, via
     currentColor, of the badge's own border - see .rule-status below. Tuned
     against --rules-panel/--rules-bg for each theme rather than shared
     across both: the original single hardcoded set (kept here as the dark
     default) reads fine on this near-black panel (contrast ~8-9:1) but drops
     to ~2:1 on the light theme's cream panel - well under WCAG AA's 4.5:1
     minimum for text, hence "washed out" there. */
  --status-source-derived: #4dbf83;
  --status-reconstructed: #d7a94a;
  --status-syncrota-model: #73a7df;
  --status-protected: #b59ae8;
}
html[data-theme="light"] {
  --rules-bg: #f6f3eb;
  --rules-panel: #fffdf8;
  --rules-panel-2: #f2ede2;
  --rules-text: #262117;
  --rules-muted: #665e50;
  --rules-line: #c9b98e;
  --rules-line-strong: #a58a50;
  --rules-gold: #8a651e;
  /* Darker/more saturated versions of the same four hues, each re-picked to
     clear 4.5:1 contrast against both --rules-panel and --rules-bg (~4.8-5.4:1
     here) instead of inheriting the dark-theme values above. --status-reconstructed
     is also shifted further from amber toward orange so it doesn't read as a
     near-duplicate of --rules-gold just above (both were ~H:40 before). */
  --status-source-derived: #24784c;
  --status-reconstructed: #aa4d17;
  --status-syncrota-model: #1f6bbe;
  --status-protected: #7e49e2;
}
body {
  background: var(--rules-bg);
  color: var(--rules-text);
}
.rules-main {
  width: min(1680px, calc(100% - 40px));
  max-width: none;
  margin: 0 auto;
  padding: 28px 0 48px;
}
.rules-hero,
.rules-status-key,
.rules-card,
.rule-block {
  border-color: var(--rules-line);
  background: var(--rules-panel);
  color: var(--rules-text);
}
.rules-hero p,
.rules-card p,
.rules-status-key,
.rules-callout,
.rules-footnote,
.degree-reference-count,
.degree-reference-controls label {
  color: var(--rules-muted);
}
.rules-kicker,
.rule-block h3 {
  color: var(--rules-gold);
}
.rules-version,
.rules-callout,
.degree-reference-controls select {
  border-color: var(--rules-line);
  background: var(--rules-panel-2);
  color: var(--rules-text);
}
.rules-content {
  gap: 12px;
}
.rules-card {
  padding: 0;
  overflow: visible;
}
.rules-card-heading {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0;
  padding: 16px 18px;
  user-select: none;
}
.rules-card-heading::-webkit-details-marker {
  display: none;
}
.rules-card-heading::marker {
  display: none;
  content: "";
}
.rules-card-heading-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.rules-chevron {
  font-size: 18px;
  line-height: 1;
  transition: transform 0.18s ease;
  color: var(--rules-muted);
}
.rules-card[open] .rules-chevron {
  transform: rotate(180deg);
}
.rules-card-body {
  padding: 0 18px 18px;
  border-top: 1px solid var(--rules-line);
}
.rules-card-body > .rules-callout:first-child {
  margin-top: 14px;
}
.rules-admin-note {
  padding: 18px;
}
.rules-table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--rules-line-strong);
  border-radius: 9px;
  background: var(--rules-bg);
  scrollbar-gutter: stable;
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
}
.rules-table-wrap:focus {
  outline: 2px solid color-mix(in srgb, var(--rules-gold) 60%, transparent);
  outline-offset: 2px;
}
.rules-table {
  width: 100%;
  min-width: max-content;
  border-collapse: separate;
  border-spacing: 0;
  color: var(--rules-text);
}
.rules-table th,
.rules-table td {
  border-right: 1px solid var(--rules-line);
  border-bottom: 1px solid var(--rules-line);
  padding: 9px 11px;
  white-space: nowrap;
}
.rules-table th:last-child,
.rules-table td:last-child {
  border-right: 0;
}
.rules-table tbody tr:last-child td {
  border-bottom: 0;
}
.rules-table thead th {
  background: var(--rules-panel-2);
  color: var(--rules-text);
  font-weight: 800;
}
.rules-zodiac-symbol,
.rules-planet-symbol {
  display: inline-block;
  min-width: 1.15em;
  text-align: center;
  font-family: var(--font-symbol);
  font-size: 1.15em;
  line-height: 1;
  vertical-align: -0.06em;
}
.rules-planet-symbol {
  font-size: 1.25em;
}
@media (max-width: 700px) {
  .rules-main {
    width: calc(100% - 16px);
    padding-top: 14px;
  }
  .rules-card-heading {
    padding: 13px 14px;
  }
  .rules-card-body {
    padding: 0 12px 14px;
  }
  .rules-grid {
    grid-template-columns: 1fr;
  }
}

/* Wide-table containment + always-usable horizontal scrolling. */
.rules-card-body,
.rule-block,
.rules-grid > * {
  min-width: 0;
}
.rules-card-body {
  max-width: 100%;
  overflow: hidden;
}
.rules-table-wrap {
  display: block;
  max-width: 100%;
  overflow-x: scroll;
  overflow-y: hidden;
  padding-bottom: 2px;
}
.rules-table-wrap::-webkit-scrollbar {
  height: 12px;
}
.rules-table-wrap::-webkit-scrollbar-track {
  background: var(--rules-panel-2);
  border-top: 1px solid var(--rules-line);
}
.rules-table-wrap::-webkit-scrollbar-thumb {
  background: var(--rules-line-strong);
  border: 2px solid var(--rules-panel-2);
  border-radius: 999px;
}
.rules-table-wrap {
  scrollbar-width: auto;
  scrollbar-color: var(--rules-line-strong) var(--rules-panel-2);
}

/* Reviewer glyph badges mirror the app's visual language. */
.rules-zodiac-symbol {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  width: 22px;
  height: 22px;
  margin-right: 5px;
  border: 1px solid rgba(0, 0, 0, 0.28);
  border-radius: 4px;
  background: #9b36c5;
  color: #fff;
  font:
    400 15px/22px "Segoe UI Symbol",
    "Noto Sans Symbols 2",
    sans-serif;
  vertical-align: middle;
}
.rules-planet-symbol {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  width: 22px;
  height: 22px;
  margin-right: 5px;
  border-radius: 50%;
  color: #111;
  font:
    400 15px/22px "Segoe UI Symbol",
    "Noto Sans Symbols 2",
    sans-serif;
  vertical-align: middle;
}
.rules-planet-symbol[data-planet="Sun"] {
  background: #ffd31a;
}
.rules-planet-symbol[data-planet="Moon"] {
  background: #22b5d4;
}
.rules-planet-symbol[data-planet="Mercury"] {
  background: #f47a55;
}
.rules-planet-symbol[data-planet="Venus"] {
  background: #3db84a;
}
.rules-planet-symbol[data-planet="Mars"] {
  background: #d92f55;
}
.rules-planet-symbol[data-planet="Jupiter"] {
  background: #3f69b1;
}
.rules-planet-symbol[data-planet="Saturn"] {
  background: #73508d;
}

/* Rules audit tables: keep the scroll viewport inside the browser viewport. */
.rules-main,
.rules-content,
.rules-card,
.rules-card-body,
.rule-block {
  min-width: 0;
  max-width: 100%;
}
.rules-card-body {
  width: 100%;
  overflow: hidden;
}
.rules-table-wrap {
  display: block;
  width: 100%;
  max-width: calc(100vw - 80px);
  overflow-x: auto;
  overflow-y: hidden;
  contain: inline-size;
  touch-action: pan-x pan-y;
}
.rules-table {
  width: max-content;
  min-width: 100%;
  max-width: none;
}
@media (max-width: 700px) {
  .rules-table-wrap {
    max-width: calc(100vw - 42px);
  }
}

/* Match the square glyph badges used by the Syncrota Wheel. */
.rules-zodiac-symbol,
.rules-planet-symbol {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  min-width: 24px;
  max-width: 24px;
  height: 24px;
  min-height: 24px;
  max-height: 24px;
  margin-right: 6px;
  padding: 0;
  box-sizing: border-box;
  border: 1px solid rgba(0, 0, 0, 0.38);
  border-radius: 5px;
  color: #000;
  font-family:
    var(--font-symbol), "Segoe UI Symbol", "Noto Sans Symbols 2", sans-serif;
  font-size: 18px;
  font-weight: 500;
  line-height: 1;
  vertical-align: middle;
  text-shadow: none;
}
.rules-zodiac-symbol {
  background: #7c3aed;
  color: #fff;
  text-shadow: none;
}
.rules-zodiac-glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 21px;
  font-weight: 700;
  line-height: 1;
  color: #fff;
}

/* iPhone Rules audit tables: Safari must not inflate wide-table text. */
.rules-main {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
@media (max-width: 700px) {
  .rules-table {
    font-size: 11px;
    line-height: 1.25;
  }
  .rules-table th {
    font-size: 9px;
    line-height: 1.2;
    letter-spacing: 0.035em;
  }
  .rules-table td {
    font-size: 11px;
    line-height: 1.3;
  }
  .rules-table th,
  .rules-table td {
    padding: 7px 8px;
  }
  .rules-zodiac-symbol,
  .rules-planet-symbol {
    width: 22px;
    min-width: 22px;
    max-width: 22px;
    height: 22px;
    min-height: 22px;
    max-height: 22px;
    font-size: 16px;
  }
  .rules-zodiac-glyph {
    font-size: 19px;
  }
}

/* Rules reference alignment: tables use the full available section width. */
.rules-table-wrap {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}
.rule-block > .rules-table-wrap {
  width: calc(100% + 24px);
  max-width: calc(100% + 24px);
  margin-left: -12px;
  margin-right: -12px;
}
.rules-full-block {
  width: 100%;
  box-sizing: border-box;
}
.rules-table-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}
@media (max-width: 700px) {
  .rule-block > .rules-table-wrap {
    width: calc(100% + 24px);
    max-width: calc(100% + 24px);
  }
  .rules-table-note {
    font-size: 10px;
  }
}

/* Stenudd source badge (Santos uses .source-derived, app model uses .syncrota-model). */
.rule-status.src-stenudd {
  color: var(--status-protected);
}
.rules-table small {
  opacity: 0.85;
}
