:root {
  --bg: #f5f6fa; --surface: #fff; --surface-2: #f0f1f6; --text: #16181f; --muted: #6a6f80;
  --line: #e3e5ed; --line-strong: #c3c7d4; --accent: #5b5bf0; --accent-soft: rgba(91, 91, 240, .12);
  --danger: #ef5b5b; --rim: #2a2c3b; --shadow: 0 1px 2px rgba(16, 18, 40, .04), 0 8px 28px rgba(16, 18, 40, .06);
  --font: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1016; --surface: #181a22; --surface-2: #21232d; --text: #eceef5; --muted: #9aa0b2;
    --line: #2a2d39; --line-strong: #4a4e60; --accent: #7b7bff; --accent-soft: rgba(123, 123, 255, .16);
    --rim: #d8dbe8; --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1016; --surface: #181a22; --surface-2: #21232d; --text: #eceef5; --muted: #9aa0b2;
  --line: #2a2d39; --line-strong: #4a4e60; --accent: #7b7bff; --accent-soft: rgba(123, 123, 255, .16);
  --rim: #d8dbe8; --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 5px; font-size: .92em; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; }
button:disabled { opacity: .45; cursor: default; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid transparent; border-radius: 10px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); background: var(--surface); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* nav */
.nav { max-width: 1200px; margin: 0 auto; padding: 14px 16px; display: flex; align-items: center; gap: 20px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 19px; color: var(--text); letter-spacing: -.3px; }
.brand:hover { text-decoration: none; }
.links { display: flex; gap: 16px; font-size: 14px; }
.links a { color: var(--muted); }
.tools { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.chip { font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); }
.icon-btn { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.hero { text-align: center; padding: 18px 16px 6px; }
.hero h1 { margin: 0; font-size: clamp(22px, 4vw, 32px); letter-spacing: -.6px; }
.hero p { margin: 6px 0 0; color: var(--muted); }

.ad { max-width: 1200px; margin: 16px auto; padding: 0 16px; min-height: 90px; }
.ad:empty { display: none; }

/* layout */
.app { max-width: 1200px; margin: 16px auto; padding: 0 16px; display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
@media (max-width: 900px) { .app { grid-template-columns: minmax(0, 1fr); } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 20px; box-shadow: var(--shadow); }
.stage-card { position: relative; }
.stage-card:fullscreen { display: flex; flex-direction: column; justify-content: center; border-radius: 0; overflow: auto; }

/* mode tabs */
.modes { display: flex; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 14px; overflow-x: auto; scrollbar-width: none; }
.modes::-webkit-scrollbar { display: none; }
.modes button { flex: 1 0 auto; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 12px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.modes button svg { width: 18px; height: 18px; }
.modes button:hover:not(:disabled) { color: var(--text); }
.modes button.on { background: var(--surface); color: var(--accent); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }

.stage { width: min(100%, 520px); aspect-ratio: 1; margin: 20px auto 8px; display: flex; align-items: center; justify-content: center; position: relative; }
.stage-card:fullscreen .stage { width: min(100%, 68vh); }

.result { text-align: center; font-size: clamp(22px, 4vw, 32px); font-weight: 800; min-height: 48px; letter-spacing: -.5px; word-break: break-all; padding: 0 8px; }
.result.pop { animation: pop .45s ease; }
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 60% { transform: scale(1.12); } 100% { transform: scale(1); opacity: 1; } }

/* controls */
.controls { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center; margin-top: 12px; }
.ctl-side { display: flex; gap: 8px; align-items: center; }
.ctl-side.right { justify-content: flex-end; }
@media (max-width: 640px) {
  .card { padding: 14px; }
  .controls { display: flex; flex-wrap: wrap; justify-content: space-between; }
  .spin { width: 100%; order: -1; }
  .seg button { padding: 6px 7px; }
  .field input { width: 52px; }
}
.field { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.field input { width: 64px; padding: 8px; text-align: center; }
.spin { background: var(--accent); color: #fff; font-size: 17px; font-weight: 700; padding: 14px 44px; border-radius: 999px; box-shadow: 0 6px 18px var(--accent-soft); transition: transform .1s, background .2s; }
.spin:active { transform: scale(.97); }
.spin.running { background: var(--danger); }

.seg { display: flex; padding: 3px; gap: 2px; background: var(--surface-2); border-radius: 10px; }
.seg button { padding: 6px 9px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .1); }
.seg.wide button { flex: 1; }

/* panel */
.panel { padding: 8px 16px 16px; position: sticky; top: 12px; }
@media (max-width: 900px) { .panel { position: static; } }
.tabs { display: flex; border-bottom: 1px solid var(--line); margin: 0 -16px 14px; padding: 0 8px; }
.tabs button { flex: 1; padding: 12px 4px; font-weight: 600; font-size: 15px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--text); border-color: var(--accent); }
.tabs small { font-weight: 500; color: var(--muted); font-size: 12px; }
.row { display: flex; gap: 6px; align-items: center; margin: 8px 0; flex-wrap: wrap; }
.row select { flex: 1; min-width: 0; padding: 8px 10px; }
.btn { padding: 7px 12px; border-radius: 9px; font-size: 13px; font-weight: 600; background: var(--surface-2); }
.btn:hover:not(:disabled) { background: var(--accent-soft); color: var(--accent); }
textarea { width: 100%; resize: vertical; font-size: 15px; line-height: 1.7; padding: 10px 12px; }
#items { height: 210px; }
.hint { margin: 6px 0; font-size: 12.5px; color: var(--muted); }
.hint a { cursor: pointer; font-weight: 600; }
.range { font-size: 13px; color: var(--muted); }
.range input { width: 64px; padding: 7px; text-align: center; }
.sub { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.sub label, .label { display: block; font-size: 13px; font-weight: 600; margin: 0 0 6px; }
.label { margin-top: 16px; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; font-size: 14.5px; cursor: pointer; border-bottom: 1px solid var(--line); flex-direction: row-reverse; }
.switch input { appearance: none; width: 40px; height: 24px; border-radius: 999px; background: var(--line-strong); position: relative; cursor: pointer; transition: background .2s; flex: none; margin: 0; border: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(16px); }
.switch span { flex: 1; }

.empty { text-align: center; color: var(--muted); font-size: 14px; padding: 24px 0; margin: 0; }
.tally { display: grid; gap: 4px; margin-top: 4px; }
.tally-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; font-size: 13.5px; position: relative; padding: 5px 10px; border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.tally-row i { position: absolute; inset: 0 auto 0 0; opacity: .45; }
.tally-row span { position: relative; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tally-row span + span { color: var(--muted); font-variant-numeric: tabular-nums; }
.history { max-height: 280px; overflow: auto; padding: 0; list-style: none; font-size: 14px; margin: 12px 0 0; }
.history li { display: flex; gap: 8px; align-items: baseline; padding: 6px 2px; border-bottom: 1px solid var(--line); }
.history b { color: var(--muted); font-weight: 500; font-size: 12px; min-width: 28px; font-variant-numeric: tabular-nums; }
.history i { width: 8px; height: 8px; border-radius: 50%; flex: none; align-self: center; }

/* wheel */
.wheel-box { position: relative; width: 100%; height: 100%; }
.wheel-box canvas { cursor: pointer; }
.wheel-box canvas, .drum, .ladder { width: 100%; height: 100%; display: block; }
.pointer { position: absolute; top: -2px; left: 50%; transform: translateX(-50%); width: 0; height: 0;
  border-left: 15px solid transparent; border-right: 15px solid transparent; border-top: 28px solid var(--danger); filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .3)); }

/* slot */
.slot { width: 100%; padding: 16px; border-radius: 22px; background: linear-gradient(160deg, #3b3e62, #1f2136); box-shadow: 0 10px 30px rgba(0, 0, 0, .25), inset 0 1px 0 rgba(255, 255, 255, .1); }
.slot-window { height: 228px; overflow: hidden; border-radius: 14px; background: #fff; position: relative; }
.slot-window::before, .slot-window::after { content: ""; position: absolute; left: 0; right: 0; height: 76px; z-index: 1; pointer-events: none; }
.slot-window::before { top: 0; background: linear-gradient(rgba(20, 22, 40, .45), rgba(20, 22, 40, .05)); }
.slot-window::after { bottom: 0; background: linear-gradient(rgba(20, 22, 40, .05), rgba(20, 22, 40, .45)); }
.slot-strip { will-change: transform; }
.slot-cell { height: 76px; display: flex; align-items: center; justify-content: center; font-size: 28px; font-weight: 800; color: #16181f;
  border-left: 10px solid var(--c); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 14px; }

/* card */
.cards { width: 100%; max-height: 100%; overflow: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 10px; padding: 10px; align-content: center; }
.cards.many { grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 6px; }
.flipcard { aspect-ratio: 3/4; perspective: 600px; transition: transform .15s; padding: 0; }
.flipcard:not(.flip):hover { transform: translateY(-5px); }
.flipcard:not(.flip):hover .back { box-shadow: 0 0 0 3px var(--accent-soft), 0 8px 18px rgba(0, 0, 0, .2); }
.flipcard .inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform var(--flip, .5s); }
.flipcard.flip .inner { transform: rotateY(180deg); }
.flipcard .face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 12px; display: flex; align-items: center; justify-content: center; text-align: center; padding: 4px; font-weight: 700; word-break: break-all; }
.flipcard .back { background: var(--accent); background-image: radial-gradient(rgba(255, 255, 255, .22) 1.5px, transparent 1.5px); background-size: 10px 10px; color: #fff; font-size: 20px; }
.flipcard .front { background: var(--c); color: #16181f; transform: rotateY(180deg); font-size: 18px; }
.cards.many .front { font-size: 12px; }
.flipcard.dim { opacity: .35; }
.flipcard.picked .front { box-shadow: 0 0 0 3px var(--danger), 0 8px 18px rgba(0, 0, 0, .25); }
.cards.tiny { grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 5px; }
.cards.tiny .back { font-size: 11px; }
.cards.tiny .front { font-size: 10px; }

/* team */
.teams { width: 100%; max-height: 100%; overflow: auto; display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; align-content: center; padding: 4px; }
.team { background: var(--surface-2); border-radius: 14px; padding: 10px; min-height: 120px; }
.team h3 { margin: 0 0 8px; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.team h3 i { width: 10px; height: 10px; border-radius: 50%; }
.team h3 small { margin-left: auto; color: var(--muted); font-weight: 500; }
.member { background: var(--surface); border-left: 4px solid var(--c); border-radius: 8px; padding: 5px 8px; margin: 4px 0; font-size: 14px; font-weight: 600; animation: pop .3s ease; word-break: break-all; }

/* doc pages */
.doc { max-width: 760px; margin: 16px auto 40px; padding: 0 16px; }
.doc .card { padding: 28px; line-height: 1.8; }
.doc h1 { margin: 0 0 16px; font-size: 26px; letter-spacing: -.5px; }
.doc h2 { font-size: 19px; margin: 28px 0 8px; }
.doc p, .doc li { color: var(--muted); }
.doc b { color: var(--text); }

.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 16px 16px 40px; }
.foot nav { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }
.foot a { color: var(--muted); }
.foot p { margin: 10px 0 0; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 14px; opacity: 0; transition: .25s; pointer-events: none; z-index: 20; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 10; }
/* countdown */
.countdown { position: absolute; inset: 0; display: grid; place-items: center; font-size: clamp(100px, 22vw, 200px); font-weight: 900; color: var(--accent);
  background: color-mix(in srgb, var(--surface) 70%, transparent); border-radius: inherit; z-index: 5; pointer-events: none; }
.countdown.pop { animation: pop .5s ease; }

/* odds */
.probs { margin: 4px 0 8px; font-size: 13px; }
.probs summary { cursor: pointer; color: var(--muted); font-size: 12.5px; }
#probs { max-height: 180px; overflow: auto; margin-top: 6px; display: grid; gap: 2px; }
.prob { display: flex; align-items: center; gap: 8px; padding: 3px 4px; }
.prob i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.prob span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prob b { font-weight: 600; font-variant-numeric: tabular-nums; }

.opt-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; font-size: 14.5px; border-bottom: 1px solid var(--line); }
.opt-row input { width: 64px; padding: 6px; text-align: center; }
.wide-btn { width: 100%; padding: 10px; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent); color: #fff; filter: brightness(1.1); }
.btn.danger { color: var(--danger); }

/* dialogs */
.dlg { border: 1px solid var(--line); border-radius: 18px; background: var(--surface); color: var(--text); padding: 22px; width: min(92vw, 380px); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.dlg::backdrop { background: rgba(10, 12, 24, .45); }
.dlg h3 { margin: 0 0 14px; font-size: 18px; }
.dlg-field { display: flex; align-items: center; gap: 12px; margin: 10px 0; font-size: 14px; }
.dlg-field span { width: 56px; color: var(--muted); }
.dlg-field input { flex: 1; padding: 9px 10px; min-width: 0; }
.dlg-field input[type="color"] { height: 40px; padding: 4px; cursor: pointer; }
.dlg-actions { display: flex; gap: 6px; margin-top: 18px; }
.dlg-actions span { flex: 1; }

[hidden] { display: none !important; }
