/* DigitalCalc — shared stylesheet. Keep this file small; it loads on every page. */

:root {
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --bg-card: #ffffff;
  --text: #1a1d23;
  --text-soft: #5b6472;
  --border: #e2e5ea;
  --accent: #2f5cff;
  --accent-soft: #eaefff;
  --accent-text: #ffffff;
  --good: #0f9d58;
  --warn: #b45309;
  --bad: #d13438;
  --radius: 10px;
  --maxw: 880px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --bg-soft: #161b23;
    --bg-card: #161b23;
    --text: #e8eaed;
    --text-soft: #9aa4b2;
    --border: #2a313c;
    --accent: #6d8dff;
    --accent-soft: #1c2436;
    --accent-text: #0f1218;
    --good: #4ade80;
    --warn: #fbbf24;
    --bad: #f87171;
  }
}

:root[data-theme="light"] {
  --bg: #ffffff; --bg-soft: #f6f7f9; --bg-card: #ffffff;
  --text: #1a1d23; --text-soft: #5b6472; --border: #e2e5ea;
  --accent: #2f5cff; --accent-soft: #eaefff; --accent-text: #ffffff;
  --good: #0f9d58; --warn: #b45309; --bad: #d13438;
}
:root[data-theme="dark"] {
  --bg: #0f1218; --bg-soft: #161b23; --bg-card: #161b23;
  --text: #e8eaed; --text-soft: #9aa4b2; --border: #2a313c;
  --accent: #6d8dff; --accent-soft: #1c2436; --accent-text: #0f1218;
  --good: #4ade80; --warn: #fbbf24; --bad: #f87171;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.65 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 16px; }

/* ---------- header / footer ---------- */

.site-head {
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky; top: 0; z-index: 20;
}
.site-head .wrap {
  display: flex; align-items: center; gap: 16px;
  height: 58px;
}
.brand {
  font-weight: 700; font-size: 18px; letter-spacing: -0.02em;
  color: var(--text); text-decoration: none; white-space: nowrap;
}
.brand span { color: var(--accent); }
.site-head nav { margin-left: auto; display: flex; align-items: center; gap: 18px; }
.site-head nav a { color: var(--text-soft); text-decoration: none; font-size: 15px; }
.site-head nav a:hover { color: var(--accent); }

#theme-toggle {
  background: none; border: 1px solid var(--border); color: var(--text-soft);
  width: 34px; height: 34px; border-radius: 8px; cursor: pointer; font-size: 15px;
  line-height: 1; display: grid; place-items: center;
}
#theme-toggle:hover { border-color: var(--accent); color: var(--accent); }

.site-foot {
  border-top: 1px solid var(--border); margin-top: 56px; padding: 28px 0 40px;
  color: var(--text-soft); font-size: 14px;
}
.site-foot a { color: var(--text-soft); }
.foot-links { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-bottom: 12px; }

/* ---------- typography ---------- */

h1 { font-size: 30px; line-height: 1.25; letter-spacing: -0.02em; margin: 28px 0 8px; }
h2 { font-size: 22px; line-height: 1.3; letter-spacing: -0.01em; margin: 36px 0 10px; }
h3 { font-size: 17px; margin: 24px 0 8px; }
p  { margin: 0 0 14px; }
a  { color: var(--accent); }
.lead { color: var(--text-soft); font-size: 17px; margin-bottom: 22px; }
.muted { color: var(--text-soft); }
.small { font-size: 14px; }

.breadcrumb { font-size: 14px; color: var(--text-soft); margin-top: 18px; }
.breadcrumb a { color: var(--text-soft); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent); }

/* ---------- calculator card ---------- */

.calc {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin: 20px 0;
}
.calc + .calc { margin-top: 16px; }
.calc h2, .calc h3 { margin-top: 0; }

.grid { display: grid; gap: 14px; grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 560px) { .grid, .grid-3 { grid-template-columns: 1fr; } }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label { font-size: 14px; font-weight: 600; color: var(--text-soft); }
.field .hint { font-size: 12.5px; color: var(--text-soft); font-weight: 400; }

input[type="text"], input[type="number"], select, textarea {
  width: 100%; padding: 10px 12px; font-size: 16px; font-family: inherit;
  color: var(--text); background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; outline: none;
}
textarea { font-family: var(--mono); font-size: 14px; line-height: 1.6; resize: vertical; }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type="number"] { -moz-appearance: textfield; }

.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 16px; }
.checks { display: flex; flex-wrap: wrap; gap: 14px 20px; margin-top: 4px; }
.checks label { display: flex; align-items: center; gap: 7px; font-size: 14.5px; color: var(--text); }
.checks input { accent-color: var(--accent); width: 16px; height: 16px; }

button, .btn {
  font: inherit; font-weight: 600; font-size: 15px; cursor: pointer;
  padding: 10px 20px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-soft); color: var(--text);
}
button:hover { border-color: var(--accent); }
.btn-primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-text);
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-sm { padding: 7px 13px; font-size: 14px; font-weight: 500; }

