:root {
  --bg: #191919;
  --surface: #202020;
  --line: #2c2c2c;
  --line-strong: #3a3a3a;
  --text: #ececec;
  --muted: #8d8d8d;
  --pink: #f472b6;
  --pink-soft: rgba(244, 114, 182, 0.16);
  --pink-glow: 0 0 0 1px var(--pink), 0 0 18px rgba(244, 114, 182, 0.35);
  --num: "Space Grotesk", "Inter", sans-serif;
  --sans: "Inter", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
img { image-orientation: from-image; }

.wrap {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.wrap.wide { max-width: 980px; }

h1 {
  font-size: 1.6rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
  margin: 0 0 8px;
}
h2 { font-size: 1.05rem; font-weight: 600; margin: 28px 0 10px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.num { font-family: var(--num); font-variant-numeric: tabular-nums; }
.err { color: var(--pink); min-height: 1.5em; margin: 8px 0 0; }
.err:empty { display: none; }
a { color: var(--pink); }

header { margin-bottom: 20px; }
header p { margin-bottom: 0; }

label { display: block; margin: 14px 0; }
label span { display: block; color: var(--muted); font-size: 0.875rem; margin-bottom: 6px; }
input[type="text"], input[type="password"] {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 12px 14px;
  font: inherit;
  outline: none;
}
input:focus-visible { border-color: var(--pink); box-shadow: 0 0 0 3px var(--pink-soft); }

button {
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  border-radius: 8px;
  padding: 12px 18px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s, opacity 0.15s, transform 0.08s;
}
button:hover { border-color: var(--pink); }
button:active { transform: scale(0.98); }
button:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--pink-soft); }
button:disabled { opacity: 0.4; cursor: default; pointer-events: none; }
button.primary { background: var(--pink); border-color: var(--pink); color: #1a0b12; width: 100%; padding: 14px 18px; }
button.primary:hover { box-shadow: var(--pink-glow); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); padding: 8px 10px; }
button.ghost:hover { color: var(--text); border-color: var(--line-strong); }
button.danger:hover { border-color: #e5484d; color: #e5484d; }

.row { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-top: 16px; }
.row .primary { width: auto; flex: 1; }

hr.rule { border: 0; border-top: 1px solid var(--line); margin: 22px 0; }

/* ---------- swipe stage ---------- */
.topbar { display: flex; justify-content: space-between; align-items: center; height: 40px; margin-bottom: 10px; }
.topbar .num { font-size: 1.1rem; color: var(--muted); }
.topbar .num b { color: var(--text); font-weight: 600; }

#deck {
  position: relative;
  flex: 1;
  min-height: 300px;
  height: calc(100dvh - 250px);
  max-height: 720px;
}
.card {
  position: absolute; inset: 0;
  background: #111;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
  transition: transform 0.25s ease, opacity 0.25s ease, box-shadow 0.15s;
  will-change: transform;
}
.card.under { transform: scale(0.965) translateY(10px); opacity: 0.6; pointer-events: none; border-color: var(--line); }
.card.dragging { transition: none; cursor: grabbing; }
.card img {
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
}
.card .lean {
  position: absolute; top: 18px;
  padding: 6px 12px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  opacity: 0;
  transition: opacity 0.12s;
  border: 1px solid;
}
.card .lean.yes { right: 18px; color: var(--pink); border-color: var(--pink); background: rgba(25,25,25,0.7); }
.card .lean.no { left: 18px; color: #bdbdbd; border-color: #bdbdbd; background: rgba(25,25,25,0.7); }
.card[data-lean="yes"] .lean.yes, .card[data-lean="no"] .lean.no { opacity: 1; }
.card[data-lean="yes"] { box-shadow: var(--pink-glow); border-color: var(--pink); }
.card.fly-right { transform: translateX(130%) rotate(14deg); opacity: 0; }
.card.fly-left { transform: translateX(-130%) rotate(-14deg); opacity: 0; }

.actions { display: flex; justify-content: center; gap: 28px; margin: 18px 0 6px; }
.round {
  width: 74px; height: 74px;
  border-radius: 50%;
  padding: 0;
  font-weight: 600;
  font-size: 0.95rem;
}
.round.yes { border-color: var(--pink); color: var(--pink); }
.round.yes:hover { box-shadow: var(--pink-glow); }
.round.no { color: #bdbdbd; }
.round.no:hover { border-color: #bdbdbd; }
.hint { text-align: center; color: var(--muted); font-size: 0.8rem; margin: 0; }

/* ---------- rank stage ---------- */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tile {
  position: relative;
  padding: 0;
  aspect-ratio: 3 / 4;
  border-radius: 10px;
  overflow: hidden;
  background: #111;
  border: 1px solid var(--line);
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; transition: opacity 0.15s; }
.tile.picked { border-color: var(--pink); box-shadow: 0 0 0 1px var(--pink); }
.tile.picked img { opacity: 0.55; }
.tile .badge {
  position: absolute; top: 10px; left: 10px;
  min-width: 34px; height: 34px;
  padding: 0 8px;
  border-radius: 17px;
  background: var(--pink);
  color: #1a0b12;
  font-family: var(--num);
  font-weight: 600;
  font-size: 1.05rem;
  display: none;
  align-items: center; justify-content: center;
}
.tile.picked .badge { display: inline-flex; }
.tile:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--pink-soft); }

/* ---------- results / setup ---------- */
table { width: 100%; border-collapse: collapse; font-size: 0.925rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 0.8rem; }
td.num, th.num { text-align: right; }
tr.top td { background: var(--pink-soft); }
.thumb { width: 54px; height: 72px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); display: block; background: #111; }
.thumb.sm { width: 34px; height: 46px; border-radius: 4px; }
.bar { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; margin-top: 6px; min-width: 90px; }
.bar i { display: block; height: 100%; background: var(--pink); }
.strip { display: flex; gap: 4px; flex-wrap: wrap; }
.voter { padding: 14px 0; border-bottom: 1px solid var(--line); }
.voter .row { margin-top: 0; }
.voter h3 { margin: 0; font-size: 1rem; font-weight: 600; }
.mono-list { font-size: 0.85rem; color: var(--muted); columns: 2; margin: 8px 0 0; padding-left: 18px; }
.file { border: 1px dashed var(--line-strong); border-radius: 10px; padding: 18px; text-align: center; color: var(--muted); }
.file input { display: none; }
.ok { color: #7bd88f; }

@media (prefers-reduced-motion: reduce) {
  .card, button, .tile img, .card .lean { transition: none; }
}
@media (min-width: 640px) {
  .grid { grid-template-columns: repeat(3, 1fr); }
}

/* ---------- compare stage ---------- */
.ask { text-align: center; margin: 4px 0 14px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice {
  padding: 0;
  background: #111;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  height: calc(100dvh - 300px);
  min-height: 260px;
  max-height: 620px;
  touch-action: manipulation;
}
.choice img { width: 100%; height: 100%; object-fit: contain; display: block; pointer-events: none; -webkit-user-drag: none; }
.choice:hover { border-color: var(--line-strong); }
.choice.chosen { border-color: var(--pink); box-shadow: var(--pink-glow); }
.choice.chosen img { opacity: 0.9; }
.progress { height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; margin-bottom: 12px; }
.progress i { display: block; height: 100%; background: var(--pink); transition: width 0.2s; }
.tile.first { grid-column: 1 / -1; aspect-ratio: 4 / 3; }
.tile.first img { object-fit: contain; opacity: 1; }
.tile.picked.first img { opacity: 1; }
