:root {
  color-scheme: light dark;
  --bg: #fbf5ee; --bg2: #f4e9dd; --card: #fffdf9; --fg: #3a2a22; --muted: #8a7568; --line: #ecdccd;
  --accent: #d9734e; --accent-fg: #fff; --yes: #4f9d78; --no: #d4605b; --maybe: #d9a53c;
  --f: #e48aa0; --m: #6c9fd1; --u: #a991c9;
  --shadow: 0 10px 30px rgba(120, 70, 40, .12), 0 2px 6px rgba(120, 70, 40, .08);
  --radius: 18px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1714; --bg2: #26201b; --card: #2b241f; --fg: #f3e8de; --muted: #a8958a; --line: #3b322b;
    --accent: #e8875f; --yes: #63b48d; --no: #e2706a; --maybe: #e2b553;
    --shadow: 0 10px 30px rgba(0, 0, 0, .4), 0 2px 6px rgba(0, 0, 0, .3);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.small { font-size: 14px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0 0 8px; }
h2 { font-size: 24px; }
h3 { font-size: 18px; }

.shell { max-width: 480px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; padding: 0 16px; padding-top: env(safe-area-inset-top); }
.top { display: flex; align-items: center; justify-content: space-between; padding: 14px 2px 8px; }
.brand { font-family: var(--serif); font-size: 22px; font-weight: 600; letter-spacing: .2px; }
.logo { color: var(--accent); }
.duo-label { font-size: 13px; color: var(--muted); text-align: right; }
.view { flex: 1; display: flex; flex-direction: column; }

.hero { padding: 20px 2px 8px; }
.hero h1 { font-size: 30px; line-height: 1.15; }
.hero em { color: var(--accent); font-style: italic; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin: 12px 0; box-shadow: 0 1px 0 rgba(0,0,0,.02); }
.form { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
input, select {
  font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; width: 100%; min-width: 0;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn {
  font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--bg2); color: var(--fg);
  padding: 12px 16px; border-radius: 12px; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--no); }
.btn.danger.small { padding: 6px 10px; font-size: 14px; background: var(--no); color: #fff; border: 0; margin-top: 8px; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row .btn { flex: 1; }

.seg { display: inline-flex; background: var(--bg2); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { font: inherit; font-size: 14px; border: 0; background: transparent; color: var(--muted); padding: 7px 12px; border-radius: 999px; cursor: pointer; }
.seg button.on { background: var(--card); color: var(--fg); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }
.seg.wide { display: flex; }
.seg.wide button { flex: 1; }

/* Swipe */
.tab { flex: 1; display: flex; flex-direction: column; padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
#tab-swipe { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
.filters { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 4px 0 10px; }
.letter select { padding: 7px 10px; border-radius: 999px; background: var(--bg2); border: 0; font-size: 14px; }
.deck { position: relative; flex: 1; min-height: 340px; max-height: 460px; margin: 6px 0 14px; touch-action: none; }
.namecard {
  position: absolute; inset: 0; background: var(--card); border-radius: 26px; box-shadow: var(--shadow);
  border: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 28px 22px; text-align: center; user-select: none; -webkit-user-select: none; will-change: transform;
  transition: transform .3s ease, opacity .3s ease;
}
.namecard.back { transform: scale(.94) translateY(14px); opacity: .7; }
.namecard.drag { transition: none; }
.namecard .g { font-size: 13px; font-weight: 600; letter-spacing: .4px; text-transform: uppercase; padding: 4px 10px; border-radius: 999px; margin-bottom: 18px; }
.g-f { color: var(--f); background: color-mix(in srgb, var(--f) 15%, transparent); }
.g-m { color: var(--m); background: color-mix(in srgb, var(--m) 15%, transparent); }
.g-u { color: var(--u); background: color-mix(in srgb, var(--u) 15%, transparent); }
.namecard .nm { font-family: var(--serif); font-size: clamp(44px, 14vw, 64px); line-height: 1.05; font-weight: 600; word-break: break-word; }
.namecard .or { margin-top: 16px; color: var(--muted); font-size: 15px; max-width: 30ch; }
.namecard .own { margin-top: 10px; font-size: 13px; color: var(--accent); }
.stamp { position: absolute; top: 22px; font-weight: 800; font-size: 20px; letter-spacing: 1px; padding: 4px 12px; border: 3px solid; border-radius: 10px; opacity: 0; text-transform: uppercase; }
.stamp.y { left: 20px; color: var(--yes); transform: rotate(-12deg); }
.stamp.n { right: 20px; color: var(--no); transform: rotate(12deg); }
.stamp.m { left: 50%; top: auto; bottom: 26px; color: var(--maybe); transform: translateX(-50%); }
.empty-deck { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; border: 2px dashed var(--line); border-radius: 26px; color: var(--muted); }
.empty-deck .big { font-size: 40px; margin-bottom: 8px; }

.actions { display: flex; justify-content: center; align-items: center; gap: 16px; }
.act { width: 64px; height: 64px; border-radius: 50%; border: 0; background: var(--card); box-shadow: var(--shadow); font-size: 26px; cursor: pointer; display: grid; place-items: center; transition: transform .12s ease; }
.act:active { transform: scale(.9); }
.act.no { color: var(--no); }
.act.yes { color: var(--yes); width: 72px; height: 72px; font-size: 30px; }
.act.maybe { color: var(--maybe); width: 54px; height: 54px; font-size: 22px; font-weight: 700; }
.act.undo { color: var(--muted); width: 44px; height: 44px; font-size: 20px; }
.act:disabled { opacity: .35; }
.hint { text-align: center; font-size: 13px; margin: 12px 0 0; }

/* Lists */
.list { list-style: none; margin: 8px 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list li { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list .nm { font-family: var(--serif); font-size: 20px; font-weight: 600; }
.list .meta { flex: 1; min-width: 0; }
.list .or { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.g-f { background: var(--f); } .dot.g-m { background: var(--m); } .dot.g-u { background: var(--u); }
.list .empty { color: var(--muted); justify-content: center; text-align: center; padding: 22px 14px; }
.mini { display: flex; gap: 4px; }
.mini button { border: 1px solid var(--line); background: var(--bg); color: var(--muted); border-radius: 10px; width: 34px; height: 34px; font-size: 15px; cursor: pointer; }
.mini button.on.y { background: var(--yes); color: #fff; border-color: transparent; }
.mini button.on.m { background: var(--maybe); color: #fff; border-color: transparent; }
.mini button.on.n { background: var(--no); color: #fff; border-color: transparent; }
#matchList .nm::before { content: "♥ "; color: var(--accent); font-size: 16px; }

.code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 28px; letter-spacing: 3px; text-align: center; padding: 12px; margin: 8px 0 12px; background: var(--bg); border-radius: 12px; border: 1px dashed var(--line); user-select: all; }
.danger-zone { display: flex; flex-direction: column; gap: 8px; background: transparent; }
.stat { display: flex; justify-content: space-between; padding: 6px 0; }

/* Tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); z-index: 5;
}
.tabs button { flex: 1; max-width: 120px; position: relative; font: inherit; font-size: 12px; border: 0; background: none; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px; cursor: pointer; }
.tabs button span { font-size: 20px; line-height: 1; }
.tabs button.on { color: var(--accent); font-weight: 600; }
.badge { position: absolute; top: 2px; left: 55%; background: var(--accent); color: #fff; font-size: 11px; min-width: 18px; height: 18px; border-radius: 9px; padding: 0 5px; display: grid; place-items: center; }

/* Celebration */
.celebrate { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(40, 20, 10, .45); padding: 24px; animation: fade .25s ease; }
.cele-card { position: relative; background: var(--card); border-radius: 26px; padding: 28px 24px; text-align: center; box-shadow: var(--shadow); max-width: 340px; width: 100%; animation: pop .45s cubic-bezier(.2, 1.4, .4, 1); }
.cele-kicker { margin: 0; color: var(--accent); font-weight: 700; letter-spacing: .5px; text-transform: uppercase; font-size: 14px; }
.cele-name { font-family: var(--serif); font-size: 52px; font-weight: 600; margin: 6px 0; line-height: 1.1; word-break: break-word; }
.burst { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.burst i { position: absolute; bottom: -40px; font-style: normal; animation: rise linear forwards; }
@keyframes rise { to { transform: translateY(-115vh) rotate(var(--r, 30deg)); opacity: 0; } }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 30; max-width: calc(100% - 32px); box-shadow: var(--shadow); }

@media (min-height: 800px) { .deck { min-height: 400px; } }
@media (prefers-reduced-motion: reduce) { .namecard, .act { transition: none; } .burst { display: none; } }
