/* ============ Calculators (topic page) ============ */
/* Inherits tokens from main.css */
/* ===== Calculator page header (UX / UI enhanced) ===== */

.calc-layout .calc-header{
  background:
    radial-gradient(circle at top left, rgba(56,189,248,.18) 0, rgba(56,189,248,0) 55%),
    linear-gradient(135deg, #eff6ff 0%, #e0f2fe 40%, #d0dff9 100%);
  border-bottom: 1px solid #dbeafe;
  padding: 1rem 0 1.1rem;
  margin-bottom: 1.25rem;
}

.calc-layout .calc-header-inner{
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.calc-layout .calc-header-main{
  min-width: 240px;
  flex: 1 1 auto;
}

/* breadcrumb */

.calc-layout .calc-breadcrumb{
  font-size: .95rem;
  color: #64748b; /* slate-500 */
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  margin: 0 0 .25rem;
  font-family: roboto;
}

.calc-layout .calc-breadcrumb .crumb-link{
  color: #466bd3;            /* blue-700 */
  text-decoration: none;
}
.calc-layout .calc-breadcrumb .crumb-link:hover{
  text-decoration: underline;
}

.calc-layout .calc-breadcrumb .crumb-sep{
  color: #94a3b8;            /* slate-400 */
}

.calc-layout .calc-breadcrumb .crumb-current{
  font-weight: 500;
  color: #0f172a;            /* slate-900 */
}

/* title + subtitle */

.calc-layout .calc-title{
  margin: 0;
  font-size: 1.4rem;
  line-height: 1.25;
  color: #0f172a;
}

.calc-layout .calc-subtitle{
  margin: .25rem 0 0;
  font-size: .9rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem .75rem;
  color: #475569;            /* slate-600 */
}

.calc-layout .calc-subject-chapter{
  display: inline-flex;
  align-items: center;
  gap: .35rem;
}

/* Hide the content-byline row on calculator pages */
.content-byline-row.is-calculator {
  display: none !important;
}

/* right side actions */

.calc-layout .calc-header-actions{
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-left: auto;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.calc-layout .calc-header-chapter-link{
  font-size: .85rem;
  padding: .35rem .75rem;
  border-radius: 999px;
}

/* small screens: stack nicely */

@media (max-width: 640px){
  .calc-layout .calc-header-inner{
    align-items: flex-start;
  }
  .calc-layout .calc-header-actions{
    width: 100%;
    justify-content: flex-end;
    margin-top: .5rem;
  }

  .calc-layout .calc-breadcrumb{
    font-size: 0.8rem;
  }
}
/* ===========================
   Calculator header — dark theme overrides
   (manual toggle: html[data-theme="dark"])
   =========================== */

html[data-theme="dark"] .calc-layout .calc-header{
  background:
    radial-gradient(circle at top left, rgba(56,189,248,.25) 0, rgba(15,23,42,0) 55%),
    linear-gradient(135deg, #020617 0%, #020617 40%, #020617 100%); /* deep navy */
  border-bottom-color: #1e293b; /* slate-800 */
}

/* breadcrumb */

html[data-theme="dark"] .calc-layout .calc-breadcrumb{
  color: #94a3b8; /* slate-400 */
}

html[data-theme="dark"] .calc-layout .calc-breadcrumb .crumb-link{
  color: #93c5fd; /* blue-300 */
}

html[data-theme="dark"] .calc-layout .calc-breadcrumb .crumb-link:hover{
  color: #bfdbfe; /* blue-200 */
}

html[data-theme="dark"] .calc-layout .calc-breadcrumb .crumb-sep{
  color: #64748b; /* slate-500 */
}

html[data-theme="dark"] .calc-layout .calc-breadcrumb .crumb-current{
  color: #e5e7eb; /* light text */
}

/* title + subtitle */

html[data-theme="dark"] .calc-layout .calc-title{
  color: #e5e7eb; /* slate-200 */
}

html[data-theme="dark"] .calc-layout .calc-subtitle{
  color: #9ca3af; /* slate-400 */
}

/* subject + chapter inline bits */
html[data-theme="dark"] .calc-layout .calc-subject-chapter{
  color: inherit;
}

/* right-side chapter link can stay neutral but we nudge contrast a bit */
html[data-theme="dark"] .calc-layout .calc-header-chapter-link{
  color: #e5e7eb;
  background-color: rgba(15,23,42,.7);
  border: 1px solid #1e293b;
}


/* Body/grid */
.calc-body {
  padding: 1rem 0 2rem;
}
.calc-grid {
  display: grid;
  grid-template-columns: 1fr; /* stack on mobile */
  gap: 1rem;
}
@media (min-width: 992px) {
  .calc-grid {
    grid-template-columns: 1.15fr 0.85fr;
  } /* calc | theory */
}

/* Full-width layout toggle */
.calc-grid--wide {
  grid-template-columns: 1fr !important;
}

/* Layout toggle button — only visible when two-column layout is active */
.calc-layout-toggle {
  display: none; /* hidden on mobile/single-column widths */
  align-items: center;
  gap: 0.3rem;
  font-size: .8rem;
  padding: .3rem .6rem;
  border-radius: 999px;
  color: var(--bs-muted, #64748b);
  border: 1px solid transparent;
  transition: color .15s, background .15s, border-color .15s;
  white-space: nowrap;
}
@media (min-width: 992px) {
  .calc-layout-toggle {
    display: inline-flex; /* show only when two columns are possible */
  }
}
.calc-layout-toggle:hover,
.calc-layout-toggle:focus-visible {
  color: var(--bs-primary);
  background: color-mix(in oklab, var(--bs-primary) 10%, transparent);
  border-color: color-mix(in oklab, var(--bs-primary) 30%, transparent);
}
.calc-layout-toggle[aria-pressed="true"] {
  color: var(--bs-primary);
  background: color-mix(in oklab, var(--bs-primary) 12%, var(--bs-surface));
  border-color: color-mix(in oklab, var(--bs-primary) 35%, transparent);
}
.calc-layout-toggle svg {
  flex-shrink: 0;
}
@media (max-width: 640px) {
  .calc-layout-toggle-label { display: none; }
}

/* Panels wrap the included EJS files without fighting their own styles */
.panel {
  background: var(--bs-surface);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1rem;
  overflow: hidden;
}
.panel-calc {
  min-height: 280px;
}
.panel-theory {
  min-height: 220px;
}

/* Make generic form controls inside included calculators feel consistent */
.panel input[type="number"],
.panel input[type="text"],
.panel select,
.panel textarea {
  width: 100%;
  border-radius: 0.5rem;
  border: 1px solid var(--bs-border-color);
  background: var(--bs-surface-2);
  color: var(--bs-body-color);
  padding: 0.6rem 0.7rem;
  margin: 0.5rem 0;
  box-sizing: border-box;
}
.panel button {
  font-weight: 700;
  border-radius: 0.5rem;
}


/* If the included calculator already provides its own card styles,
   let them win: */
.panel * {
  /* low specificity reset helpers */
  box-sizing: border-box;
}

/* Ensure MathJax output doesn’t overflow */
.panel .mjx-container {
  overflow-x: auto;
}

/* Spacing helpers for sections inside included content */
.panel h1,
.panel h2,
.panel h3 {
  color: var(--bs-heading);
}
.panel h1 {
  font-size: clamp(1.1rem, 2vw, 1.5rem);
}

/* Rating panel (inside calculator card) */
.calc-rating {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--bs-border-color);
}

.calc-rating-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.calc-rating-title h3 {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
}

.calc-rating-summary {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
  font-weight: 700;
}

.calc-rating-average {
  font-size: 1.25rem;
}

.calc-rating-scale,
.calc-rating-count {
  font-weight: 500;
  color: var(--bs-muted);
}

.calc-rating-empty {
  margin-top: 0.25rem;
  font-size: 0.9rem;
  color: var(--bs-muted);
}

.calc-rating-status {
  min-height: 1.2rem;
  font-size: 0.9rem;
  color: var(--bs-muted);
  margin-top: 0.35rem;
}

.calc-rating-status.is-error {
  color: #dc2626;
}

.calc-rating-status.is-success {
  color: #16a34a;
}

.calc-rating-average-stars {
  margin-top: 0.35rem;
  display: flex;
  gap: 0.25rem;
}

.calc-rating-average-stars .calc-star {
  width: 1.6rem;
  height: 1.6rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #f59e0b;
}

.calc-rating-average-stars .calc-star svg {
  width: 1.1rem;
  height: 1.1rem;
}

.calc-rating-average-stars .calc-star svg path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
}

.calc-rating-average-stars .calc-star.is-on svg path {
  fill: currentColor;
}

.calc-rating-stars-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
}

.calc-rating-user-label {
  font-size: 0.95rem;
  color: var(--bs-muted);
  font-weight: 600;
}

.calc-rating-stars {
  display: flex;
  gap: 0.35rem;
}

.calc-rating-stars .calc-star {
  width: 2.4rem;
  height: 2.4rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid var(--bs-border-color);
  background: var(--bs-surface-2);
  color: #f59e0b;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
}

.calc-rating-stars .calc-star svg {
  width: 1.25rem;
  height: 1.25rem;
}

.calc-rating-stars .calc-star svg path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
}

.calc-rating-stars .calc-star.is-on svg path {
  fill: currentColor;
}

.calc-rating-stars .calc-star:hover {
  transform: translateY(-1px);
  border-color: rgba(245, 158, 11, 0.6);
  box-shadow: 0 4px 10px rgba(245, 158, 11, 0.18);
}

.calc-rating-stars .calc-star:focus-visible {
  outline: 2px solid rgba(59, 130, 246, 0.7);
  outline-offset: 2px;
}

.calc-rating-form {
  margin-top: 0.9rem;
  display: grid;
  gap: 0.45rem;
}

.calc-rating-label {
  font-size: 0.9rem;
  color: var(--bs-muted);
}

.calc-rating-input {
  width: 100%;
  border-radius: 0.5rem;
  border: 1px solid var(--bs-border-color);
  background: var(--bs-surface-2);
  color: var(--bs-body-color);
  padding: 0.55rem 0.7rem;
  box-sizing: border-box;
}

.calc-rating-actions {
  margin-top: 0.35rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
  flex-direction: column;
}

.calc-rating-hint {
  font-size: 0.85rem;
  color: var(--bs-muted);
}

.calc-rating-comments {
  margin-top: 1.1rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--bs-border-color);
}

