:root {
  --primary: #007bff;
  --primary-soft: #e7f1ff;
  --primary-hover: #0056b3;
  --success: #28a745;
  --danger: #dc3545;
  --warning: #ffc107;
  
  --bg-app: #f8f9fa;
  --bg-card: #ffffff;
  --text-main: #212529;
  --text-sub: #6c757d;
  --border: #dee2e6;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  
  --ball-size: 38px;
  --app-gap: 20px;
}

[data-theme="dark"] {
  --bg-app: #121212;
  --bg-card: #1e1e1e;
  --text-main: #f8f9fa;
  --text-sub: #adb5bd;
  --border: #2d2d2d;
  --shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  --primary-soft: #1a2635;
}

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

body {
  font-family: 'Pretendard Variable', Pretendard, -apple-system, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.6;
  display: flex;
  justify-content: center;
  padding: 40px 15px;
  transition: background-color 0.3s;
}

.app-container {
  max-width: 500px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--app-gap);
}

header { text-align: center; }
.brand { margin-bottom: 15px; }
header h1 { font-size: 2rem; font-weight: 800; letter-spacing: -1px; margin-bottom: 8px; }

.countdown-badge {
  display: inline-block;
  padding: 5px 15px;
  background: var(--danger);
  color: white;
  border-radius: 30px;
  font-size: 0.8rem;
  font-weight: 700;
  box-shadow: 0 4px 10px rgba(220, 53, 69, 0.2);
}

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 18px;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Latest Win Card */
.latest-card {
  background: linear-gradient(135deg, #007bff, #00c6ff);
  color: white;
  padding: 24px;
  border-radius: 20px;
  box-shadow: 0 8px 20px rgba(0, 123, 255, 0.15);
  text-align: center;
}

.latest-win-balls {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 15px;
  flex-wrap: wrap;
}

/* Filters */
.filter-tabs {
  display: flex;
  background: var(--bg-app);
  padding: 4px;
  border-radius: 12px;
  margin-bottom: 15px;
}

.tab-btn {
  flex: 1;
  padding: 10px;
  border: none;
  background: none;
  color: var(--text-sub);
  font-weight: 700;
  cursor: pointer;
  border-radius: 10px;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.tab-btn.active {
  background: var(--bg-card);
  color: var(--primary);
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.number-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 6px;
  margin-bottom: 15px;
}

.num-chip {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.num-chip:hover { border-color: var(--primary); color: var(--primary); }
.num-chip.fixed { background: var(--primary); color: white; border-color: var(--primary); }
.num-chip.excluded { background: var(--danger); color: white; border-color: var(--danger); }

/* Buttons */
.main-btn {
  width: 100%;
  padding: 20px;
  border-radius: 18px;
  border: none;
  background: var(--primary);
  color: white;
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 8px 20px rgba(0, 123, 255, 0.25);
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.main-btn:hover { background: var(--primary-hover); transform: translateY(-3px); box-shadow: 0 12px 25px rgba(0, 123, 255, 0.3); }
.main-btn:active { transform: translateY(0); }

.utility-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.sub-btn {
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main);
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.9rem;
}

.sub-btn:hover { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.sub-btn.secondary { background: var(--primary-soft); border-color: transparent; color: var(--primary); }

.text-btn { border: none; background: none; color: var(--primary); font-weight: 700; font-size: 0.8rem; cursor: pointer; }

/* Results Animation */
.lotto-row {
  background: var(--bg-card);
  padding: 20px;
  border-radius: 20px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  animation: revealRow 0.6s cubic-bezier(0.23, 1, 0.32, 1) both;
}

@keyframes revealRow {
  0% { opacity: 0; transform: scale(0.9) translateY(20px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

.balls-container { display: flex; gap: 8px; align-items: center; }

/* Balls styling */
.ball {
  width: var(--ball-size); height: var(--ball-size);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 800; font-size: 0.95rem;
  box-shadow: inset -3px -3px 6px rgba(0,0,0,0.2);
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
  animation: popBall 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

@keyframes popBall {
  0% { transform: scale(0) rotate(-180deg); }
  100% { transform: scale(1) rotate(0); }
}

.ball-yellow { background: radial-gradient(circle at 30% 30%, #ffdf00, #fbc400); }
.ball-blue { background: radial-gradient(circle at 30% 30%, #87ceeb, #69c8f2); }
.ball-red { background: radial-gradient(circle at 30% 30%, #ff9a9e, #ff7272); }
.ball-gray { background: radial-gradient(circle at 30% 30%, #cccccc, #aaa); }
.ball-green { background: radial-gradient(circle at 30% 30%, #d4fc79, #b0d840); }

/* Analysis Badges */
.analysis-row { display: flex; gap: 5px; }
.analysis-badge { padding: 3px 10px; background: var(--bg-app); border-radius: 8px; font-size: 0.7rem; font-weight: 700; color: var(--text-sub); }

.saved-list { max-height: 250px; overflow-y: auto; padding-right: 5px; }
.saved-item { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }

.theme-btn {
  position: fixed; top: 20px; right: 20px; width: 44px; height: 44px;
  border-radius: 50%; border: none; background: var(--bg-card);
  box-shadow: 0 4px 15px rgba(0,0,0,0.1); cursor: pointer; z-index: 3000; font-size: 1.2rem;
}

@media (max-width: 480px) {
  .number-grid { grid-template-columns: repeat(7, 1fr); }
  .ball { --ball-size: 32px; font-size: 0.85rem; }
  .lotto-row { padding: 15px; }
}
