:root {
  --navy: #0F2D52;
  --navy-2: #1F5A8F;
  --gold: #C9A13B;
  --gold-soft: #F3E8C8;
  --cream: #F7F4EC;
  --paper: #FFFFFF;
  --ink: #1C2433;
  --ink-2: #4A5568;
  --muted: #6B7280;
  --line: #E3DDCC;
  --ok: #2F7D4F;
  --warn: #A26A00;
  --danger: #B42318;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 45, 82, .06), 0 4px 16px rgba(15, 45, 82, .06);
  --serif: 'Lora', Georgia, 'Times New Roman', serif;
  --sans: 'Source Sans 3', 'Segoe UI', system-ui, -apple-system, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--cream); color: var(--ink); font: 16px/1.55 var(--sans); }
a { color: var(--navy-2); }
h1, h2, h3, h4 { font-family: var(--serif); color: var(--navy); line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: clamp(1.7rem, 3.2vw, 2.4rem); }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.1rem; margin-top: 1.4em; }
h4 { font-size: 1rem; }
.container { max-width: 1180px; margin: 0 auto; padding: 24px 16px 48px; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.loading { padding: 60px 0; text-align: center; color: var(--muted); }

/* Header */
.site-header { background: var(--navy); color: #fff; display: flex; align-items: center; justify-content: space-between; padding: 10px 20px; gap: 12px; border-bottom: 3px solid var(--gold); }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-family: var(--serif); font-size: 1.35rem; font-weight: 700; letter-spacing: .01em; }
.brand-sub { font-size: .78rem; text-transform: uppercase; letter-spacing: .12em; color: var(--gold-soft); }
.site-header nav { display: flex; align-items: center; gap: 16px; }
.site-header nav a:not(.btn) { color: #fff; text-decoration: none; font-weight: 600; }
.site-footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 24px 16px 40px; border-top: 1px solid var(--line); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--paper); color: var(--navy); font: 600 .95rem var(--sans); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--navy-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-2); }
.btn-gold { background: var(--gold); border-color: var(--gold); color: var(--navy); }
.btn-danger { color: var(--danger); border-color: #F1C9C5; }
.btn-lg { padding: 12px 20px; font-size: 1.05rem; }

.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); margin-bottom: 22px; }
.pill { display: inline-block; padding: 1px 9px; border-radius: 999px; background: #EEF1F5; color: var(--ink-2); font-size: .8rem; font-weight: 600; }
.pill-ok { background: #E3F1E8; color: var(--ok); }
.pill-warn { background: #FBF0D9; color: var(--warn); }

/* Home */
.hero { display: grid; grid-template-columns: 1.6fr 1fr; gap: 28px; align-items: center; background: linear-gradient(135deg, var(--navy), #183F6E); color: #fff; border-radius: 14px; padding: 34px; margin-bottom: 24px; }
.hero h1 { color: #fff; }
.hero p { color: #DCE4EE; max-width: 60ch; }
.hero .verse { color: var(--gold-soft); border-left-color: var(--gold); }
.verse { font-family: var(--serif); font-style: italic; font-size: 1.1rem; border-left: 3px solid var(--gold); margin: 0; padding: 6px 0 6px 16px; color: var(--ink-2); }
.verse cite { display: block; font-style: normal; font-family: var(--sans); font-size: .85rem; margin-top: 6px; opacity: .85; }
.area-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.area-card { display: block; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; text-decoration: none; color: var(--ink); background: #FDFCF8; transition: border-color .15s, box-shadow .15s; }
.area-card:hover { border-color: var(--gold); box-shadow: var(--shadow); }
.area-card-title { font-family: var(--serif); font-size: 1.15rem; font-weight: 600; color: var(--navy); }
.area-card-classes { color: var(--ink-2); font-size: .92rem; margin: 4px 0; }
.area-card-meta { font-size: .85rem; color: var(--muted); margin-top: 8px; }
.how ol { padding-left: 1.2em; } .how li { margin-bottom: 6px; }

/* Editor */
.editor { display: grid; grid-template-columns: 1fr 380px; gap: 20px; align-items: start; }
.editor-map-wrap { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.map { height: 620px; border-radius: 8px; overflow: hidden; background: #E8EEF3; }
.map-toolbar { display: flex; gap: 10px; justify-content: space-between; flex-wrap: wrap; margin-bottom: 10px; }
.search { display: flex; gap: 6px; flex: 1; min-width: 220px; }
.search input { flex: 1; }
.map-actions { display: flex; gap: 6px; }
.map-help { font-size: .9rem; color: var(--ink-2); margin: 10px 2px 0; }
.editor-form label { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 12px; color: var(--ink-2); }
input, textarea { width: 100%; font: inherit; padding: 8px 10px; border: 1px solid #D6D0BF; border-radius: 7px; background: #fff; color: var(--ink); margin-top: 4px; }
input:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 1px; border-color: var(--gold); }
details summary { cursor: pointer; font-weight: 600; color: var(--navy); margin: 6px 0; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 10px 0; padding: 8px 12px; }
legend { font-weight: 700; color: var(--navy); font-size: .9rem; padding: 0 4px; }
.att-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
label.att { font-weight: 400; font-size: .85rem; margin: 0; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.vertex-handle { background: var(--gold); border: 2px solid var(--navy); border-radius: 50%; }

/* Build */
.build-panel { max-width: 760px; margin: 20px auto; }
.progress { height: 10px; background: #EEE8D8; border-radius: 99px; overflow: hidden; margin: 14px 0 18px; }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--navy-2), var(--gold)); transition: width .4s; }
.steps { list-style: none; padding: 0; margin: 0; }
.step { padding: 7px 0 7px 30px; position: relative; border-bottom: 1px dashed var(--line); color: var(--muted); }
.step .step-icon { position: absolute; left: 4px; top: 11px; width: 14px; height: 14px; border-radius: 50%; border: 2px solid #C9C2AE; }
.step-done { color: var(--ink); }
.step-done .step-icon { background: var(--ok); border-color: var(--ok); }
.step-retry .step-icon { border-color: var(--warn); }
.notice { background: #FBF5E6; border: 1px solid #EBD9A8; padding: 10px 14px; border-radius: 8px; }
.notice-error { background: #FDECEA; border-color: #F4C1BB; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 8px; box-shadow: var(--shadow); z-index: 9999; max-width: 90vw; }
.toast-error { background: var(--danger); } .toast-warn { background: var(--warn); }

/* Report */
.report-toolbar { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar-right { display: flex; gap: 8px; flex-wrap: wrap; }
.toc { position: sticky; top: 0; z-index: 5; display: flex; gap: 4px 14px; flex-wrap: wrap; background: rgba(247, 244, 236, .96); padding: 8px 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; font-size: .9rem; }
.toc a { text-decoration: none; color: var(--navy-2); font-weight: 600; }
.report { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 34px 40px; }
.report-cover { border-bottom: 3px solid var(--gold); padding-bottom: 20px; margin-bottom: 10px; }
.cover-brand { display: flex; gap: 18px; align-items: center; }
.cover-logo { width: 76px; height: 76px; flex: none; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .78rem; color: var(--gold); font-weight: 700; }
.cover-classes { color: var(--ink-2); margin: 0; }
.cover-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 8px 20px; margin: 18px 0; }
.cover-meta dt { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.cover-meta dd { margin: 0; font-weight: 600; }
.report-section { padding: 22px 0 8px; border-bottom: 1px solid var(--line); }
.report-section:last-of-type { border-bottom: 0; }
.section-intro { color: var(--ink-2); max-width: 80ch; }
.report-map { height: 440px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: #E8EEF3; }
.caption { font-size: .85rem; color: var(--muted); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 14px; }
.tile { border: 1px solid var(--line); border-top: 3px solid var(--navy); border-radius: 8px; padding: 12px 14px; background: #FDFCF8; }
.tile-value { font-family: var(--serif); font-size: 1.65rem; font-weight: 700; color: var(--navy); line-height: 1.1; }
.tile-label { font-size: .85rem; color: var(--ink-2); font-weight: 600; margin-top: 4px; }
.tile-sub { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.highlights li { margin-bottom: 4px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.card { border: 1px solid var(--line); border-left: 4px solid var(--gold); border-radius: 8px; padding: 12px 16px; background: #FFFDF7; break-inside: avoid; }
.card h4 { margin-bottom: 4px; }
.card .evidence { margin: 0 0 6px; color: var(--navy-2); font-weight: 600; font-size: .93rem; }
.card ul { margin: 0; padding-left: 1.1em; font-size: .93rem; }

/* Comparison bars */
.legend { display: flex; gap: 18px; font-size: .85rem; color: var(--ink-2); margin: 6px 0 10px; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.sw-area { background: var(--navy-2); } .sw-base { background: var(--gold); }
.bars { display: grid; gap: 8px; margin-bottom: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(150px, 34%) 1fr; gap: 12px; align-items: center; break-inside: avoid; }
.bar-label { font-size: .9rem; color: var(--ink); }
.bar-pair { display: grid; gap: 2px; }
.bar-track { display: flex; align-items: center; gap: 8px; height: 13px; }
.bar { height: 100%; border-radius: 0 4px 4px 0; min-width: 2px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.bar-area { background: var(--navy-2); }
.bar-base { background: var(--gold); height: 9px; }
.bar-val { font-size: .8rem; color: var(--ink-2); font-variant-numeric: tabular-nums; min-width: 42px; }
.bar-row:hover .bar-label { color: var(--navy-2); font-weight: 600; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.data-table { width: 100%; border-collapse: collapse; font-size: .9rem; margin: 6px 0 12px; }
.data-table th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border-bottom: 2px solid var(--line); padding: 6px 8px; }
.data-table td { border-bottom: 1px solid #EFEBE0; padding: 5px 8px; font-variant-numeric: tabular-nums; }
.data-table td:not(:first-child), .data-table th:not(:first-child) { text-align: right; }
.data-table.compact td:not(:first-child), .data-table.compact th:not(:first-child) { text-align: left; }
.data-table tr { break-inside: avoid; }
.gap-pos { color: var(--danger); } .gap-neg { color: var(--ok); }
.questions li { margin-bottom: 14px; font-weight: 600; }
.write-lines { display: none; }
.sources li { margin-bottom: 4px; }
.report-footer { text-align: center; color: var(--muted); font-size: .8rem; margin-top: 20px; }
.error-panel { border-left: 4px solid var(--danger); }

@media (max-width: 900px) {
  .hero, .editor, .two-col { grid-template-columns: 1fr; }
  .map { height: 460px; }
  .report { padding: 20px 16px; }
  .bar-row { grid-template-columns: 1fr; gap: 2px; }
  .brand-sub { display: none; }
}

/* Print */
@page { size: letter; margin: 0.55in 0.5in; }
@media print {
  body { background: #fff; font-size: 10.5pt; }
  .no-print, .site-header, .site-footer, .toc, .report-toolbar { display: none !important; }
  .container { max-width: none; padding: 0; }
  .report { border: 0; box-shadow: none; padding: 0; }
  .report-section { break-inside: auto; }
  h2, h3 { break-after: avoid; }
  .report-section h2 { border-bottom: 2px solid var(--gold); padding-bottom: 4px; }
  #opportunities, #age, #religion, #discussion { break-before: page; }
  .report-map { height: 380px; break-inside: avoid; }
  .cards { grid-template-columns: 1fr 1fr; }
  .tiles { grid-template-columns: repeat(4, 1fr); }
  .tile, .card, .bar-row, .data-table tr { break-inside: avoid; }
  .write-lines { display: block; height: 64px; background: repeating-linear-gradient(#fff 0 20px, #ccc 20px 21px); margin-top: 6px; }
  details.places > summary { list-style: none; }
  a { color: inherit; text-decoration: none; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
.step-running { color: var(--navy); font-weight: 600; }
.step-running .step-icon { border-color: var(--gold); border-top-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
