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

:root {
  --transition-speed: 0.3s;
}

[data-theme="light"] {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-secondary: #555;
  --border: #ddd;
  --btn-bg: #4a6cf7;
  --btn-hover: #3a5ce5;
  --btn-text: #fff;
  --shadow: rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
  --bg: #1a1a2e;
  --surface: #16213e;
  --text: #eee;
  --text-secondary: #aaa;
  --border: #2a2a4a;
  --btn-bg: #4a6cf7;
  --btn-hover: #5b7bf8;
  --btn-text: #fff;
  --shadow: rgba(0, 0, 0, 0.3);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background var(--transition-speed), color var(--transition-speed);
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem 2rem;
  max-width: 600px;
  margin: 0 auto;
}

header h1 {
  font-size: 1.5rem;
}

#theme-toggle {
  background: none;
  border: 2px solid var(--border);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 1.3rem;
  cursor: pointer;
  transition: border-color var(--transition-speed), transform 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

#theme-toggle:hover {
  border-color: var(--btn-bg);
  transform: scale(1.1);
}

main {
  max-width: 600px;
  margin: 0 auto;
  padding: 1rem 2rem 3rem;
  text-align: center;
}

#generate-btn {
  background: var(--btn-bg);
  color: var(--btn-text);
  border: none;
  padding: 1rem 3rem;
  font-size: 1.2rem;
  font-weight: 600;
  border-radius: 12px;
  cursor: pointer;
  transition: background var(--transition-speed), transform 0.15s;
}

#generate-btn:hover {
  background: var(--btn-hover);
  transform: translateY(-2px);
}

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

#result {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 2rem;
  padding: 1.5rem;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 4px 20px var(--shadow);
  transition: background var(--transition-speed), box-shadow var(--transition-speed);
  position: relative;
}

.hidden {
  display: none !important;
}

.ball-container {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.ball {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  animation: pop 0.3s ease-out;
}

.ball.yellow { background: #fbc400; color: #333; text-shadow: none; }
.ball.blue { background: #69c8f2; }
.ball.red { background: #ff7272; }
.ball.gray { background: #aaa; }
.ball.green { background: #b0d840; color: #333; text-shadow: none; }

@keyframes pop {
  0% { transform: scale(0); opacity: 0; }
  70% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

.separator {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin: 0 0.25rem;
}

.bonus-label {
  position: absolute;
  bottom: 0.4rem;
  right: 1.2rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

#history-section {
  margin-top: 2rem;
  text-align: left;
}

#history-section h2 {
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
  color: var(--text-secondary);
}

.history-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-radius: 12px;
  margin-bottom: 0.5rem;
  box-shadow: 0 2px 8px var(--shadow);
  transition: background var(--transition-speed);
}

.history-item .ball {
  width: 34px;
  height: 34px;
  font-size: 0.85rem;
  animation: none;
}

.history-item .separator {
  font-size: 1rem;
}

@media (max-width: 480px) {
  header {
    padding: 1rem;
  }

  header h1 {
    font-size: 1.2rem;
  }

  main {
    padding: 1rem;
  }

  .ball {
    width: 40px;
    height: 40px;
    font-size: 0.95rem;
  }

  .history-item .ball {
    width: 30px;
    height: 30px;
    font-size: 0.8rem;
  }
}
