:root {
  --bg: #fdf8ff;
  --panel: #ffffff;
  --ink: #2b2240;
  --muted: #736a86;
  --line: #ece4f7;
  --lilac: #8a63f0;
  --lilac-deep: #6a44d6;
  --lilac-soft: #f0e9ff;
  --coral: #ff6b5e;
  --coral-deep: #e04a3d;
  --coral-soft: #ffe8e4;
  --coral-ink: #a82a22;   /* coral text on coral-soft, >= 4.5:1 */
  --mint: #16a47a;
  --mint-soft: #d9f6ea;
  --sun: #ffc23d;
  --sun-soft: #fff3d1;
  --shadow: 0 6px 24px rgba(106, 68, 214, .10);
  --radius: 22px;
  --display: "Fredoka", ui-rounded, system-ui, sans-serif;
  --body: "Nunito", ui-sans-serif, system-ui, -apple-system, sans-serif;
  color-scheme: light;
}
/* Each friend has her own colour. */
.f0 { --me: var(--lilac); --me-soft: var(--lilac-soft); }
.f1 { --me: var(--coral); --me-soft: var(--coral-soft); }
.f2 { --me: var(--mint); --me-soft: var(--mint-soft); }

* { box-sizing: border-box; }
::selection { background: var(--lilac-soft); color: var(--ink); }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--body); font-size: 16px; line-height: 1.5; color: var(--ink);
  background:
    radial-gradient(600px 400px at 110% -10%, #ffe1f0 0%, transparent 60%),
    radial-gradient(500px 380px at -20% 10%, #e8ddff 0%, transparent 60%),
    radial-gradient(500px 400px at 50% 110%, #d8f7ea 0%, transparent 60%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
}
h1, h2, h3, .display { font-family: var(--display); font-weight: 600; letter-spacing: -.01em; margin: 0; }
h1 { font-size: clamp(30px, 8vw, 44px); line-height: 1.1; }
h2 { font-size: 22px; line-height: 1.2; }
h3 { font-size: 18px; line-height: 1.25; }
p { margin: 0; }
a { color: var(--lilac-deep); }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.wrap { max-width: 640px; margin: 0 auto; padding: 20px 16px 120px; }
.stack > * + * { margin-top: 14px; }

.topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; max-width: 640px; margin: 0 auto; }
.logo { font-family: var(--display); font-weight: 600; font-size: 18px; color: var(--ink); text-decoration: none; display: flex; align-items: center; gap: 8px; }
.logo span { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 12px; background: linear-gradient(135deg, var(--lilac), var(--coral)); color: #fff; font-size: 18px; }

.card { background: var(--panel); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); border: 1px solid var(--line); }

/* Buttons */
.btn { appearance: none; font: 700 16px/1 var(--body); border: 2px solid transparent; border-radius: 999px; padding: 14px 22px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; transition: transform .12s, box-shadow .12s, background .12s; min-height: 48px; }
.btn:active { transform: scale(.97); }
.btn:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; }
.btn-primary { background: linear-gradient(135deg, var(--lilac), var(--lilac-deep)); color: #fff; box-shadow: 0 6px 0 #4f2fb0, 0 10px 20px rgba(106, 68, 214, .25); }
.btn-primary:active { box-shadow: 0 2px 0 #4f2fb0; transform: translateY(4px); }
.btn-coral { background: var(--coral); color: #fff; box-shadow: 0 5px 0 var(--coral-deep); }
.btn-ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--lilac); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* Forms */
label.lbl { display: block; font-weight: 700; font-size: 14px; margin-bottom: 6px; }
input, select, textarea { width: 100%; font: 500 16px var(--body); color: var(--ink); background: #fbf9ff; border: 2px solid var(--line); border-radius: 14px; padding: 12px 14px; min-height: 48px; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--lilac); background: #fff; box-shadow: 0 0 0 4px var(--lilac-soft); }
.field + .field { margin-top: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { font-size: 13px; color: var(--muted); margin-top: 6px; }

/* Chips (multi-select) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; min-height: 0; cursor: pointer; }
.chip span { display: inline-block; padding: 9px 14px; border-radius: 999px; background: #fff; border: 2px solid var(--line); font-weight: 700; font-size: 14px; }
.chip input:checked + span { background: var(--me-soft, var(--lilac-soft)); border-color: var(--me, var(--lilac)); color: var(--ink); }
.chip input:focus-visible + span { outline: 3px solid var(--sun); }

/* Yes/no switch */
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 700; cursor: pointer; }
.switch input { appearance: none; width: 52px; height: 30px; min-height: 0; padding: 0; border-radius: 999px; background: var(--line); border: 0; position: relative; flex: none; cursor: pointer; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.15); transition: transform .15s; }
.switch input:checked { background: var(--me, var(--lilac)); }
.switch input:checked::after { transform: translateX(22px); }

/* Friends row */
.friends { display: flex; gap: 6px; flex-wrap: wrap; }
.friend { display: flex; align-items: center; gap: 6px; background: #fff; border-radius: 999px; padding: 4px 10px 4px 4px; border: 2px solid var(--line); font-weight: 700; font-size: 14px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--me); color: #fff; font-family: var(--display); font-size: 15px; flex: none; }
.friend.done { border-color: var(--me); background: var(--me-soft); }

/* Tabs */
.tabs { display: flex; background: #fff; border-radius: 999px; padding: 5px; border: 2px solid var(--line); gap: 4px; }
.tabs button { flex: 1; border: 0; background: none; font: 800 15px var(--body); color: var(--muted); padding: 11px 8px; border-radius: 999px; cursor: pointer; min-height: 44px; }
.tabs button.on { background: var(--ink); color: #fff; }
.tabs .dot { display: inline-grid; place-items: center; min-width: 20px; height: 20px; border-radius: 999px; background: var(--coral); color: #fff; font-size: 12px; margin-left: 4px; padding: 0 6px; }

/* Stepper */
.steps { display: flex; gap: 6px; }
.steps i { flex: 1; height: 8px; border-radius: 99px; background: var(--line); }
.steps i.on { background: linear-gradient(90deg, var(--me), var(--lilac)); }
.step-title { display: flex; align-items: center; gap: 12px; }
.step-emoji { font-size: 34px; line-height: 1; }

/* Preference cards */
.pref { background: #fff; border-radius: 20px; border: 2px solid var(--line); overflow: hidden; transition: border-color .15s, box-shadow .15s; }
.pref.set { border-color: var(--me); box-shadow: 0 4px 0 var(--me-soft); }
.pref-head { width: 100%; display: flex; align-items: center; gap: 12px; padding: 16px; background: none; border: 0; font: inherit; color: inherit; text-align: left; cursor: pointer; min-height: 64px; }
.pref-emoji { font-size: 26px; width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: var(--me-soft); flex: none; }
.pref-title { flex: 1; min-width: 0; }
.pref-title b { display: block; font-family: var(--display); font-weight: 600; font-size: 17px; }
.pref-title small { display: block; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag { font-size: 12px; font-weight: 800; padding: 5px 10px; border-radius: 999px; white-space: nowrap; flex: none; }
.tag.add { background: var(--lilac-soft); color: var(--lilac-deep); }
.tag.must { background: var(--coral-soft); color: var(--coral-deep); }
.tag.flex { background: var(--mint-soft); color: var(--mint); }
.pref-body { padding: 0 16px 18px; display: none; }
.pref.open .pref-body { display: block; }
.prio { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.prio button { border: 2px solid var(--line); background: #fff; border-radius: 16px; padding: 10px 8px; font: 800 14px var(--body); cursor: pointer; color: var(--ink); min-height: 56px; line-height: 1.2; }
.prio button small { display: block; font-weight: 600; font-size: 12px; color: var(--muted); }
.prio button.must.on { background: var(--coral-soft); border-color: var(--coral); }
.prio button.flex.on { background: var(--mint-soft); border-color: var(--mint); }
.clear { background: none; border: 0; color: var(--muted); font: 700 14px var(--body); text-decoration: underline; cursor: pointer; margin-top: 12px; padding: 6px 0; }
.interp { margin-top: 10px; font-size: 13px; background: var(--sun-soft); border-radius: 12px; padding: 8px 12px; }

/* Sticky action bar */
.bar { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: rgba(253, 248, 255, .92); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-top: 1px solid var(--line); z-index: 10; }
.bar-inner { max-width: 640px; margin: 0 auto; display: flex; gap: 10px; }
.bar-inner .btn-primary { flex: 1; }

/* Results */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: #fff; border-radius: 18px; padding: 14px 10px; text-align: center; border: 2px solid var(--line); }
.stat b { display: block; font-family: var(--display); font-size: 28px; line-height: 1.1; }
.stat span { font-size: 12px; color: var(--muted); font-weight: 700; }
.stat.pass b { color: var(--mint); } .stat.out b { color: var(--coral); }
.banner { border-radius: 18px; padding: 14px 16px; background: var(--sun-soft); font-weight: 700; display: flex; gap: 10px; align-items: center; }
.apt { background: #fff; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); border: 1px solid var(--line); }
.apt.rejected { opacity: .6; }
.apt-photo { position: relative; aspect-ratio: 16 / 9; background: linear-gradient(135deg, var(--lilac-soft), var(--coral-soft)); }
.apt-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.rank { position: absolute; top: 12px; left: 12px; background: #fff; border-radius: 999px; padding: 6px 12px; font-family: var(--display); font-weight: 600; box-shadow: var(--shadow); }
.ring { position: absolute; right: 12px; bottom: -28px; width: 68px; height: 68px; border-radius: 50%; background: conic-gradient(var(--lilac) calc(var(--v) * 1%), var(--line) 0); display: grid; place-items: center; box-shadow: var(--shadow); }
.ring b { width: 56px; height: 56px; border-radius: 50%; background: #fff; display: grid; place-items: center; font-family: var(--display); font-size: 22px; line-height: 1; }
.ring b small { display: block; font-size: 9px; font-family: var(--body); font-weight: 800; color: var(--muted); letter-spacing: .04em; }
.apt-body { padding: 18px 18px 20px; }
.apt-body h3 { padding-right: 70px; }
.facts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.facts span { background: #f7f3ff; border-radius: 999px; padding: 5px 10px; font-size: 13px; font-weight: 700; }
.facts .money { background: var(--sun-soft); }
.scores { margin-top: 14px; display: grid; gap: 8px; }
.score-row { display: grid; grid-template-columns: 76px 1fr 32px; gap: 10px; align-items: center; font-size: 14px; font-weight: 700; }
.score-row i { height: 10px; border-radius: 99px; background: var(--line); overflow: hidden; }
.score-row i::after { content: ""; display: block; height: 100%; width: var(--w); background: var(--me); border-radius: 99px; }
.score-row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 800; padding: 6px 12px; border-radius: 999px; margin-top: 14px; }
.pill.agreed { background: var(--mint-soft); color: var(--mint); }
.pill.pending { background: var(--sun-soft); color: #9a6a00; }
.pill.rejected { background: var(--coral-soft); color: var(--coral-deep); }
.comps { margin-top: 14px; display: grid; gap: 8px; }
.comp { border-radius: 16px; padding: 12px 14px; background: #faf7ff; border-left: 5px solid var(--me); font-size: 14px; }
.comp.mine { background: var(--me-soft); }
.comp .who { font-weight: 800; }
.comp .answer { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.comp .answer .btn { min-height: 44px; padding: 10px; font-size: 14px; }
.comp .done { margin-top: 6px; font-weight: 800; }
.happy { margin-top: 14px; font-weight: 800; color: var(--mint); }
.why { margin-top: 12px; font-size: 14px; color: var(--muted); font-style: italic; }
details.check { margin-top: 12px; font-size: 14px; }
details.check summary { cursor: pointer; font-weight: 800; color: #9a6a00; }
details.check ul { margin: 6px 0 0; padding-left: 18px; }
.apt-actions { margin-top: 16px; display: flex; gap: 8px; }

/* Repeatable commute places */
.trips { display: grid; gap: 16px; }
.trip { border-top: 2px dashed var(--line); padding-top: 14px; }
.trip:first-child { border-top: 0; padding-top: 2px; }
.trip > * + * { margin-top: 12px; }
.trip .grid2 .field + .field { margin-top: 0; }
.trip-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.trip-head b { font-family: var(--display); font-weight: 600; font-size: 15px; }
.trip-remove { background: none; border: 0; padding: 4px 0; font: 700 13px var(--body); color: var(--muted); text-decoration: underline; cursor: pointer; }
.trip-remove:hover { color: var(--coral-deep); }
.trip-add { border-style: dashed; color: var(--lilac-deep); }

/* Who gets / gives up what, per flat */
.bd { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 10px; }
.bd-row { border-radius: 16px; background: #faf7ff; padding: 12px 12px 12px 14px; }
.bd-head { display: flex; align-items: center; gap: 8px; }
.bd-head b { font-weight: 800; }
.bd-head .avatar { width: 24px; height: 24px; font-size: 14px; }
.bd-verdict { font-size: 12px; font-weight: 800; padding: 3px 9px; border-radius: 999px; }
.bd-verdict.all { background: var(--mint-soft); color: #0d7a5a; }
.bd-verdict.some { background: var(--coral-soft); color: var(--coral-ink); }
.bd-score { margin-left: auto; font-family: var(--display); font-size: 18px; color: var(--me); font-variant-numeric: tabular-nums; }
.bd-chips, .legend { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.bd-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 700; line-height: 1.2; padding: 5px 10px 5px 7px; border-radius: 999px; background: #fff; border: 1.5px solid var(--line); }
.bd-chip svg { width: 14px; height: 14px; flex: none; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.bd-chip small { font-size: 11px; font-weight: 800; opacity: .8; }
.bd-chip.got { color: #0d7a5a; background: #f1fbf7; border-color: #bfe9d8; }
.bd-chip.gave { color: var(--coral-ink); background: var(--coral-soft); border-color: #ffc7bf; }
.bd-chip.gave.accepted { color: #0d7a5a; background: #f1fbf7; border-color: #bfe9d8; }
.bd-chip.gave.rejected span { text-decoration: line-through; }
.bd-chip.check { color: #8a5d00; background: var(--sun-soft); border-color: #f5dc93; }
.bd-chip[title] { cursor: help; }
.legend { margin: 0; align-items: center; }
.legend-title { font-size: 13px; font-weight: 800; color: var(--muted); margin-right: 2px; }
.legend .bd-chip { font-size: 12px; }

/* Tradeoff grid: friends x flats */
.tradeoff h2 { margin-bottom: 4px; }
.tg-scroll { margin: 14px -6px 0; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tg { width: 100%; border-collapse: separate; border-spacing: 6px; table-layout: fixed; min-width: 300px; }
.tg thead td { width: 88px; background: none; padding: 0; }
.tg thead th { text-align: left; vertical-align: bottom; font-weight: 800; font-size: 14px; line-height: 1.25; padding: 0 4px 4px; }
.tg thead a { color: var(--ink); text-decoration: none; display: block; }
.tg thead a:hover .tg-rank, .tg thead a:focus-visible .tg-rank { background: var(--lilac); color: #fff; }
.tg-rank { display: inline-block; font-family: var(--display); font-size: 13px; background: var(--lilac-soft); color: var(--lilac-deep); border-radius: 999px; padding: 1px 8px; margin-bottom: 4px; transition: background .15s, color .15s; }
.tg thead small { display: block; font-size: 12px; color: var(--muted); font-weight: 700; font-variant-numeric: tabular-nums; }
.tg tbody th { text-align: left; font-weight: 800; font-size: 14px; vertical-align: top; padding: 10px 0 0; }
.tg tbody th .avatar { width: 26px; height: 26px; margin-bottom: 4px; }
.tg-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg td { vertical-align: top; border-radius: 14px; padding: 9px 10px; background: var(--coral-soft); font-size: 13px; font-weight: 700; line-height: 1.3; }
.tg td.all { background: var(--mint-soft); }
.tg td ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; color: var(--coral-ink); }
.tg td li small { display: block; font-size: 11px; color: #6e4642; }
.tg td li.accepted { color: #0d7a5a; }
.tg td li.rejected { text-decoration: line-through; }
.tg-all { display: inline-flex; align-items: center; gap: 4px; color: #0d7a5a; }
.tg-all svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.tg-check { display: block; margin-top: 6px; font-size: 11px; color: #8a5d00; }

/* Runners-up */
details.more summary { cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 12px; list-style: none; }
details.more summary::-webkit-details-marker { display: none; }
.more-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.more-toggle { flex: none; display: inline-flex; align-items: center; gap: 4px; font-weight: 800; font-size: 14px; color: var(--lilac-deep); background: var(--lilac-soft); border-radius: 999px; padding: 8px 12px; }
.more-toggle svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; transition: transform .2s; }
details.more[open] .more-toggle svg { transform: rotate(180deg); }
details.more .when-open, details.more[open] .when-closed { display: none; }
details.more[open] .when-open { display: inline; }
details.more summary:focus-visible { outline: 3px solid var(--sun); outline-offset: 4px; border-radius: 12px; }
details.more summary .display { font-size: 18px; }
.more-list { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 12px; }
.more-list li { display: flex; gap: 12px; align-items: flex-start; padding-top: 12px; border-top: 1px solid var(--line); }
.more-list li:first-child { border-top: 0; padding-top: 0; }
.more-rank { flex: none; font-family: var(--display); background: var(--lilac-soft); color: var(--lilac-deep); border-radius: 999px; padding: 2px 10px; }

/* Shared shortlist page */
.wrap.wide { max-width: 720px; }
.sl-intro h1 { margin-bottom: 2px; }
.sl-foot { text-align: center; padding: 8px 12px 0; }
a.banner { color: var(--ink); text-decoration: none; }
a.banner:hover { background: #ffe9a8; }
.apt { scroll-margin-top: 16px; }

/* Home */
.hero { text-align: center; padding: 20px 0 8px; }
.hero .emoji { font-size: 56px; }
.how { display: grid; gap: 10px; counter-reset: s; }
.how li { list-style: none; display: flex; gap: 14px; align-items: flex-start; background: #fff; border-radius: 18px; padding: 14px; border: 2px solid var(--line); }
.how li::before { counter-increment: s; content: counter(s); flex: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-family: var(--display); color: #fff; background: var(--lilac); }
.how li:nth-child(2)::before { background: var(--coral); } .how li:nth-child(3)::before { background: var(--mint); }
code { background: var(--lilac-soft); padding: 2px 8px; border-radius: 8px; font-size: 14px; word-break: break-word; }

/* Celebration */
.celebrate { text-align: center; padding: 28px 20px; }
.celebrate .big { font-size: 64px; line-height: 1; }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 5px solid var(--lilac-soft); border-top-color: var(--lilac); animation: spin 1s linear infinite; margin: 16px auto 0; }
@keyframes spin { to { transform: rotate(360deg); } }
.confetti { position: fixed; top: -12px; width: 10px; height: 14px; border-radius: 3px; z-index: 50; pointer-events: none; animation: fall linear forwards; }
@keyframes fall { to { transform: translate3d(var(--dx), 105vh, 0) rotate(var(--r)); } }

#toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 16px; font-weight: 700; opacity: 0; transition: .2s; pointer-events: none; z-index: 60; max-width: calc(100vw - 32px); white-space: pre-line; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (max-width: 480px) {
  .tradeoff { padding: 18px 14px; }
  .tg { border-spacing: 4px; }
  .tg thead td { width: 50px; }
  .tg thead th { font-size: 13px; padding: 0 2px 4px; }
  .tg tbody th { font-size: 12px; }
  .tg td { padding: 8px 7px; font-size: 12px; border-radius: 12px; }
  .tg-all svg { display: none; }
  .tg-rank { display: table; }
}
@media (max-width: 420px) {
  .trip .trip-who { grid-template-columns: 1fr; gap: 12px; }
  .legend-title { flex-basis: 100%; }
}
@media (max-width: 380px) {
  .grid2 { grid-template-columns: 1fr; }
  .stats { gap: 6px; } .stat b { font-size: 22px; }
}
