/* ══════════════════════════════════════════════════════════════════
   Shared styles for the static pages (rules, faq, about, privacy).
   Mirrors the app's design tokens so the whole site reads as one thing.
   ══════════════════════════════════════════════════════════════════ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  color-scheme: light dark;

  --bg: #fbfbfa;
  --surface: #ffffff;
  --surface-2: #f5f5f3;
  --border: #e5e5e1;
  --border-strong: #d3d3ce;

  --text: #1a1a18;
  --text-2: #57574f;
  --text-3: #8c8c84;

  --accent: #0f766e;
  --accent-soft: #e7f3f1;
  --accent-border: #a7d5cf;

  --danger: #b4231f;
  --success: #16704a;
  --success-soft: #e6f4ed;
  --success-border: #a8d5bf;
  --warn: #92610b;
  --warn-soft: #fdf3e2;
  --warn-border: #edd39a;

  --font-bn: 'Noto Sans Bengali', system-ui, -apple-system, sans-serif;
  --font-num: 'Inter', system-ui, -apple-system, sans-serif;

  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --r-full: 999px;

  --maxw: 780px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #131315;
    --surface: #1b1b1e;
    --surface-2: #232327;
    --border: #303036;
    --border-strong: #414149;

    --text: #f0f0ee;
    --text-2: #b0b0aa;
    --text-3: #83837d;

    --accent: #4fb3a8;
    --accent-soft: #16302e;
    --accent-border: #2c5c57;

    --danger: #f08a86;
    --success: #6cc79a;
    --success-soft: #142e22;
    --success-border: #2a5540;
    --warn: #e3b562;
    --warn-soft: #2e2413;
    --warn-border: #55431f;
  }
}

:root[data-theme='dark'] {
  --bg: #131315;
  --surface: #1b1b1e;
  --surface-2: #232327;
  --border: #303036;
  --border-strong: #414149;

  --text: #f0f0ee;
  --text-2: #b0b0aa;
  --text-3: #83837d;

  --accent: #4fb3a8;
  --accent-soft: #16302e;
  --accent-border: #2c5c57;

  --danger: #f08a86;
  --success: #6cc79a;
  --success-soft: #142e22;
  --success-border: #2a5540;
  --warn: #e3b562;
  --warn-soft: #2e2413;
  --warn-border: #55431f;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-bn);
  font-size: 0.9375rem;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

h1,
h2,
h3,
p {
  margin: 0;
}

a {
  color: var(--accent);
  text-underline-offset: 2px;
}

:where(a, button):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* ══════════ Layout ══════════ */

.legal-wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 24px 20px 64px 32px;
}

.legal-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 20px;
  padding: 6px 12px 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface);
  color: var(--text-2);
  font-size: 0.8125rem;
  font-weight: 500;
  text-decoration: none;
  transition: border-color 0.16s ease, color 0.16s ease;
}

.legal-back:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.legal-header {
  margin-bottom: 24px;
}

.legal-header h1 {
  font-size: 1.625rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.legal-header p {
  margin-top: 8px;
  color: var(--text-2);
  font-size: 0.875rem;
}

.legal-notice {
  padding: 12px 14px;
  margin-bottom: 24px;
  border-radius: var(--r-sm);
  border: 1px solid var(--warn-border);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 0.8125rem;
  line-height: 1.65;
}

.legal-section {
  margin-bottom: 28px;
}

.legal-section h2 {
  margin-bottom: 8px;
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

.legal-section p,
.legal-section li {
  margin-bottom: 8px;
  color: var(--text-2);
}

.legal-section ul,
.legal-section ol {
  padding-left: 20px;
}

/* Definition-list FAQ */
dl dt {
  margin-top: 20px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

dl dd {
  margin: 6px 0 0;
  color: var(--text-2);
}

/* ══════════ Footer nav ══════════ */

.legal-footer-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: 0.8125rem;
  color: var(--text-3);
}

/* ══════════ Rules page ══════════ */

.rules-wrap {
  max-width: 880px;
}

.source-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  margin-bottom: 28px;
  border: 1px solid var(--accent-border);
  border-radius: var(--r);
  background: var(--accent-soft);
  text-decoration: none;
  transition: border-color 0.16s ease;
}

.source-link:hover {
  border-color: var(--accent);
}

.source-link__icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}

.source-link__text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.source-link__text strong {
  color: var(--accent);
  font-size: 0.875rem;
}