.calc-rating-comments-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.calc-rating-comments-head h4 {
  margin: 0;
  font-size: 1rem;
}

.calc-rating-comments-meta {
  font-size: 0.85rem;
  color: var(--bs-muted);
}

.calc-rating-comments-list {
  margin-top: 0.75rem;
  display: grid;
  gap: 0.7rem;
}

.calc-review-card {
  border: 1px solid var(--bs-border-color);
  background: var(--bs-surface-2);
  border-radius: 0.75rem;
  padding: 0.75rem 0.85rem;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
}

.calc-review-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.calc-review-name {
  font-weight: 700;
  color: var(--bs-heading);
}

.calc-review-rating {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--bs-muted);
}

.calc-review-score {
  font-weight: 700;
  color: var(--bs-body-color);
  background: rgba(245, 158, 11, 0.14);
  border: 1px solid rgba(245, 158, 11, 0.45);
  padding: 0.08rem 0.45rem;
  border-radius: 999px;
}

.calc-review-stars {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
}

.calc-review-star {
  width: 1rem;
  height: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #f59e0b;
}

.calc-review-star svg {
  width: 0.75rem;
  height: 0.75rem;
}

.calc-review-star svg path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
}

.calc-review-star.is-on svg path {
  fill: currentColor;
}

.calc-review-text {
  margin: 0.5rem 0 0;
  color: var(--bs-body-color);
  line-height: 1.45;
}

.calc-rating-comments-more {
  margin-top: 0.6rem;
}

.calc-rating-comments-more summary {
  cursor: pointer;
  color: var(--bs-primary);
  font-weight: 600;
}

.calc-rating-comments-more summary::marker {
  color: var(--bs-primary);
}

.calc-rating-comments-more[open] summary {
  margin-bottom: 0.6rem;
}

.calc-rating-comments-more .calc-rating-comments-list {
  margin-top: 0;
}

@media (max-width: 640px) {
  .calc-rating-stars-wrap {
    align-items: center;
  }
}

@media (max-width: 480px) {
  .calc-rating-header {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    text-align: left;
  }

  .calc-rating-title {
    flex: 1 1 180px;
    min-width: 0;
  }

  .calc-rating-summary {
    flex-wrap: wrap;
    row-gap: 0.2rem;
  }

  .calc-rating-average-stars {
    flex-wrap: wrap;
  }

  .calc-rating-stars-wrap {
    align-items: flex-start;
  }

  .calc-rating-form {
    margin-top: 0.75rem;
  }

  .calc-rating-average-stars .calc-star,
  .calc-rating-stars .calc-star {
    width: 2rem;
    height: 2rem;
  }

  .calc-review-head {
    align-items: flex-start;
  }
}
.panel h2 {
  font-size: clamp(1rem, 1.6vw, 1.25rem);
}
.panel p.lead {
  color: var(--bs-muted);
}

/* Subtle separation between the two columns on large screens */
@media (min-width: 992px) {
  .panel-calc {
    border-color: color-mix(
      in oklab,
      var(--bs-border-color) 80%,
      var(--bs-primary) 20%
    );
  }
  .panel-theory {
    border-color: color-mix(
      in oklab,
      var(--bs-border-color) 85%,
      var(--bs-primary) 15%
    );
  }
}

.actions {
  align-items: center;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
  margin: 1rem auto;
}

