:root {
  --bg: #f3ecdf;
  --bg-deep: #e7dece;
  --paper: #fffdf8;
  --ink: #221c16;
  --muted: #4e463e;
  --line: #e0d5c4;
  --accent: #0f5c4c;
  --accent-dark: #0a3f35;
  --accent-soft: #e5f3ee;
  --clay: #b85a2a;
  --gold: #a8842d;
  --navy: #243e66;
  --warn-bg: #fff4e0;
  --warn: #8a4b08;
  --bad-bg: #fdecea;
  --bad: #8d2a2a;
  --good-bg: #e7f6ef;
  --good: #0f6b45;
  --shadow: 0 1px 0 rgba(34, 28, 22, 0.04), 0 16px 40px rgba(70, 48, 20, 0.06);
  --radius: 16px;
  --font: "Segoe UI", "Avenir Next", "Trebuchet MS", sans-serif;
  --display: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(var(--accent) 0 7px, transparent 7px),
    var(--bg);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.5;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }
a { color: var(--accent-dark); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--paper);
  padding: 8px 12px;
  z-index: 5;
}
.skip:focus { top: 12px; }

.wrap { width: min(1080px, calc(100% - 32px)); margin: 0 auto; }
.page { padding: 28px 0 48px; }
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 22px 0 8px;
}
.brand { display: flex; gap: 12px; align-items: center; background: none; border: 0; padding: 0; text-align: left; }
.brand svg { width: 42px; height: 42px; flex: none; }
.brand strong { font-family: var(--display); font-size: 1.7rem; letter-spacing: -0.03em; display: block; line-height: 1; }
.brand span { color: var(--muted); font-size: 0.92rem; }
.account { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.who { color: var(--muted); }

h1, h2, h3 { font-family: var(--display); font-weight: 600; letter-spacing: -0.02em; line-height: 1.15; margin: 0 0 8px; }
h1 { font-size: clamp(2rem, 4vw, 3.1rem); }
h2 { font-size: 1.55rem; }
h3 { font-size: 1.2rem; }
.lede { font-size: 1.08rem; max-width: 42rem; color: var(--ink); }
.muted, .hint { color: var(--muted); }
.hint { margin: 4px 0 0; font-size: 0.95rem; }

.card, .panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.stack { display: grid; gap: 14px; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.template {
  text-align: left;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  min-height: 150px;
  box-shadow: var(--shadow);
}
.template:hover { border-color: var(--accent); }
.template strong { display: block; font-size: 1.08rem; margin: 8px 0; }
.badge {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.btn, button.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #f4faf7;
  text-decoration: none;
}
.btn.ghost { background: transparent; color: var(--accent-dark); }
.btn.danger { background: transparent; color: var(--bad); border-color: #e4b6b2; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field span { font-weight: 650; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 10px 12px;
  min-height: 44px;
}
textarea { min-height: 96px; resize: vertical; }

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 0 14px;
  position: sticky;
  top: 0;
  background: linear-gradient(var(--bg), var(--bg) 80%, transparent);
  z-index: 2;
}
.tabs button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  min-height: 40px;
  padding: 6px 12px;
  white-space: nowrap;
}
.tabs button[aria-selected="true"] {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--line);
  font-weight: 700;
}

.choice-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice-card {
  text-align: left;
  border: 2px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 14px;
  min-height: 120px;
}
.choice-card[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }

.tree { list-style: none; margin: 8px 0 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); }
.tree-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.tree-row input.name { flex: 1 1 180px; }
.callout {
  border-left: 4px solid var(--gold);
  background: var(--warn-bg);
  color: var(--warn);
  padding: 12px 14px;
  border-radius: 12px;
}
.callout.bad { border-color: var(--bad); background: var(--bad-bg); color: var(--bad); }
.callout.good { border-color: var(--good); background: var(--good-bg); color: var(--good); }
.callout.info { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }

.pair {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}
.pair.warn { border-color: #e2b15a; background: #fffaf1; }
.pair-ends { display: flex; justify-content: space-between; gap: 12px; font-weight: 700; }
.pair-ends span { max-width: 46%; }
.pair-ends .hot { color: var(--accent-dark); }
input[type="range"] { width: 100%; accent-color: var(--accent); min-height: 44px; }
.scale-words { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.82rem; }

.rank { display: grid; gap: 10px; }
.rank-row { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; }
.place {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent); color: white; font-weight: 700;
}
.place.tie { background: var(--navy); }
.bar-track { height: 12px; background: var(--bg-deep); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 999px; }
.score-num { text-align: right; }
.score-num strong { font-family: var(--display); font-size: 1.6rem; display: block; line-height: 1; }

.charts { display: grid; gap: 16px; }
.chart-card h3 { margin-bottom: 4px; }
.chart-card canvas { max-height: 280px; }
table { width: 100%; border-collapse: collapse; font-size: 0.98rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 650; font-size: 0.85rem; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--accent-soft); }

.timeline { display: grid; gap: 12px; }
.event {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 12px;
}
.dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent); margin-top: 6px;
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.event ul { margin: 8px 0; padding-left: 18px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.filters select, .filters input { width: auto; min-width: 140px; }

.toast {
  position: sticky;
  bottom: 12px;
  background: var(--ink);
  color: #fffdf8;
  padding: 12px 14px;
  border-radius: 12px;
  margin: 12px 0;
}
.modal-back {
  position: fixed; inset: 0; background: rgba(34, 28, 22, 0.45);
  display: grid; place-items: center; padding: 16px; z-index: 6;
}
.modal { width: min(560px, 100%); max-height: min(80vh, 720px); overflow: auto; }
.check-list { display: grid; gap: 8px; margin: 10px 0; }
.check-list label { display: flex; gap: 8px; align-items: flex-start; }

.banner { margin-bottom: 12px; }
.split { display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; }
.loading { padding: 48px 16px; }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.print-only { display: none; }

@media (max-width: 720px) {
  .choice-cards, .rank-row { grid-template-columns: 1fr; }
  .score-num { text-align: left; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .tree-row .btn { flex: 1 1 auto; }
}

@media print {
  body { background: white; }
  .no-print, .tabs, .topbar .account, .whatif, .toast, .modal-back { display: none !important; }
  .print-only { display: block; }
  .card, .panel { box-shadow: none; break-inside: avoid; }
  a { text-decoration: none; color: inherit; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
