/* SMART LOTTO 6/45 모바일 - 세로(320~430px 기준, 그 이상은 가운데 정렬) + 가로(낮은 화면: 왼쪽 메뉴 + 2단 배치) */
:root {
  --bg0: #020a24; --bg1: #0d3278; --panel: #071a45; --line: #2b63c4; --line2: #1f4a92;
  --gold: #ffb51f; --gold2: #ffc94d; --txt: #e6f0ff; --sub: #9cc3ff; --dim: #6fa8ff; --warn: #ff9f7a;
  --btn: #143a78; --btn-hi: #1d4f9e; --danger: #7a1f2b;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  --tabs-h: 58px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: #020818; color: var(--txt); }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  font-size: 15px; line-height: 1.4; touch-action: manipulation; overscroll-behavior-y: contain;
  -webkit-text-size-adjust: 100%; -webkit-user-select: none; user-select: none;
}
#app {
  height: 100vh; height: 100dvh; max-width: 520px; margin: 0 auto; display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--bg0), var(--bg1) 45%, var(--bg0)); position: relative;
}
.top {
  flex: none; display: flex; align-items: center; gap: 10px; padding: calc(8px + var(--safe-t)) 14px 8px;
  background: #03102e; border-bottom: 2px solid var(--gold); box-shadow: 0 2px 0 #1f5fc8;
}
.emblem {
  flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle, #0b2d6e 62%, var(--gold) 64%); color: #ffd34d; font-weight: 800; font-size: 11px;
  border: 2px solid #ffe08a;
}
.titles { min-width: 0; flex: 1; }
.titles h1 { margin: 0; font-size: 19px; letter-spacing: .3px; white-space: nowrap; }
.titles h1 span { color: var(--gold); }
.titles p { margin: 0; font-size: 12px; color: var(--sub); }
.badge {
  flex: none; font-size: 11px; font-weight: 700; color: #ffcf6b; background: #2b1800; border: 1.5px solid var(--gold);
  border-radius: 12px; padding: 4px 7px; text-align: center; line-height: 1.2; max-width: 92px;
}
main { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; padding: 10px 14px 12px; }
.view { display: none; }
.view.active { display: block; }
h2 { margin: 4px 0 10px; font-size: 18px; color: #fff; }
h3 { margin: 0 0 6px; font-size: 15px; color: var(--gold); }
.panel { background: var(--panel); border: 1.5px solid var(--line); border-radius: 16px; padding: 10px 12px; margin-bottom: 10px; }
.sub { font-size: 13px; color: var(--sub); margin: 4px 0 8px; }
.sub code { background: #0b2a63; padding: 1px 5px; border-radius: 4px; font-size: 12px; user-select: text; }
.seg-label { font-size: 12px; color: var(--dim); margin: 2px 0 5px; font-weight: 700; }
.seg { display: flex; gap: 8px; margin-bottom: 8px; }
.seg:last-child { margin-bottom: 2px; }
.seg button {
  flex: 1; min-height: 44px; border-radius: 12px; border: 1.5px solid #3b7be0; background: var(--btn); color: var(--txt);
  font: inherit; font-size: 14px; font-weight: 700; padding: 4px 2px;
}
.seg button[aria-checked="true"] { background: var(--gold); color: #1b1300; border-color: #ffe08a; }
.seg button:disabled { opacity: .45; }
.stage-wrap { display: flex; justify-content: center; margin: 2px 0 4px; }
#stage { display: block; touch-action: manipulation; }
.status { text-align: center; margin: 2px 0 6px; }
#status-main { font-size: 22px; font-weight: 800; color: #fff; min-height: 30px; }
#status-sub { font-size: 14px; color: var(--sub); min-height: 20px; }
.info { background: var(--panel); border: 1.5px solid var(--line2); border-radius: 14px; padding: 8px 12px; margin-bottom: 8px; }
.info > div { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; padding: 2px 0; }
.info .k { color: #7fa6dd; font-weight: 700; flex: none; }
.info .v { text-align: right; min-width: 0; overflow-wrap: anywhere; }
.startbar {
  position: sticky; bottom: -12px; padding: 8px 14px 8px; margin: 0 -14px;
  background: linear-gradient(180deg, rgba(3,16,46,0), rgba(3,16,46,.96) 28%);
}
.selectors { padding: 8px 10px 4px; }
.selectors .seg { margin-bottom: 6px; }
.selectors .seg button { min-height: 44px; }
.btn {
  display: flex; align-items: center; justify-content: center; width: 100%; min-height: 48px; border-radius: 14px;
  border: 1.5px solid #3b7be0; background: var(--btn); color: var(--txt); font: inherit; font-size: 15px; font-weight: 700;
  padding: 6px 8px; cursor: pointer; text-align: center;
}
.btn:active { background: var(--btn-hi); }
.btn:disabled { opacity: .4; }
.btn.primary { background: var(--gold); border-color: #ffe08a; color: #1b1300; font-size: 20px; min-height: 56px; }
.btn.primary:active { background: var(--gold2); }
.btn.danger { background: var(--danger); border-color: #d9565f; margin-top: 10px; font-size: 14px; }
.row3 { display: flex; gap: 8px; margin-top: 8px; }
.row3 .btn { min-height: 46px; font-size: 14px; }
.btn.file { position: relative; overflow: hidden; margin: 6px 0; }
.btn.file input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; font-size: 16px; }
.notice { font-size: 12px; color: var(--warn); margin: 6px 0 4px; text-align: center; }
.toplist { list-style: none; margin: 0 0 8px; padding: 0; }
.toplist li { display: grid; grid-template-columns: 24px 38px 1fr auto; align-items: center; gap: 8px; min-height: 44px; padding: 3px 0; }
.toplist .rank { color: var(--dim); font-weight: 800; text-align: center; }
.chip { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 14px; box-shadow: inset -3px -4px 6px rgba(0,0,0,.28), inset 3px 3px 5px rgba(255,255,255,.3); }
.chip::after { content: attr(data-n); background: #fff; border-radius: 50%; width: 22px; height: 22px; display: grid; place-items: center; font-size: 12px; font-weight: 800; color: var(--c); }
.bar { height: 14px; background: #0b2a63; border-radius: 7px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, #2f6fd1, #5b9cff); border-radius: 7px; }
.cnt { font-size: 14px; font-weight: 700; text-align: right; min-width: 74px; }
.cnt small { color: var(--sub); font-weight: 400; }
.empty { padding: 14px 6px; color: var(--txt); font-size: 14px; }
.kv { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: #7fa6dd; font-weight: 700; }
.kv dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
.kv dd.ok { color: #6be08a; } .kv dd.bad { color: #ff8a7a; }
.report { margin-top: 8px; border-radius: 12px; padding: 8px 10px; font-size: 13px; background: #0b2a63; user-select: text; }
.report.ok { border: 1.5px solid #3fb950; } .report.bad { border: 1.5px solid #e8453c; }
.report b { display: block; margin-bottom: 4px; }
.report ul { margin: 0; padding-left: 18px; }
.help { margin: 4px 0 6px; padding-left: 18px; font-size: 13px; color: var(--txt); }
.tabs {
  flex: none; display: flex; height: calc(var(--tabs-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: #03102e; border-top: 2px solid var(--line2);
}
.tab { flex: 1; border: 0; background: none; color: var(--sub); font: inherit; font-size: 13px; font-weight: 700; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; min-height: 44px; }
.tab i { font-style: normal; font-size: 18px; line-height: 1; }
.tab.active { color: var(--gold); box-shadow: inset 0 3px 0 var(--gold); }
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + var(--safe-b) + 74px); transform: translate(-50%, 20px);
  background: rgba(10, 30, 70, .96); border: 1.5px solid #5b9cff; color: #fff; padding: 10px 16px; border-radius: 22px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: 88vw; text-align: center; z-index: 20;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#update-bar { position: fixed; left: 8px; right: 8px; top: calc(8px + var(--safe-t)); z-index: 30; background: #143a78; border: 1.5px solid var(--gold); border-radius: 12px; padding: 8px 12px; font-size: 14px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
#update-bar[hidden] { display: none; }
#update-bar button { min-height: 40px; padding: 0 14px; border-radius: 10px; border: 0; background: var(--gold); color: #1b1300; font: inherit; font-weight: 800; }
.row2 { display: flex; gap: 8px; margin-top: 8px; }
.row2 .btn { min-height: 46px; font-size: 14px; line-height: 1.2; }
.row2 .btn.danger { margin-top: 0; }
h2 small { font-size: 14px; color: var(--sub); font-weight: 700; margin-left: 6px; }
.center { text-align: center; }
.draw-side { min-width: 0; }
/* 공 6개를 한 줄에: 칸 폭에 맞춰 줄어들므로 어떤 화면에서도 잘리지 않는다 */
.balls { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: clamp(3px, 1.2vw, 8px); min-width: 0; }
.balls .chip { width: 100%; height: auto; aspect-ratio: 1; max-width: 56px; justify-self: center; }
.balls .chip::after { width: 64%; height: 64%; font-size: clamp(11px, 3.6vw, 18px); }
.vaultlist { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 8px; }
.vaultlist li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; background: var(--panel); border: 1.5px solid var(--line2); border-radius: 14px; padding: 8px 10px; }
.vaultlist li.empty { display: block; border-style: dashed; }
.vhead { grid-column: 1 / -1; display: flex; align-items: baseline; gap: 6px; font-size: 14px; }
.vhead .when { margin-left: auto; color: var(--dim); font-size: 12px; }
.tag { font-style: normal; font-size: 11px; font-weight: 800; color: #1b1300; background: var(--gold); border-radius: 8px; padding: 1px 6px; }
.vdel { min-height: 44px; min-width: 56px; border-radius: 12px; border: 1.5px solid #d9565f; background: var(--danger); color: #fff; font: inherit; font-size: 14px; font-weight: 700; }
.toplist li.chosen { background: #13306a; border-radius: 10px; padding-right: 8px; padding-left: 4px; box-shadow: inset 0 0 0 1px var(--gold); }
.toplist li.chosen .cnt small { color: var(--gold); font-weight: 700; }
.finalbox { text-align: center; border-color: var(--gold); }
.finalbox .balls { margin: 6px 0; }
@media (max-width: 374px) {
  .tab { font-size: 12px; }
  .titles h1 { font-size: 17px; } .badge { max-width: 88px; padding: 4px 6px; }
  #status-main { font-size: 20px; } .seg button { font-size: 13px; }
}
@media (min-width: 521px) { #app { border-left: 2px solid var(--line2); border-right: 2px solid var(--line2); } }
/* 가로 화면(낮은 높이): 메뉴는 왼쪽, 추첨기는 왼쪽·조작부는 오른쪽, 목록은 2단 */
@media (orientation: landscape) and (max-height: 600px) {
  #app { max-width: none; border: 0 !important; display: grid; grid-template-columns: calc(76px + env(safe-area-inset-left, 0px)) minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .top { grid-column: 1 / -1; padding: calc(4px + var(--safe-t)) 14px 4px; gap: 8px; }
  .emblem { width: 30px; height: 30px; font-size: 9px; }
  .titles h1 { font-size: 16px; } .titles p { display: none; }
  .badge { font-size: 10px; padding: 2px 6px; max-width: none; }
  .tabs { grid-column: 1; grid-row: 2; flex-direction: column; height: auto; padding: 0 0 0 env(safe-area-inset-left, 0px); border-top: 0; border-right: 2px solid var(--line2); }
  .tab { flex: 1; min-height: 44px; font-size: 12px; box-shadow: none; }
  .tab.active { box-shadow: inset 3px 0 0 var(--gold); }
  main { grid-column: 2; grid-row: 2; padding: 8px calc(14px + env(safe-area-inset-right, 0px)) 8px 14px; }
  #view-draw.active .draw-grid { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 12px; align-items: start; }
  .stage-wrap { position: sticky; top: 0; margin: 0; }
  .startbar { bottom: -8px; margin: 0 -14px 0 -4px; }
  #status-main { font-size: 18px; min-height: 24px; } #status-sub { font-size: 13px; min-height: 18px; }
  .notice { font-size: 11px; }
  .vaultlist li.empty { grid-column: 1 / -1; }
  #toast { bottom: 16px; }
  #update-bar { left: 90px; }
}
@media (orientation: landscape) and (max-height: 600px) and (min-width: 760px) { .vaultlist { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

/* 최신 회차·업데이트 시각 표시줄 */
.updateline{display:flex;flex-wrap:wrap;justify-content:space-between;gap:2px 10px;padding:4px 12px;font-size:12px;color:#9fb4e8;background:rgba(255,255,255,.05);border-bottom:1px solid rgba(255,255,255,.08)}
.updateline.err #ul-time{color:#ffb86b}

/* 아이폰 Safari 보완: 길게 눌러도 메뉴·돋보기 없음, 가로 화면 노치 안전 영역, 주소창 변동 높이 */
body { -webkit-touch-callout: none; }
.sub, .report, code { -webkit-touch-callout: default; }
@supports (height: -webkit-fill-available) { #app { min-height: -webkit-fill-available; } }
.top, .updateline { padding-left: max(14px, env(safe-area-inset-left, 0px)); padding-right: max(14px, env(safe-area-inset-right, 0px)); }
button, .btn { -webkit-appearance: none; appearance: none; }