.actions span{
  background-color:transparent;
  padding: 0.2rem 0.4rem;
  border-radius: 0.25rem;
  /* border: solid 2px grey; */
}

.crumb-link{
  text-decoration:none;
  /* color: var(--bs-muted); */
}

/* @media (min-width: 1400px){
  .MathJax svg {
    max-width: 80ex;
  }

  .theory .MathJax svg {
    max-width: 60ex;
  }
}

@media (min-width: 1200px) and (max-width: 1400px){
  .MathJax svg {
    max-width: 75ex;
  }

  .theory .MathJax svg {
    max-width: 50ex;
  }
}

@media (min-width: 992px) and (max-width: 1200px){
  .panel-calc .MathJax svg {
    max-width: 57ex;
  }

  .theory .MathJax svg {
    max-width: 42ex;
  }
}


@media (min-width: 481px) and (max-width: 992px){
  .MathJax svg {
    max-width: 50ex;
  }
}

@media (min-width: 401px) and (max-width: 480px){
  .MathJax svg {
    max-width: 40ex;
  }
}


@media (max-width: 400px){
  .MathJax svg {
    max-width: 35ex;
    
  }
} */

.calculator-image{
  width: 100%;
  margin: 0;
}

.MathJax {
  max-width: 100%;
  overflow-x: auto;   /* let long formulas scroll instead of overflowing */
  overflow-y: hidden;
}

/* ===================== Tables (token-aware + dark mode) ===================== */
/* Wrap tables on small screens without breaking layout */
.table-wrap{
  overflow-x:auto; /* UPDATED: auto instead of scroll */
  -webkit-overflow-scrolling: touch;
  margin: 0 auto 1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--bs-border-color);
  background: var(--bs-surface);
}

/* Base table */
table.table{
  width: 100%;
  border-collapse: collapse;
  background: var(--bs-surface);
  color: var(--bs-body-color);
  table-layout: fixed; /* NEW: enables wrapping within fixed cell widths */
}

/* Cells */
.table th,
.table td{
  padding: .25rem .35rem;
  text-align: center;
  border-bottom: 1px solid var(--bs-border-color);

  /* --- RESPONSIVE WRAPPING FIX --- */
  white-space: normal;          /* UPDATED: allow wrapping (was invalid 'wrap') */
  overflow-wrap: anywhere;      /* prefer breaking long tokens anywhere */
  word-break: normal;           /* keep words intact where possible */
  hyphens: auto;                /* allow soft hyphenation for long words */
  line-height: 1.3;             /* a bit tighter to save space on small screens */
  vertical-align: middle;          /* better multi-line readability */
}

/* Header (brand gradient + accessible text) */
.table thead th{
  background: linear-gradient(
    135deg,
    var(--brand-start),
    var(--brand-mid) 60%,
    var(--brand-end) 100%
  );
  color: var(--text-on-hero);
  /* text-transform: uppercase; */
  border-bottom-color: color-mix(in oklab, var(--text-on-hero) 20%, transparent);
}

/* Row hover (subtle, theme-aware) */
.table tbody tr:hover{
  background: color-mix(in oklab, var(--bs-primary) 12%, var(--bs-surface));
}

/* Caption */
.table caption{
  caption-side: top;
  font-size: 1rem;
  font-weight: 700;
  color: var(--bs-heading);
  margin: .25rem 0 .15rem;
  text-align: center;
  
}

/* Numeric alignment helper */
.table .num{ text-align: right; }

/* Compact density option */
.table--compact th,
.table--compact td{ padding: .35rem .55rem; }

/* Striped rows option */
.table--striped tbody tr:nth-child(even){
  background: color-mix(in oklab, var(--bs-surface) 90%, var(--bs-primary) 10%);
}

/* ===================== Responsive type & spacing ===================== */
@media (max-width: 768px){
  .table{ font-size: .95rem; }                 /* slightly smaller text */
  .table th, .table td{ padding: .3rem .4rem; }
  .table caption{ font-size: .95rem; }
}
@media (max-width: 560px){
  .table{ font-size: .8rem; }                /* smaller again for phones */
  .table th, .table td{ padding: .28rem .36rem; }
  .table caption{ font-size: .9rem; }
}
@media (max-width: 400px){
  .table{ font-size: .7rem; }                 /* very small devices */
  .table th, .table td{ padding: .24rem .32rem; }
}

