*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:      #4f46e5;
  --primary-dark: #3730a3;
  --primary-bg:   #eef2ff;
  --agree:        #059669;
  --agree-bg:     #d1fae5;
  --disagree:     #dc2626;
  --disagree-bg:  #fee2e2;
  --consider:     #d97706;
  --consider-bg:  #fef3c7;
  --surface:      #ffffff;
  --bg:           #f8fafc;
  --text:         #0f172a;
  --muted:        #64748b;
  --border:       #e2e8f0;
  --radius:       12px;
  --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg:    0 10px 25px rgba(0,0,0,.10), 0 4px 10px rgba(0,0,0,.05);
  color-scheme: light;
}

/* ── Dark theme ──
   Overrides the palette only; every component already reads these variables,
   so the whole UI re-themes from here. A handful of components below use
   hardcoded light tints (factor buttons, skip badges) and get explicit
   dark overrides further down. */
[data-theme="dark"] {
  --primary:      #a5b4fc;
  --primary-dark: #c7d2fe;
  --primary-bg:   #1e1b4b;
  --agree:        #34d399;
  --agree-bg:     #064e3b;
  --disagree:     #f87171;
  --disagree-bg:  #4c1d1d;
  --consider:     #fbbf24;
  --consider-bg:  #422006;
  --surface:      #1e293b;
  --bg:           #0f172a;
  --text:         #f8fafc;
  --muted:        #aab6c8;
  --border:       #334155;
  --shadow:       0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
  --shadow-lg:    0 12px 28px rgba(0,0,0,.55), 0 4px 12px rgba(0,0,0,.4);
  color-scheme: dark;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Header ── */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
}
.logo {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.5px;
  cursor: pointer;
}
.logo em { color: var(--text); font-style: normal; }
.logo sub { font-size: .6rem; font-weight: 400; color: var(--muted); vertical-align: baseline; margin-left: 3px; }

.header-right { display: flex; align-items: center; gap: 16px; }
.header-meta  { font-size: .8rem; color: var(--muted); }
.about-link {
  font-size: .85rem;
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 6px;
  transition: background .15s, color .15s;
}
.about-link:hover { background: var(--bg); color: var(--text); }

.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.05rem;
  line-height: 1;
  padding: 6px 9px;
  border-radius: 6px;
  transition: background .15s;
}
.theme-toggle:hover { background: var(--bg); }

/* ── Progress ── */
.progress-wrap {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 24px;
  position: sticky;
  top: 53px;
  z-index: 19;
}
.progress-inner { max-width: 760px; margin: 0 auto; }
.progress-label {
  font-size: .7rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 6px;
}
.progress-track { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.crumb {
  font-size: .72rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 5px;
  letter-spacing: .03em;
}
.crumb.done   { background: var(--primary-bg); color: var(--primary); }
.crumb.active { background: var(--primary); color: #fff; }
.crumb.leaf-yes { background: var(--agree-bg); color: var(--agree); }
.crumb.leaf-no  { background: var(--disagree-bg); color: var(--disagree); }
.crumb-sep { color: var(--muted); font-size: .8rem; }

/* ── Main ── */
main {
  max-width: 760px;
  margin: 0 auto;
  padding: 36px 24px 72px;
}

/* ── Screens ── */
.screen { display: none; }
.screen.active { display: block; animation: fadeUp .22s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── Welcome ── */
.hero {
  text-align: center;
  padding: 44px 0 36px;
}
.badge {
  display: inline-block;
  background: var(--primary-bg);
  color: var(--primary);
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 4px 12px;
  border-radius: 999px;
  margin-bottom: 20px;
}
.hero h1 {
  font-size: 2.5rem;
  font-weight: 900;
  line-height: 1.12;
  letter-spacing: -.6px;
  margin-bottom: 14px;
}
.hero h1 span { color: var(--primary); }
.hero p {
  font-size: 1rem;
  color: var(--muted);
  max-width: 500px;
  margin: 0 auto 36px;
}

.proof-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 36px;
  flex-wrap: wrap;
}
.proof-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: .82rem;
  color: var(--muted);
  font-weight: 500;
}
.proof-pill-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--primary);
  flex-shrink: 0;
}

/* Start form & import */
.mode-tabs {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border);
}
.mode-tab {
  padding: 10px 18px;
  background: none;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: .9rem;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: color .15s;
}
.mode-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.mode-tab:hover { color: var(--text); }

