:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #1c1f24;
  --muted: #6b7280;
  --primary: #e8590c;
  --primary-text: #ffffff;
  --danger: #d6336c;
  --ok: #2f9e44;
  --warn: #f08c00;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --ball-1: #fbc400; --ball-2: #69c8f2; --ball-3: #ff7272; --ball-4: #aaaaaa; --ball-5: #b0d840;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1a1d23;
    --surface-2: #23272e;
    --border: #2e333b;
    --text: #e8eaed;
    --muted: #9aa0a8;
    --primary: #ff7a2f;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", sans-serif;
}
code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
h2 { font-size: 17px; margin: 0; }
h3 { font-size: 15px; margin: 18px 0 8px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small-text { font-size: 13px; margin: 10px 0 0; }
.error { color: var(--danger); min-height: 1.2em; margin: 6px 0 0; }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.flex { flex: 1; }

/* 버튼·입력 */
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 8px; font: inherit; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: progress; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
input, select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.field input, .field select { color: var(--text); font-size: 15px; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.round-input { width: 90px; }

/* 레이아웃 */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; font-size: 17px; white-space: nowrap; }
.brand.big { font-size: 26px; }
#nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
#nav a { padding: 6px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); white-space: nowrap; }
#nav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
main { max-width: 1100px; margin: 0 auto; padding: 20px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head.spaced { margin: 22px 0 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 20px; font-weight: 700; margin-top: 2px; }
.pill { display: inline-block; font-size: 12px; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.pill.ok { color: var(--ok); }
.pill.bad { color: var(--danger); }

/* 로그인 */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; text-align: center; }

/* 공 */
.balls { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.ball {
  width: 34px; height: 34px; border-radius: 50%; display: inline-grid; place-items: center;
  font-weight: 700; font-size: 14px; color: #fff; text-shadow: 0 1px 1px rgba(0,0,0,.25); flex: none;
}
.ball.sm { width: 28px; height: 28px; font-size: 12px; }
.ball.c1 { background: var(--ball-1); } .ball.c2 { background: var(--ball-2); } .ball.c3 { background: var(--ball-3); }
.ball.c4 { background: var(--ball-4); } .ball.c5 { background: var(--ball-5); }
.ball.dim { opacity: .35; }
.plus { color: var(--muted); font-weight: 700; margin: 0 2px; }

/* 계정 카드 */
.acc-card { display: flex; flex-direction: column; gap: 10px; }
.acc-card .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.acc-card .name { font-weight: 700; font-size: 16px; }
.acc-card .balance { font-size: 22px; font-weight: 800; }
.acc-card .meta { font-size: 13px; color: var(--muted); }
.acc-card .actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* 슬롯 */
.slots { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.slot { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: var(--surface); }
.slot-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.slot-letter { font-weight: 800; width: 20px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 5px 12px; font: inherit; font-size: 13px; cursor: pointer; }
.seg button.on { background: var(--primary); color: var(--primary-text); }
.picker { display: grid; grid-template-columns: repeat(9, 1fr); gap: 5px; margin-top: 10px; max-width: 420px; }
.picker button {
  aspect-ratio: 1; border-radius: 50%; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); font: inherit; font-size: 13px; cursor: pointer; padding: 0;
}
.picker button.sel { color: #fff; border-color: transparent; font-weight: 700; }
.picker button.sel.c1 { background: var(--ball-1); } .picker button.sel.c2 { background: var(--ball-2); }
.picker button.sel.c3 { background: var(--ball-3); } .picker button.sel.c4 { background: var(--ball-4); }
.picker button.sel.c5 { background: var(--ball-5); }
.buy-footer { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.buy-footer strong { font-size: 20px; }

/* 내역 */
.ticket { border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.ticket-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.game-row { display: flex; align-items: center; gap: 10px; padding: 4px 0; flex-wrap: wrap; }
.game-row .tag { font-size: 12px; color: var(--muted); width: 58px; }
.rank { font-weight: 700; font-size: 13px; }
.rank.win { color: var(--primary); }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; }
.lvl-error, .lvl-warn { color: var(--danger); }

/* 모달 */
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 0; width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 32px); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.dialog-body { padding: 20px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; margin-top: 12px; align-items: end; }
fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px 4px; margin: 8px 0 0; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; z-index: 100; max-width: calc(100vw - 32px); white-space: pre-line; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.toast.err { background: var(--danger); color: #fff; }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; padding: 10px 16px; gap: 8px; }
  #nav { order: 3; flex-basis: 100%; }
  main { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr; }
  .picker { grid-template-columns: repeat(7, 1fr); }
  .ball { width: 30px; height: 30px; font-size: 13px; }
}

/* 인증·관리자 */
.auth-tabs { align-self: center; }
.notice { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; font-size: 13px; margin: 0; }
.ok-text { color: var(--ok); margin: 0; min-height: 1.2em; }
.user-badge { font-size: 13px; white-space: nowrap; }
#signup-mode button { padding: 7px 16px; }
.login-card input { width: 100%; }

/* 연금복권 */
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); margin-bottom: 16px; }
.grid.two .card { margin-bottom: 0; }
.game-tag { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 6px; margin-right: 4px; vertical-align: 1px; color: #fff; }
.game-tag.lotto { background: var(--primary); }
.game-tag.pension { background: #1c7ed6; }
.game-seg button.on { background: var(--text); color: var(--bg); }
.pnum { display: inline-flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.pnum .pd { width: 30px; height: 30px; border-radius: 50%; display: inline-grid; place-items: center; font-weight: 700; color: #fff; font-size: 14px; }
.pnum.sm .pd { width: 24px; height: 24px; font-size: 12px; }
.pnum .pg { padding: 3px 9px; border-radius: 999px; background: #1c7ed6; color: #fff; font-weight: 700; font-size: 13px; margin-right: 2px; }
.pd.d0 { background: #e03131; } .pd.d1 { background: #f76707; } .pd.d2 { background: #f59f00; }
.pd.d3 { background: #1c7ed6; } .pd.d4 { background: #7048e8; } .pd.d5 { background: #868e96; }
.pd.hit { outline: 2px solid var(--text); outline-offset: 1px; }
.pd.miss { opacity: .3; }
.pentry { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pentry select { min-width: 110px; }
.pentry input.pno { width: 110px; letter-spacing: 3px; font-variant-numeric: tabular-nums; }
.win720 { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.win720 .row { gap: 10px; }
.win720 .lbl { width: 54px; font-size: 13px; color: var(--muted); }
