:root {
  --bg: #fff8f3;
  --surface: #ffffff;
  --ink: #1f1a17;
  --muted: #7a6e66;
  --line: #f0e3d9;
  --accent: #ff5a36;
  --accent-ink: #ffffff;
  --accent-soft: #ffe7df;
  --naver: #03c75a;
  --kakao: #fee500;
  --gold: #ffb800;
  --shadow: 0 6px 24px rgba(80, 40, 20, 0.08);
  --radius: 18px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17130f;
    --surface: #221c17;
    --ink: #f6eee8;
    --muted: #a59a92;
    --line: #362c25;
    --accent-soft: #3a2018;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Pretendard Variable', Pretendard, -apple-system, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}
main { max-width: 760px; margin: 0 auto; padding: 20px 16px 80px; }
h1, h2, h3 { margin: 0; letter-spacing: -0.02em; }
button { font: inherit; cursor: pointer; }
input, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; width: 100%;
  outline: none; transition: border-color .15s;
}
input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 92px; }
a { color: inherit; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 12px; padding: 13px 18px; font-weight: 700; text-decoration: none;
  background: var(--accent); color: var(--accent-ink); transition: transform .1s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.ghost { background: var(--accent-soft); color: var(--accent); }
.btn.plain { background: transparent; color: var(--muted); padding: 8px 10px; font-weight: 600; }
.btn.block { width: 100%; }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.stack { display: grid; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.label { font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 6px; display: block; }

/* home */
.hero { text-align: center; padding: 28px 0 22px; }
.hero .logo { font-size: 52px; line-height: 1; }
.hero h1 { font-size: 30px; margin-top: 10px; }
.hero p { color: var(--muted); margin: 8px 0 0; }
.home-grid { display: grid; gap: 14px; }
.pin-input { font-size: 26px; font-weight: 800; letter-spacing: .35em; text-align: center; }
.how { margin-top: 18px; display: grid; gap: 8px; font-size: 14px; color: var(--muted); }
.how b { color: var(--ink); }

/* room header */
.room-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.room-head h2 { font-size: 22px; }
.pin-box { text-align: right; flex-shrink: 0; }
.pin-box .pin { font-size: 22px; font-weight: 800; letter-spacing: .12em; color: var(--accent); }
.people { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 16px; }
.chip { font-size: 13px; padding: 5px 10px; border-radius: 99px; background: var(--surface); border: 1px solid var(--line); }
.chip.host::before { content: '👑 '; }
.chip.done { border-color: var(--accent); color: var(--accent); }
.chip.done::after { content: ' ✓'; }

/* candidates */
.cands { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-top: 14px; }
.cand { background: var(--surface); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); position: relative; }
.thumb { aspect-ratio: 4/3; background: var(--accent-soft); display: grid; place-items: center; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .ph { font-size: 34px; font-weight: 800; color: var(--accent); opacity: .8; }
.cand .body { padding: 10px 12px 12px; }
.cand .name { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cand .meta { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cand .x {
  position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.55); color: #fff; font-size: 15px; line-height: 1;
}
.src { position: absolute; top: 8px; left: 8px; font-size: 11px; font-weight: 800; padding: 3px 7px; border-radius: 6px; }
.src.naver { background: var(--naver); color: #fff; }
.src.kakao { background: var(--kakao); color: #3b1e1e; }
.src.manual { background: rgba(0,0,0,.55); color: #fff; }
.add-results { font-size: 13px; display: grid; gap: 4px; margin-top: 8px; }
.add-results .ok { color: var(--naver); }
.add-results .err { color: #e5484d; }
.sticky-cta {
  position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 30%);
}
.sticky-cta > div { max-width: 760px; margin: 0 auto; }

/* game */
.game-head { text-align: center; margin: 4px 0 16px; }
.game-head .round { font-size: 26px; font-weight: 800; }
.game-head .prog { color: var(--muted); font-size: 14px; }
.bar { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.bar > i { display: block; height: 100%; background: var(--accent); transition: width .3s; }
.duel { display: grid; grid-template-columns: 1fr; gap: 10px; position: relative; }
@media (min-width: 640px) { .duel { grid-template-columns: 1fr 1fr; gap: 16px; } }
.pick {
  border: 0; padding: 0; text-align: left; background: var(--surface); color: var(--ink);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  transition: transform .18s, opacity .25s, box-shadow .18s;
}
.pick:hover { transform: translateY(-2px); box-shadow: 0 10px 30px rgba(255, 90, 54, .18); }
.pick .thumb { aspect-ratio: 16/10; }
@media (min-width: 640px) { .pick .thumb { aspect-ratio: 1/1; } }
.pick .body { padding: 14px 16px 16px; }
.pick .name { font-size: 20px; font-weight: 800; }
.pick .meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.pick.win { transform: scale(1.03); box-shadow: 0 0 0 4px var(--accent), var(--shadow); }
.pick.lose { opacity: .25; transform: scale(.96); }
.vs {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 2;
  width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 900; font-size: 18px; font-style: italic;
  box-shadow: 0 0 0 5px var(--bg); pointer-events: none;
}
.maplink { font-size: 12px; color: var(--muted); }

/* results */
.champ { text-align: center; }
.champ .crown { font-size: 44px; }
.champ .thumb { border-radius: 16px; max-width: 360px; margin: 10px auto; aspect-ratio: 16/10; }
.champ .name { font-size: 26px; font-weight: 800; }
.section-title { font-size: 17px; font-weight: 800; margin: 26px 0 10px; }
.rank { display: grid; gap: 8px; }
.rank-row { display: grid; grid-template-columns: 28px 48px 1fr auto; gap: 10px; align-items: center; background: var(--surface); padding: 8px 12px; border-radius: 12px; }
.rank-row .no { font-weight: 800; color: var(--muted); text-align: center; }
.rank-row:first-child .no { color: var(--gold); }
.rank-row .thumb { width: 48px; height: 48px; border-radius: 10px; aspect-ratio: auto; }
.rank-row .thumb .ph { font-size: 18px; }
.rank-row .nm { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-row .sub { font-size: 12px; color: var(--muted); }
.rank-row .score { text-align: right; font-size: 13px; }
.rank-row .score b { font-size: 16px; color: var(--accent); }
.wins-bar { height: 4px; border-radius: 99px; background: var(--line); margin-top: 4px; overflow: hidden; }
.wins-bar i { display: block; height: 100%; background: var(--accent); }
.votes { display: grid; gap: 8px; }
.vote {
  display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 10px; width: 100%;
  border: 2px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 14px; padding: 8px 12px; text-align: left;
}
.vote.mine { border-color: var(--accent); background: var(--accent-soft); }
.vote .thumb { width: 44px; height: 44px; border-radius: 10px; aspect-ratio: auto; }
.vote .cnt { font-weight: 800; color: var(--accent); }
.final {
  margin-top: 18px; padding: 18px; border-radius: var(--radius); text-align: center;
  background: var(--accent); color: #fff;
}
.final .k { font-size: 13px; opacity: .85; }
.final .v { font-size: 24px; font-weight: 800; margin-top: 2px; }
.who { display: grid; gap: 6px; font-size: 14px; }
.who div { display: flex; justify-content: space-between; background: var(--surface); padding: 10px 12px; border-radius: 10px; }

#toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 99px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: all .2s; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* presence */
.chip.on::before { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--naver); margin-right: 5px; vertical-align: 1px; }
.chip.host.on::before { content: '👑'; width: auto; height: auto; background: none; margin-right: 3px; }
.chip.off { opacity: .55; }

/* add panel */
.tabs { display: flex; gap: 6px; background: var(--bg); padding: 4px; border-radius: 12px; }
.tab { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 9px 6px; border-radius: 9px; font-weight: 700; font-size: 14px; }
.tab.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.results { display: grid; gap: 6px; max-height: 420px; overflow: auto; }
.result {
  display: grid; grid-template-columns: 52px 1fr 32px; gap: 10px; align-items: center; text-align: left;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 12px; padding: 6px 8px;
}
.result:hover:not(:disabled) { border-color: var(--accent); }
.result .thumb { width: 52px; height: 52px; border-radius: 9px; aspect-ratio: auto; }
.result .thumb .ph { font-size: 20px; }
.result .nm { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result .sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result .plus { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: #fff; font-weight: 800; font-size: 18px; }
.result.added { opacity: .55; }
.result.added .plus { background: var(--naver); font-size: 14px; }
.err { color: #e5484d; }

/* live voting */
.banner { text-align: center; padding: 10px 14px; border-radius: 12px; margin-bottom: 12px; background: var(--accent); color: #fff; font-size: 15px; }
.banner.tie { background: var(--gold); color: #3a2a00; }
.banner.soft { background: var(--surface); color: var(--muted); font-size: 13px; box-shadow: var(--shadow); }
.banner.soft span { margin: 0 2px; }
.banner.soft span.v { color: var(--accent); font-weight: 700; }
.banner.soft span.v::after { content: ' ✓'; }
.pick { position: relative; }
.pick.mine { box-shadow: 0 0 0 4px var(--accent), var(--shadow); }
.pick:disabled { cursor: default; }
.tally {
  position: absolute; top: 12px; right: 12px; z-index: 1; background: rgba(0,0,0,.65); color: #fff;
  padding: 6px 12px; border-radius: 99px; font-size: 14px;
}
.tally b { font-size: 20px; }
.tally.mine { background: var(--accent); font-weight: 700; }
.pick.win .tally { background: var(--accent); }

/* history */
.hists { display: grid; gap: 6px; }
.hist { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; background: var(--surface); padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.hist .rd { font-size: 12px; font-weight: 800; color: var(--accent); min-width: 44px; }
.hist .w { font-weight: 700; }
.hist .l { color: var(--muted); }
.hist b { color: var(--accent); margin-left: 2px; }
.hist .l b { color: var(--muted); }
