:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f242e;
  --text: #e8eaf0;
  --muted: #8a93a6;
  --accent: #00d09c;
  --accent-soft: #00d09c22;
  --danger: #ff5a5f;
  --warn: #ffb84d;
  --border: #ffffff14;
  --shadow: 0 8px 30px rgba(0,0,0,.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Pretendard Variable', Pretendard, system-ui, sans-serif;
  background:
    radial-gradient(1200px 600px at 80% -10%, #00d09c1a, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, #6b7cff1a, transparent 60%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 2rem 1rem 4rem;
}

main { max-width: 900px; margin: 0 auto; }

/* ── 게이트 ── */
.gate {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 2rem 1rem;
}
.gate-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 18px; padding: 2.5rem 2rem;
  max-width: 380px; width: 100%; text-align: center;
  box-shadow: var(--shadow);
}
.gate-icon { font-size: 3rem; margin-bottom: .8rem; }
.gate-card h1 { font-size: 1.4rem; font-weight: 800; margin-bottom: .4rem; letter-spacing: -0.02em; }
.gate-desc { color: var(--muted); font-size: .9rem; margin-bottom: 1.5rem; }
.gate-card input {
  width: 100%; padding: .8rem 1rem;
  background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); font-size: 1rem; font-family: inherit;
  text-align: center; letter-spacing: .05em;
}
.gate-card input:focus { outline: none; border-color: var(--accent); }
.gate-error { color: var(--danger); font-size: .85rem; height: 1.2rem; margin: .5rem 0; }
.gate-card button {
  width: 100%; padding: .8rem;
  background: var(--accent); color: #0a0e15;
  border: none; border-radius: 10px;
  font-size: 1rem; font-weight: 700; font-family: inherit;
  cursor: pointer; margin-top: .5rem;
}
.gate-card button:hover { filter: brightness(1.1); }

