:root {
  --bg: #f4f5f8;
  --card: #ffffff;
  --text: #1b1d24;
  --muted: #6b7280;
  --line: #e2e5ea;
  --accent: #2f6fd0;
  --accent-text: #ffffff;
  --win: #fff3c4;
  --nav: #ffffffee;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12141c;
    --card: #1c1f2a;
    --text: #e8eaf0;
    --muted: #9aa1ad;
    --line: #2d3240;
    --accent: #4d8ef0;
    --win: #4a3f12;
    --nav: #1c1f2aee;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #12141c;
    --card: #1c1f2a;
    --text: #e8eaf0;
    --muted: #9aa1ad;
    --line: #2d3240;
    --accent: #4d8ef0;
    --win: #4a3f12;
    --nav: #1c1f2aee;
    color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  padding: env(safe-area-inset-top) 0 calc(64px + env(safe-area-inset-bottom));
}
.top {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  padding: 10px 16px 4px;
}
h1 { font-size: 18px; margin: 0; }
h3 { font-size: 15px; margin: 14px 0 6px; }
main { max-width: 720px; margin: 0 auto; padding: 0 12px; }
.tab { display: none; }
.tab.active { display: block; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.row.wrap { flex-wrap: wrap; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; margin: 10px 0;
}
details.card > summary { font-weight: 600; cursor: pointer; padding: 2px 0; }

button, select, input, .filebtn {
  font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; min-height: 40px;
}
button:disabled { opacity: 0.45; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
input[type=number] { width: 4.6em; text-align: center; }
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; margin: 0; vertical-align: middle; accent-color: var(--accent); }
#check-input { flex: 1; min-width: 0; }
.filebtn { display: inline-flex; align-items: center; position: relative; overflow: hidden; }
.filebtn input { position: absolute; inset: 0; opacity: 0; }
label.check { display: flex; align-items: center; gap: 8px; margin: 8px 0; }

#drum {
  display: block; width: 100%; aspect-ratio: 1 / 0.95; max-height: 60vh;
  border-radius: 14px; background: #12141c; touch-action: none; margin-top: 6px;
}
.controls { flex-wrap: nowrap; gap: 6px; }
.controls .stepper { font-size: 13px; gap: 3px; }
.controls .stepper button { min-width: 34px; }
.controls #gen-btn { flex: 1; }
.controls button { white-space: nowrap; }
.controls input[type=number] { width: 2.6em; padding: 8px 2px; }
.controls button { padding: 8px 10px; }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper button { min-width: 40px; padding: 8px 0; }

/* 공 */
.balls { display: inline-flex; gap: 4px; flex-wrap: nowrap; }
.ball {
  --c: #ccc;
  display: inline-grid; place-items: center; flex: none;
  width: 34px; height: 34px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffffffaa 0 12%, transparent 40%), var(--c);
  color: #111; font-weight: 700; font-size: 14px;
  box-shadow: inset 0 -2px 3px #0003;
}
.ball.sm { width: 26px; height: 26px; font-size: 12px; }
.ball.miss { opacity: 0.35; }
.ball.hit { outline: 2px solid var(--text); outline-offset: 1px; }

.games { list-style: none; padding: 0; margin: 8px 0; }
.games li {
  display: grid; grid-template-columns: 24px auto; align-items: center; gap: 2px 8px;
  padding: 8px 4px; border-bottom: 1px solid var(--line);
  animation: pop 0.3s ease-out;
}
.games .idx { color: var(--muted); text-align: right; font-size: 13px; }
.games .meta { grid-column: 2; color: var(--muted); font-size: 12px; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }

/* Rule */
.rules .rule { padding: 8px 0; border-bottom: 1px solid var(--line); }
.rule label { font-weight: 500; }
.rule select { padding: 4px 6px; min-height: 34px; margin: 0 2px; }
.rule .hint { color: var(--muted); font-size: 12px; margin-left: 6px; }
.rule .desc { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* 번호판 */
.board { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin: 8px 0; }
.board button { padding: 0; aspect-ratio: 1; min-height: 0; border-radius: 50%; font-weight: 600; }
.board button.fixed { background: var(--c); color: #111; border-color: #0005; }
.board button.excl { background: var(--line); color: var(--muted); text-decoration: line-through; }
#picker-tip { min-height: 1.4em; margin-bottom: 6px; }

/* 추천 */
.rec { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin: 6px 0; }
.rec.on .verdict { color: #1a7f37; }
.rec.off .verdict { color: var(--muted); }
.rec.differs { border-left: 4px solid var(--accent); }
@media (prefers-color-scheme: dark) { .rec.on .verdict { color: #4cc26a; } }

/* 통계 */
.seg { display: flex; gap: 0; margin: 10px 0; }
.seg button { flex: 1; border-radius: 0; }
.seg button:first-child { border-radius: 10px 0 0 10px; }
.seg button:last-child { border-radius: 0 10px 10px 0; }
.seg button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.hot { color: #d62728; }
.cold { color: #2f6fd0; }
.bar-row { display: grid; grid-template-columns: 30px 1fr 40px; align-items: center; gap: 8px; margin: 3px 0; }
.bar-row > .bar { height: 14px; border-radius: 4px; min-width: 2px; }
.bar-row > span:last-child { font-size: 12px; text-align: right; }
.bar.hotbar { outline: 2px solid #d62728; }

table.tbl { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 13px; }
.tbl th, .tbl td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.tbl th { color: var(--muted); font-weight: 500; }
.tbl tr.win td { background: var(--win); }
.tbl .nums { font-variant-numeric: tabular-nums; white-space: nowrap; }
#history td { vertical-align: middle; }

/* 용지 */
svg.slip { width: 100%; max-width: 380px; display: block; margin: 8px auto; background: #fff; border-radius: 10px; }
svg.slip .cellnum { font-size: 13px; fill: #e27878; text-anchor: middle; }
svg.slip .ballnum { font-size: 15px; font-weight: 700; fill: #111; text-anchor: middle; }
svg.chart { width: 100%; display: block; color: var(--text); }
svg.chart .axis { font-size: 10px; fill: var(--muted); }

/* 구매 번호 */
.ticket {
  display: grid; grid-template-columns: 22px 48px auto 1fr; align-items: center; gap: 8px;
  padding: 8px 2px; border-bottom: 1px solid var(--line);
}
.ticket .ball { width: 28px; height: 28px; font-size: 12px; }
.ticket > b { text-align: right; }
.ticket.win { background: var(--win); border-radius: 8px; }
pre#check-out { white-space: pre-wrap; margin: 6px 0 0; font-family: inherit; }

/* 아래 탭 */
nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex;
  background: var(--nav); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs button {
  flex: 1; border: 0; background: none; border-radius: 0; padding: 6px 0 4px; min-height: 56px;
  font-size: 11px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 1px;
}
nav.tabs button span { font-size: 20px; line-height: 1.2; }
nav.tabs button.on { color: var(--accent); font-weight: 600; }

#toast {
  position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  max-width: calc(100% - 32px); background: #000d; color: #fff; padding: 10px 14px; border-radius: 12px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: 0.25s; z-index: 10;
}
#toast.show { opacity: 1; transform: translateX(-50%); }

@media (max-width: 380px) {
  .ball { width: 30px; height: 30px; font-size: 13px; }
  .ticket .ball { width: 25px; height: 25px; font-size: 11px; }
}
h1 { white-space: nowrap; }
.top { flex-wrap: wrap; }
@media (max-width: 360px) {
  .controls .lbl { display: none; }
  .controls button { padding: 8px 7px; font-size: 14px; }
  .controls .stepper button { min-width: 30px; }
}
