/* ==========================================================
   Your Opportunity Cost — V4 shared stylesheet
   Light theme by default; dark via [data-theme="dark"]
   (set by system preference or the header toggle).
   ========================================================== */

:root {
  --bg: #FAFAF7;
  --surface: #FFFFFF;
  --surface-2: #F3F3EE;
  --text: #16181D;
  --muted: #5B606B;
  --border: #E4E4DF;
  --accent: #D9480F;
  --accent-soft: #FDEDE5;
  --accent-text: #FFFFFF;
  --focus: #2F5BEA;
  --shadow: 0 1px 2px rgba(16,18,24,.04), 0 8px 24px rgba(16,18,24,.06);
  --radius: 14px;
  --radius-sm: 10px;
  --maxw: 1080px;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Instrument Serif", Georgia, "Times New Roman", serif;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0F1115;
  --surface: #171A20;
  --surface-2: #1D2129;
  --text: #ECEDEF;
  --muted: #9AA0AA;
  --border: #2A2F39;
  --accent: #FF7A45;
  --accent-soft: #2A1A12;
  --accent-text: #16181D;
  --focus: #7C9BFF;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.6;
  transition: background-color .2s ease, color .2s ease;
}
img, svg, canvas { max-width: 100%; display: block; }
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }

.container { max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }
.narrow { max-width: 720px; }

.skip-link { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }
.skip-link:focus { left: 8px; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; gap: 16px; height: 64px; }
.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--text); text-decoration: none; font-weight: 700; letter-spacing: -.01em;
  white-space: nowrap;
}
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; background: var(--accent);
  display: grid; place-items: center; color: var(--accent-text); font-family: var(--font-display); font-size: 20px; line-height: 1;
}
.nav { display: flex; gap: 4px; margin-left: auto; }
.nav a {
  color: var(--muted); text-decoration: none; font-size: 15px; font-weight: 500;
  padding: 8px 12px; border-radius: 8px;
}
.nav a:hover, .nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); }