/* ===================== Dark mode polish ===================== */
@media (prefers-color-scheme: dark){
  .table-wrap{ box-shadow: 0 8px 20px rgba(0,0,0,.35); }
  .table tbody tr:hover{
    background: color-mix(in oklab, var(--bs-primary) 18%, var(--bs-surface));
  }
  .table thead th{
    background: linear-gradient(
      135deg,
      color-mix(in oklab, var(--brand-start) 85%, #000),
      color-mix(in oklab, var(--brand-mid)   85%, #000) 60%,
      color-mix(in oklab, var(--brand-end)   85%, #000) 100%
    );
    text-shadow: 0 1px 0 rgba(0,0,0,.35);
  }
}
html[data-theme="dark"] .table-wrap{ box-shadow: 0 8px 20px rgba(0,0,0,.45); }
html[data-theme="dark"] .table tbody tr:hover{
  background: color-mix(in oklab, var(--bs-primary) 20%, var(--bs-surface));
}
html[data-theme="dark"] .table thead th{
  background: linear-gradient(
    135deg,
    color-mix(in oklab, var(--brand-start) 85%, #000),
    color-mix(in oklab, var(--brand-mid)   85%, #000) 60%,
    color-mix(in oklab, var(--brand-end)   85%, #000) 100%
  );
  text-shadow: 0 1px 0 rgba(0,0,0,.4);
}

/* Optional: rounded header corners when using .table-wrap */
.table thead th:first-child{ border-top-left-radius: calc(var(--radius) - 1px); }
.table thead th:last-child{  border-top-right-radius: calc(var(--radius) - 1px); }

  /* --- Scoped styles for the left drawer (kept minimal) --- */
  .chapter-drawer {
    position: fixed; inset: 0 auto 0 0;
    width: min(88vw, 320px);
    background: var(--bs-surface);
    border-right: 1px solid var(--bs-border-color);
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 1050; /* above page content, below header if any sticky layers */
    display: flex; flex-direction: column;
  }
  .chapter-drawer.open { transform: translateX(0); }
  .chapter-drawer header {
    padding: .75rem 1rem; border-bottom: 1px solid var(--bs-border-color);
    display: flex; align-items: center; gap: .5rem; justify-content: space-between;
  }
  .chapter-drawer .topics-scroll { overflow:auto; padding: .5rem 0; }
  .chapter-drawer .list-of-topics { list-style: none; margin: 0; padding: .25rem .5rem .75rem; }
  .chapter-drawer .list-of-topics li a {
    display:block; padding:.5rem .75rem; border-radius:.5rem; text-decoration:none;
    color: var(--bs-body-color);
  }
  .chapter-drawer .list-of-topics li a:hover { background: var(--bs-surface-2); }
  .chapter-drawer .list-of-topics li.active a {
    background: var(--bs-surface-2); font-weight: 600; border-left: 3px solid var(--bs-primary);
  }
  .chapter-drawer-mask {
    position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 1040;
  }
  .chapter-drawer-mask[hidden] { display: none; }

  /* Floating Action Button (always visible) */
  .topics-fab {
    position: fixed; right: 1rem; bottom: 1rem;
    z-index: 1060;
    display:flex; align-items:center; justify-content:center;
    height: 3.25rem; width: 3.25rem; border-radius: 50%;
    background: var(--bs-primary); color: #fff; border: none;
    box-shadow: 0 6px 18px rgba(0,0,0,.18);
    cursor: pointer; font-weight: 600;
  }
  .topics-fab:focus-visible { outline: 3px solid var(--bs-primary-400); outline-offset: 3px; }
  .topics-fab .icon { font-size: 1.25rem; line-height: 1; }

  /* Left edge tab (mid-screen) – SVG arrowhead only */
  .topics-tab {
    position: fixed; left: 0; top: 50%; transform: translateY(-50%);
    z-index: 1055;
    background: var(--bs-surface);
    border: 1px solid var(--bs-border-color);
    border-left: none;
    border-radius: 0 .75rem .75rem 0;
    padding: .5rem .5rem;
    width: 2.25rem; height: 5rem;
    box-shadow: 0 6px 18px rgba(0,0,0,.08);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: var(--bs-body-color);
  }
  .topics-tab svg,
  .topics-tab svg path{
    fill: currentColor;
    stroke: currentColor;
    stroke-width: 0;
  }
  .topics-tab:hover { background: var(--bs-surface-2); }
  .topics-tab:focus-visible { outline: 3px solid var(--bs-primary-400); outline-offset: 3px; }
  .topics-tab.hidden { display: none; } /* vanish when drawer is open */

  /* Accessible helper */
  .sr-only {
    position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);border:0;
  }

  @media (prefers-reduced-motion: reduce) {
    .chapter-drawer { transition: none; }
  }

  @media (max-width: 480px){
    .topics-tab{
      padding: 0;
      width: 1rem;
    }

  }

  @media (max-width: 675px){
    .topics-fab{
      display: none;
    }
  }

  /* Dark mode: keep the arrowhead visible */
  @media (prefers-color-scheme: dark){
    .topics-tab{
      color: var(--bs-heading);
    }
    .topics-tab svg,
    .topics-tab svg path{
      fill: currentColor;
      stroke: currentColor;
    }
  }

  html[data-theme="dark"] .topics-tab{
    color: var(--bs-heading);
  }
  html[data-theme="dark"] .topics-tab svg,
  html[data-theme="dark"] .topics-tab svg path{
    fill: currentColor;
    stroke: currentColor;
  }


  /* Light mode (default) */
  .theory .boxed-eq{
    text-align:center;
    background:#eef7ff;                 /* soft light panel */
    border:1px solid #d7e9ff;
    border-radius:.5rem;
    padding:.6rem .8rem;
    margin:.6rem 0;
  }

  /* Prefer dark color scheme */
  @media (prefers-color-scheme: dark){
    .theory .boxed-eq{
      background:rgba(255,255,255,.08); /* dark glass panel for white MathJax */
      border-color:rgba(255,255,255,.18);
      box-shadow: 0 0 0 1px rgba(255,255,255,.06) inset;
    }
  }

  /* Also support class/attribute based dark themes some sites use */
  .dark .theory .boxed-eq,
  [data-theme="dark"] .theory .boxed-eq{
    background:rgba(255,255,255,.08);
    border-color:rgba(255,255,255,.18);
    box-shadow: 0 0 0 1px rgba(255,255,255,.06) inset;
  }

  /* Keep MathJax readable inside the box in both modes */
  .theory .boxed-eq mjx-container{
    color:inherit;                /* use the surrounding text color (often white in dark mode) */
  }

  /* ===== Print button inside the calculator panel ===== */

.panel-calc {
  position: relative; /* anchor for absolute button */
}

.calc-print-btn {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem 0.4rem;
  border-radius: 999px;
  cursor: pointer;
  z-index: 1;
}

.calc-print-btn svg,
.calc-print-btn svg path {
  width: 1.1rem;
  height: 1.1rem;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 0;
}

@media (hover:hover) {
  .calc-print-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
  }
}

@media (prefers-color-scheme: dark) {
  .calc-print-btn {
    color: var(--bs-heading); /* light ink for icon in dark mode */
  }

  .calc-print-btn:hover {
    background-color: rgba(255, 255, 255, 0.08);
  }

  .calc-print-btn svg,
  .calc-print-btn svg path {
    fill: currentColor;
    stroke: currentColor;
  }
}

html[data-theme="dark"] .calc-print-btn {
  color: var(--bs-heading); /* manual toggle */
}

html[data-theme="dark"] .calc-print-btn:hover {
  background-color: rgba(255, 255, 255, 0.08);
}

html[data-theme="dark"] .calc-print-btn svg,
html[data-theme="dark"] .calc-print-btn svg path {
  fill: currentColor;
  stroke: currentColor;
}

/* ===== PRINT: ONLY article.panel-calc and its children ===== */

@page {
  size: A3 portrait;
  margin: 1.5cm;
}

@media print {
  /* Reset body for clean print page */
  body.print-calc-only {
    margin: 0;
    padding: 25px 50px;
  }

  /* 1) Hide all direct children of body (header, footer, etc.) */
  body.print-calc-only > * {
    display: none !important;
  }

  form .actions {
    display: none !important;
  }

  .calc-related-footer{
    display: none !important;
  }

  /* 2) Show the main.calc-layout again */
  body.print-calc-only > main.calc-layout {
    display: block !important;
  }

  /* 3) Inside calc-layout, keep only .calc-body (no outer header/footer) */
  body.print-calc-only main.calc-layout > *:not(.calc-body) {
    display: none !important;
  }

  /* 4) Let the calculator grid collapse to a single column */
  body.print-calc-only .calc-body .container {
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  body.print-calc-only .calc-body .calc-grid {
    display: block !important;
  }

  /* 5) Show ONLY the calculator article, hide its siblings (theory panel, etc.) */
  body.print-calc-only .calc-body .calc-grid > article.panel-calc {
    display: block !important;
    margin: 0 !important;
    box-shadow: none !important;
    border-radius: 0 !important;
  }

  body.print-calc-only .calc-body .calc-grid > *:not(.panel-calc) {
    display: none !important;
  }

  /* 6) Do not print the print button itself */
  body.print-calc-only .calc-print-btn {
    display: none !important;
  }

  /* 7) Scripts never need to be printed */
  body.print-calc-only script {
    display: none !important;
  }
}

/* FOOTER OF RELATED TOPICS-CALCULATORS */
.calc-related-footer{
  margin-top: 1.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--bs-border-color);

  /* behave like a .container */
  width: 90%;
  padding-right: var(--bs-gutter-x, 0.75rem);
  padding-left:  var(--bs-gutter-x, 0.75rem);
  margin-right: auto;
  margin-left:  auto;
}

/* FOOTER OF RELATED QUESTIONS (topic page) */
.calc-related-questions{
  margin-top: 1rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--bs-border-color);

  /* behave like a .container */
  width: 90%;
  padding-right: var(--bs-gutter-x, 0.75rem);
  padding-left:  var(--bs-gutter-x, 0.75rem);
  margin-right: auto;
  margin-left:  auto;
}

/* Avoid double horizontal padding in trending widget on calculator pages */
.calc-related-questions .qtrend-widget > .container{
  padding-left: 0;
  padding-right: 0;
}

/* Avoid double horizontal padding in recent widget on calculator pages */
.calc-related-questions .qrecent-widget > .container{
  padding-left: 0;
  padding-right: 0;
}

.qtrend-widget {
    padding: 1rem 0 !important;
}

/* same max-width breakpoints as .container */
@media (min-width: 576px){
  .calc-related-footer{ max-width: 540px; }
  .calc-related-questions{ max-width: 540px; }
}
@media (min-width: 768px){
  .calc-related-footer{ max-width: 720px; }
  .calc-related-questions{ max-width: 720px; }
}
@media (min-width: 992px){
  .calc-related-footer{ max-width: 960px; }
  .calc-related-questions{ max-width: 960px; }
}
@media (min-width: 1200px){
  .calc-related-footer{ max-width: 1140px; }
  .calc-related-questions{ max-width: 1140px; }
}
@media (min-width: 1400px){
  .calc-related-footer{ max-width: 1320px; }
  .calc-related-questions{ max-width: 1320px; }
}

.calc-related-heading{
  text-align: center;
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0 0 1rem;
  color: var(--bs-heading);
}

.calc-related-questions .calc-related-heading{
  margin-bottom: 0;
}

/* list/grid */
.calc-related-list{
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 1fr;          /* 1 column on very small screens */
}

/* 2 columns from small screens up */
@media (min-width: 576px){
  .calc-related-list{
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* match calc/theory ratio on desktop: 1.15fr / 0.85fr */
@media (min-width: 992px){
  .calc-related-list{
    grid-template-columns: 1fr 1fr;
  }
}

.calc-related-item{
  align-self: stretch;
}

/* card */
.calc-related-link{
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 0.2rem;
  height: 100%;

  padding: 0.7rem 0.9rem;
  border-radius: 0.75rem;
  border: 1px solid var(--bs-border-color);
  background: var(--bs-surface);

  text-decoration: none;
  color: var(--bs-body-color);

  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    transform 0.15s ease,
    background-color 0.15s ease;
}

.calc-related-link:hover,
.calc-related-link:focus-visible{
  border-color: color-mix(in oklab, var(--bs-primary) 60%, var(--bs-border-color) 40%);
  background: color-mix(in oklab, var(--bs-primary) 6%, var(--bs-surface));
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.16);
  transform: translateY(-1px);
  outline: none;
}

.calc-related-topic{
  display: block;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--bs-heading);
}

.calc-related-meta{
  display: block;
  font-size: 0.82rem;
  color: var(--bs-muted);
  margin-top: 0.1rem;
}

/* dark-mode tweaks */
@media (prefers-color-scheme: dark){
  .calc-related-link{
    border-color: color-mix(in oklab, var(--bs-border-color) 80%, #000 20%);
    background: color-mix(in oklab, var(--bs-surface) 90%, #000 10%);
    box-shadow: 0 6px 16px rgba(0,0,0,0.45);
  }

.calc-related-link:hover,
.calc-related-link:focus-visible{
  background: color-mix(in oklab, var(--bs-primary) 16%, var(--bs-surface) 84%);
  border-color: color-mix(in oklab, var(--bs-primary) 70%, var(--bs-border-color) 30%);
}

/* ===========================
   Calculator feedback button + modal
   =========================== */
.calc-feedback-trigger{
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
}
.calc-feedback-icon{
  width: 1em;
  height: 1em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(59,130,246,.12);
  color: #1d4ed8;
  font-weight: 700;
  font-size: 1em;
  line-height: 1;
}
.calc-feedback-label{
  font-weight: 600;
}

}

html[data-theme="dark"] .calc-related-link{
  border-color: color-mix(in oklab, var(--bs-border-color) 80%, #000 20%);
  background: color-mix(in oklab, var(--bs-surface) 90%, #000 10%);
  box-shadow: 0 6px 16px rgba(0,0,0,0.45);
}

html[data-theme="dark"] .calc-related-link:hover,
html[data-theme="dark"] .calc-related-link:focus-visible{
  background: color-mix(in oklab, var(--bs-primary) 16%, var(--bs-surface) 84%);
  border-color: color-mix(in oklab, var(--bs-primary) 70%, var(--bs-border-color) 30%);
}

/* ---------- Dark-mode readability for solubility/complex-ion calculators ---------- */
@media (prefers-color-scheme: dark){
  /* General text + muted helpers */
  .calc-local .muted,
  .calc-local .tiny,
  .calc-local small{
    color: var(--bs-muted);
  }
  .calc-local label,
  .calc-local legend,
  .calc-local .card-title,
  .calc-local .opt-name,
  .calc-local .step-title,
  .calc-local .result-value,
  .calc-local .seg-item span{
    color: var(--bs-heading);
  }
  .calc-local .step-head{
    background: color-mix(in oklab, var(--bs-surface) 96%, var(--bs-primary) 4%);
    border-color: var(--bs-border-color);
  }
  /* Decision chips/alerts */
  .calc-local .dec-green,
  .calc-local .dec-red,
  .calc-local .dec-yellow,
  .calc-local .mode-btn{
    color: var(--bs-heading);
    border-color: color-mix(in oklab, var(--bs-border-color) 70%, var(--bs-primary) 30%);
  }
  .calc-local .mode-btn.active{
    color: var(--bs-heading);
    border-color: color-mix(in oklab, var(--bs-primary) 70%, var(--bs-border-color) 30%);
  }
}

html[data-theme="dark"] .calc-local .muted,
html[data-theme="dark"] .calc-local .tiny,
html[data-theme="dark"] .calc-local small{
  color: var(--bs-muted);
}
html[data-theme="dark"] .calc-local label,
html[data-theme="dark"] .calc-local legend,
html[data-theme="dark"] .calc-local .card-title,
html[data-theme="dark"] .calc-local .opt-name,
html[data-theme="dark"] .calc-local .step-title,
html[data-theme="dark"] .calc-local .result-value,
html[data-theme="dark"] .calc-local .seg-item span{
  color: var(--bs-heading);
}
html[data-theme="dark"] .calc-local .step-head{
  background: color-mix(in oklab, var(--bs-surface) 96%, var(--bs-primary) 4%);
  border-color: var(--bs-border-color);
}
html[data-theme="dark"] .calc-local .dec-green,
html[data-theme="dark"] .calc-local .dec-red,
html[data-theme="dark"] .calc-local .dec-yellow,
html[data-theme="dark"] .calc-local .mode-btn{
  color: var(--bs-heading);
  border-color: color-mix(in oklab, var(--bs-border-color) 70%, var(--bs-primary) 30%);
}
html[data-theme="dark"] .calc-local .mode-btn.active{
  color: var(--bs-heading);
  border-color: color-mix(in oklab, var(--bs-primary) 70%, var(--bs-border-color) 30%);
}


/* ---------- Dark-mode contrast for tools & utilities cards/tables ---------- */
:root{
  --calc-card-dark: color-mix(in oklab, var(--bs-surface) 92%, #0b1220 8%);
  --calc-card-strong-dark: color-mix(in oklab, var(--bs-surface) 88%, #0b1220 12%);
  --calc-chip-dark: color-mix(in oklab, var(--bs-surface-2) 88%, #0b1220 12%);
  --calc-shadow-strong-dark: 0 10px 24px rgba(0,0,0,.48);
  --calc-shadow-soft-dark: 0 6px 16px rgba(0,0,0,.38);
}

@media (prefers-color-scheme: dark){
  /* Cards */
  .calc-local .team-card,
  .calc-local .group-card,
  .calc-local .pair-card,
  .calc-local .extra-card,
  .calc-local .age-card,
  .calc-local .time-card,
  .calc-local .birthday-card,
  .calc-local .event-card,
  .calc-local .dow-card,
  .calc-local .life-card,
  .calc-local .agegap-card,
  .calc-local .day-card,
  .calc-local .planet-card{
    background: var(--calc-card-dark);
    border-color: var(--bs-border-color);
    box-shadow: var(--calc-shadow-strong-dark);
    color: var(--bs-heading);
  }

  .calc-local .pair-card--highlight{
    background: color-mix(in oklab, var(--bs-primary) 20%, var(--bs-surface) 80%);
    box-shadow: var(--calc-shadow-strong-dark);
  }

  .calc-local .extra-card{
    background: color-mix(in oklab, #f59e0b 18%, var(--bs-surface) 82%);
    border-color: var(--bs-border-color);
  }

  .calc-local .dow-card--weekend{
    background: color-mix(in oklab, #fb7185 18%, var(--bs-surface) 82%);
  }

  .calc-local .life-card--over{
    background: color-mix(in oklab, #22c55e 18%, var(--bs-surface) 82%);
  }

  .calc-local .agegap-card--A-older{
    background: color-mix(in oklab, #38bdf8 18%, var(--bs-surface) 82%);
  }

  .calc-local .agegap-card--B-older{
    background: color-mix(in oklab, #f59e0b 18%, var(--bs-surface) 82%);
  }

  .calc-local .agegap-card--same{
    background: color-mix(in oklab, #22c55e 18%, var(--bs-surface) 82%);
  }

  .calc-local .day-card--balanced{
    background: color-mix(in oklab, #22c55e 18%, var(--bs-surface) 82%);
  }

  .calc-local .day-card--overbooked{
    background: color-mix(in oklab, #f97316 18%, var(--bs-surface) 82%);
  }

  .calc-local .planet-card--tiny-age{
    background: color-mix(in oklab, #a855f7 18%, var(--bs-surface) 82%);
  }

  /* Chips, metrics, and badges */
  .calc-local .rand-chip{
    background: color-mix(in oklab, var(--bs-primary) 32%, var(--bs-surface) 68%);
    border-color: var(--bs-border-color);
    color: var(--bs-heading);
  }

  .calc-local .time-metric,
  .calc-local .birthday-metric,
  .calc-local .agegap-metric,
  .calc-local .life-metric,
  .calc-local .day-metric,
  .calc-local .event-metric{
    background: var(--calc-chip-dark);
    border: 1px solid var(--bs-border-color);
    color: var(--bs-heading);
  }

  .calc-local .agegap-person-chip{
    background: var(--calc-chip-dark);
    border-color: var(--bs-border-color);
    color: var(--bs-heading);
    box-shadow: var(--calc-shadow-soft-dark);
  }

  .calc-local .dow-chip{
    background: var(--calc-chip-dark);
    color: var(--bs-heading);
  }

  .calc-local .dow-chip--active{
    box-shadow: var(--calc-shadow-soft-dark);
  }

  .calc-local .dow-chip--weekend{
    background: color-mix(in oklab, #fb923c 20%, var(--bs-surface) 80%);
  }

  /* Muted text helpers inside cards */
  .calc-local .team-size,
  .calc-local .group-size,
  .calc-local .pair-size,
  .calc-local .extra-note,
  .calc-local .rand-label,
  .calc-local .rand-meta,
  .calc-local .age-dates,
  .calc-local .life-bar-label,
  .calc-local .life-bar-pct,
  .calc-local .time-dates,
  .calc-local .time-metric-label,
  .calc-local .time-note,
  .calc-local .birthday-dates,
  .calc-local .birthday-year-label,
  .calc-local .birthday-year-pct,
  .calc-local .birthday-metric-label,
  .calc-local .dow-date-line,
  .calc-local .dow-meta,
  .calc-local .event-dates,
  .calc-local .event-secondary,
  .calc-local .event-note,
  .calc-local .agegap-dates,
  .calc-local .agegap-person-role,
  .calc-local .agegap-metric-label,
  .calc-local .agegap-note,
  .calc-local .life-age-line,
  .calc-local .life-bar-labels,
  .calc-local .life-metric-label,
  .calc-local .life-note,
  .calc-local .life-grid-heading,
  .calc-local .day-secondary,
  .calc-local .day-note,
  .calc-local .day-strip-labels,
  .calc-local .day-summary-line,
  .calc-local .planet-note,
  .calc-local .planet-secondary,
  .calc-local .sim-summary{
    color: var(--bs-muted);
  }

  /* Bars, tracks, and grids */
  .calc-local .life-bar-track,
  .calc-local .birthday-year-track,
  .calc-local .day-strip-track{
    background: color-mix(in oklab, var(--bs-surface-2) 82%, #000 18%);
  }

  .calc-local .life-weeks-grid{
    background: color-mix(in oklab, var(--bs-surface-2) 86%, #000 14%);
  }

  .calc-local .life-week-cell{
    background: color-mix(in oklab, var(--bs-surface) 88%, #000 12%);
  }

  .calc-local .life-week-cell--past{
    background: color-mix(in oklab, var(--bs-primary) 78%, #000 22%);
  }

  .calc-local .life-week-cell--current{
    background: color-mix(in oklab, #facc15 82%, #000 18%);
  }

  .calc-local .life-week-cell--future{
    background: color-mix(in oklab, var(--bs-surface) 92%, #000 8%);
  }

  .calc-local .life-legend-swatch{
    background: color-mix(in oklab, var(--bs-surface-2) 86%, #000 14%);
  }

  .calc-local .life-legend-swatch--past{
    background: color-mix(in oklab, var(--bs-primary) 78%, #000 22%);
  }

  .calc-local .life-legend-swatch--current{
    background: color-mix(in oklab, #facc15 80%, #000 20%);
  }

  .calc-local .life-legend-swatch--future{
    background: color-mix(in oklab, var(--bs-surface) 92%, #000 8%);
  }

  /* Tables inside simulators/planet age */
  .calc-local .sim-table,
  .calc-local .planet-table{
    background: var(--bs-surface);
    color: var(--bs-heading);
    border-color: var(--bs-border-color);
  }

  .calc-local .sim-table th,
  .calc-local .planet-table th{
    background: linear-gradient(
      135deg,
      color-mix(in oklab, var(--brand-start) 80%, #000),
      color-mix(in oklab, var(--brand-mid) 85%, #000) 60%,
      color-mix(in oklab, var(--brand-end) 80%, #000) 100%
    );
    color: var(--text-on-hero);
    border-color: var(--bs-border-color);
    text-shadow: 0 1px 0 rgba(0,0,0,.45);
  }

  .calc-local .sim-table td,
  .calc-local .planet-table td{
    border-color: var(--bs-border-color);
  }

  .calc-local .sim-table tbody tr:nth-child(even),
  .calc-local .planet-table tbody tr:nth-child(even){
    background: color-mix(in oklab, var(--bs-primary) 12%, var(--bs-surface) 88%);
  }
}

html[data-theme="dark"] .calc-local .team-card,
html[data-theme="dark"] .calc-local .group-card,
html[data-theme="dark"] .calc-local .pair-card,
html[data-theme="dark"] .calc-local .extra-card,
html[data-theme="dark"] .calc-local .age-card,
html[data-theme="dark"] .calc-local .time-card,
html[data-theme="dark"] .calc-local .birthday-card,
html[data-theme="dark"] .calc-local .event-card,
html[data-theme="dark"] .calc-local .dow-card,
html[data-theme="dark"] .calc-local .life-card,
html[data-theme="dark"] .calc-local .agegap-card,
html[data-theme="dark"] .calc-local .day-card,
html[data-theme="dark"] .calc-local .planet-card{
  background: var(--calc-card-dark);
  border-color: var(--bs-border-color);
  box-shadow: var(--calc-shadow-strong-dark);
  color: var(--bs-heading);
}

html[data-theme="dark"] .calc-local .pair-card--highlight{
  background: color-mix(in oklab, var(--bs-primary) 20%, var(--bs-surface) 80%);
  box-shadow: var(--calc-shadow-strong-dark);
}

html[data-theme="dark"] .calc-local .extra-card{
  background: color-mix(in oklab, #f59e0b 18%, var(--bs-surface) 82%);
  border-color: var(--bs-border-color);
}

html[data-theme="dark"] .calc-local .dow-card--weekend{
  background: color-mix(in oklab, #fb7185 18%, var(--bs-surface) 82%);
}

html[data-theme="dark"] .calc-local .life-card--over{
  background: color-mix(in oklab, #22c55e 18%, var(--bs-surface) 82%);
}

html[data-theme="dark"] .calc-local .agegap-card--A-older{
  background: color-mix(in oklab, #38bdf8 18%, var(--bs-surface) 82%);
}

html[data-theme="dark"] .calc-local .agegap-card--B-older{
  background: color-mix(in oklab, #f59e0b 18%, var(--bs-surface) 82%);
}

html[data-theme="dark"] .calc-local .agegap-card--same{
  background: color-mix(in oklab, #22c55e 18%, var(--bs-surface) 82%);
}

html[data-theme="dark"] .calc-local .day-card--balanced{
  background: color-mix(in oklab, #22c55e 18%, var(--bs-surface) 82%);
}

html[data-theme="dark"] .calc-local .day-card--overbooked{
  background: color-mix(in oklab, #f97316 18%, var(--bs-surface) 82%);
}

html[data-theme="dark"] .calc-local .planet-card--tiny-age{
  background: color-mix(in oklab, #a855f7 18%, var(--bs-surface) 82%);
}

html[data-theme="dark"] .calc-local .rand-chip{
  background: color-mix(in oklab, var(--bs-primary) 32%, var(--bs-surface) 68%);
  border-color: var(--bs-border-color);
  color: var(--bs-heading);
}

html[data-theme="dark"] .calc-local .time-metric,
html[data-theme="dark"] .calc-local .birthday-metric,
html[data-theme="dark"] .calc-local .agegap-metric,
html[data-theme="dark"] .calc-local .life-metric,
html[data-theme="dark"] .calc-local .day-metric,
html[data-theme="dark"] .calc-local .event-metric{
  background: var(--calc-chip-dark);
  border: 1px solid var(--bs-border-color);
  color: var(--bs-heading);
}

html[data-theme="dark"] .calc-local .agegap-person-chip{
  background: var(--calc-chip-dark);
  border-color: var(--bs-border-color);
  color: var(--bs-heading);
  box-shadow: var(--calc-shadow-soft-dark);
}

html[data-theme="dark"] .calc-local .dow-chip{
  background: var(--calc-chip-dark);
  color: var(--bs-heading);
}

html[data-theme="dark"] .calc-local .dow-chip--active{
  box-shadow: var(--calc-shadow-soft-dark);
}

html[data-theme="dark"] .calc-local .dow-chip--weekend{
  background: color-mix(in oklab, #fb923c 20%, var(--bs-surface) 80%);
}

html[data-theme="dark"] .calc-local .team-size,
html[data-theme="dark"] .calc-local .group-size,
html[data-theme="dark"] .calc-local .pair-size,
html[data-theme="dark"] .calc-local .extra-note,
html[data-theme="dark"] .calc-local .rand-label,
html[data-theme="dark"] .calc-local .rand-meta,
html[data-theme="dark"] .calc-local .age-dates,
html[data-theme="dark"] .calc-local .life-bar-label,
html[data-theme="dark"] .calc-local .life-bar-pct,
html[data-theme="dark"] .calc-local .time-dates,
html[data-theme="dark"] .calc-local .time-metric-label,
html[data-theme="dark"] .calc-local .time-note,
html[data-theme="dark"] .calc-local .birthday-dates,
html[data-theme="dark"] .calc-local .birthday-year-label,
html[data-theme="dark"] .calc-local .birthday-year-pct,
html[data-theme="dark"] .calc-local .birthday-metric-label,
html[data-theme="dark"] .calc-local .dow-date-line,
html[data-theme="dark"] .calc-local .dow-meta,
html[data-theme="dark"] .calc-local .event-dates,
html[data-theme="dark"] .calc-local .event-secondary,
html[data-theme="dark"] .calc-local .event-note,
html[data-theme="dark"] .calc-local .agegap-dates,
html[data-theme="dark"] .calc-local .agegap-person-role,
html[data-theme="dark"] .calc-local .agegap-metric-label,
html[data-theme="dark"] .calc-local .agegap-note,
html[data-theme="dark"] .calc-local .life-age-line,
html[data-theme="dark"] .calc-local .life-bar-labels,
html[data-theme="dark"] .calc-local .life-metric-label,
html[data-theme="dark"] .calc-local .life-note,
html[data-theme="dark"] .calc-local .life-grid-heading,
html[data-theme="dark"] .calc-local .day-secondary,
html[data-theme="dark"] .calc-local .day-note,
html[data-theme="dark"] .calc-local .day-strip-labels,
html[data-theme="dark"] .calc-local .day-summary-line,
html[data-theme="dark"] .calc-local .planet-note,
html[data-theme="dark"] .calc-local .planet-secondary,
html[data-theme="dark"] .calc-local .sim-summary{
  color: var(--bs-muted);
}

html[data-theme="dark"] .calc-local .life-bar-track,
html[data-theme="dark"] .calc-local .birthday-year-track,
html[data-theme="dark"] .calc-local .day-strip-track{
  background: color-mix(in oklab, var(--bs-surface-2) 82%, #000 18%);
}

html[data-theme="dark"] .calc-local .life-weeks-grid{
  background: color-mix(in oklab, var(--bs-surface-2) 86%, #000 14%);
}

html[data-theme="dark"] .calc-local .life-week-cell{
  background: color-mix(in oklab, var(--bs-surface) 88%, #000 12%);
}

html[data-theme="dark"] .calc-local .life-week-cell--past{
  background: color-mix(in oklab, var(--bs-primary) 78%, #000 22%);
}

html[data-theme="dark"] .calc-local .life-week-cell--current{
  background: color-mix(in oklab, #facc15 82%, #000 18%);
}

html[data-theme="dark"] .calc-local .life-week-cell--future{
  background: color-mix(in oklab, var(--bs-surface) 92%, #000 8%);
}

html[data-theme="dark"] .calc-local .life-legend-swatch{
  background: color-mix(in oklab, var(--bs-surface-2) 86%, #000 14%);
}

html[data-theme="dark"] .calc-local .life-legend-swatch--past{
  background: color-mix(in oklab, var(--bs-primary) 78%, #000 22%);
}

html[data-theme="dark"] .calc-local .life-legend-swatch--current{
  background: color-mix(in oklab, #facc15 80%, #000 20%);
}

html[data-theme="dark"] .calc-local .life-legend-swatch--future{
  background: color-mix(in oklab, var(--bs-surface) 92%, #000 8%);
}

html[data-theme="dark"] .calc-local .sim-table,
html[data-theme="dark"] .calc-local .planet-table{
  background: var(--bs-surface);
  color: var(--bs-heading);
  border-color: var(--bs-border-color);
}

html[data-theme="dark"] .calc-local .sim-table th,
html[data-theme="dark"] .calc-local .planet-table th{
  background: linear-gradient(
    135deg,
    color-mix(in oklab, var(--brand-start) 80%, #000),
    color-mix(in oklab, var(--brand-mid) 85%, #000) 60%,
    color-mix(in oklab, var(--brand-end) 80%, #000) 100%
  );
  color: var(--text-on-hero);
  border-color: var(--bs-border-color);
  text-shadow: 0 1px 0 rgba(0,0,0,.45);
}

html[data-theme="dark"] .calc-local .sim-table td,
html[data-theme="dark"] .calc-local .planet-table td{
  border-color: var(--bs-border-color);
}

html[data-theme="dark"] .calc-local .sim-table tbody tr:nth-child(even),
html[data-theme="dark"] .calc-local .planet-table tbody tr:nth-child(even){
  background: color-mix(in oklab, var(--bs-primary) 12%, var(--bs-surface) 88%);
}

/* ======================= FAQ Section ======================= */
.calc-faq-section {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--bs-border-color);
  width: 90%;
  padding-right: var(--bs-gutter-x, 0.75rem);
  padding-left: var(--bs-gutter-x, 0.75rem);
  margin-right: auto;
  margin-left: auto;
}

.calc-faq-heading {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--bs-heading);
  margin: 0 0 1.25rem;
  text-align: left;
}

.calc-faq-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.calc-faq-item {
  background: var(--bs-surface);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--radius);
  overflow: hidden;
  transition: all 0.2s ease;
}

.calc-faq-item:hover {
  border-color: color-mix(in oklab, var(--bs-primary) 40%, var(--bs-border-color));
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.calc-faq-item[open] {
  border-color: color-mix(in oklab, var(--bs-primary) 50%, var(--bs-border-color));
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.calc-faq-question {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  font-size: 1rem;
  color: var(--bs-heading);
  background: linear-gradient(
    to right,
    color-mix(in oklab, var(--bs-primary) 5%, var(--bs-surface)),
    var(--bs-surface)
  );
  transition: background 0.2s ease;
  list-style: none;
}

.calc-faq-question::-webkit-details-marker {
  display: none;
}

.calc-faq-question:hover {
  background: color-mix(in oklab, var(--bs-primary) 8%, var(--bs-surface));
}

.calc-faq-question-text {
  flex: 1;
  padding-right: 1rem;
  line-height: 1.4;
}

.calc-faq-icon {
  flex-shrink: 0;
  color: var(--bs-primary);
  transition: transform 0.3s ease;
}

.calc-faq-item[open] .calc-faq-icon {
  transform: rotate(180deg);
}

.calc-faq-answer {
  padding: 0.5rem 1.25rem 0.75rem;
  color: var(--bs-body-color);
  line-height: 1.6;
  animation: fadeIn 0.3s ease;
}

.calc-faq-answer p {
  margin: 0;
  font-size: 0.95rem;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Responsive adjustments */
@media (min-width: 576px) {
  .calc-faq-section {
    max-width: 540px;
  }
}

@media (min-width: 768px) {
  .calc-faq-section {
    max-width: 720px;
  }
}

@media (min-width: 992px) {
  .calc-faq-section {
    max-width: 960px;
  }
}

@media (min-width: 1200px) {
  .calc-faq-section {
    max-width: 1140px;
  }
}

@media (min-width: 1400px) {
  .calc-faq-section {
    max-width: 1320px;
  }
}

@media (max-width: 640px) {
  .calc-faq-heading {
    font-size: 1.15rem;
  }
  
  .calc-faq-question {
    padding: 0.85rem 1rem;
    font-size: 0.95rem;
  }
  
  .calc-faq-answer {
    padding: 0 1rem 1rem;
  }
  
  .calc-faq-answer p {
    font-size: 0.9rem;
  }
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  .calc-faq-item:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  }
  
  .calc-faq-item[open] {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  }
}

html[data-theme="dark"] .calc-faq-item:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

html[data-theme="dark"] .calc-faq-item[open] {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* Print: hide FAQ */
@media print {
  .calc-faq-section {
    display: none !important;
  }
}