/* ---------- results ---------- */

.result {
  margin-top: 18px; padding: 16px; border-radius: var(--radius);
  background: var(--accent-soft); border: 1px solid var(--border);
}
.result[hidden] { display: none; }
.result .big {
  font-size: 28px; font-weight: 700; letter-spacing: -0.02em;
  font-family: var(--mono); word-break: break-all; line-height: 1.3;
}
.result .label { font-size: 13.5px; color: var(--text-soft); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em; }
.error { color: var(--bad); font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px;
  background: var(--border); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; margin-top: 16px; }
.stat { background: var(--bg-card); padding: 12px 14px; }
.stat .k { font-size: 13px; color: var(--text-soft); }
.stat .v { font-size: 18px; font-weight: 650; font-family: var(--mono); word-break: break-all; }

/* ---------- tables ---------- */

.tablewrap { overflow-x: auto; margin: 14px 0; }
table { border-collapse: collapse; width: 100%; font-size: 15px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); }
th { font-size: 13.5px; color: var(--text-soft); text-transform: uppercase; letter-spacing: 0.03em; }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-family: var(--mono); }

/* ---------- formula / code ---------- */

.formula {
  background: var(--bg-soft); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 12px 16px; margin: 14px 0;
  font-family: var(--mono); font-size: 15px; overflow-x: auto; white-space: pre;
}
code { font-family: var(--mono); font-size: 0.92em; background: var(--bg-soft);
  padding: 2px 5px; border-radius: 4px; }

/* ---------- tabs ---------- */

.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.tabs button {
  padding: 8px 15px; font-size: 14.5px; font-weight: 500;
  background: var(--bg-soft); border: 1px solid var(--border);
}
.tabs button[aria-selected="true"] {
  background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600;
}
.panel[hidden] { display: none; }

/* ---------- tool grid (hub pages) ---------- */

.tools { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); margin: 22px 0; }
.tool {
  display: block; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-card); text-decoration: none; color: var(--text);
}
.tool:hover { border-color: var(--accent); }
.tool b { display: block; font-size: 16px; margin-bottom: 3px; }
.tool span { font-size: 14px; color: var(--text-soft); }

/* ---------- FAQ ---------- */

.faq details {
  border-bottom: 1px solid var(--border); padding: 4px 0;
}
.faq summary {
  cursor: pointer; padding: 11px 0; font-weight: 600; font-size: 16px; list-style: none;
  display: flex; justify-content: space-between; gap: 12px; align-items: baseline;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; color: var(--accent); font-size: 20px; font-weight: 400; }
.faq details[open] summary::after { content: "\2212"; }
.faq details p { margin: 0 0 12px; color: var(--text-soft); }

/* ---------- misc ---------- */

.related { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 0; padding: 0; list-style: none; }
.related a {
  display: inline-block; padding: 6px 13px; font-size: 14px; text-decoration: none;
  border: 1px solid var(--border); border-radius: 999px; color: var(--text-soft);
}
.related a:hover { border-color: var(--accent); color: var(--accent); }

.note { font-size: 14px; color: var(--text-soft); border-left: 3px solid var(--border);
  padding-left: 12px; margin: 14px 0; }

.byline { font-size: 13.5px; color: var(--text-soft); margin: 0 0 20px; }

/* ---------- embed mode (?embed=1) ---------- */

/* Strip everything except the calculator itself, so the page can sit inside
   someone else's article without dragging our chrome along. Direct-child
   selectors keep the calculator's own headings and text intact. */
body.embed .site-head,
body.embed .site-foot,
body.embed main > h2,
body.embed main > p,
body.embed main > ul,
body.embed main > .faq,
body.embed main > .tablewrap,
body.embed main > .formula { display: none; }

body.embed main { padding-top: 14px; padding-bottom: 14px; }
body.embed h1 { font-size: 22px; margin-bottom: 12px; }

.embed-credit {
  display: block;
  margin-top: 14px;
  font-size: 13px;
  color: var(--text-soft);
  text-decoration: none;
}
.embed-credit:hover { color: var(--accent); }

/* ---------- consent banner and ad slots ---------- */

.consent {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  justify-content: center;
  box-shadow: 0 -6px 20px rgba(0, 0, 0, .10);
}
.consent p { margin: 0; max-width: 60ch; font-size: 14px; color: var(--text-soft); }

/* Both choices carry identical weight: rejecting must not be the harder path. */
.consent-actions { display: flex; gap: 10px; flex: none; }
.consent-actions .btn { min-width: 150px; justify-content: center; }

/* Ads sit below the answer, never above it. The reserved height keeps the
   result from jumping once a slot fills, which is what wrecks CLS. */
.ad-slot {
  min-height: 100px;
  margin: 24px 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ad-slot:empty { display: none; }

body.embed .consent,
body.embed .ad-slot { display: none; }
