:root {
  --bg: #f6efe9; --card: #fffaf6; --ink: #2b2320; --muted: #8a7d76;
  --like: #2f9e6e; --pass: #d0524a; --accent: #6b4fbb; --line: #e8ddd4;
  --f: #c2577e; --m: #3d78b8; --u: #8a6f2f;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1d1918; --card: #2a2422; --ink: #f3ebe5; --muted: #a39790; --line: #3b3330; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overscroll-behavior: none; }
body { display: flex; flex-direction: column; min-height: 100dvh; }
main { flex: 1; display: flex; flex-direction: column; padding: max(16px, env(safe-area-inset-top)) 16px 0; max-width: 520px; width: 100%; margin: 0 auto; }
.view { flex: 1; display: flex; flex-direction: column; }
.view[hidden] { display: none; }
h1 { font-size: 2.4rem; margin: 8vh 0 8px; letter-spacing: -0.02em; }
h2 { margin: 0; font-size: 1.5rem; }
.top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.lede { font-size: 1.05rem; line-height: 1.5; color: var(--muted); }
label { display: block; font-weight: 600; }
input:not([type=radio]) { display: block; width: 100%; margin-top: 6px; padding: 14px; font: inherit; font-weight: 400; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink); }
fieldset { border: 0; padding: 0; margin: 20px 0; }
legend { font-weight: 600; margin-bottom: 8px; padding: 0; }
.seg { display: flex; gap: 8px; }
.seg label { flex: 1; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: block; text-align: center; padding: 12px 4px; border: 1px solid var(--line); border-radius: 12px; font-weight: 500; background: var(--card); }
.seg input:checked + span { border-color: var(--accent); background: var(--accent); color: #fff; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
button { font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 12px; padding: 12px 16px; cursor: pointer; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); width: 100%; font-weight: 600; padding: 14px; }
#setup-form label { margin-top: 24px; }
.stack { display: flex; flex-direction: column; gap: 12px; margin-bottom: 24px; }
.danger button { color: var(--pass); }
.row { display: flex; gap: 8px; margin-top: 8px; }
.row input { margin: 0; }

/* Deck */
.deck { position: relative; flex: 1; min-height: 320px; }
.card { position: absolute; inset: 0 0 8px; background: var(--card); border-radius: 24px; box-shadow: 0 8px 24px rgba(0,0,0,.08); display: flex; flex-direction: column; align-items: center; justify-content: center; touch-action: none; user-select: none; transition: transform .25s ease, opacity .25s ease; border: 1px solid var(--line); }
.card.behind { transform: scale(.95) translateY(10px); opacity: .7; }
.card.dragging { transition: none; }
.card .name { font-size: clamp(2.6rem, 12vw, 3.6rem); font-weight: 700; letter-spacing: -0.02em; text-align: center; padding: 0 16px; }
.card .tag { margin-top: 12px; font-size: .9rem; padding: 4px 12px; border-radius: 99px; color: #fff; }
.tag.f { background: var(--f); } .tag.m { background: var(--m); } .tag.u { background: var(--u); }
.card .stamp { position: absolute; top: 28px; font-weight: 800; font-size: 1.4rem; padding: 4px 12px; border: 3px solid; border-radius: 8px; opacity: 0; }
.stamp.yes { left: 24px; color: var(--like); transform: rotate(-12deg); }
.stamp.no { right: 24px; color: var(--pass); transform: rotate(12deg); }
.card .partner-liked { position: absolute; bottom: 24px; font-size: .9rem; color: var(--muted); }
.empty { text-align: center; margin: auto; padding: 24px; color: var(--muted); line-height: 1.5; }
.actions { display: flex; justify-content: center; align-items: center; gap: 24px; padding: 16px 0; }
.round { width: 68px; height: 68px; border-radius: 50%; font-size: 1.8rem; padding: 0; box-shadow: 0 4px 12px rgba(0,0,0,.08); }
.round.undo { width: 48px; height: 48px; font-size: 1.3rem; color: var(--muted); }
.round.pass { color: var(--pass); } .round.like { color: var(--like); }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; padding: 14px 4px; border-bottom: 1px solid var(--line); font-size: 1.15rem; }
.list li .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 10px; }
.dot.f { background: var(--f); } .dot.m { background: var(--m); } .dot.u { background: var(--u); }
.list li button { padding: 6px 10px; font-size: .85rem; color: var(--muted); }
.share-box { margin: 24px 0; }
.share-box details { margin-top: 12px; }
.share-box summary { color: var(--muted); cursor: pointer; }
.hero-count { font-size: 1rem; color: var(--muted); margin: 0 0 8px; }

