:root {
  --radius: 8px;

  /* Past (already taken) vs Future (planned) — shared across themes */
  --past: #4f9eff;
  --past-text: #ffffff;
}

:root,
[data-theme="dark"] {
  --bg: #0f1419;
  --panel: #1a212b;
  --panel-2: #232b37;
  --border: #2d3744;
  --text: #e8ecf1;
  --text-dim: #8b97a8;
  --accent: #4f9eff;
  --ok: #3ec28a;
  --warn: #f5a623;
  --danger: #ef5b5b;

  --future: #b388ff;
  --future-text: #1a0f2b;

  --in-window: rgba(79, 158, 255, 0.10);
  --in-window-border: rgba(79, 158, 255, 0.45);

  --date-picker-filter: invert(0.8);
  --shadow-tooltip: 0 6px 24px rgba(0, 0, 0, 0.4);
  --stripe-overlay: rgba(255, 255, 255, 0.18);
  --stripe-overlay-strong: rgba(255, 255, 255, 0.25);
}

[data-theme="light"] {
  --bg: #eef1f5;
  --panel: #ffffff;
  --panel-2: #f4f6fa;
  --border: #d8dde4;
  --text: #1a212b;
  --text-dim: #5a6675;
  --accent: #2b7fff;
  --ok: #1e9e6e;
  --warn: #c97a00;
  --danger: #d24545;

  --future: #8b5cf6;
  --future-text: #ffffff;

  --in-window: rgba(43, 127, 255, 0.10);
  --in-window-border: rgba(43, 127, 255, 0.55);

  --date-picker-filter: none;
  --shadow-tooltip: 0 6px 24px rgba(15, 20, 25, 0.18);
  --stripe-overlay: rgba(255, 255, 255, 0.35);
  --stripe-overlay-strong: rgba(255, 255, 255, 0.5);
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
}
html, body { height: 100%; }
body {
  display: flex; flex-direction: column;
  overflow: hidden;
}
.app-header {
  padding: 10px 20px 2px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.app-header__titles { min-width: 0; }
.app-header h1 { margin: 0; font-size: 16px; font-weight: 600; }
.app-header h1 a { color: inherit; text-decoration: none; }
.app-header h1 a:hover { color: var(--accent); }
.subtitle { margin: 1px 0 0; color: var(--text-dim); font-size: 11px; }

/* ----- Theme toggle ----- */
.theme-toggle {
  flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  background: var(--panel-2); color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; padding: 0;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-toggle__icon { display: none; }
[data-theme="dark"] .theme-toggle__icon--sun { display: block; }
[data-theme="light"] .theme-toggle__icon--moon { display: block; }
.app {
  display: grid;
  grid-template-columns: 240px 1fr 280px;
  gap: 10px;
  padding: 6px 16px;
  align-items: stretch;
  flex: 1; min-height: 0;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  overflow-y: auto;
  min-height: 0;
}
.panel--calendar {
  display: flex; flex-direction: column;
  overflow: hidden;          /* let inner grid resize, not panel scroll */
}
.app-footer { padding: 4px 20px 8px; color: var(--text-dim); font-size: 10px; flex-shrink: 0; }
.app-footer a { color: var(--accent); }
.app-footer p { margin: 4px 0 0; }
.site-nav { display: flex; flex-wrap: wrap; gap: 14px; font-size: 11px; }
.site-nav a { color: var(--text-dim); text-decoration: none; }
.site-nav a:hover { color: var(--accent); text-decoration: underline; }

/* ----- Ads & affiliate blocks (hidden until body.ads-on) ----- */
.ad-slot, .affiliate-card { display: none; }
body.ads-on .ad-slot { display: block; }
body.ads-on .affiliate-card { display: block; }

.ad-slot {
  position: relative;
  margin: 10px auto; padding: 8px;
  width: 100%;
  background: var(--panel-2);
  border: 1px dashed var(--border);
  border-radius: 6px;
  text-align: center;
  overflow: hidden;
}
.ad-slot__label {
  display: block; margin-bottom: 4px;
  font-size: 9px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-dim);
}
.ad-slot ins { display: block; }
/* reserved heights so the reserved space is visible even before real ads fill in */
.ad-slot--top, .ad-slot--bottom { min-height: 100px; max-width: 970px; }
.ad-slot--inline { min-height: 250px; margin: 20px auto; }

/* Calculator page: once ads are on, stop forcing everything into the viewport */
body.ads-on:not(.content) { height: auto; min-height: 100%; overflow-y: auto; }
body.ads-on .app { flex: 0 0 auto; }
body.ads-on .panel { overflow-y: visible; }
body.ads-on .panel--calendar { overflow: visible; }
body.ads-on .months { min-height: 520px; }

/* Affiliate card */
.affiliate-card {
  margin: 16px 0; padding: 14px 16px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
}
.affiliate-card__label {
  font-size: 9px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-dim);
}
.affiliate-card h3 { margin: 4px 0 6px; font-size: 15px; }
.affiliate-card p { margin: 0 0 10px; font-size: 13px; color: var(--text-dim); line-height: 1.5; }
.affiliate-card .aff-btn {
  display: inline-block; padding: 8px 14px;
  background: var(--accent); color: #fff;
  border-radius: 6px; text-decoration: none; font-size: 13px; font-weight: 600;
}
.affiliate-card .aff-btn:hover { filter: brightness(1.08); }