.source-link__text span {
  color: var(--text-2);
  font-size: 0.75rem;
}

.source-link__arrow {
  margin-left: auto;
  flex-shrink: 0;
  color: var(--accent);
  font-weight: 700;
}

.rules-toc {
  padding: 16px 18px;
  margin-bottom: 32px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
}

.rules-toc h2 {
  margin-bottom: 10px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-3);
}

.rules-toc ol {
  margin: 0;
  padding-left: 22px;
  columns: 2;
  column-gap: 28px;
  list-style-type: bengali;
}

.rules-toc li {
  margin-bottom: 5px;
  break-inside: avoid;
}

.rules-toc a {
  color: var(--text-2);
  text-decoration: none;
  font-size: 0.8438rem;
}

.rules-toc a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.rule-section {
  scroll-margin-top: 16px;
  margin-bottom: 40px;
}

.rule-section > h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  font-size: 1.1875rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.rule-section h3 {
  margin: 22px 0 8px;
  font-size: 0.9688rem;
  font-weight: 700;
  color: var(--text);
}

.rule-section__ref {
  padding: 2px 9px;
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-3);
  font-size: 0.6875rem;
  font-weight: 600;
}

.rule-section > p {
  margin-bottom: 12px;
  color: var(--text-2);
}

/* ── Tables ── */

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 14px 0;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}

.rules-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.rules-table th {
  padding: 10px 13px;
  text-align: left;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 0.75rem;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}

.rules-table td {
  padding: 10px 13px;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
}

.rules-table tr:last-child td {
  border-bottom: none;
}

.rules-table td:last-child,
.rules-table th:last-child {
  text-align: right;
}

.rules-table--prose td:last-child,
.rules-table--prose th:last-child {
  text-align: left;
}

.rules-table--prose td:first-child {
  width: 32%;
  font-weight: 600;
  color: var(--text);
}

.rules-table .num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

/* ── Badges & callouts ── */

.change-badge {
  display: inline-block;
  padding: 2px 8px;
  margin-left: 4px;
  border-radius: var(--r-full);
  font-size: 0.6875rem;
  font-weight: 700;
  vertical-align: middle;
  white-space: nowrap;
}

.change-badge--new {
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid var(--success-border);
}

.change-badge--changed {
  background: var(--warn-soft);
  color: var(--warn);
  border: 1px solid var(--warn-border);
}

.callout {
  padding: 12px 14px;
  margin: 14px 0;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 0.875rem;
  line-height: 1.7;
}

.callout--info {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
}

.callout--warn {
  background: var(--warn-soft);
  border-color: var(--warn-border);
  color: var(--warn);
}

.callout--good {
  background: var(--success-soft);
  border-color: var(--success-border);
  color: var(--success);
}

.callout strong {
  color: inherit;
}

/* ── Worked examples ── */

.example {
  padding: 13px 15px;
  margin: 14px 0;
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  font-size: 0.8438rem;
}

.example__title {
  margin-bottom: 8px;
  font-weight: 700;
  color: var(--text);
}

.example dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 14px;
  margin: 0;
}

.example dt {
  color: var(--text-2);
}

.example dd {
  margin: 0;
  text-align: right;
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text);
}

.example .total {
  margin-top: 5px;
  padding-top: 7px;
  border-top: 1px solid var(--border-strong);
  color: var(--text);
  font-weight: 700;
}

/* ── CTA & source ── */

.cta-box {
  padding: 22px;
  margin: 36px 0 24px;
  border-radius: var(--r-lg);
  border: 1px solid var(--accent-border);
  background: var(--accent-soft);
  text-align: center;
}

.cta-box h2 {
  margin-bottom: 6px;
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--text);
}

.cta-box p {
  margin-bottom: 14px;
  font-size: 0.875rem;
  color: var(--text-2);
}

.cta-box a {
  display: inline-block;
  padding: 11px 24px;
  border-radius: var(--r-sm);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 0.9375rem;
  text-decoration: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .cta-box a {
    color: #08201e;
  }
}

:root[data-theme='dark'] .cta-box a {
  color: #08201e;
}

.source-note {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 0.8125rem;
  color: var(--text-3);
  line-height: 1.7;
}

/* ══════════ Responsive ══════════ */