.start-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 28px;
  max-width: 480px;
  margin: 0 auto;
  text-align: left;
}
.start-form label {
  display: block;
  font-weight: 700;
  font-size: .9rem;
  margin-bottom: 8px;
}
.start-form input,
.start-form textarea {
  width: 100%;
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 11px 14px;
  font-size: 1rem;
  font-family: inherit;
  background: var(--bg);
  transition: border-color .2s;
  margin-bottom: 16px;
}
.start-form input:focus,
.start-form textarea:focus { outline: none; border-color: var(--primary); background: var(--surface); }

.file-upload-zone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 24px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  margin-bottom: 12px;
}
.file-upload-zone:hover { border-color: var(--primary); background: var(--primary-bg); }
.file-upload-zone.active { border-color: var(--primary); background: var(--primary-bg); }
.file-upload-zone input { display: none; }
.upload-icon { font-size: 2rem; margin-bottom: 8px; }
.upload-text { font-size: .875rem; color: var(--muted); }
.upload-text strong { color: var(--text); }

.mode-hint {
  font-size: .78rem;
  color: var(--muted);
  text-align: center;
  margin-top: 12px;
}

.loading-spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.api-error {
  background: var(--disagree-bg);
  border: 1px solid var(--disagree);
  color: var(--disagree);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: .875rem;
  margin-bottom: 16px;
}

/* ── Gate screen ── */
.gate-intro { margin-bottom: 22px; }
.gate-label {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--primary);
  margin-bottom: 6px;
}
.gate-intro h2 { font-size: 1.4rem; font-weight: 800; margin-bottom: 5px; }
.gate-intro p  { color: var(--muted); font-size: .9rem; line-height: 1.55; }

.factors-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 22px; }