/* ----- Content pages (legal, about, articles) ----- */
body.content { height: auto; min-height: 100%; overflow: visible; }
body.content .content-page { flex: 1 0 auto; }
body.content .app-footer { flex-shrink: 0; }
body.content .app-header { border-bottom: 1px solid var(--border); }
.content-page {
  flex: 1; min-height: 0;
  max-width: 720px; margin: 0 auto;
  padding: 24px 24px 48px;
  font-size: 15px; line-height: 1.6;
  color: var(--text);
}
.content-page h1 {
  font-size: 28px; font-weight: 700; line-height: 1.25;
  margin: 0 0 8px;
}
.content-page .lead {
  color: var(--text-dim); font-size: 16px; margin: 0 0 24px;
}
.content-page h2 {
  font-size: 20px; font-weight: 700; line-height: 1.3;
  margin: 32px 0 10px;
}
.content-page h3 {
  font-size: 16px; font-weight: 600;
  margin: 24px 0 8px;
}
.content-page p, .content-page ul, .content-page ol { margin: 0 0 14px; }
.content-page ul, .content-page ol { padding-left: 22px; }
.content-page li { margin: 4px 0; }
.content-page a { color: var(--accent); }
.content-page strong { font-weight: 600; }
.content-page code {
  background: var(--panel-2); border: 1px solid var(--border);
  padding: 1px 5px; border-radius: 3px; font-size: 90%;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.content-page blockquote {
  border-left: 3px solid var(--accent);
  margin: 16px 0; padding: 4px 14px;
  background: var(--panel-2); color: var(--text-dim);
  border-radius: 0 4px 4px 0;
}
.content-page hr { margin: 24px 0; }
.content-page .meta {
  color: var(--text-dim); font-size: 12px;
  margin-bottom: 24px;
}
.content-page .back-link {
  display: inline-block; margin-bottom: 16px;
  color: var(--text-dim); font-size: 13px; text-decoration: none;
}
.content-page .back-link:hover { color: var(--accent); }
.content-page table {
  width: 100%; border-collapse: collapse;
  margin: 0 0 16px;
}
.content-page th, .content-page td {
  text-align: left; padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.content-page th {
  color: var(--text-dim); font-weight: 600;
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em;
}
.article-list { list-style: none; padding: 0; margin: 0; }
.article-list li {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.article-list li:last-child { border-bottom: none; }
.article-list h2 {
  font-size: 18px; margin: 0 0 4px;
}
.article-list h2 a { color: var(--text); text-decoration: none; }
.article-list h2 a:hover { color: var(--accent); }
.article-list p { color: var(--text-dim); font-size: 14px; margin: 0; }
@media (max-width: 1100px) {
  body { overflow: auto; }
  .app { grid-template-columns: 1fr; }
  .panel { overflow-y: visible; }
  .panel--calendar { overflow: visible; }
}

/* Controls */
.panel-title { margin: 0 0 10px; font-size: 13px; font-weight: 600; }
.panel-subtitle {
  margin: 0 0 6px; font-size: 10px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.08em;
}
.field {
  display: flex; flex-direction: column; gap: 3px; margin-bottom: 8px;
  font-size: 11px; color: var(--text-dim);
}
.field input, .field select {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 5px; padding: 6px 8px;
  font: inherit; font-size: 12px;
}
.field input[type=date]::-webkit-calendar-picker-indicator { filter: var(--date-picker-filter); }
.row { display: flex; gap: 5px; margin-bottom: 8px; flex-wrap: wrap; }
.row button {
  flex: 1; min-width: 56px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 5px;
  padding: 6px 8px; cursor: pointer; font: inherit; font-size: 11px;
}
.row button:hover { background: var(--border); }
.row button.primary { background: var(--accent); border-color: var(--accent); color: white; }
.row button.danger  { background: transparent; border-color: var(--danger); color: var(--danger); }
hr { border: 0; border-top: 1px solid var(--border); margin: 10px 0; }

.panel-subtitle small { color: var(--text-dim); font-weight: 400; letter-spacing: 0; text-transform: none; }

/* ----- Tooltip ----- */
.tooltip {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
  cursor: help; outline: none;
}
.tooltip__icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--panel-2); color: var(--text-dim);
  border: 1px solid var(--border);
  font-size: 10px; font-weight: 700; font-style: italic;
  font-family: Georgia, "Times New Roman", serif;
  user-select: none;
}
.tooltip:hover .tooltip__icon,
.tooltip:focus .tooltip__icon {
  color: var(--accent); border-color: var(--accent);
}
.tooltip__bubble {
  position: fixed;
  top: 0; left: 0;
  width: 280px; max-width: calc(100vw - 16px);
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 11px; line-height: 1.45;
  box-shadow: var(--shadow-tooltip);
  z-index: 1000;
  display: none;
  text-align: left;
  --arrow-y: 50%;
}
.tooltip__bubble--visible { display: block; }
.tooltip__bubble::after {
  content: ''; position: absolute;
  top: var(--arrow-y); left: -6px;
  margin-top: -6px;
  border: 6px solid transparent;
  border-right-color: var(--border);
}
.tooltip__bubble--flip-left::after {
  left: auto; right: -6px;
  border-right-color: transparent;
  border-left-color: var(--border);
}
.tooltip__bubble strong { display: block; margin-bottom: 4px; font-size: 12px; }
.tooltip__bubble p { margin: 0 0 6px; color: var(--text-dim); }
.tooltip__bubble pre {
  margin: 0 0 6px; padding: 6px 8px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 4px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 10px; line-height: 1.4;
  color: var(--text);
  white-space: pre; overflow-x: auto;
}
.tooltip__bubble ul {
  margin: 0; padding-left: 16px;
  color: var(--text-dim);
}
.tooltip__bubble li { margin: 2px 0; }
.tooltip__bubble code {
  background: var(--panel-2); padding: 0 3px;
  border-radius: 2px; font-size: 10px;
  color: var(--text);
}

/* ----- Slider + month ticks ----- */
.win-summary {
  display: flex; flex-direction: column; gap: 4px;
  padding: 6px 10px; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 6px;
  margin-bottom: 8px;
  flex-shrink: 0;
}
.win-summary__head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; font-size: 11px;
}
.win-summary__head > span { color: var(--text-dim); }
.view-nav {
  display: flex; align-items: center; gap: 4px;
}
.view-nav__title {
  color: var(--text); font-size: 12px; font-weight: 600;
  padding: 0 6px; min-width: 150px; text-align: center;
}
.view-nav__btn {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 2px 7px; cursor: pointer;
  font: inherit; font-size: 12px; line-height: 1.2;
}
.view-nav__btn:hover { background: var(--border); border-color: var(--accent); }
.view-nav__btn--today {
  margin-left: 4px; font-size: 10px;
  padding: 3px 8px;
}
.slider-wrap { position: relative; padding: 14px 0 18px; }
.slider-wrap input[type=range] {
  width: 100%; margin: 0; accent-color: var(--accent);
}
.month-ticks {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 14px; pointer-events: none;
}
.month-ticks .mtick {
  position: absolute; transform: translateX(-50%);
  font-size: 9px; color: var(--text-dim);
  cursor: pointer; pointer-events: auto;
  padding: 1px 2px;
  user-select: none;
}
.month-ticks .mtick:hover { color: var(--accent); }
.month-ticks .mtick--year { color: var(--text); font-weight: 600; }
.month-ticks .mtick::before {
  content: ''; position: absolute; left: 50%; top: -6px;
  width: 1px; height: 5px; background: var(--border);
  transform: translateX(-50%);
}