@media (max-width: 620px) {
  .legal-wrap {
    padding: 20px 16px 48px;
  }

  .legal-header h1 {
    font-size: 1.375rem;
  }

  .rules-toc ol {
    columns: 1;
  }

  .rule-section > h2 {
    font-size: 1.0625rem;
  }

  /* Stack table rows into labelled cards rather than scrolling sideways. */
  .table-scroll {
    border: none;
    overflow: visible;
  }

  .rules-table,
  .rules-table tbody,
  .rules-table tr,
  .rules-table td {
    display: block;
    width: 100%;
  }

  .rules-table thead {
    display: none;
  }

  .rules-table tr {
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    overflow: hidden;
  }

  .rules-table td {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 14px;
    padding: 9px 13px;
    text-align: right;
    border-bottom: 1px solid var(--border);
  }

  .rules-table td:last-child {
    border-bottom: none;
  }

  .rules-table td::before {
    content: attr(data-label);
    flex-shrink: 0;
    text-align: left;
    font-size: 0.75rem;
    color: var(--text-3);
  }

  .rules-table td:first-child {
    background: var(--surface-2);
    font-weight: 600;
    color: var(--text);
    text-align: left;
  }

  .rules-table td:first-child::before {
    content: none;
  }

  .rules-table--prose td:first-child {
    width: 100%;
  }

  .example dl {
    grid-template-columns: 1fr auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ══════════════════════════════════════════════════════════════════
   App shell — injected by shell.js so the static pages sit in the same
   frame as the calculator. Mirrors the tokens/classes used by the app.
   ══════════════════════════════════════════════════════════════════ */

:root {
  --topbar-h: 56px;
  --sidebar-w: 244px;
  --sidebar-w-collapsed: 64px;
  --ease: 0.16s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow-lift: 0 2px 4px rgba(20, 20, 18, 0.05), 0 12px 32px rgba(20, 20, 18, 0.08);
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-md: 1.0625rem;
}

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 70;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: 0 var(--sp-4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar .topbar__menu {
  display: none;
}

.topbar__left,
.topbar__right {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
  text-decoration: none;
  color: var(--text);
}

.topbar__name {
  font-size: var(--text-md);
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.topbar__badge {
  padding: 2px 9px;
  border-radius: var(--r-full);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  color: var(--accent);
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: none;
  color: var(--text-2);
  cursor: pointer;
  transition: background var(--ease), color var(--ease);
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.topbar__cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-full);
  color: var(--text-2);
  font-size: var(--text-sm);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--ease), color var(--ease), border-color var(--ease);
}

.topbar__cta:hover {
  background: var(--surface-2);
  border-color: var(--accent);
  color: var(--accent);
}

.app-body {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  align-items: start;
  padding-top: var(--topbar-h);
}

.app-shell--collapsed .app-body {
  grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--sp-3) var(--sp-2);
  border-right: 1px solid var(--border);
  background: var(--surface);
}

.sidebar__nav {
  display: grid;
  gap: var(--sp-1);
}

.sidebar__group {
  display: grid;
  gap: 2px;
  padding-bottom: var(--sp-2);
  margin-bottom: var(--sp-2);
  border-bottom: 1px solid var(--border);
}

.sidebar__group:last-child {
  border-bottom: none;
}

.sidebar__group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  width: 100%;
  padding: 6px 10px;
  border: none;
  border-radius: var(--r-sm);
  background: none;
  color: var(--text-3);
  font-family: var(--font-bn);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.sidebar__group-head:hover {
  color: var(--text-2);
}

.sidebar__group-chevron {
  display: inline-flex;
  transition: transform var(--ease);
}

.sidebar__group.is-open .sidebar__group-chevron {
  transform: rotate(180deg);
}

.sidebar__group-body {
  display: grid;
  gap: 2px;
}

.sidebar__group-body[hidden] {
  display: none;
}

.sidebar__item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: var(--r-sm);
  background: none;
  color: var(--text-2);
  font-family: var(--font-bn);
  font-size: var(--text-sm);
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--ease), color var(--ease);
}

.sidebar__item:hover {
  background: var(--surface-2);
  color: var(--text);
}

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

/* ── Notch for the item the edge toggle overlaps ──
   The toggle is a 38px circle centred on the sidebar's right border. Rather
   than letting it sit on top of the item's highlight, mask a slightly larger
   circle out of the item so the button nests into a concave bite with an even
   gap all the way round. --notch-x is the toggle centre's distance past the
   item's right edge (sidebar padding), --notch-r the toggle radius plus gap. */
