:root {
  --bg: #f6f3f7;
  --surface: #ffffff;
  --surface-2: #efe9f1;
  --text: #1f1a24;
  --muted: #6b6274;
  --border: #ddd3e2;
  --accent: #8c2f5d;
  --accent-ink: #ffffff;
  --accent-soft: #f3dbe7;
  --ok: #2f7d55;
  --warn: #a8630b;
  --danger: #b3261e;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .05);

  --fam-power: #8c2f5d;
  --fam-pain: #c0392b;
  --fam-bondage: #7a5c1f;
  --fam-mind: #5b3fa0;
  --fam-roles: #1f6f8b;
  --fam-sex: #2f7d55;
  --fam-fetish: #4a4a4a;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141016;
    --surface: #1d181f;
    --surface-2: #272029;
    --text: #efe8f1;
    --muted: #a99fb0;
    --border: #3a3140;
    --accent: #e0739f;
    --accent-ink: #1a0f14;
    --accent-soft: #3b2230;
    --ok: #6cc59a;
    --warn: #e7a74a;
    --danger: #f08a82;
    --shadow: none;
    --fam-power: #e0739f;
    --fam-pain: #f08a82;
    --fam-bondage: #d6b56a;
    --fam-mind: #a990f0;
    --fam-roles: #6fc3df;
    --fam-sex: #6cc59a;
    --fam-fetish: #b8b8b8;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.hidden { display: none !important; }

/* Layout ------------------------------------------------------------------ */
.site-header {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.site-header .inner {
  max-width: 960px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.brand span { color: var(--accent); }
.site-nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.site-nav a {
  text-decoration: none; color: var(--muted); padding: 6px 10px; border-radius: 8px; font-size: .95rem;
}
.site-nav a[aria-current="page"], .site-nav a:hover { color: var(--text); background: var(--surface-2); }

main { max-width: 960px; margin: 0 auto; padding: 24px 16px 64px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }

/* Forms ------------------------------------------------------------------- */
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-weight: 600; margin-bottom: 4px; }
input[type="text"], select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 84px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem; word-break: break-all; }
.choice-group { display: grid; gap: 8px; }
.choice {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--border); cursor: pointer;
}
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { margin-top: 4px; accent-color: var(--accent); }
.choice small { display: block; color: var(--muted); }
.check { display: flex; gap: 10px; align-items: flex-start; margin: 10px 0; }
.check input { margin-top: 4px; accent-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.small { padding: 6px 12px; font-size: .875rem; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 16px; }
.actions .spacer { flex: 1; }

/* Progress ---------------------------------------------------------------- */
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 8px 0 20px; }
.progress > div { height: 100%; background: var(--accent); transition: width .2s; }

/* Likert ------------------------------------------------------------------ */
.statement { padding: 16px 0; border-bottom: 1px solid var(--border); }
.statement:last-child { border-bottom: 0; }
.statement p { font-weight: 500; margin-bottom: 10px; }
.likert { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; }
.likert .pole { font-size: .75rem; color: var(--muted); width: 72px; }
.likert .pole.right { text-align: right; }
.likert .dots { display: flex; justify-content: space-between; gap: 4px; }
.likert label { cursor: pointer; display: grid; place-items: center; }
.likert input { position: absolute; opacity: 0; pointer-events: none; }
.likert .dot {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--border); background: var(--surface);
  transition: transform .1s, background .1s;
}
.likert label:nth-child(1) .dot, .likert label:nth-child(7) .dot { width: 38px; height: 38px; }
.likert label:nth-child(2) .dot, .likert label:nth-child(6) .dot { width: 34px; height: 34px; }
.likert label:nth-child(4) .dot { width: 24px; height: 24px; }
.likert label:nth-child(-n+3) .dot { border-color: color-mix(in srgb, var(--danger) 55%, var(--border)); }
.likert label:nth-child(n+5) .dot { border-color: color-mix(in srgb, var(--ok) 55%, var(--border)); }
.likert input:checked + .dot { transform: scale(1.08); }
.likert label:nth-child(-n+3) input:checked + .dot { background: var(--danger); }
.likert label:nth-child(4) input:checked + .dot { background: var(--muted); }
.likert label:nth-child(n+5) input:checked + .dot { background: var(--ok); }
.likert input:focus-visible + .dot { outline: 3px solid var(--accent); outline-offset: 2px; }

@media (max-width: 520px) {
  .likert { grid-template-columns: 1fr; }
  .likert .pole { display: none; }
  .likert .dot { width: 28px !important; height: 28px !important; }
  .likert-legend { display: flex !important; }
}
.likert-legend { display: none; justify-content: space-between; font-size: .75rem; color: var(--muted); margin-top: 4px; }

