:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f3eee6;
  --text: #2b2620;
  --muted: #7a7064;
  --line: #e6dfd4;
  --accent: #e8792b;
  --accent-ink: #ffffff;
  --accent-soft: #fde8d7;
  --gold: #d69e1a;
  --gold-soft: #fbf0d2;
  --danger: #c43d3d;
  --danger-soft: #fbe3e3;
  --ok: #2f8a57;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 14px rgba(60, 40, 20, .05);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1916;
    --surface: #24211d;
    --surface-2: #2d2924;
    --text: #efe9e1;
    --muted: #a39a8e;
    --line: #3a352e;
    --accent: #f08c45;
    --accent-ink: #1b1916;
    --accent-soft: #3d2a1b;
    --gold: #f0bf47;
    --gold-soft: #3a3020;
    --danger: #f07070;
    --danger-soft: #3d2222;
    --ok: #5fc48a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; }

.container { max-width: 980px; margin: 0 auto; padding: 24px 16px 64px; }

/* 상단바 */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; text-decoration: none; white-space: nowrap; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a {
  padding: 6px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.usermenu { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 8px; }
  .nav { order: 3; flex-basis: 100%; }
}

/* 카드 */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.card + .card, .stack > * + * { margin-top: 16px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }

/* 버튼 / 폼 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 4px 10px; font-size: .85rem; border-radius: 7px; }
.btn.big { padding: 12px 22px; font-size: 1.05rem; }

label { display: block; font-weight: 600; font-size: .9rem; }
label > input, label > textarea, label > select { margin-top: 6px; }
input, textarea, select {
  width: 100%; padding: 9px 11px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit;
}
input:focus, textarea:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); border-color: var(--accent); }
form.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 180px; }
.error { color: var(--danger); background: var(--danger-soft); padding: 8px 12px; border-radius: 8px; margin: 0; }
.hint { font-size: .85rem; color: var(--muted); background: var(--surface-2); padding: 10px 12px; border-radius: 9px; }

/* 로그인 */
.auth { max-width: 380px; margin: 8vh auto 0; }
.auth h1 { text-align: center; }
.auth .lead { text-align: center; margin-bottom: 18px; }

/* 배지 / 칩 */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted);
}
.badge.void { background: var(--danger-soft); color: var(--danger); }
.badge.officer { background: var(--accent-soft); color: var(--accent); }
.badge.admin { background: var(--gold-soft); color: var(--gold); }
.badge.warn { background: var(--gold-soft); color: var(--gold); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px;
  background: var(--gold-soft); color: var(--text); font-weight: 600; font-size: .9rem; text-decoration: none;
}

/* 뽑기 목록 */
.draw-list { display: grid; gap: 12px; }
.draw-item { display: block; text-decoration: none; transition: border-color .15s; }
.draw-item:hover { border-color: var(--accent); }
.draw-item .top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; margin-bottom: 8px; }
.draw-item .title { font-weight: 700; font-size: 1.05rem; }
.draw-item.voided { opacity: .6; }
.draw-item.voided .title { text-decoration: line-through; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .85rem; color: var(--muted); margin-top: 8px; }

/* 표 */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
td.r, th.r { text-align: right; }
tr.win td { background: var(--gold-soft); }
tr:last-child td { border-bottom: none; }

/* 막대 */
.bar { position: relative; height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; min-width: 80px; }
.bar > span { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: 99px; }
.bar > i { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--text); opacity: .55; }
.luck-pos { color: var(--ok); }
.luck-neg { color: var(--danger); }

/* 통계 요약 */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi .label { font-size: .82rem; color: var(--muted); }
.kpi .value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* 새 뽑기 */
.entry-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.entry {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 6px 10px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
}
.entry.on { border-color: var(--accent); background: var(--accent-soft); }
.entry .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .prob { grid-column: 1 / -1; font-size: .82rem; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.entry .prob .bar { flex: 1; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.stepper button { border: 0; background: transparent; color: var(--text); width: 30px; height: 32px; font-size: 1.1rem; cursor: pointer; }
.stepper button:hover { background: var(--surface-2); }
.stepper input { width: 48px; border: 0; border-radius: 0; text-align: center; padding: 6px 2px; background: transparent; }
.stepper input:focus { outline: none; }
.summary-bar {
  position: sticky; bottom: 12px; margin-top: 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}

/* 결과 발표 */
.reveal { display: grid; gap: 10px; }
.slot {
  display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-radius: 12px;
  background: var(--surface-2); border: 1px dashed var(--line);
}
.slot .slot-rank { font-size: .85rem; color: var(--muted); min-width: 80px; }
.slot .slot-name { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.slot.won { background: var(--gold-soft); border: 1px solid var(--gold); animation: pop .35s ease-out; }
.slot.won .slot-name::before { content: "🏆 "; }
@keyframes pop { 0% { transform: scale(.96); } 60% { transform: scale(1.03); } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .slot.won { animation: none; } }

/* 토스트 */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 50;
  box-shadow: var(--shadow); max-width: calc(100% - 32px);
}
.toast.err { background: var(--danger); color: #fff; }

details summary { cursor: pointer; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