/* ── 헤더 ── */
header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.5rem;
}
header h1 { font-size: 1.8rem; font-weight: 800; letter-spacing: -0.02em; }
.live-badge {
  display: flex; align-items: center; gap: .4rem;
  font-size: .8rem; color: var(--accent); font-weight: 700;
}
.live-dot {
  width: 8px; height: 8px; background: var(--accent); border-radius: 50%;
  box-shadow: 0 0 0 0 var(--accent-soft);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 var(--accent-soft); }
  70%  { box-shadow: 0 0 0 12px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* ── 안내 박스 ── */
.guide {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 1rem 1.25rem; margin-bottom: 1.5rem;
}
.guide strong { color: var(--accent); }
.guide small { color: var(--muted); display: block; margin-top: .4rem; font-size: .82rem; }

/* ── 후보 카드 (시청자) ── */
#cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}
.cand-card {
  background: var(--panel); border: 2px solid var(--border);
  border-radius: 16px; padding: 1.5rem 1.25rem 1.25rem;
  display: flex; flex-direction: column; align-items: center;
  gap: .65rem; cursor: pointer;
  transition: transform .2s, border-color .25s, box-shadow .25s;
}
.cand-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.cand-card.voted {
  border-color: var(--accent);
  background: linear-gradient(135deg, var(--accent-soft), var(--panel));
  cursor: default;
}
.cand-card.disabled { opacity: .55; cursor: not-allowed; }
.cand-card.disabled:hover { transform: none; border-color: var(--border); }

.avatar-wrap { position: relative; }
.avatar {
  width: 96px; height: 96px; border-radius: 50%;
  object-fit: cover; background: var(--panel-2);
  border: 2px solid #ffffff15;
}
.avatar-fallback {
  width: 96px; height: 96px; border-radius: 50%;
  background: linear-gradient(135deg, #4a6cf7, #00d09c);
  display: flex; align-items: center; justify-content: center;
  font-size: 2.2rem; font-weight: 800; color: white;
}
.num-badge {
  position: absolute; bottom: 0; right: -4px;
  background: var(--accent); color: #0a0e15;
  font-size: .75rem; font-weight: 800;
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 3px solid var(--panel);
}

.cand-name { font-size: 1.15rem; font-weight: 700; text-align: center; }
.cand-party {
  font-size: .8rem; color: var(--accent); font-weight: 600;
  background: var(--accent-soft);
  padding: 3px 12px; border-radius: 99px;
}
.cand-pledge {
  font-size: .82rem; color: var(--muted);
  text-align: center; line-height: 1.5;
  white-space: pre-wrap;
  background: var(--panel-2);
  padding: .65rem .8rem;
  border-radius: 8px;
  width: 100%;
  max-height: 120px; overflow-y: auto;
}
.voted-mark {
  margin-top: .5rem;
  background: var(--accent); color: #0a0e15;
  font-size: .8rem; font-weight: 700;
  padding: 4px 12px; border-radius: 99px;
}

.total-bar {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 1.5rem; padding: 1rem 1.25rem;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; font-size: .9rem;
}
.total-bar #total-votes { font-weight: 700; color: var(--text); font-feature-settings: "tnum"; }
.total-bar .hint { color: var(--muted); font-size: .82rem; }

.empty-state { text-align: center; padding: 4rem 1rem; color: var(--muted); }
.empty-state h2 { color: var(--text); margin-bottom: .5rem; }

/* ── 당선자 오버레이 ── */
.winner-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 100;
  background: rgba(10,12,17,.97);
  flex-direction: column; align-items: center; justify-content: flex-start;
  gap: 1.2rem; padding: 3rem 1.5rem; overflow-y: auto;
  animation: fadeIn .6s ease;
}
.winner-overlay.show { display: flex; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.winner-label { font-size: 1rem; font-weight: 700; color: var(--muted); letter-spacing: .15em; text-transform: uppercase; }
.winner-crown { font-size: 2.8rem; animation: bounce 1s ease-in-out infinite alternate; }
@keyframes bounce { from { transform: translateY(0); } to { transform: translateY(-10px); } }

.winner-avatar-wrap { position: relative; }
.winner-avatar {
  width: 200px; height: 200px; border-radius: 50%;
  object-fit: cover;
  border: 4px solid var(--accent);
  box-shadow: 0 0 0 12px var(--accent-soft), var(--shadow);
  animation: popIn .6s cubic-bezier(.175,.885,.32,1.275) .2s both;
}
.winner-fallback {
  width: 200px; height: 200px; border-radius: 50%;
  background: linear-gradient(135deg, #4a6cf7, #00d09c);
  display: none; align-items: center; justify-content: center;
  font-size: 5.5rem; font-weight: 800; color: white;
  border: 4px solid var(--accent);
  box-shadow: 0 0 0 12px var(--accent-soft), var(--shadow);
  animation: popIn .6s cubic-bezier(.175,.885,.32,1.275) .2s both;
}
@keyframes popIn {
  from { transform: scale(.5); opacity: 0; }
  to   { transform: scale(1);  opacity: 1; }
}

.winner-party {
  font-size: 1rem; color: var(--accent); font-weight: 700;
  background: var(--accent-soft);
  padding: 6px 18px; border-radius: 99px;
  display: none;
  animation: slideUp .5s ease .35s both;
}
.winner-party.show { display: block; }
.winner-name {
  font-size: 2.6rem; font-weight: 900; letter-spacing: -0.03em;
  animation: slideUp .5s ease .4s both; text-align: center;
}
.winner-pledge {
  font-size: 1rem; color: var(--text);
  background: var(--panel);
  padding: 1rem 1.25rem; border-radius: 12px;
  max-width: 500px; line-height: 1.6;
  white-space: pre-wrap; text-align: center;
  border-left: 3px solid var(--accent);
  display: none;
  animation: slideUp .5s ease .45s both;
}
.winner-pledge.show { display: block; }
.winner-votes {
  font-size: 1.1rem; color: var(--muted);
  animation: slideUp .5s ease .5s both;
}
.winner-votes strong { color: var(--accent); font-size: 1.5rem; }
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.winner-results {
  display: flex; gap: .6rem; flex-wrap: wrap; justify-content: center;
  margin-top: .5rem; max-width: 700px;
  animation: slideUp .5s ease .6s both;
}
.mini-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: .55rem .9rem;
  display: flex; align-items: center; gap: .5rem; font-size: .85rem;
}
.mini-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  object-fit: cover; background: var(--panel-2);
}
.mini-fallback {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, #4a6cf7, #00d09c);
  display: flex; align-items: center; justify-content: center;
  font-size: .9rem; font-weight: 800; color: white;
}

#confetti-canvas {
  position: fixed; inset: 0; pointer-events: none; z-index: 99;
}