/* ----- Compact calendar grid, fills available vertical space ----- */
.months {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-auto-rows: 1fr;
  gap: 6px;
  flex: 1; min-height: 0;
}
@media (max-width: 1400px) { .months { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 1100px) { .months { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 700px)  { .months { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 480px)  { .months { grid-template-columns: 1fr; } }

.month {
  background: var(--panel-2); border-radius: 5px; padding: 5px;
  display: flex; flex-direction: column; min-height: 0;
}
.month h3 {
  margin: 0 0 3px; font-size: 10px; font-weight: 600;
  color: var(--text-dim); letter-spacing: 0.06em; text-transform: uppercase;
  text-align: center;
  flex-shrink: 0;
}
.month h3 em {
  font-style: normal; color: var(--accent); font-weight: 700;
  margin-left: 4px; letter-spacing: 0;
}
.month--year-boundary { box-shadow: inset 2px 0 0 var(--accent); }
.dow-row {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px;
  flex-shrink: 0;
}
.days-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px;
  flex: 1; min-height: 0;
}
.dow { font-size: 8px; color: var(--text-dim); text-align: center; padding: 1px 0; }
.day {
  font-size: 10px; padding: 0; min-height: 0;
  border: 1px solid transparent; background: transparent;
  color: var(--text); border-radius: 3px;
  cursor: pointer; text-align: center; font-family: inherit;
  line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.day:hover { background: var(--border); }
.day.blank { cursor: default; visibility: hidden; }

/* in-window subtle tint, applied to ALL days inside window */
.day--in-window { background: var(--in-window); border-color: var(--in-window-border); }

/* PAST presence (already taken) */
.day--past { background: var(--past); color: var(--past-text); font-weight: 600; }
.day--past.day--in-window { background: var(--past); border-color: #7fb6ff; }

/* FUTURE planned presence */
.day--future {
  background: var(--future); color: var(--future-text); font-weight: 600;
  background-image: repeating-linear-gradient(
    -45deg,
    var(--stripe-overlay) 0 2px,
    transparent 2px 5px
  );
}
.day--future.day--in-window { border-color: #d4b8ff; }

.day--ref { outline: 2px solid var(--warn); outline-offset: -2px; }
.day--today { box-shadow: inset 0 0 0 1px var(--warn); }

.legend {
  display: flex; gap: 12px; flex-wrap: wrap; margin-top: 6px;
  color: var(--text-dim); font-size: 10px;
  flex-shrink: 0;
}
.legend .sw {
  display: inline-block; width: 11px; height: 11px; border-radius: 2px;
  vertical-align: middle; margin-right: 5px;
}
.sw--past { background: var(--past); }
.sw--future {
  background: var(--future);
  background-image: repeating-linear-gradient(
    -45deg, var(--stripe-overlay-strong) 0 2px, transparent 2px 5px);
}
.sw--window { background: var(--in-window); border: 1px solid var(--in-window-border); }
.sw--ref { background: transparent; outline: 2px solid var(--warn); outline-offset: -2px; }

/* ----- Metrics + pie ----- */
.big-stat {
  padding: 12px; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--border);
  margin-bottom: 10px;
}
.big-num { font-size: 30px; font-weight: 700; line-height: 1; }
.big-num span { font-size: 16px; color: var(--text-dim); font-weight: 400; }
.big-label {
  color: var(--text-dim); font-size: 10px; margin-top: 3px;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.bar {
  height: 6px; background: var(--border); border-radius: 3px;
  margin-top: 8px; overflow: hidden; display: flex;
}
.bar-past { height: 100%; background: var(--past); }
.bar-future {
  height: 100%; background: var(--future);
  background-image: repeating-linear-gradient(
    -45deg, var(--stripe-overlay-strong) 0 2px, transparent 2px 5px);
}
.big-stat--danger .big-num { color: var(--danger); }

.pie-block { display: flex; align-items: center; gap: 12px;
  padding: 10px; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 6px;
  margin-bottom: 10px; }
.donut { width: 100px; height: 100px; flex-shrink: 0; }
.donut .ring { fill: transparent; stroke-width: 4; }
.donut text {
  fill: var(--text); font-size: 9px; font-weight: 700;
  text-anchor: middle; dominant-baseline: middle;
}
.donut text.sub {
  fill: var(--text-dim); font-size: 4px; font-weight: 400;
}
.pie-legend { font-size: 11px; flex: 1; min-width: 0; }
.pie-legend ul { list-style: none; padding: 0; margin: 0; }
.pie-legend li {
  display: flex; justify-content: space-between; align-items: center;
  gap: 6px; padding: 3px 0;
}
.pie-legend .sw { display: inline-block; width: 9px; height: 9px;
  border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.pie-legend .lbl { color: var(--text-dim); flex: 1; }
.pie-legend .val { color: var(--text); font-weight: 600; }

.kv { list-style: none; padding: 0; margin: 0; }
.kv li {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 12px;
}
.kv li:last-child { border-bottom: none; }
.kv span { color: var(--text-dim); }
.kv strong { font-weight: 600; text-align: right; }
.text-danger { color: var(--danger); }
.alert {
  margin-top: 8px; padding: 8px; border-radius: 5px;
  background: rgba(239, 91, 91, 0.12); border: 1px solid var(--danger);
  color: var(--text); font-size: 11px;
}
.info {
  margin-top: 8px; padding: 8px; border-radius: 5px;
  background: rgba(79, 158, 255, 0.08); border: 1px solid var(--border);
  color: var(--text-dim); font-size: 10px;
}
