/* Dataworld design system: tokens, base elements and shared components used by every page. */

:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f4f6ff;
  --text: #0e1330;
  --muted: #59617f;
  --border: #e1e5f2;
  --accent: #4353ff;
  --accent-ink: #ffffff;
  --accent-soft: #eceeff;
  --accent-2: #9b3dff;
  --success: #1f8a4c;
  --success-soft: #e3f4ea;
  --warning: #a8630b;
  --warning-soft: #fcf0dc;
  --danger: #c2392b;
  --danger-soft: #fbe6e3;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgb(30 40 120 / 6%), 0 10px 28px rgb(30 40 120 / 9%);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Fraunces", Georgia, serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --page: 1120px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --gutter: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0c1a;
    --surface: #121530;
    --surface-2: #161a3a;
    --text: #f2f4ff;
    --muted: #a3aacb;
    --border: #272c55;
    --accent: #8a96ff;
    --accent-ink: #0a0c1a;
    --accent-soft: #1d2252;
    --accent-2: #c99bff;
    --success: #5cc98a;
    --success-soft: #16301f;
    --warning: #e6a54a;
    --warning-soft: #33260f;
    --danger: #f07a6c;
    --danger-soft: #3a1b17;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}
img, svg { max-width: 100%; display: block; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.15; margin: 0 0 0.5em; letter-spacing: -0.01em; }
h1 { font-size: clamp(2.1rem, 5vw, 3.4rem); }
h2 { font-size: clamp(1.6rem, 3.4vw, 2.2rem); }
h3 { font-size: 1.2rem; }
p { margin: 0 0 1em; }
small, .muted { color: var(--muted); }
code, pre { font-family: var(--mono); font-size: 0.9em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.container { max-width: var(--page); margin: 0 auto; padding: 0 var(--gutter); }
.section { padding: clamp(48px, 8vw, 96px) 0; }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.eyebrow { font-size: 0.8rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
.lead { font-size: 1.15rem; color: var(--muted); max-width: 60ch; }

/* ---------- Navigation ---------- */
.nav { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid transparent; transition: border-color 0.2s; }
.nav.scrolled { border-bottom-color: var(--border); }
.nav-inner { display: flex; align-items: center; gap: 24px; height: 64px; }
.brand { font-family: var(--font-display); font-weight: 700; font-size: 1.25rem; color: var(--text); text-decoration: none; display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 26px; height: 26px; flex: none; display: block; }
.brand:hover .brand-mark { transform: rotate(-6deg); }
.brand-mark { transition: transform 0.35s var(--ease); }
.nav-links { display: flex; gap: 4px; margin-left: auto; align-items: center; }
.nav-links a:not(.btn) { color: color-mix(in srgb, var(--text) 82%, transparent); text-decoration: none; font-size: 0.95rem; font-weight: 600; padding: 8px 14px; border-radius: 999px; }
.nav-links a:not(.btn):hover { color: var(--text); background: color-mix(in srgb, var(--text) 7%, transparent); }
.nav-links a[aria-current="page"] { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.nav-links a.btn, .nav-links a.btn:hover { color: var(--accent-ink); }
.nav-sep { width: 1px; height: 22px; background: var(--border); margin: 0 10px; }
.nav-toggle { display: none; margin-left: auto; background: none; border: 0; color: var(--text); font-size: 1.4rem; cursor: pointer; }
@media (max-width: 960px) {
  .nav-toggle { display: block; }
  .nav-links { display: none; position: absolute; top: 64px; left: 0; right: 0; flex-direction: column; align-items: stretch; gap: 0; background: var(--surface); border-bottom: 1px solid var(--border); padding: 8px var(--gutter) 16px; }
  .nav-links.open { display: flex; }
  .nav-links a:not(.btn) { padding: 12px 10px; border-radius: 10px; }
  .nav-sep { display: none; }
  .nav-links a.btn { margin-top: 8px; }
}

.footer { border-top: 1px solid var(--border); padding: 40px 0; color: var(--muted); font-size: 0.9rem; }
.footer-inner { display: flex; gap: 24px; flex-wrap: wrap; justify-content: space-between; }
.footer a { color: var(--muted); text-decoration: none; margin-right: 16px; }
.footer a:hover { color: var(--text); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 20px; border-radius: 999px; border: 1px solid transparent;
  font: 600 0.95rem/1 var(--font); text-decoration: none; cursor: pointer; white-space: nowrap;
  background: var(--accent); color: var(--accent-ink);
  transition: filter 0.2s var(--ease), transform 0.2s var(--ease), box-shadow 0.2s var(--ease), background-color 0.2s var(--ease);
}
.btn:hover { filter: brightness(1.08); transform: translateY(-1px); box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 28%, transparent); }
.btn-secondary:hover, .btn-ghost:hover { box-shadow: 0 4px 14px rgb(30 40 120 / 10%); }
.btn:active { transform: translateY(0) scale(0.98); transition-duration: 0.06s; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; filter: none; }
.btn:not(.btn-secondary, .btn-ghost, .btn-danger, .btn-light, .btn-outline-light) { background-image: linear-gradient(120deg, var(--accent), var(--accent-2)); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost { background: transparent; color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { min-height: 34px; padding: 0 14px; font-size: 0.85rem; }
.btn-block { width: 100%; }
.btn[aria-busy="true"]::after { content: ""; width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span, .label { font-size: 0.88rem; font-weight: 600; }
.field .hint { font-size: 0.82rem; color: var(--muted); font-weight: 400; }
.input, .select, .textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit;
}
.textarea { min-height: 110px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.form-error { color: var(--danger); background: var(--danger-soft); padding: 10px 12px; border-radius: var(--radius-sm); font-size: 0.9rem; }
.hp { position: absolute !important; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

/* Option cards and chips for one-question-per-screen flows. */
.options { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.other-sources { margin-top: 16px; }
.option { position: relative; display: flex; gap: 10px; align-items: flex-start; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); cursor: pointer; }
.option:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.option input { position: absolute; opacity: 0; pointer-events: none; }
.option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.option:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); font-size: 0.88rem; cursor: pointer; }
.chip:has(input:checked), .chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip input { position: absolute; opacity: 0; pointer-events: none; }

.progress { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); transition: width 0.3s; }

/* ---------- Surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.card-elevated { box-shadow: var(--shadow); border-color: transparent; }
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat b { font-size: 1.6rem; font-family: var(--font-display); }
.stat span { color: var(--muted); font-size: 0.85rem; }
.divider { border: 0; border-top: 1px solid var(--border); margin: 24px 0; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); background: var(--surface-2); font-weight: 600; }
.table tr:last-child td { border-bottom: 0; }

/* ---------- Overlays ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgb(10 10 8 / 45%); display: flex; align-items: flex-start; justify-content: center; padding: 6vh var(--gutter); overflow-y: auto; }
.modal { width: 100%; max-width: 560px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }
.modal-wide { max-width: 860px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.modal-head h2 { font-size: 1.35rem; margin: 0; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; z-index: 40; width: min(640px, 100vw); background: var(--surface); box-shadow: var(--shadow); overflow-y: auto; padding: 24px; }
.close { background: none; border: 0; font-size: 1.5rem; line-height: 1; color: var(--muted); cursor: pointer; padding: 4px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 0.9rem; box-shadow: var(--shadow); }

/* ---------- Estimate display ---------- */
.estimate { font-family: var(--font-display); font-size: clamp(2rem, 5vw, 3rem); font-weight: 700; letter-spacing: -0.02em; }
.meter { position: relative; height: 10px; border-radius: 999px; background: linear-gradient(90deg, var(--surface-2), var(--accent-soft), var(--accent)); }
.meter > i { position: absolute; top: 50%; width: 18px; height: 18px; border-radius: 50%; background: var(--accent); border: 3px solid var(--surface); transform: translate(-50%, -50%); box-shadow: var(--shadow); }
.bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }


/* ---------- Motion ---------- */

/* Pages cross-fade instead of flashing white; the header stays put. */
@view-transition { navigation: auto; }
.nav { view-transition-name: site-header; }
::view-transition-old(root) { animation: 160ms var(--ease) both vt-out; }
::view-transition-new(root) { animation: 260ms var(--ease) both vt-in; }
@keyframes vt-out { to { opacity: 0; transform: translateY(-6px); } }
@keyframes vt-in { from { opacity: 0; transform: translateY(8px); } }

/* Scroll reveal: only hidden once motion.js has confirmed it will reveal them. */
html.motion [data-reveal] { opacity: 0; transform: translateY(18px); transition: opacity 0.7s var(--ease) var(--reveal-delay, 0ms), transform 0.7s var(--ease) var(--reveal-delay, 0ms); }
html.motion [data-reveal].is-revealed { opacity: 1; transform: none; }

/* Interactive surfaces respond to hover and press. */
a.card, .card-link, .option, .chip { transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease), border-color 0.2s, background-color 0.2s; }
a.card:hover, .card-link:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
.option:hover, .chip:hover { transform: translateY(-1px); }
.option:active, .chip:active, a.card:active { transform: scale(0.985); }
.nav-links a { transition: color 0.2s, background-color 0.2s; }
.input, .select, .textarea { transition: border-color 0.2s, box-shadow 0.2s; }
.progress > i, .bar > i { transition: width 0.5s var(--ease); }
.meter > i { transition: left 0.6s var(--ease); }

/* Dialogs, drawers and toasts ease in and out. */
.modal-backdrop { animation: fade-in 0.2s var(--ease) both; }
.modal-backdrop > .modal { animation: pop-in 0.28s var(--ease) both; }
.modal-backdrop.closing { animation: fade-out 0.16s ease-in both; }
.modal-backdrop.closing > .modal { animation: pop-out 0.16s ease-in both; }
.drawer { animation: slide-in 0.32s var(--ease) both; }
.toast { animation: toast-in 0.3s var(--ease) both; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(12px) scale(0.97); } }
@keyframes pop-out { to { opacity: 0; transform: translateY(6px) scale(0.98); } }
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 12px); } }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after, ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { transition: none !important; animation: none !important; }
}

/* Visually hidden but available to screen readers; skip link appears on focus. */
.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: 8px; top: -48px; z-index: 100; padding: 8px 12px; border-radius: var(--radius-sm); background: var(--text); color: var(--bg); }
.skip-link:focus { top: 8px; }

/* Demo mode banner (assets/demo.js). */
.demo-bar {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 50; width: min(720px, calc(100% - 32px));
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 10px 14px; border-radius: 12px;
  background: #1d2433; color: #fff; font-size: 0.88rem; box-shadow: 0 10px 30px rgb(0 0 0 / 0.25);
}
.demo-bar span { flex: 1 1 260px; }
.demo-bar b { margin-right: 6px; color: #ffd66b; }
.demo-bar a { color: #cfe0ff; }
.demo-bar button { background: #fff; color: #1d2433; border: 0; border-radius: 8px; padding: 6px 10px; font: 600 0.85rem/1 var(--font); cursor: pointer; }
body.has-demo-bar { padding-bottom: 96px; }
