:root {
  color-scheme: light;
  --ink: #171717;
  --muted: #77747c;
  --line: #e9e5ed;
  --control: #ffffff;
  --page-start: #f8f7fb;
  --page-end: #fdfdfe;
  --app-surface: rgba(255, 255, 255, 0.96);
  --winner-surface: #fcfbfe;
  --winner-border: #eeeaf4;
  --placeholder: #aaa6b0;
  --purple: #7451d8;
  --purple-dark: #6040c1;
  --lavender: #f2effb;
  --surface: #ffffff;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #f3f0f8;
  --muted: #aaa4b5;
  --line: #3d3847;
  --control: #24212a;
  --page-start: #17151c;
  --page-end: #201d26;
  --app-surface: rgba(35, 32, 42, 0.98);
  --winner-surface: #292630;
  --winner-border: #403a49;
  --placeholder: #888192;
  --purple: #a890ef;
  --purple-dark: #9275df;
  --lavender: #3a334b;
  --surface: #23202a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 10%, rgba(116, 81, 216, 0.08), transparent 26rem),
    linear-gradient(135deg, var(--page-start) 0%, var(--page-end) 100%);
  transition: color 0.25s ease, background 0.25s ease;
  font-family: Inter, "Pretendard", "Noto Sans KR", system-ui, -apple-system, sans-serif;
}

.app {
  width: min(540px, calc(100vw - 32px));
  margin: 32px 0;
  padding: 36px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--app-surface);
  box-shadow: 0 24px 70px rgba(54, 43, 83, 0.10);
}

.header,
.count-row,
.results-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header { margin-bottom: 28px; }

.header-actions { display: flex; gap: 8px; }

.eyebrow {
  margin: 0 0 6px;
  color: var(--purple);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

h1, h2 { margin: 0; letter-spacing: -0.04em; }
h1 { font-size: 34px; }
h2 { font-size: 25px; }

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: #77717f;
  background: var(--control);
  cursor: pointer;
  transition: 0.2s ease;
}

.icon-button:hover { border-color: #cbc3dc; transform: rotate(-12deg); }
.icon-button svg { width: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.theme-button .moon-icon { display: none; }
:root[data-theme="dark"] .theme-button .sun-icon { display: none; }
:root[data-theme="dark"] .theme-button .moon-icon { display: block; }
.theme-button svg circle { fill: none; }

.setup { display: grid; gap: 20px; }
.field { display: grid; gap: 9px; }
.field-label { font-size: 14px; font-weight: 800; }

textarea {
  width: 100%;
  resize: vertical;
  min-height: 180px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  outline: none;
  padding: 14px 16px;
  color: var(--ink);
  background: var(--control);
  font: 16px/1.8 "Pretendard", "Noto Sans KR", sans-serif;
  transition: border 0.2s, box-shadow 0.2s;
}

textarea:focus {
  border-color: #aa96df;
  box-shadow: 0 0 0 4px rgba(116, 81, 216, 0.08);
}

textarea::placeholder { color: var(--placeholder); }

.count-row {
  min-height: 48px;
  padding: 0 2px;
}

.stepper {
  display: grid;
  grid-template-columns: 42px 52px 42px;
  align-items: center;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.stepper button {
  height: 100%;
  border: 0;
  background: var(--control);
  color: #706a76;
  font-size: 20px;
  cursor: pointer;
}

.stepper button:hover { background: var(--lavender); color: var(--purple); }
.stepper output {
  display: grid;
  height: 100%;
  place-items: center;
  border-inline: 1px solid var(--line);
  font-weight: 800;
}

.draw-button {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 0;
  border-radius: 14px;
  color: #fff;
  background: var(--purple);
  box-shadow: 0 10px 24px rgba(116, 81, 216, 0.24);
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  transition: 0.2s ease;
}

.draw-button:hover { background: var(--purple-dark); transform: translateY(-1px); }
.draw-button:active { transform: translateY(1px); }
.draw-button svg { width: 19px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.results {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
  animation: reveal 0.45s ease both;
}

.results-heading { margin-bottom: 14px; }
.result-count {
  padding: 7px 11px;
  border-radius: 999px;
  color: var(--purple);
  background: var(--lavender);
  font-size: 12px;
  font-weight: 800;
}

.winner-list { display: grid; gap: 8px; }
.winner {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 8px 14px 8px 8px;
  border: 1px solid var(--winner-border);
  border-radius: 14px;
  background: var(--winner-surface);
  animation: winner-in 0.35s ease both;
}

.winner-rank {
  width: 42px;
  height: 42px;
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 10px;
  color: var(--purple);
  background: var(--lavender);
  font-weight: 900;
}

.winner-name { font-size: 16px; font-weight: 800; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 10;
  transform: translate(-50%, 20px);
  padding: 11px 16px;
  border-radius: 999px;
  color: #fff;
  background: #26232b;
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: 0.25s ease;
}

.toast.show { transform: translate(-50%, 0); opacity: 1; }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }

@keyframes reveal {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes winner-in {
  from { opacity: 0; transform: translateX(-8px) scale(0.98); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

@media (max-width: 600px) {
  body { align-items: start; background: var(--page-end); }
  .app { width: 100%; margin: 0; padding: 24px 20px; border: 0; border-radius: 0; box-shadow: none; }
  h1 { font-size: 30px; }
  textarea { min-height: 155px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