/* Tabs */
.tabs { display: flex; border-top: 1px solid var(--line); background: var(--card); padding-bottom: env(safe-area-inset-bottom); position: sticky; bottom: 0; }
.tabs[hidden] { display: none; }
.tabs button { flex: 1; border: 0; border-radius: 0; background: none; padding: 14px 4px; font-size: .9rem; color: var(--muted); }
.tabs button.on { color: var(--accent); font-weight: 700; }
.badge { background: var(--like); color: #fff; border-radius: 99px; padding: 1px 7px; font-size: .75rem; margin-left: 2px; }
#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90vw; text-align: center; }
#toast.show { opacity: .95; }
.card .meta { margin-top: 20px; text-align: center; padding: 0 24px; }
.card .meaning { font-size: 1.15rem; font-style: italic; }
.card .origin { margin-top: 6px; color: var(--muted); font-size: .95rem; }
.card .tag { background: var(--f); }
label.check { display: flex; gap: 10px; align-items: center; font-weight: 500; }
label.check input { width: 20px; height: 20px; }
#setup-form .primary { margin-top: 24px; }
.error { color: var(--pass); font-weight: 500; }
.sync-status { margin: 16px 0; }
.card .surname { display: block; font-size: .5em; font-weight: 500; color: var(--muted); letter-spacing: 0; margin-top: 2px; }

/* Stats, chips, names table */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 8px; text-align: center; }
.stat b { display: block; font-size: 1.35rem; }
.stat span { font-size: .75rem; color: var(--muted); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.chips button { padding: 6px 12px; border-radius: 99px; font-size: .85rem; }
.chips button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.names-table { width: 100%; border-collapse: collapse; font-size: .95rem; margin-bottom: 12px; }
.names-table th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 600; padding: 8px 4px; border-bottom: 1px solid var(--line); cursor: pointer; user-select: none; white-space: nowrap; position: sticky; top: 0; background: var(--bg); }
.names-table th.sorted::after { content: " ▾"; }
.names-table th.sorted.asc::after { content: " ▴"; }
.names-table td { padding: 10px 4px; border-bottom: 1px solid var(--line); }
.names-table td.vote { text-align: center; width: 1%; }
.names-table th[data-sort=a], .names-table th[data-sort=b], .names-table th[data-sort=score] { text-align: center; }
.names-table td.score { text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.v-like { color: var(--like); } .v-pass { color: var(--pass); } .v-none { color: var(--muted); }
.vote button { border: 0; background: none; padding: 2px 8px; font-size: 1rem; }
.status { font-size: .8rem; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.status.match { background: var(--like); color: #fff; }
.status.a, .status.b { background: var(--line); }
.status.none { color: var(--muted); }

/* Battle */
.duel { display: flex; flex-direction: column; gap: 12px; margin: 8px 0 12px; }
.duel button.pick { padding: 28px 12px; border-radius: 20px; font-size: 2rem; font-weight: 700; background: var(--card); box-shadow: 0 6px 18px rgba(0,0,0,.06); }
.duel button.pick small { display: block; font-size: .95rem; font-weight: 400; color: var(--muted); margin-top: 4px; }
.duel button.pick:active { transform: scale(.98); border-color: var(--accent); }
.vs { text-align: center; color: var(--muted); font-weight: 700; }
.battle-actions { display: flex; justify-content: center; margin-bottom: 16px; }
.battle-actions button { color: var(--muted); }
.rank { list-style: none; padding: 0; margin: 0; counter-reset: r; }
.rank li { display: flex; justify-content: space-between; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.rank li::before { counter-increment: r; content: counter(r) "."; color: var(--muted); width: 2em; }
.rank li span:first-of-type { flex: 1; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 20px; }
.compare h4 { margin: 0 0 6px; }
.compare ol { margin: 0; padding-left: 1.4em; }
.compare li { padding: 4px 0; }
.compare li.both { color: var(--like); font-weight: 700; }
.shared { background: var(--card); border: 1px solid var(--like); border-radius: 12px; padding: 10px 12px; }

/* Flags and preferred origins */
.flags { letter-spacing: 1px; }
.flags.small { font-size: .85rem; }
.prefs { margin-bottom: 24px; }
.prefs h3 { margin: 8px 0 4px; }
.prefs h4 { margin: 16px 0 6px; }
.zone { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px; min-height: 56px; border: 2px dashed var(--line); border-radius: 14px; transition: border-color .15s, background .15s; }
.zone.pref { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, transparent); min-height: 64px; }
.zone.over { border-style: solid; border-color: var(--like); background: color-mix(in srgb, var(--like) 10%, transparent); }
.zone-empty { margin: auto; color: var(--muted); font-size: .9rem; }
.src { display: inline-flex; align-items: center; gap: 6px; padding: 7px 11px; border-radius: 99px; font-size: .9rem; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.src .flag { font-size: 1.1rem; line-height: 1; }
.src .n { color: var(--muted); font-size: .75rem; }
.zone.pref .src { border-color: var(--accent); }
.src.lifted { opacity: .35; }
.src.ghost { position: fixed; left: 0; top: 0; z-index: 50; pointer-events: none; box-shadow: 0 8px 20px rgba(0,0,0,.2); opacity: .95; }
