:root {
  --bg-gradient: linear-gradient(135deg, #f8fafc, #e2e8f0);
  --container-bg: rgba(255, 255, 255, 0.9);
  --text-color: #1e293b;
  --desc-color: #475569;
  --button-bg: #22c55e;
  --button-hover: #16a34a;
  --card-bg: rgba(0, 0, 0, 0.04);
  --panel-bg: rgba(0, 0, 0, 0.03);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  --ball-shadow: 0 6px 14px rgba(0, 0, 0, 0.2);
  --plus-color: #64748b;
  --status-color: #64748b;
  --history-item-bg: rgba(0, 0, 0, 0.02);
}

[data-theme="dark"] {
  --bg-gradient: linear-gradient(135deg, #0f172a, #1e293b);
  --container-bg: rgba(255, 255, 255, 0.08);
  --text-color: #f8fafc;
  --desc-color: #d1d5db;
  --button-bg: #22c55e;
  --button-hover: #16a34a;
  --card-bg: rgba(255, 255, 255, 0.06);
  --panel-bg: rgba(0, 0, 0, 0.18);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --ball-shadow: 0 6px 14px rgba(0, 0, 0, 0.3);
  --plus-color: #cbd5e1;
  --status-color: #cbd5e1;
  --history-item-bg: rgba(255, 255, 255, 0.05);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, Roboto, sans-serif;
  background: var(--bg-gradient);
  color: var(--text-color);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  transition: background 0.3s, color 0.3s;
}

.container {
  width: 100%;
  max-width: 760px;
  background: var(--container-bg);
  padding: 28px;
  border-radius: 22px;
  text-align: center;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  position: relative;
  transition: background 0.3s, box-shadow 0.3s;
}

.theme-toggle {
  position: absolute;
  top: 20px;
  right: 20px;
  background: var(--card-bg);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-color);
  padding: 8px 12px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

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

h1 {
  margin-top: 0;
  margin-bottom: 8px;
  font-size: 2rem;
}

.desc {
  color: var(--desc-color);
  margin-bottom: 20px;
  line-height: 1.6;
}

.button-group {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

button {
  background: var(--button-bg);
  color: white;
  border: none;
  padding: 14px 24px;
  font-size: 16px;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.2s, background 0.2s;
  font-weight: bold;
}

button:hover {
  background: var(--button-hover);
  transform: translateY(-2px);
}

button:disabled {
  background: #64748b;
  cursor: not-allowed;
  transform: none;
}

.numbers {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  margin: 24px 0 12px;
  min-height: 76px;
  align-items: center;
}

.plus {
  font-size: 28px;
  font-weight: bold;
  color: var(--plus-color);
  padding: 0 4px;
}

.ball {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 20px;
  color: white;
  box-shadow: var(--ball-shadow);
  position: relative;
  overflow: hidden;
  transform: scale(0.9);
  opacity: 0;
  animation: popIn 0.35s ease forwards;
}

.ball::before {
  content: "";
  position: absolute;
  top: 8px;
  left: 12px;
  width: 22px;
  height: 12px;
  background: rgba(255, 255, 255, 0.35);
  border-radius: 50%;
  transform: rotate(-20deg);
}

.yellow { background: #facc15; color: #111827; }
.blue { background: #3b82f6; }
.red { background: #ef4444; }
.gray { background: #6b7280; }
.green { background: #22c55e; }
.bonus { background: #a855f7; }

.mixing .ball {
  animation: shakeBall 0.35s infinite;
  opacity: 1;
  transform: scale(1);
}

.status {
  min-height: 26px;
  color: var(--status-color);
  font-size: 15px;
  margin-bottom: 16px;
}

.panel {
  margin-top: 22px;
  background: var(--panel-bg);
  border-radius: 16px;
  padding: 18px;
  text-align: left;
}

.panel h3 {
  margin-top: 0;
  margin-bottom: 12px;
  font-size: 1.1rem;
}

.analysis-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.analysis-card {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 12px;
  line-height: 1.6;
}

.analysis-card strong {
  display: block;
  margin-bottom: 4px;
  color: var(--text-color);
}

.analysis-note {
  margin-top: 12px;
  color: var(--desc-color);
  line-height: 1.7;
  font-size: 14px;
}

.history {
  margin-top: 24px;
  text-align: left;
  max-height: 240px;
  overflow-y: auto;
  background: var(--panel-bg);
  padding: 16px;
  border-radius: 16px;
}

.history h3 {
  margin-top: 0;
  margin-bottom: 12px;
}

.history-item {
  padding: 10px 12px;
  margin-bottom: 10px;
  border-radius: 10px;
  background: var(--history-item-bg);
  font-size: 14px;
  line-height: 1.6;
}

@keyframes popIn {
  from {
    transform: scale(0.6) translateY(10px);
    opacity: 0;
  }
  to {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

@keyframes shakeBall {
  0%   { transform: translate(0, 0) rotate(0deg); }
  25%  { transform: translate(-2px, -3px) rotate(-6deg); }
  50%  { transform: translate(2px, 2px) rotate(5deg); }
  75%  { transform: translate(-1px, 3px) rotate(-4deg); }
  100% { transform: translate(0, 0) rotate(0deg); }
}

@media (max-width: 640px) {
  .container {
    padding: 20px 16px;
  }

  .ball {
    width: 50px;
    height: 50px;
    font-size: 17px;
  }

  .analysis-grid {
    grid-template-columns: 1fr;
  }

  button {
    width: 100%;
  }

  .button-group {
    flex-direction: column;
  }

  .theme-toggle {
    position: static;
    margin-bottom: 15px;
    justify-content: center;
  }
}