.sidebar__item--notched {
  --notch-x: var(--sp-2);
  --notch-r: 23px;
  -webkit-mask-image: radial-gradient(
    circle var(--notch-r) at calc(100% + var(--notch-x)) 50%,
    transparent 0 var(--notch-r),
    #000 calc(var(--notch-r) + 0.5px)
  );
  mask-image: radial-gradient(
    circle var(--notch-r) at calc(100% + var(--notch-x)) 50%,
    transparent 0 var(--notch-r),
    #000 calc(var(--notch-r) + 0.5px)
  );
}

/* The rail item is only 52px wide, so a smaller bite keeps clear of the icon. */
.sidebar--collapsed .sidebar__item--notched {
  --notch-x: 6px;
  --notch-r: 21px;
}

.sidebar__item-icon {
  display: inline-flex;
  flex-shrink: 0;
}

.sidebar__item-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar__foot {
  display: grid;
  gap: var(--sp-2);
  padding: var(--sp-3) 10px 0;
  border-top: 1px solid var(--border);
}

.sidebar__note {
  color: var(--text-3);
  font-size: var(--text-xs);
  line-height: 1.5;
}

.sidebar__visitors {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-2);
  font-size: var(--text-xs);
}

.sidebar__visitors svg {
  flex-shrink: 0;
  color: var(--accent);
}

.sidebar__visitors strong {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* In the rail the label has nowhere to go, so only the figure stays — stacked
   under the icon so it still reads as a count rather than a stray number. */
.sidebar--collapsed .sidebar__foot {
  padding-inline: 2px;
  justify-items: center;
}

.sidebar--collapsed .sidebar__visitors {
  flex-direction: column;
  gap: 2px;
  text-align: center;
}

.sidebar--collapsed .sidebar__visitors-text {
  font-size: 0.6875rem;
}

.sidebar--collapsed .sidebar__visitors-label {
  display: none;
}

.sidebar--collapsed {
  padding-inline: 6px;
}

.sidebar--collapsed .sidebar__item {
  justify-content: center;
  padding: 10px 0;
}

.sidebar--collapsed .sidebar__item-label,
.sidebar--collapsed .sidebar__group-head {
  display: none;
}

/* ── Sidebar edge toggle (Reddit-style: rides the divider) ── */

.sidebar-toggle {
  position: fixed;
  /* Centres on the first nav item: sidebar's own top padding, and the toggle
     is the same 38px height as a collapsed rail item. */
  top: calc(var(--topbar-h) + var(--sp-3));
  left: calc(var(--sidebar-w) - 19px);
  z-index: 66;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  transition: left var(--ease), background var(--ease), color var(--ease),
    border-color var(--ease);
}

.sidebar-toggle:hover {
  background: var(--surface-2);
  border-color: var(--accent);
  color: var(--accent);
}

.app-shell--collapsed .sidebar-toggle {
  left: calc(var(--sidebar-w-collapsed) - 19px);
}


.sidebar__scrim {
  display: none;
}

/* Rail is not used on the static pages; content column carries the page. */
@media (max-width: 1023px) {
  .app-body,
  .app-shell--collapsed .app-body {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    z-index: 65;
    width: min(280px, 82vw);
    padding-inline: var(--sp-2);
    transform: translateX(-102%);
    transition: transform var(--ease);
    box-shadow: var(--shadow-lift);
  }

  .sidebar--collapsed .sidebar__item {
    justify-content: flex-start;
    padding: 8px 10px;
  }

  .sidebar--collapsed .sidebar__item-label,
  .sidebar--collapsed .sidebar__group-head {
    display: revert;
  }

  .sidebar--collapsed .sidebar__group-head {
    display: flex;
  }

  .sidebar--open {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: none;
  }

  .sidebar__item--notched {
    -webkit-mask-image: none;
    mask-image: none;
  }

  .topbar .topbar__menu {
    display: inline-flex;
  }

  .sidebar__scrim {
    display: block;
    position: fixed;
    inset: var(--topbar-h) 0 0;
    z-index: 64;
    border: none;
    background: rgba(20, 20, 18, 0.45);
    cursor: pointer;
  }

  .sidebar__scrim[hidden] {
    display: none;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 0 var(--sp-2);
  }

  .topbar__badge,
  .topbar__cta span {
    display: none;
  }

  .topbar__cta {
    padding: 8px;
    border-radius: var(--r-sm);
  }
}

@media print {
  .topbar,
  .sidebar,
  .sidebar__scrim,
  .no-print {
    display: none !important;
  }

  .app-body {
    display: block;
    padding-top: 0;
  }
}
