:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1c1e21;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #1f6feb;
  --accent-soft: #e8f0fe;
  --up: #d93025;
  --down: #1a73e8;
  --gain: #188038;
  --loss: #d93025;
  --heat: 31, 111, 235;
  --r1: #d4a017;
  --r2: #e8710a;
  --r3: #9334e6;
  --r4: #1a73e8;
  --r5: #188038;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --card: #1b1e24;
    --text: #e8eaed;
    --muted: #9aa0a6;
    --line: #2d3139;
    --accent: #6ea8fe;
    --accent-soft: #1d2a40;
    --up: #f28b82;
    --down: #8ab4f8;
    --gain: #81c995;
    --loss: #f28b82;
    --heat: 110, 168, 254;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

button { font: inherit; color: inherit; cursor: pointer; }

.top, main, .disclaimer { max-width: 640px; margin: 0 auto; padding: 0 16px; }
.top { display: flex; align-items: baseline; justify-content: space-between; padding-top: calc(16px + env(safe-area-inset-top)); padding-bottom: 8px; }
.top h1 { margin: 0; font-size: 20px; }
.top p { margin: 0; color: var(--muted); font-size: 13px; }

.card { background: var(--card); border-radius: 14px; padding: 16px; margin: 12px 0; }
.card h2 { margin: 0 0 12px; font-size: 18px; }
.card h2 small { color: var(--muted); font-weight: normal; font-size: 14px; margin-left: 4px; }
.card h3 { margin: 0 0 10px; font-size: 15px; }
.muted { color: var(--muted); font-size: 13px; font-weight: normal; }
.hint { color: var(--muted); font-size: 12px; margin: -4px 0 10px; }
.sub { color: var(--muted); font-size: 13px; margin: 14px 0 6px; }
.disclaimer { color: var(--muted); font-size: 12px; text-align: center; margin: 20px auto; }

