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

:root {
  --bg: oklch(15% 0.02 260);
  --surface: oklch(20% 0.025 260);
  --surface-2: oklch(25% 0.03 260);
  --border: oklch(35% 0.03 260);
  --text: oklch(95% 0.01 260);
  --text-muted: oklch(65% 0.02 260);
  --radius: 1rem;
  --ball-size: 3rem;
}

[data-theme="light"] {
  --bg: oklch(97% 0.005 260);
  --surface: oklch(100% 0 0);
  --surface-2: oklch(93% 0.008 260);
  --border: oklch(85% 0.01 260);
  --text: oklch(18% 0.02 260);
  --text-muted: oklch(48% 0.02 260);
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem 4rem;
  transition: background 0.25s, color 0.25s;
}

.container {
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* Header */
header {
  text-align: center;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.theme-toggle {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: background 0.15s, transform 0.1s, border-color 0.25s;
  flex-shrink: 0;
}

.theme-toggle:hover {
  background: var(--border);
}

.theme-toggle:active {
  transform: scale(0.9);
}

/* 다크모드: 달 아이콘, 라이트모드: 태양 아이콘 */
:root .theme-icon::before { content: '🌙'; }
[data-theme="light"] .theme-icon::before { content: '☀️'; }

h1 {
  font-size: clamp(1.8rem, 5vw, 2.5rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, oklch(85% 0.18 50), oklch(75% 0.22 30));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--text-muted);
  margin-top: 0.4rem;
  font-size: 0.95rem;
}

/* Controls */
.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.4rem;
}

.game-count-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.game-count-wrapper label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.count-selector {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.count-selector span {
  font-size: 1.5rem;
  font-weight: 700;
  min-width: 1.5rem;
  text-align: center;
}

.count-btn {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  user-select: none;
}

.count-btn:hover {
  background: var(--border);
}

.count-btn:active {
  transform: scale(0.9);
}

.count-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.generate-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.85rem 1.6rem;
  background: linear-gradient(135deg, oklch(65% 0.22 50), oklch(58% 0.25 30));
  color: white;
  font-size: 1rem;
  font-weight: 700;
  border: none;
  border-radius: 0.75rem;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 20px oklch(65% 0.22 50 / 0.35);
  white-space: nowrap;
}

.generate-btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
  box-shadow: 0 6px 24px oklch(65% 0.22 50 / 0.45);
}

.generate-btn:active {
  transform: translateY(0);
}

.btn-icon {
  font-size: 1.1rem;
}

/* Results */
.results {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.game-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1.1rem;
  animation: slideIn 0.3s ease both;
}

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

.game-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 3rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.balls-wrapper {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

/* Lotto Balls */
.ball {
  width: var(--ball-size);
  height: var(--ball-size);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  font-weight: 800;
  color: white;
  text-shadow: 0 1px 2px rgb(0 0 0 / 0.4);
  box-shadow: inset 0 -3px 6px rgb(0 0 0 / 0.25), inset 0 2px 4px rgb(255 255 255 / 0.3), 0 2px 8px rgb(0 0 0 / 0.3);
  animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.4);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.yellow-ball {
  background: radial-gradient(circle at 35% 35%, oklch(85% 0.2 90), oklch(68% 0.22 70));
}

.blue-ball {
  background: radial-gradient(circle at 35% 35%, oklch(75% 0.18 240), oklch(55% 0.22 250));
}

.red-ball {
  background: radial-gradient(circle at 35% 35%, oklch(68% 0.22 25), oklch(50% 0.24 15));
}

.gray-ball {
  background: radial-gradient(circle at 35% 35%, oklch(60% 0.01 260), oklch(42% 0.01 260));
}

.green-ball {
  background: radial-gradient(circle at 35% 35%, oklch(68% 0.2 140), oklch(52% 0.22 145));
}

/* Actions */
.actions {
  display: flex;
  gap: 0.75rem;
}

.action-btn {
  flex: 1;
  padding: 0.75rem;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.action-btn:hover {
  background: var(--surface-2);
}

.action-btn:active {
  transform: scale(0.97);
}

/* Color Guide */
.color-guide {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.guide-item {
  --ball-size: 2.8rem;
  font-size: 0.72rem;
  font-weight: 700;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(4rem);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.7rem 1.4rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 100;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Responsive */
@media (max-width: 400px) {
  :root {
    --ball-size: 2.5rem;
  }

  .controls {
    flex-direction: column;
    align-items: stretch;
  }

  .generate-btn {
    justify-content: center;
  }
}
