/* ------------------------------------------------------------------
   Tokens
   ------------------------------------------------------------------ */
:root {
  --bg: #f5f7fc;
  --surface: #ffffff;
  --surface-2: #f0f3fa;
  --text: #141a2a;
  --muted: #566078;
  --border: #e1e6f0;
  --border-strong: #c8d0df;
  --accent: #2a4fd7;
  --accent-hover: #1f3fb8;
  --accent-soft: #e9eeff;
  --accent-ink: #1c3497;
  --on-accent: #ffffff;
  --hero-1: #dfe7ff;
  --hero-2: #efe6ff;
  --error: #b42318;
  --error-soft: #fef3f2;
  --shadow: 0 1px 2px rgb(20 26 42 / .04), 0 8px 24px -6px rgb(20 26 42 / .10);
  --shadow-lg: 0 2px 4px rgb(20 26 42 / .04), 0 24px 48px -12px rgb(30 45 110 / .18);
  --radius: 14px;
  --radius-sm: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1018;
    --surface: #141a26;
    --surface-2: #1b2232;
    --text: #e8ecf5;
    --muted: #9ea8bf;
    --border: #252e40;
    --border-strong: #354057;
    --accent: #8ea6ff;
    --accent-hover: #a9bbff;
    --accent-soft: #1d2847;
    --accent-ink: #c3d0ff;
    --on-accent: #0c1018;
    --hero-1: #16204a;
    --hero-2: #261a45;
    --error: #ffa39a;
    --error-soft: #2c1517;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px -6px rgb(0 0 0 / .45);
    --shadow-lg: 0 2px 4px rgb(0 0 0 / .3), 0 24px 48px -12px rgb(0 0 0 / .6);
    color-scheme: dark;
  }
}

/* ------------------------------------------------------------------
   Base
   ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 1rem/1.65 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 52rem;
  margin: 0 auto;
  padding-inline: 1rem;
}

h1, h2, h3 { line-height: 1.2; letter-spacing: -.015em; }
h1 { font-size: clamp(2rem, 5vw, 2.9rem); margin: 0 0 .75rem; letter-spacing: -.03em; }
h2 { font-size: 1.5rem; margin: 3rem 0 .5rem; }
h3 { font-size: 1.05rem; margin: 0 0 .4rem; }

a { color: var(--accent); text-underline-offset: .15em; }
a:hover { color: var(--accent-hover); }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

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

.skip-link {
  position: absolute; left: -999px; top: .5rem; z-index: 10;
  padding: .5rem 1rem; border-radius: var(--radius-sm);
  background: var(--accent); color: var(--on-accent);
}
.skip-link:focus { left: .5rem; }

.muted { color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ------------------------------------------------------------------
   Header and footer
   ------------------------------------------------------------------ */
.site-header {
  position: relative;
  z-index: 1;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 3.75rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: .6rem;
  color: var(--text);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -.01em;
  text-decoration: none;
  white-space: nowrap;
}
.brand:hover { color: var(--text); }
.brand-mark { width: 1.75rem; height: 1.75rem; color: var(--accent); flex: none; }
.header-nav { display: flex; gap: .25rem; }
.header-nav a {
  color: var(--muted);
  font-weight: 500;
  text-decoration: none;
  padding: .4rem .7rem;
  border-radius: 8px;
}
.header-nav a:hover { color: var(--text); background: var(--surface-2); }

.site-footer {
  margin-top: 4rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: .9rem;
  padding-block: 2rem 2.5rem;
}
.footer-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.brand-small { font-size: .95rem; }
.brand-small .brand-mark { width: 1.4rem; height: 1.4rem; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; }
.site-footer nav a { color: var(--muted); text-decoration: none; }
.site-footer nav a:hover { color: var(--text); text-decoration: underline; }
.site-footer p { margin: .25rem 0; }

/* ------------------------------------------------------------------
   Hero
   ------------------------------------------------------------------ */
.hero {
  background:
    radial-gradient(60rem 22rem at 15% -10%, var(--hero-1), transparent 70%),
    radial-gradient(50rem 22rem at 90% 0%, var(--hero-2), transparent 70%);
  padding-block: 3rem 6.5rem;
  margin-bottom: -4.5rem;
}
.eyebrow {
  display: inline-block;
  margin: 0 0 1rem;
  padding: .3rem .75rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .02em;
}
.lead { color: var(--muted); font-size: 1.125rem; max-width: 40rem; margin: 0; }