/* Catalog ----------------------------------------------------------------- */
.cat-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.scale-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .8rem; color: var(--muted); margin: 8px 0 4px; }
.scale-legend b { color: var(--text); }
.kink { padding: 14px 0; border-bottom: 1px solid var(--border); }
.kink:last-child { border-bottom: 0; }
.kink-title { font-weight: 600; }
.kink-desc { font-size: .875rem; color: var(--muted); margin-bottom: 8px; }
.kink-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.kink-row .side { width: 150px; font-size: .85rem; color: var(--muted); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button {
  border: 0; background: var(--surface); color: var(--text); font: inherit; font-size: .85rem;
  padding: 6px 0; width: 40px; cursor: pointer; border-right: 1px solid var(--border);
}
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--surface-2); }
.seg button[aria-pressed="true"][data-v="-2"] { background: var(--danger); color: #fff; }
.seg button[aria-pressed="true"][data-v="-1"] { background: color-mix(in srgb, var(--danger) 45%, var(--surface)); }
.seg button[aria-pressed="true"][data-v="0"] { background: var(--surface-2); outline: 2px solid var(--muted); outline-offset: -2px; }
.seg button[aria-pressed="true"][data-v="1"] { background: color-mix(in srgb, var(--ok) 30%, var(--surface)); }
.seg button[aria-pressed="true"][data-v="2"] { background: color-mix(in srgb, var(--ok) 60%, var(--surface)); }
.seg button[aria-pressed="true"][data-v="3"] { background: var(--accent); color: var(--accent-ink); }
@media (max-width: 520px) {
  .kink-row .side { width: 100%; }
  .seg button { width: 44px; }
}

.badge {
  display: inline-block; font-size: .7rem; font-weight: 700; letter-spacing: .02em; padding: 2px 7px;
  border-radius: 999px; vertical-align: middle; margin-left: 6px; text-transform: uppercase;
}
.badge.risk1 { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.badge.risk2 { background: color-mix(in srgb, var(--danger) 20%, transparent); color: var(--danger); }
.badge.new { background: var(--accent-soft); color: var(--accent); }
.badge.classic { background: var(--surface-2); color: var(--muted); }

/* Results ----------------------------------------------------------------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs button {
  border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 999px;
  padding: 6px 12px; font: inherit; font-size: .875rem; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }

.arch-list { list-style: none; margin: 0; padding: 0; }
.arch { display: grid; grid-template-columns: 52px 1fr; gap: 4px 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.arch:last-child { border-bottom: 0; }
.arch .pct { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; grid-row: span 2; align-self: center; }
.arch .name { font-weight: 600; }
.arch .bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.arch .bar > div { height: 100%; border-radius: 999px; }
.arch details { grid-column: 2; font-size: .875rem; color: var(--muted); }
.arch summary { cursor: pointer; list-style: none; }
.arch summary::-webkit-details-marker { display: none; }
.fam-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }

.profile-row { display: grid; grid-template-columns: minmax(120px, 220px) 1fr; gap: 8px 14px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.profile-row:last-child { border-bottom: 0; }
.mini-bars { display: grid; gap: 4px; }
.mini-bar { display: grid; grid-template-columns: 56px 1fr 38px; gap: 8px; align-items: center; font-size: .75rem; color: var(--muted); }
.mini-bar .track { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.mini-bar .track > div { height: 100%; background: var(--accent); }
.mini-bar .v { text-align: right; font-variant-numeric: tabular-nums; }

.chip-list { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; padding: 0; margin: 0; }
.chip { border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px; font-size: .85rem; background: var(--surface); }
.chip em { font-style: normal; color: var(--muted); font-size: .78rem; }

.notice { border-left: 4px solid var(--warn); background: color-mix(in srgb, var(--warn) 10%, var(--surface)); padding: 12px 14px; border-radius: 8px; margin: 12px 0; font-size: .925rem; }
.notice.info { border-left-color: var(--accent); background: var(--accent-soft); }
.error { color: var(--danger); font-weight: 600; }

.match-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.match-table th, .match-table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.match-table th { color: var(--muted); font-weight: 600; font-size: .8rem; }
.scroll-x { overflow-x: auto; }

.site-footer {
  max-width: 960px; margin: 0 auto; padding: 0 16px 32px;
  font-size: .85rem; display: flex; gap: 6px; flex-wrap: wrap;
}
.legal h3 { margin-top: 18px; }
.legal dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0 0 1em; }
.legal dt { color: var(--muted); }
.legal dd { margin: 0; overflow-wrap: anywhere; }
.placeholder { color: var(--danger); font-weight: 600; }
@media (max-width: 520px) {
  .legal dl { grid-template-columns: 1fr; gap: 0; }
  .legal dt { font-size: .8rem; margin-top: 8px; }
}

@media print {
  .site-header, .site-footer, .actions, .tabs, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; break-inside: avoid; }
}