.factor-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 18px;
  transition: border-color .18s;
  position: relative;
}
.factor-card.is-agree    { border-color: var(--agree); }
.factor-card.is-disagree { border-color: var(--disagree); }
.factor-card.is-unsure   { border-color: #94a3b8; }

.factor-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.factor-id   { font-size: .62rem; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.factor-badge {
  display: inline-block;
  font-size: .62rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: .08em;
  flex-shrink: 0;
}
.factor-badge.ai    { background: var(--primary-bg); color: var(--primary); }
.factor-badge.skip  { background: #f1f5f9; color: #94a3b8; }

.factor-text { font-size: .9375rem; font-weight: 500; margin-bottom: 12px; line-height: 1.5; }

.factor-btns { display: flex; gap: 8px; }
.fbt {
  flex: 1;
  padding: 7px 10px;
  border-radius: 7px;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all .12s;
  line-height: 1;
}
.fbt-agree    { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }
.fbt-agree:hover, .fbt-agree.on    { background: var(--agree-bg); border-color: var(--agree); }
.fbt-unsure   { background: #f8fafc; color: #475569; border-color: var(--border); }
.fbt-unsure:hover, .fbt-unsure.on  { background: #e2e8f0; border-color: #94a3b8; }
.fbt-disagree { background: #fff1f2; color: #991b1b; border-color: #fecdd3; }
.fbt-disagree:hover, .fbt-disagree.on { background: var(--disagree-bg); border-color: var(--disagree); }

/* ── Step nav ── */
.step-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.answered-count { font-size: .82rem; color: var(--muted); text-align: center; flex: 1; }
.answered-count.warn { color: var(--disagree); font-weight: 600; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 22px;
  border-radius: 8px;
  font-size: .9375rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: all .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.btn-ghost { background: var(--surface); color: var(--text); border: 2px solid var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-full { width: 100%; justify-content: center; }

/* ── Results ── */
.verdict-card {
  border-radius: 16px;
  padding: 32px 28px;
  text-align: center;
  margin-bottom: 24px;
  box-shadow: var(--shadow-lg);
}
.verdict-icon  { font-size: 3.5rem; margin-bottom: 10px; }
.verdict-title { font-size: 1.9rem; font-weight: 900; letter-spacing: -.5px; margin-bottom: 10px; }
.verdict-msg   { font-size: .9375rem; color: var(--muted); max-width: 500px; margin: 0 auto; line-height: 1.6; }

.score-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 22px;
  margin-bottom: 22px;
}
.score-block-title { font-size: .875rem; font-weight: 700; margin-bottom: 12px; }
.score-track { height: 10px; background: var(--border); border-radius: 5px; overflow: hidden; margin-bottom: 6px; }
.score-fill  { height: 100%; border-radius: 5px; transition: width .55s ease; }
.score-ends  { display: flex; justify-content: space-between; font-size: .72rem; color: var(--muted); }

.breakdown-title { font-size: .875rem; font-weight: 700; margin-bottom: 12px; }
.breakdown-list  { display: flex; flex-direction: column; gap: 8px; }
.breakdown-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.bd-badge {
  width: 36px; height: 36px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: .72rem; font-weight: 800;
  flex-shrink: 0;
}
.bd-badge.pass { background: var(--agree-bg); color: var(--agree); }
.bd-badge.fail { background: var(--disagree-bg); color: var(--disagree); }
.bd-badge.skip { background: #f1f5f9; color: #94a3b8; }
.bd-info { flex: 1; }
.bd-name { font-weight: 600; font-size: .9rem; }
.bd-sub  { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.bd-verdict { font-weight: 700; font-size: .85rem; }
.bd-verdict.pass { color: var(--agree); }
.bd-verdict.fail { color: var(--disagree); }
.bd-verdict.skip { color: #94a3b8; }

.results-title { font-size: 1.25rem; font-weight: 800; margin-bottom: 20px; }
.results-actions { display: flex; gap: 12px; justify-content: center; margin-top: 28px; flex-wrap: wrap; }

/* ── Landing "how it works" link ── */
.link-btn {
  display: block;
  margin: 18px auto 0;
  background: none;
  border: none;
  color: var(--primary);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 8px;
  transition: background .15s;
}
.link-btn:hover { background: var(--primary-bg); }

/* ── Decision tree visualization ── */
.tree-viz { width: 100%; }
.tree-viz svg { width: 100%; height: auto; display: block; }
.tree-viz .tnode rect,
.tree-viz .tchip rect { transition: opacity .2s; }

/* Animated state (loading screen) */
.tree-viz.animating .tnode { animation: tnodePulse 1.8s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.tree-viz.animating .tedge { stroke-dasharray: 6 6; animation: tedgeFlow 1s linear infinite; }
@keyframes tnodePulse { 0%, 100% { opacity: .5; } 50% { opacity: 1; } }
@keyframes tedgeFlow  { to { stroke-dashoffset: -12; } }

/* ── Loading screen ── */
.loading-wrap { text-align: center; padding: 28px 0 12px; }
.loading-status {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--text);
  min-height: 1.5em;
}
.loading-sub { font-size: .9rem; color: var(--muted); margin: 6px 0 24px; }

/* ── Tree modal legend ── */
.modal-wide { max-width: 760px; }
.tree-legend { font-size: .875rem; color: var(--muted); line-height: 1.7; margin-bottom: 18px; }
.lg { font-weight: 700; padding: 1px 7px; border-radius: 5px; white-space: nowrap; }
.lg-agree  { color: var(--agree);    background: var(--agree-bg); }
.lg-dis    { color: var(--disagree); background: var(--disagree-bg); }
.lg-auto   { color: var(--agree);    background: var(--agree-bg); }
.lg-manual { color: var(--disagree); background: var(--disagree-bg); }

/* ── Tree why (expandable) ── */
.tree-why {
  margin-top: 22px;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.tree-why summary {
  padding: 13px 18px;
  font-weight: 700;
  font-size: .875rem;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--bg);
  color: var(--text);
  user-select: none;
}
.tree-why summary::-webkit-details-marker { display: none; }
.tree-why summary::after {
  content: '▸';
  font-size: .8rem;
  color: var(--muted);
  transition: transform .18s;
}
.tree-why[open] summary::after { transform: rotate(90deg); }
.tree-why[open] summary { border-bottom: 1px solid var(--border); }
.tree-why-body {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.tree-why-body > p {
  font-size: .875rem;
  color: var(--muted);
  line-height: 1.65;
}
.why-row {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.why-node {
  flex-shrink: 0;
  width: 38px; height: 38px;
  border-radius: 8px;
  background: var(--primary-bg);
  color: var(--primary);
  font-weight: 800;
  font-size: .8rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.why-text {
  font-size: .875rem;
  color: var(--muted);
  line-height: 1.6;
}
.why-text strong { color: var(--text); }

/* ── About modal ── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.5);
  backdrop-filter: blur(4px);
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-backdrop.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: 16px;
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: fadeUp .2s ease;
}
.modal-header {
  padding: 24px 28px 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.modal-header h2 { font-size: 1.3rem; font-weight: 800; }
.modal-close {
  background: var(--bg);
  border: none;
  cursor: pointer;
  width: 32px; height: 32px;
  border-radius: 999px;
  font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
  flex-shrink: 0;
  transition: background .15s;
}
.modal-close:hover { background: var(--border); }
.modal-body { padding: 20px 28px 28px; }

.thesis-meta {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 20px;
  font-size: .875rem;
}
.thesis-meta-row { display: flex; gap: 8px; margin-bottom: 5px; }
.thesis-meta-row:last-child { margin-bottom: 0; }
.meta-key   { font-weight: 600; color: var(--muted); min-width: 110px; }
.meta-value { color: var(--text); }

.about-section { margin-bottom: 20px; }
.about-section h3 { font-size: .9rem; font-weight: 700; margin-bottom: 8px; }
.about-section p  { font-size: .875rem; color: var(--muted); line-height: 1.65; }

.finding-list { list-style: none; padding: 0; }
.finding-list li {
  display: flex;
  gap: 10px;
  font-size: .875rem;
  color: var(--muted);
  padding: 7px 0;
  border-top: 1px solid var(--border);
  line-height: 1.5;
}
.finding-list li:first-child { border-top: none; }
.finding-list li::before { content: "→"; color: var(--primary); font-weight: 700; flex-shrink: 0; }

.portfolio-link {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--primary-bg);
  border: 1px solid #c7d2fe;
  border-radius: 10px;
  padding: 14px 18px;
  text-decoration: none;
  color: var(--primary-dark);
  font-weight: 600;
  font-size: .9rem;
  transition: background .15s;
}
.portfolio-link:hover { background: #dde1fd; }
.portfolio-link-icon { font-size: 1.3rem; }

/* ── Footer ── */
.site-footer {
  text-align: center;
  padding: 20px 24px;
  font-size: .75rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

/* ── Responsive ── */
@media (max-width: 520px) {
  .hero h1 { font-size: 1.8rem; }
  .stat-row { gap: 10px; }
  .stat { min-width: 110px; padding: 12px 14px; }
  .fbt { font-size: .74rem; padding: 6px 6px; }
  .start-form { padding: 18px 18px; }
}

/* ── Dark-theme overrides for components with hardcoded light tints ── */
[data-theme="dark"] .fbt-agree {
  background: rgba(52,211,153,.12); color: #6ee7b7; border-color: rgba(52,211,153,.35);
}
[data-theme="dark"] .fbt-unsure {
  background: rgba(148,163,184,.12); color: #cbd5e1; border-color: var(--border);
}
[data-theme="dark"] .fbt-unsure:hover,
[data-theme="dark"] .fbt-unsure.on {
  background: rgba(148,163,184,.22); border-color: #94a3b8;
}
[data-theme="dark"] .fbt-disagree {
  background: rgba(248,113,113,.12); color: #fca5a5; border-color: rgba(248,113,113,.35);
}
[data-theme="dark"] .factor-badge.skip,
[data-theme="dark"] .bd-badge.skip {
  background: #334155; color: #94a3b8;
}
[data-theme="dark"] .portfolio-link { border-color: #3730a3; }
[data-theme="dark"] .portfolio-link:hover { background: #312e81; }
/* --primary is light in dark mode, so white-on-primary elements need a
   saturated indigo background instead to keep their white text legible. */
[data-theme="dark"] .btn-primary,
[data-theme="dark"] .crumb.active { background: #4f46e5; color: #fff; }
[data-theme="dark"] .btn-primary:hover { background: #6366f1; }

/* Print-only branded header (hidden on screen) */
.print-header { display: none; }
.print-logo {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.5px;
}
.print-logo em { color: var(--text); font-style: normal; }
.print-logo span { font-size: .8rem; font-weight: 400; color: var(--muted); }
.print-tagline { font-size: .82rem; color: var(--muted); margin-top: 2px; }

@media print {
  /* Always print on a light palette, even when dark mode is active on screen */
  :root, [data-theme="dark"] {
    --primary: #4f46e5; --primary-dark: #3730a3; --primary-bg: #eef2ff;
    --agree: #059669; --agree-bg: #d1fae5;
    --disagree: #dc2626; --disagree-bg: #fee2e2;
    --surface: #ffffff; --bg: #f8fafc; --text: #0f172a; --muted: #64748b; --border: #e2e8f0;
    color-scheme: light;
  }
  body { background: #fff; }

  .site-header, .progress-wrap, .step-nav, .results-actions,
  .modal-backdrop, .site-footer { display: none !important; }
  main { padding: 0; }

  /* Print only the results screen — never the welcome or gate screens */
  .screen { display: none !important; }
  #screen-results.active { display: block !important; }

  .print-header {
    display: block !important;
    border-bottom: 2px solid var(--border);
    padding-bottom: 12px;
    margin-bottom: 20px;
  }

  /* Keep verdict colours when printing */
  .verdict-card, .bd-badge, .crumb { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