/* ------------------------------------------------------------------
   Calculator card
   ------------------------------------------------------------------ */
.calc {
  position: relative;
  box-shadow: var(--shadow-lg);
  padding: .5rem 1.5rem 1.25rem;
}

.tabs {
  display: flex;
  gap: .25rem;
  padding: .3rem;
  margin: 1rem 0 1.5rem;
  background: var(--surface-2);
  border-radius: 12px;
}
html:not(.js) .tabs { display: none; }
.tabs button {
  flex: 1;
  font: inherit;
  font-weight: 600;
  font-size: .95rem;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 9px;
  padding: .65rem .75rem;
  cursor: pointer;
  transition: background-color .15s, color .15s, box-shadow .15s;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] {
  background: var(--surface);
  color: var(--accent-ink);
  box-shadow: 0 1px 3px rgb(20 26 42 / .12);
}

.js .panel:not(.active) { display: none; }
html:not(.js) .panel + .panel { margin-top: 2rem; padding-top: 2rem; border-top: 1px solid var(--border); }

/* Form fields */
.fields {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: .75rem;
}
.fields-add { grid-template-columns: 1.3fr 1fr 1fr; }
.field-arrow {
  color: var(--muted);
  font-size: 1.25rem;
  padding-bottom: .7rem;
}
.field { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.field > span {
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: var(--muted);
}
.field-wide { margin-top: 1rem; }
.field-wide > span { text-transform: none; letter-spacing: 0; font-size: .9rem; }

input[type="date"], input[type="number"], select, textarea {
  font: inherit;
  font-size: 1.05rem;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: .65rem .8rem;
  min-height: 3rem;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input[type="date"], input[type="number"], select { height: 3.1rem; padding-block: 0; }
input[type="date"]:hover, input[type="number"]:hover, select:hover, textarea:hover { border-color: var(--muted); }
input[type="date"]:focus, input[type="number"]:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent);
}
textarea { font-family: ui-monospace, Consolas, monospace; font-size: .95rem; resize: vertical; min-height: 5rem; }

/* Switch-style checkboxes */
.toggles { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; margin-top: 1rem; }
.switch {
  display: inline-flex;
  align-items: center;
  gap: .6rem;
  min-height: 2.25rem;
  cursor: pointer;
  user-select: none;
}
.switch input {
  appearance: none;
  flex: none;
  position: relative;
  width: 2.4rem;
  height: 1.4rem;
  margin: 0;
  border-radius: 999px;
  background: var(--border-strong);
  cursor: pointer;
  transition: background-color .15s;
}
.switch input::after {
  content: "";
  position: absolute;
  top: .2rem;
  left: .2rem;
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgb(0 0 0 / .25);
  transition: transform .15s;
}
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(1rem); }

/* Results */
.result {
  margin-top: 1.5rem;
  padding: 1.5rem;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent-soft), color-mix(in srgb, var(--accent-soft) 40%, var(--surface)));
  border: 1px solid color-mix(in srgb, var(--accent) 18%, transparent);
  min-height: 15rem;
}
.answer { display: flex; align-items: baseline; flex-wrap: wrap; gap: .25rem .6rem; }
.answer-stack { flex-direction: column; gap: 0; }
.answer-value {
  font-size: clamp(2.6rem, 9vw, 3.6rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.04em;
  color: var(--accent-ink);
  font-variant-numeric: tabular-nums;
}
.answer-date { font-size: clamp(2rem, 7vw, 2.75rem); letter-spacing: -.03em; }
.answer-unit { font-size: 1.25rem; font-weight: 600; color: var(--accent-ink); }
.answer-weekday {
  font-size: .85rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: .2rem;
}
.answer-detail { margin: .9rem 0 0; color: var(--text); }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .6rem;
  margin: 1.25rem 0 0;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .7rem .85rem;
}
.stat dt { font-size: .78rem; color: var(--muted); font-weight: 600; line-height: 1.3; }
.stat dd { margin: .2rem 0 0; font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.formula {
  margin: 1rem 0 0;
  font-size: .95rem;
  color: var(--muted);
}
.formula strong { color: var(--text); }

.list-title { margin: 1.1rem 0 .4rem; font-size: .8rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.holiday-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .35rem; }
.holiday-list li {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: .1rem 1rem;
  padding: .5rem .8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .93rem;
}
.h-name { font-weight: 600; }
.h-date { color: var(--muted); }
.h-more { color: var(--muted); }

.error {
  margin: 0;
  padding: .75rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--error-soft);
  color: var(--error);
  font-weight: 600;
}
.error:empty { display: none; }
.settings .error { margin-top: 1rem; }