/* ── 관리자 페이지 ── */
.section-title {
  font-size: 1rem; color: var(--muted);
  margin: 2rem 0 .75rem; font-weight: 600;
}
.form-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: .25rem;
}
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 1.25rem; margin-bottom: .75rem;
}
.card label {
  display: block; font-size: .8rem; color: var(--muted);
  margin: .65rem 0 .3rem; font-weight: 600;
}
.card input[type=text],
.card textarea {
  width: 100%; padding: .65rem .8rem;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: .95rem;
  font-family: inherit;
}
.card input:focus, .card textarea:focus {
  outline: none; border-color: var(--accent);
}
.card textarea { resize: vertical; min-height: 70px; line-height: 1.5; }

/* 후보 입력 카드 */
.cand-input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  margin-top: .75rem;
}
.cand-input-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: .5rem;
}
.cand-num {
  background: var(--accent); color: #0a0e15;
  font-weight: 800; font-size: .85rem;
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.cand-input-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: .75rem;
}

/* ── 파일 업로드 영역 ── */
.upload-area {
  display: flex; align-items: center; gap: .75rem;
  margin-top: .25rem;
  padding: .75rem;
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: 10px;
  transition: border-color .2s;
}
.upload-area:hover { border-color: var(--accent); }
.upload-area.has-image { border-style: solid; border-color: var(--accent); }

.preview-img {
  width: 64px; height: 64px; border-radius: 50%;
  object-fit: cover; background: var(--panel-2);
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.preview-placeholder {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--panel-2); border: 1px dashed var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; color: var(--muted);
  flex-shrink: 0;
}

.upload-info { flex: 1; min-width: 0; }
.upload-label {
  display: inline-block;
  padding: .45rem .9rem;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 7px;
  font-size: .82rem; font-weight: 600;
  cursor: pointer;
  transition: background .2s;
}
.upload-label:hover { background: var(--accent); color: #0a0e15; }
.upload-input { display: none; }
.upload-status {
  display: block; margin-top: .35rem;
  font-size: .75rem; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.upload-clear {
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 1.2rem; padding: 0 .3rem;
  flex-shrink: 0;
}
.upload-clear:hover { color: var(--danger); }

.btn {
  padding: .6rem 1.1rem; border-radius: 8px; border: none;
  background: var(--accent); color: #0a0e15;
  font-weight: 700; cursor: pointer;
  font-size: .9rem; font-family: inherit;
}
.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-danger { background: var(--danger); color: white; }
.btn-warn { background: var(--warn); color: #0a0e15; }
.btn-ghost {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border);
}
.btn-small { padding: .35rem .8rem; font-size: .8rem; }
.btn-add {
  width: 100%; margin-top: .75rem;
  background: transparent; color: var(--accent);
  border: 1px dashed var(--accent);
  padding: .8rem;
}
.btn-add:hover { background: var(--accent); color: #0a0e15; }

.actions { display: flex; gap: .5rem; margin-top: 1rem; align-items: center; }

.poll-row {
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
  padding: .9rem 1.1rem; background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px; margin-bottom: .5rem;
}
.poll-row.active { border-color: var(--accent); }
.poll-row.ended { border-color: var(--warn); }
.poll-row.archived { opacity: .55; }
.poll-row .title { flex: 1; font-weight: 600; min-width: 0; }
.poll-row .meta { font-size: .78rem; color: var(--muted); }
.poll-row .badge {
  font-size: .7rem; font-weight: 800;
  padding: 2px 9px; border-radius: 99px;
}
.poll-row .badge.live { background: var(--accent); color: #0a0e15; }
.poll-row .badge.ended { background: var(--warn); color: #0a0e15; }

.poll-row .row-actions { display: flex; gap: .4rem; flex-wrap: wrap; }