/* Theme switch */
.theme-switch {
  display: inline-flex; align-items: center; gap: 8px; flex-shrink: 0;
  background: none; border: 0; padding: 4px; cursor: pointer; color: var(--muted); font: inherit; font-size: 14px;
}
.theme-switch .track {
  width: 46px; height: 26px; border-radius: 999px; background: var(--surface-2);
  border: 1px solid var(--border); position: relative; transition: background .2s;
}
.theme-switch .thumb {
  position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.25);
  display: grid; place-items: center; font-size: 12px; transition: transform .2s ease;
}
:root[data-theme="dark"] .theme-switch .track { background: var(--accent); border-color: var(--accent); }
:root[data-theme="dark"] .theme-switch .thumb { transform: translateX(20px); background: #16181D; }
.theme-switch .thumb::before { content: "☀"; color: #B7791F; }
:root[data-theme="dark"] .theme-switch .thumb::before { content: "☾"; color: #FFD27A; }

.menu-btn { display: none; }

@media (max-width: 720px) {
  .nav { display: none; position: absolute; top: 64px; left: 0; right: 0; flex-direction: column;
         background: var(--bg); border-bottom: 1px solid var(--border); padding: 8px 20px 16px; }
  .nav.open { display: flex; }
  .menu-btn {
    display: inline-flex; margin-left: auto; background: none; border: 1px solid var(--border);
    color: var(--text); border-radius: 8px; padding: 6px 10px; font: inherit; font-size: 14px; cursor: pointer;
  }
  .theme-switch .label { display: none; }
}

/* ---------- Type ---------- */
h1, h2, h3 { line-height: 1.15; letter-spacing: -.02em; margin: 0 0 .5em; }
/* V2 experiment: page titles use the same font as card headings like "Your commute" (Inter, bold).
   To revert to the serif titles, restore: font-family: var(--font-display); font-weight: 400; letter-spacing: -.01em; */
h1 { font-family: var(--font-body); font-weight: 700; font-size: clamp(36px, 5.5vw, 56px); letter-spacing: -.03em; text-wrap: balance; }
h2 { font-size: clamp(24px, 3vw, 30px); }
h3 { font-size: 19px; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: 12px; font-weight: 600; color: var(--accent); margin: 0 0 12px; }
.lede { font-size: 19px; color: var(--muted); max-width: 640px; margin: 0; }
.muted { color: var(--muted); }
.lines span { display: block; }          /* one sentence per line (V3) */
.lede-wide { max-width: 760px; }         /* keeps the scrolling lede on one line on desktop (V3) */
.lede-home { max-width: 760px; }         /* home lede runs slightly past the title (V4) */
.small { font-size: 14px; }

/* ---------- Layout sections ---------- */
.hero { padding: 56px 0 28px; }
.section { padding: 40px 0; }
.section + .section { border-top: 1px solid var(--border); }

/* ---------- Calculator ---------- */
.calc {
  display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 20px; align-items: start;
  padding-bottom: 24px;
}
@media (max-width: 860px) { .calc { grid-template-columns: 1fr; } }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 24px;
}
.card h2 { font-size: 20px; margin-bottom: 4px; }

.field { margin-top: 18px; }
.field label { display: block; font-weight: 600; font-size: 15px; margin-bottom: 6px; }
.field .hint { display: block; font-weight: 400; color: var(--muted); font-size: 13px; margin-top: 2px; }
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap input {
  width: 100%; font: inherit; font-size: 18px; font-variant-numeric: tabular-nums;
  padding: 12px 84px 12px 14px; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius-sm); appearance: textfield; -moz-appearance: textfield;
}
.input-wrap input::-webkit-outer-spin-button, .input-wrap input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.input-wrap input:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.input-wrap .unit { position: absolute; right: 14px; color: var(--muted); font-size: 14px; pointer-events: none; }
/* Dropdowns (V3) */
.select-wrap select {
  width: 100%; font: inherit; font-size: 17px; color: var(--text); background: var(--bg);
  padding: 12px 40px 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  appearance: none; -webkit-appearance: none; cursor: pointer;
}
.select-wrap::after {
  content: ""; position: absolute; right: 16px; top: 50%; width: 8px; height: 8px; margin-top: -6px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); pointer-events: none;
}
.select-wrap select:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-row .field { margin-top: 18px; }
.field input[aria-invalid="true"] { border-color: #C92A2A; }
.error-msg { color: #C92A2A; font-size: 13px; margin-top: 4px; min-height: 0; }
:root[data-theme="dark"] .error-msg { color: #FF8787; }

details.assumptions { margin-top: 20px; border-top: 1px solid var(--border); padding-top: 14px; }
details.assumptions summary { cursor: pointer; font-weight: 600; font-size: 14px; color: var(--muted); }
details.assumptions[open] summary { color: var(--text); }

/* Results */
.results { position: sticky; top: 84px; }
@media (max-width: 860px) { .results { position: static; } }
.result-headline { font-size: 15px; color: var(--muted); margin: 0 0 4px; }
.big-number {
  font-family: var(--font-display); font-size: clamp(48px, 8vw, 76px); line-height: 1; letter-spacing: -.01em;
  color: var(--accent); font-variant-numeric: tabular-nums; margin: 4px 0 6px;
}
.big-sub { color: var(--muted); margin: 0 0 20px; }
.big-number .big-unit { font-family: inherit; font-size: .38em; color: var(--muted); margin-left: .3em; letter-spacing: 0; }
.big-number:has(.big-unit) { margin-bottom: 20px; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--surface-2); border-radius: var(--radius-sm); padding: 14px; }
.stat .value { font-size: 24px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .label { font-size: 13px; color: var(--muted); }

.breakdown { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
.breakdown table { width: 100%; border-collapse: collapse; font-size: 15px; font-variant-numeric: tabular-nums; }
.breakdown th, .breakdown td { text-align: right; padding: 6px 0; }
.breakdown th:first-child, .breakdown td:first-child { text-align: left; }
.breakdown th { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.breakdown tr + tr td { border-top: 1px solid var(--border); }
.breakdown tr.total td { font-weight: 700; }

.bar { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 8px 0 4px; display: flex; }
.bar span { display: block; height: 100%; }
.bar .past { background: color-mix(in srgb, var(--accent) 45%, var(--surface-2)); }
.bar .future { background: var(--accent); }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

.equivalents { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
.equivalents ul { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 8px; }
.equivalents li { display: flex; gap: 10px; align-items: baseline; font-size: 15px; }
.equivalents li strong { font-variant-numeric: tabular-nums; min-width: 64px; }

.whatif { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.chip {
  font: inherit; font-size: 14px; padding: 6px 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.whatif-out { font-size: 15px; margin: 0; }
.whatif-out strong { color: var(--accent); }

.share { margin-top: 20px; display: flex; flex-wrap: wrap; gap: 10px; }
.btn {
  font: inherit; font-size: 15px; font-weight: 600; padding: 10px 16px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none;
  display: inline-flex; align-items: center; gap: 8px;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.06); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  transition: all .2s ease; pointer-events: none; z-index: 20;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Share preview modal */
.modal { border: 0; padding: 0; border-radius: var(--radius); background: var(--surface); color: var(--text); max-width: min(520px, 92vw); box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(10,12,16,.55); }
.modal-body { padding: 20px; }
.modal-body canvas { width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--border); }
.modal-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; justify-content: flex-end; }

/* ---------- Vaping-$ (V4) ---------- */
/* Disposable / rechargeable switch */
.seg {
  position: relative; display: grid; grid-template-columns: 1fr 1fr; margin-top: 16px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 3px;
}
.seg button {
  position: relative; z-index: 1; font: inherit; font-size: 15px; font-weight: 600; cursor: pointer;
  background: none; border: 0; border-radius: 999px; padding: 8px 10px; color: var(--muted); transition: color .2s;
}
.seg button[aria-checked="true"] { color: var(--accent-text); }
.seg .seg-thumb {
  position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc(50% - 3px); border-radius: 999px;
  background: var(--accent); transition: transform .22s ease;
}
.seg[data-mode="rechargeable"] .seg-thumb { transform: translateX(100%); }
.mode-note { margin: 10px 0 0; }

/* A cost group: price each + how many per week/month/year */
.cost-group { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.cost-group:first-of-type { border-top: 0; padding-top: 0; }
.cost-group > .group-title { font-weight: 700; font-size: 16px; margin: 0; }
.cost-group > .group-hint { color: var(--muted); font-size: 13px; margin: 2px 0 0; }
.cost-group .field { margin-top: 10px; }
.input-wrap.prefix input { padding: 12px 12px 12px 30px; }
.input-wrap.prefix .unit { left: 14px; right: auto; font-size: 18px; color: var(--muted); }
.freq { display: flex; gap: 6px; }
.freq .input-wrap { flex: 0 0 64px; min-width: 0; }
.freq .input-wrap input { padding-right: 10px; }
.freq .select-wrap { flex: 1 1 auto; min-width: 0; }
.freq .select-wrap select { padding: 12px 28px 12px 12px; font-size: 16px; }
.freq .select-wrap::after { right: 12px; }
@media (max-width: 520px) { .cost-group .field-row { grid-template-columns: 1fr; gap: 0; } }
.field select[aria-invalid="true"] { border-color: #C92A2A; }

/* "If invested" section with chart */
.invest { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
.invest-summary { font-size: 15px; margin: 6px 0 0; }
.invest-summary strong { font-variant-numeric: tabular-nums; }
.chart-legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
.chart-legend .key { display: inline-block; width: 16px; height: 2px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.chart-wrap { position: relative; }
.chart-wrap svg { width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.chart-wrap svg:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; }
.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-axis-text { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart-label { fill: var(--text); font-size: 12px; font-weight: 600; }
.line-invest { stroke: var(--accent); }
.line-spent { stroke: var(--muted); }
.area-invest { fill: var(--accent); opacity: .1; }
.chart-cross { stroke: var(--muted); stroke-width: 1; }
.chart-dot { stroke: var(--surface); stroke-width: 2; }
.chart-tip {
  position: absolute; top: 0; pointer-events: none; z-index: 2; min-width: 150px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
  padding: 8px 10px; font-size: 13px; line-height: 1.4;
}
.chart-tip .tip-head { color: var(--muted); font-size: 12px; margin-bottom: 2px; }
.chart-tip .tip-row { display: flex; align-items: center; gap: 8px; }
.chart-tip .tip-row strong { font-size: 15px; font-variant-numeric: tabular-nums; }
.chart-tip .tip-row span { color: var(--muted); }
.chart-tip .key { width: 12px; height: 2px; border-radius: 2px; flex-shrink: 0; }
.key-invest { background: var(--accent); }
.key-spent { background: var(--muted); }
.chart-table { margin-top: 10px; font-size: 14px; }
.chart-table summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.chart-table table { width: 100%; border-collapse: collapse; margin-top: 8px; font-variant-numeric: tabular-nums; }
.chart-table th, .chart-table td { text-align: right; padding: 4px 0; }
.chart-table th:first-child, .chart-table td:first-child { text-align: left; }
.chart-table th { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.chart-table tr + tr td { border-top: 1px solid var(--border); }

/* ---------- Article / guide content ---------- */
.prose { max-width: 720px; }
.prose h2 { margin-top: 8px; }
.prose h3 { margin-top: 28px; }
.prose p, .prose li { color: var(--text); }
.prose ul, .prose ol { padding-left: 22px; }
.prose li + li { margin-top: 6px; }
.callout { background: var(--accent-soft); border-left: 3px solid var(--accent); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; padding: 14px 18px; margin: 20px 0; }
.formula { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 14px; background: var(--surface-2); padding: 12px 14px; border-radius: var(--radius-sm); overflow-x: auto; }

.tips { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin-top: 16px; }
.tip { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.tip h3 { font-size: 17px; margin-bottom: 6px; }
.tip p { margin: 0; font-size: 15px; color: var(--muted); }

.faq details { border-bottom: 1px solid var(--border); padding: 14px 0; }
.faq summary { cursor: pointer; font-weight: 600; }
.faq details p { margin: 10px 0 0; color: var(--muted); }

.sources { font-size: 14px; color: var(--muted); }
.sources li + li { margin-top: 4px; }

/* ---------- Home ---------- */
.calc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; margin-top: 28px; }
.calc-card {
  display: block; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px;
  box-shadow: var(--shadow); transition: transform .15s ease, border-color .15s ease;
}
.calc-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.calc-card .icon { width: 40px; height: 40px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin-bottom: 14px; }
.calc-card h3 { font-size: 21px; margin-bottom: 6px; }
.calc-card p { margin: 0; color: var(--muted); font-size: 15px; }
.calc-card .go { display: inline-block; margin-top: 14px; color: var(--accent); font-weight: 600; font-size: 15px; }
.calc-card.soon { opacity: .6; pointer-events: none; box-shadow: none; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; background: var(--surface-2); color: var(--muted); padding: 3px 8px; border-radius: 999px; margin-left: 6px; vertical-align: middle; }

/* ---------- Ad slot placeholders (hidden until ads are wired up) ---------- */
.ad-slot { display: none; }
body.show-ad-slots .ad-slot {
  display: grid; place-items: center; min-height: 100px; margin: 24px 0;
  border: 1px dashed var(--border); border-radius: var(--radius-sm); color: var(--muted); font-size: 13px;
}

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--border); margin-top: 48px; padding: 28px 0 40px; color: var(--muted); font-size: 14px; }
.footer-inner { display: flex; flex-wrap: wrap; gap: 12px 24px; justify-content: space-between; }
.footer-links { display: flex; gap: 16px; flex-wrap: wrap; }
.footer-links a { color: var(--muted); }

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