/* Settings */
.settings {
  margin-top: 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.settings summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .15rem .75rem;
  padding: .9rem 2.75rem .9rem 1rem;
  cursor: pointer;
  list-style: none;
  position: relative;
  border-radius: var(--radius);
}
.settings summary::-webkit-details-marker { display: none; }
.settings summary::after {
  content: "";
  position: absolute;
  right: 1.1rem;
  top: 50%;
  width: .55rem;
  height: .55rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-70%) rotate(45deg);
  transition: transform .15s;
}
.settings[open] summary::after { transform: translateY(-30%) rotate(-135deg); }
.settings-title { font-weight: 600; }
.settings-summary { color: var(--muted); font-size: .9rem; }
.settings-body { padding: 0 1rem 1rem; }
.settings fieldset { border: 0; padding: 0; margin: .5rem 0 0; }
.settings fieldset + fieldset { margin-top: 1.25rem; }
.settings legend { font-size: .8rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); padding: 0; margin-bottom: .5rem; }

.pills { display: flex; flex-wrap: wrap; gap: .4rem; }
.pill { position: relative; }
.pill input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.pill span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 3.25rem;
  min-height: 2.5rem;
  padding: 0 .75rem;
  border-radius: 999px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: .9rem;
  cursor: pointer;
  user-select: none;
  transition: background-color .15s, border-color .15s, color .15s;
}
.pill span:hover { border-color: var(--accent); }
.pill input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.pill input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

.calc-note { margin: 1rem 0 0; font-size: .85rem; color: var(--muted); text-align: center; }

.notice {
  padding: .9rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

/* ------------------------------------------------------------------
   Explanation section
   ------------------------------------------------------------------ */
.explain h2:first-child { margin-top: 3.5rem; }
.section-lead { color: var(--muted); margin: 0 0 1.25rem; max-width: 42rem; }

.rules {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}
.rule { padding: 1.25rem 1.25rem 1rem; border-top: 3px solid var(--accent); }
.rule p { margin: 0; color: var(--muted); font-size: .95rem; }

.examples { display: grid; gap: 1rem; margin-top: 1rem; }
.example { padding: 1.25rem; }
.example p, .example ul { font-size: .97rem; }
.example p:last-child { margin-bottom: 0; }
.example ul { padding-left: 1.25rem; }

.table-card { overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: .75rem 1rem; border-bottom: 1px solid var(--border); vertical-align: top; }
thead th {
  background: var(--surface-2);
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}
tbody th { font-weight: 600; }
tbody tr:last-child th, tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
.badge {
  display: inline-block;
  padding: .1rem .55rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 600;
  font-size: .88rem;
}

/* ------------------------------------------------------------------
   Text pages (about, privacy, contact)
   ------------------------------------------------------------------ */
.page { padding-top: 2.5rem; }
.prose { padding: clamp(1.25rem, 4vw, 2.5rem); max-width: 46rem; margin: 0 auto; }
.prose h1 { font-size: clamp(1.75rem, 4vw, 2.25rem); }
.prose h2 { font-size: 1.25rem; margin: 2rem 0 .5rem; }
.prose ul { padding-left: 1.25rem; }
.prose li + li { margin-top: .4rem; }

/* ------------------------------------------------------------------
   Ad slots (only rendered when ads are enabled in site.config.json)
   ------------------------------------------------------------------ */
.ad-slot { min-height: 280px; margin-block: 2rem; }
.ad-top { min-height: 100px; margin-block: 1rem; }

/* ------------------------------------------------------------------
   Small screens
   ------------------------------------------------------------------ */
@media (max-width: 640px) {
  .hero { padding-block: 2rem 5.5rem; }
  .calc { padding: .25rem 1rem 1rem; }
  .tabs button { font-size: .88rem; padding: .6rem .4rem; }
  .fields, .fields-add { grid-template-columns: 1fr; }
  .field-arrow { display: none; }
  .result { padding: 1.1rem; }
  .stats { gap: .4rem; }
  .stat { padding: .55rem .6rem; }
  .stat dd { font-size: 1.25rem; }
  .rules { grid-template-columns: 1fr; }
  .header-nav a { padding: .4rem .5rem; }
  .header-nav a[href="/"] { display: none; }
  .brand { font-size: 1rem; }
  th, td { padding: .6rem .75rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