/* 공 */
.ball {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%;
  font-weight: 700; font-size: 14px; color: #fff; border: 0; padding: 0;
  text-shadow: 0 1px 1px rgba(0, 0, 0, .25); flex: none;
}
.ball.sm { width: 26px; height: 26px; font-size: 12px; }
.c-y { background: #f5b400; }
.c-b { background: #4aa8e0; }
.c-r { background: #f0605d; }
.c-k { background: #8a8f98; }
.c-g { background: #7cbf3a; }
.ball.dim { opacity: .25; }
.ball.off { background: var(--line); color: var(--muted); text-shadow: none; }
.plus { color: var(--muted); margin: 0 2px; }
.balls { display: inline-flex; flex-wrap: wrap; gap: 4px; align-items: center; }

.roll .ball { animation: pop .45s backwards cubic-bezier(.2, 1.4, .4, 1); }
.roll .ball:nth-child(2) { animation-delay: .12s; }
.roll .ball:nth-child(3) { animation-delay: .24s; }
.roll .ball:nth-child(4) { animation-delay: .36s; }
.roll .ball:nth-child(5) { animation-delay: .48s; }
.roll .ball:nth-child(6) { animation-delay: .6s; }
@keyframes pop { from { transform: scale(0) rotate(-180deg); opacity: 0; } }

/* 컨트롤 */
.row { display: flex; align-items: center; gap: 10px; margin: 10px 0; flex-wrap: wrap; }
.row-label { font-size: 13px; color: var(--muted); min-width: 56px; }
.seg { display: inline-flex; background: var(--bg); border-radius: 10px; padding: 3px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; font-size: 13px; }
.seg button.on { background: var(--card); color: var(--accent); font-weight: 700; box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }

.strategies { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 8px; }
.strat { border: 1px solid var(--line); background: none; border-radius: 10px; padding: 9px 4px; font-size: 14px; font-weight: 600; }
.strat.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.strategies + .hint { margin: 0 0 6px; }

.primary { width: 100%; margin-top: 8px; padding: 13px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 700; font-size: 16px; }
.primary:disabled { opacity: .4; cursor: default; }
.ghost { border: 1px solid var(--line); background: none; border-radius: 10px; padding: 6px 12px; font-size: 13px; }
.ghost:disabled { color: var(--muted); cursor: default; }
.actions { display: flex; gap: 8px; align-items: center; }
.actions .primary { flex: 1; }
.actions .ghost { margin-top: 8px; padding: 12px 16px; }

/* 추천 카드 */
.game-head { display: flex; align-items: center; gap: 10px; }
.game-head .balls { flex: 1; }
.game-label { width: 24px; color: var(--muted); }
.game-list { list-style: none; margin: 12px 0 0; padding: 0; }
.game-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 10px; cursor: pointer; }
.game-row .balls { flex: 1; flex-wrap: nowrap; }
.game-row .ball { width: 32px; height: 32px; }
.game-row .game-label { width: 16px; }
.game-row.on { background: var(--accent-soft); }
.game-row.on .game-label { color: var(--accent); }
.sub.first { margin-top: 0; }
.sub .game-label { display: inline-block; width: auto; margin-right: 4px; color: var(--accent); }
.reasons, .combo-reasons, .hits, .after { list-style: none; margin: 0; padding: 0; }
.reasons li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.reasons li:last-child { border-bottom: 0; }
.reasons p { margin: 0; font-size: 14px; }
.reasons p.weak { color: var(--muted); }
.reasons .facts { color: var(--muted); font-size: 12px; margin-top: 2px; }
.combo-reasons li { font-size: 14px; padding: 4px 0 4px 14px; position: relative; }
.combo-reasons li::before { content: "·"; position: absolute; left: 4px; color: var(--muted); }

details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸"; display: inline-block; width: 14px; color: var(--muted); transition: transform .15s; }
details[open] > summary::before { transform: rotate(90deg); }
.history { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.history > summary { font-size: 14px; font-weight: 600; }

/* 등수 */
.ranks { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin: 10px 0; }
.rank { background: var(--bg); border-radius: 10px; padding: 8px 4px; text-align: center; }
.rank b { display: block; font-size: 12px; color: var(--muted); }
.rank .cnt { display: block; font-size: 20px; font-weight: 700; color: var(--muted); }
.rank small { display: block; font-size: 10px; color: var(--muted); }
.rank.got .cnt { color: var(--text); }
.rank.got.r1 { box-shadow: inset 0 0 0 2px var(--r1); }
.rank.got.r2 { box-shadow: inset 0 0 0 2px var(--r2); }
.rank.got.r3 { box-shadow: inset 0 0 0 2px var(--r3); }
.rank.got.r4 { box-shadow: inset 0 0 0 2px var(--r4); }
.rank.got.r5 { box-shadow: inset 0 0 0 2px var(--r5); }
.money { font-size: 13px; margin: 6px 0 10px; }
.gain { color: var(--gain); }
.loss { color: var(--loss); }

.tag { display: inline-block; font-size: 11px; font-weight: 700; color: #fff; border-radius: 6px; padding: 1px 6px; margin: 0 4px; }
.tag.r1 { background: var(--r1); }
.tag.r2 { background: var(--r2); }
.tag.r3 { background: var(--r3); }
.tag.r4 { background: var(--r4); }
.tag.r5 { background: var(--r5); }
.tag.none { background: var(--muted); }

.rank-detail { border-top: 1px solid var(--line); padding: 10px 0; }
.rank-detail > summary { font-size: 14px; }
.freq { display: flex; flex-wrap: wrap; gap: 8px; }
.freq span { display: inline-flex; flex-direction: column; align-items: center; }
.freq small { font-size: 11px; color: var(--muted); }
.hits li { padding: 8px 0; border-bottom: 1px dashed var(--line); }
.hit-head { font-size: 13px; margin-bottom: 4px; }
.hit-row { display: flex; align-items: center; gap: 3px; margin: 3px 0; flex-wrap: wrap; }
.hit-row small { font-size: 11px; color: var(--muted); margin-left: 2px; }
.lbl { font-size: 12px; color: var(--muted); width: 58px; flex: none; }
.bt { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }

/* 최근 동향 */
.heat { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; }
.heat .cell {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; border-radius: 8px; background: rgba(var(--heat), calc(var(--h) * .35));
}
.heat .cell span { font-size: 12px; font-weight: 700; }
.draw { border-top: 1px solid var(--line); padding: 10px 0; }
.draw > summary { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.draw .balls { gap: 3px; }
.prize { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 13px; }
.prize th, .prize td { padding: 6px 4px; text-align: right; border-bottom: 1px solid var(--line); }
.prize th:first-child, .prize td:first-child, .prize th:nth-child(2), .prize td:nth-child(2) { text-align: left; }
.prize th { color: var(--muted); font-weight: normal; }

/* 장기 동향 */
.tr.up { color: var(--up); }
.tr.down { color: var(--down); }
.trendline.up { stroke: var(--up); }
.trendline.down { stroke: var(--down); }
.chip-btn { cursor: pointer; }
.chip-btn small, .trend-grid small { font-weight: 700; }
.trend-grid .cell { border: 0; background: none; border-radius: 8px; }
.trend-grid .cell.on { background: var(--accent-soft); box-shadow: inset 0 0 0 1.5px var(--accent); }
.trend-grid small { font-size: 11px; }
.chart-title { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 4px 0 8px; font-size: 14px; }
.chart { width: 100%; height: auto; display: block; }
.chart .bar { fill: rgba(var(--heat), .55); }
.chart .grid { stroke: var(--line); }
.chart .axis { fill: var(--muted); font-size: 10px; }
.chart .avg { stroke: var(--muted); stroke-dasharray: 4 3; }
.chart .trendline { stroke-width: 2.5; }
.legend { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 6px 0 0; }
.lg { display: inline-block; width: 14px; height: 3px; margin-left: 6px; }
.lg.bar { height: 10px; background: rgba(var(--heat), .55); }
.lg.avg { border-top: 2px dashed var(--muted); height: 0; }
.lg.tl { background: var(--up); }

/* 내 번호 */
.picker { display: grid; grid-template-columns: repeat(9, 1fr); gap: 6px; justify-items: center; margin-bottom: 4px; }
.after li { display: flex; align-items: center; gap: 6px; padding: 6px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; font-size: 14px; }
.wait { background: var(--bg); border-radius: 10px; padding: 10px 12px; font-size: 13px; color: var(--muted); }

/* 전략 비교 */
.cmp { width: 100%; border-collapse: collapse; font-size: 13px; margin: 8px 0; }
.cmp th, .cmp td { padding: 8px 4px; text-align: center; border-bottom: 1px solid var(--line); }
.cmp thead th { color: var(--muted); font-weight: normal; }
.cmp tbody th { text-align: left; font-weight: 600; }
.cmp tr.exp { color: var(--muted); }
.cmp tr.exp th { font-weight: normal; }

/* 하단 탭 */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { flex: 1; max-width: 128px; border: 0; background: none; padding: 14px 2px; font-size: 13px; color: var(--muted); }
.tabs button.on { color: var(--accent); font-weight: 700; }

@media (max-width: 520px) {
  .strategies { grid-template-columns: 1fr 1fr; }
  .heat { grid-template-columns: repeat(9, 1fr); gap: 2px; }
  .heat .ball.sm { width: 24px; height: 24px; font-size: 11px; }
  .picker .ball { width: 32px; height: 32px; font-size: 13px; }
  .cmp { font-size: 12px; }
}
