:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --accent: #db2777;
  --accent-hover: #be185d;
  --bar: #818cf8;
  --bar-hover: #4f46e5;
  --track: #eef0f6;

  /* 동행복권 공 색상 기준 */
  --ball-yellow: #fbc400;
  --ball-blue: #69c8f2;
  --ball-red: #ff7272;
  --ball-gray: #aaaaaa;
  --ball-green: #b0d840;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141a;
    --card: #1c1f27;
    --text: #e8eaf0;
    --muted: #9ca3af;
    --border: #2d313c;
    --bar: #6366f1;
    --bar-hover: #a5b4fc;
    --track: #262a35;
  }
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 40px 16px;
}

.container {
  max-width: 640px;
  margin: 0 auto;
}

header {
  text-align: center;
  margin-bottom: 28px;
}

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

.subtitle {
  color: var(--muted);
}

.controls {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.controls label {
  font-weight: 600;
}

select {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 1rem;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 20px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

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

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

.btn.primary {
  background: var(--primary);
  color: #fff;
}

.btn.primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 6px 12px;
  font-size: 0.85rem;
}

.results {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.placeholder {
  text-align: center;
  color: var(--muted);
  padding: 20px 0;
}

.game {
  display: flex;
  align-items: center;
  gap: 10px;
}

.game-label {
  width: 18px;
  font-weight: 700;
  color: var(--muted);
  flex-shrink: 0;
}

.balls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.ball {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  box-shadow: inset -3px -4px 8px rgba(0, 0, 0, 0.15), 0 2px 4px rgba(0, 0, 0, 0.15);
  opacity: 0;
  transform: scale(0.3) rotate(-180deg);
  animation: pop 0.4s ease-out forwards;
}

.ball.yellow { background: var(--ball-yellow); }
.ball.blue   { background: var(--ball-blue); }
.ball.red    { background: var(--ball-red); }
.ball.gray   { background: var(--ball-gray); }
.ball.green  { background: var(--ball-green); }

.plus {
  color: var(--muted);
  font-weight: 700;
  margin: 0 2px;
}

@keyframes pop {
  to {
    opacity: 1;
    transform: scale(1) rotate(0);
  }
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.history h2 {
  font-size: 1.1rem;
}

#history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#history-list li {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

#history-list .time {
  color: var(--muted);
  flex-shrink: 0;
}

#history-list .empty {
  color: var(--muted);
  justify-content: center;
}

@media (max-width: 480px) {
  h1 { font-size: 1.6rem; }
  .ball { width: 34px; height: 34px; font-size: 0.85rem; }
  .balls { gap: 4px; }
}

/* ---------- 데이터 상태 ---------- */

.data-status {
  margin-top: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.data-status.error {
  color: var(--accent);
}

/* ---------- 탭 ---------- */

.tabs {
  display: flex;
  gap: 4px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 24px;
}

.tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 10px 6px;
  border-radius: 9px;
  cursor: pointer;
}

.tab.active {
  background: var(--primary);
  color: #fff;
}

.btn.accent {
  background: var(--accent);
  color: #fff;
}

.btn.accent:hover:not(:disabled) {
  background: var(--accent-hover);
}

/* ---------- 추천 결과 ---------- */

.game-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.game-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.ball.static {
  opacity: 1;
  transform: none;
  animation: none;
}

.tag {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: 6px;
  padding: 1px 6px;
  margin-right: 6px;
  vertical-align: 1px;
}

.notice {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 28px;
  font-size: 0.9rem;
  line-height: 1.6;
}

.notice summary {
  cursor: pointer;
  font-weight: 600;
}

.notice p {
  margin-top: 10px;
}

.rule-list {
  margin: 10px 0 0 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rule-share {
  color: var(--muted);
  margin-left: 6px;
  font-size: 0.8rem;
}

.disclaimer {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.6;
}

/* ---------- 패턴 분석 ---------- */

.segmented {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 16px;
}

.seg {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.seg.active {
  border-color: var(--primary);
  color: var(--primary);
}

.tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.tile-label,
.tile-sub {
  font-size: 0.75rem;
  color: var(--muted);
}

.tile-value {
  font-size: 1.2rem;
}

.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 16px;
}

.card h2 {
  font-size: 1rem;
  margin-bottom: 4px;
}

.card-sub {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 14px;
}

.freq-chart {
  position: relative;
  height: 180px;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin: 34px 0 22px;
}

.bar-col {
  position: relative;
  flex: 1;
  height: 100%;
  display: flex;
  align-items: flex-end;
  cursor: default;
  outline: none;
}

.bar {
  width: 100%;
  background: var(--bar);
  border-radius: 4px 4px 0 0;
}

.bar-col.hover .bar {
  background: var(--bar-hover);
}

.bar-x {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 4px;
  font-size: 0.7rem;
  color: var(--muted);
}

.avg-line {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px dashed var(--muted);
  opacity: 0.7;
  pointer-events: none;
  z-index: 1;
}

.avg-label {
  position: absolute;
  right: 0;
  bottom: 2px;
  font-size: 0.7rem;
  color: var(--muted);
  background: var(--card);
  padding: 0 4px;
}

.chart-tooltip {
  position: absolute;
  transform: translate(-50%, -100%);
  background: var(--text);
  color: var(--bg);
  font-size: 0.8rem;
  padding: 6px 10px;
  border-radius: 8px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 2;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.grid-2 .card {
  margin-bottom: 0;
}

.rank-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.rank-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
}

.rank-item .ball {
  width: 32px;
  height: 32px;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.pattern-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.dist h3 {
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.dist-row {
  display: grid;
  grid-template-columns: 56px 1fr 44px;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  margin-bottom: 4px;
}

.dist-label {
  color: var(--muted);
}

.dist-track {
  background: var(--track);
  border-radius: 4px;
  height: 10px;
}

.dist-fill {
  background: var(--bar);
  height: 100%;
  border-radius: 4px;
}

.dist-value {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ---------- 역대 당첨번호 ---------- */

.search {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.search input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 0.95rem;
  min-width: 0;
}

.past-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.past-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.past-list .empty {
  color: var(--muted);
  text-align: center;
  padding: 20px 0;
}

.past-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.past-date,
.past-prize {
  color: var(--muted);
  font-size: 0.85rem;
}

.btn.more {
  display: block;
  margin: 16px auto 0;
  padding: 10px 24px;
}

@media (max-width: 560px) {
  .tiles { grid-template-columns: 1fr 1fr; }
  .grid-2,
  .pattern-list { grid-template-columns: 1fr; }
  .search { grid-template-columns: 1fr; }
}

[hidden] {
  display: none !important;
}
