/* ══════════════════════════════════════════════════
   style.css — Tailwind 보완용 (최소화)
   ══════════════════════════════════════════════════ */

:root {
    --bg:     #0F172A;
    --bg2:    #1E293B;
    --bg3:    #263347;
    --card:   #1A2744;
    --gold:   #F5C842;
    --gold2:  #E8A800;
    --blue:   #3B82F6;
    --blue2:  #1D4ED8;
    --green:  #22C55E;
    --green2: #15803D;
    --red:    #EF4444;
    --text:   #F1F5F9;
    --text2:  #94A3B8;
    --text3:  #64748B;
    --nav-h:  64px;
    --radius: 18px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; overflow-x: hidden; }

/* ── 페이지 전환 ── */
.page        { display: none; }
.page.active { display: block; animation: fadeIn .22s ease; }
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}

/* ══ 번호 볼 ══
   flex-shrink:0 + 고정 크기 — 절대 줄어들지 않음
   부모가 flex여도 볼이 찌그러지지 않도록 min-width 동일하게 */
.ball, .mini-ball {
    position: relative; overflow: hidden; border-radius: 9999px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 900; color: #fff;
    flex-shrink: 0; flex-grow: 0;   /* ★ 크기 고정 */
    line-height: 1;
}
.ball {
    /* 6개 + gap5px*5 + 패딩28px*2 = 최소 필요폭 계산
       (100vw - 32px패딩 - 28px카드패딩*2 - 6px헤더) / 6 - 5px gap
       → clamp(32px, calc((100vw - 120px)/6), 42px) */
    width:  clamp(32px, calc((100vw - 120px) / 6), 42px);
    height: clamp(32px, calc((100vw - 120px) / 6), 42px);
    min-width: 0;
    font-size: clamp(11px, calc((100vw - 120px) / 6 * 0.33), 14px);
    box-shadow: 0 3px 10px rgba(0,0,0,.4);
}
.mini-ball {
    /* JS에서 개별 크기를 clamp로 덮어쓰므로 여기선 기본값만 */
    width: 30px; height: 30px; min-width: 0;
    font-size: 11px;
    box-shadow: 0 2px 6px rgba(0,0,0,.35);
}
/* 광택 */
.ball::after, .mini-ball::after {
    content: ''; position: absolute;
    top: 18%; left: 18%; width: 30%; height: 22%;
    background: rgba(255,255,255,.32); border-radius: 50%;
    transform: rotate(-30deg); pointer-events: none;
}
/* 색상 */
.b-y   { background: linear-gradient(135deg,#FBC02D,#F59E0B); }
.b-b   { background: linear-gradient(135deg,#3B82F6,#1D4ED8); }
.b-r   { background: linear-gradient(135deg,#EF4444,#B91C1C); }
.b-gr  { background: linear-gradient(135deg,#22C55E,#15803D); }
.b-gry { background: linear-gradient(135deg,#9CA3AF,#4B5563); }

@keyframes ballBounce {
    0%   { transform: translateY(-40px) scale(.5); opacity: 0; }
    60%  { transform: translateY(4px) scale(1.07); opacity: 1; }
    80%  { transform: translateY(-2px) scale(.97); }
    100% { transform: none; opacity: 1; }
}
.ball.anim { animation: ballBounce .45s cubic-bezier(.36,1.6,.26,.9) both; }

/* ══ 세트 카드 — 볼 행 ══
   wrap 금지, 볼 6개가 한 줄에 꽉 차도록 */
.balls-row {
    display: flex;
    flex-wrap: nowrap;          /* ★ 줄바꿈 금지 */
    align-items: center;
    gap: 5px;
    overflow: hidden;           /* 삐져나와도 카드 밖으로 안 나감 */
}
/* 볼 사이 gap을 뷰포트에 맞게 조정 */
@media (max-width: 380px) { .balls-row { gap: 3px; } }

/* ══ 세트 카드 레이아웃 ══ */
.set-card {
    background: var(--card);
    border: 1px solid rgba(255,255,255,.07);
    border-radius: var(--radius);
    padding: 12px 10px;   /* 좌우 패딩 축소로 볼 공간 확보 */
    margin-bottom: 10px;
    position: relative; overflow: hidden;
    transition: border-color .2s;
    box-shadow: 0 4px 20px rgba(0,0,0,.22);
    animation: fadeIn .3s ease both;
}
.set-card:hover { border-color: rgba(245,200,66,.2); }
.set-card::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
    opacity: 0; transition: opacity .2s;
}
.set-card:hover::before { opacity: 1; }

.set-card-header {
    display: flex; align-items: center;
    justify-content: space-between; margin-bottom: 10px;
}
.set-label {
    font-size: 10px; font-weight: 700; color: var(--text3);
    letter-spacing: 1px; text-transform: uppercase;
    display: flex; align-items: center; gap: 4px;
}
.save-btn {
    display: flex; align-items: center; gap: 4px;
    padding: 4px 10px; border-radius: 8px;
    font-family: inherit; font-size: 11px; font-weight: 700;
    border: 1.5px solid rgba(245,200,66,.3);
    background: rgba(245,200,66,.08); color: var(--gold);
    cursor: pointer; transition: all .15s; white-space: nowrap;
}
.save-btn:hover { background: rgba(245,200,66,.18); border-color: var(--gold); }

/* ══ QR — 뷰파인더 높이 제한 (소형화면) ══ */
.viewfinder {
    border-radius: 18px; overflow: hidden;
    background: #060D1A; margin-bottom: 8px;
    position: relative;
    /* 화면 높이의 35%로 제한 — 버튼이 화면 안에 들어오게 */
    height: clamp(220px, 45vh, 400px);
}
.viewfinder #reader        { width: 100%; height: 100%; display: none; }
.viewfinder #reader video  { width: 100% !important; height: 100% !important; object-fit: cover !important; }

.scan-overlay {
    position: absolute; inset: 0;
    display: none; align-items: center; justify-content: center;
    pointer-events: none; z-index: 5;
}
.scan-overlay.active { display: flex; }
.scan-box { width: 200px; height: 200px; position: relative; }
.scan-corner {
    position: absolute; width: 20px; height: 20px;
    border-color: rgba(245,200,66,.9); border-style: solid;
}
.sc-tl { top:0;    left:0;  border-width:3px 0 0 3px; border-radius:4px 0 0 0; }
.sc-tr { top:0;    right:0; border-width:3px 3px 0 0; border-radius:0 4px 0 0; }
.sc-bl { bottom:0; left:0;  border-width:0 0 3px 3px; border-radius:0 0 0 4px; }
.sc-br { bottom:0; right:0; border-width:0 3px 3px 0; border-radius:0 0 4px 0; }
.scan-line {
    position: absolute; left: 4px; right: 4px; height: 2px; top: 0;
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
    border-radius: 2px; animation: scanMove 2s ease-in-out infinite;
}
@keyframes scanMove {
    0%,100% { top: 8px;   opacity: .7; }
    50%      { top: 188px; opacity: 1; }
}

.cam-placeholder {
    position: absolute; inset: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 8px; text-align: center; padding: 16px;
}
.cam-placeholder .big-emoji { font-size: 40px; line-height: 1; }
.cam-placeholder p { font-size: 12.5px; color: var(--text2); line-height: 1.5; }

/* ── cam-status ── */
#cam-status { text-align: center; font-size: 12px; color: var(--text2); min-height: 18px; margin-bottom: 8px; }
#cam-status.ok  { color: var(--green); }
#cam-status.err { color: var(--red); }

/* ── 카메라 선택 드롭다운 ── */
.cam-selector-label {
    font-size: 10px; color: var(--text3); font-weight: 700;
    letter-spacing: .6px; text-transform: uppercase;
    margin-bottom: 4px; padding-left: 2px;
}
.cam-selector-inner {
    display: flex; align-items: center; gap: 8px;
    background: var(--card); border: 1.5px solid rgba(255,255,255,.09);
    border-radius: 12px; padding: 9px 12px; margin-bottom: 8px;
}
.cam-selector-inner select {
    flex: 1; border: none; outline: none;
    background: transparent; font-family: inherit;
    font-size: 12.5px; color: var(--text); cursor: pointer;
}
.cam-selector-inner select option { background: #1A2744; }

/* ── 하단 네비 active ── */
#bottom-nav .tab-btn.active { color: var(--gold); }
#bottom-nav .tab-btn.active .material-symbols-rounded {
    filter: drop-shadow(0 0 6px rgba(245,200,66,.55));
}
#bottom-nav .tab-btn.active::before {
    content: ''; position: absolute;
    top: 0; left: 20%; right: 20%;
    height: 2px; background: var(--gold);
    border-radius: 0 0 3px 3px;
}
#top-nav .tab-btn.active { background: rgba(245,200,66,.12); color: var(--gold); font-weight: 700; }

/* ── 배지 ── */
.badge {
    position: absolute; top: 6px; right: calc(50% - 20px);
    min-width: 15px; height: 15px;
    background: var(--red); color: #fff; font-size: 9px; font-weight: 700;
    border-radius: 99px; padding: 0 3px;
    display: none; align-items: center; justify-content: center;
    border: 1.5px solid var(--bg);
}
.badge.show { display: flex; }
#pc-badge {
    position: absolute; top: 4px; right: 4px;
    min-width: 15px; height: 15px;
    background: var(--red); color: #fff; font-size: 9px; font-weight: 700;
    border-radius: 99px; padding: 0 3px;
    display: none; align-items: center; justify-content: center;
}
#pc-badge.show { display: flex; }

/* ── 토스트 ── */
#toast {
    position: fixed; bottom: calc(var(--nav-h) + 12px); left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(245,200,66,.13); backdrop-filter: blur(12px);
    border: 1px solid rgba(245,200,66,.3); color: var(--gold);
    font-size: 13px; font-weight: 600; padding: 10px 22px;
    border-radius: 99px; opacity: 0;
    transition: opacity .22s, transform .22s;
    pointer-events: none; white-space: nowrap; z-index: 999;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── 로고 펄스 ── */
@keyframes pulse-dot {
    0%,100% { box-shadow: 0 0 6px var(--gold); }
    50%      { box-shadow: 0 0 14px var(--gold), 0 0 28px rgba(245,200,66,.3); }
}
.logo-dot { animation: pulse-dot 2s ease-in-out infinite; }

/* ── 빈도 바 ── */
.freq-bar { height: 100%; border-radius: 99px; width: 0; transition: width .9s cubic-bezier(.25,.8,.25,1); }

/* ── 내 번호 날짜 구분 ── */
.my-date-label::after { content: ''; flex: 1; height: 1px; background: rgba(255,255,255,.06); }

/* ── stats badge 충돌 방지 ── */
.stats-card-title .badge {
    position: static; background: none; min-width: unset;
    height: auto; border: none; padding: 0; display: inline;
    font-size: 10px; color: var(--text3);
}

/* ── QR 슬라이드인 ── */
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── html5-qrcode 오버라이드 ── */
#reader { border: none !important; width: 100% !important; }
#reader__dashboard, #reader__dashboard_section_swaplink { display: none !important; }

/* ── 스크롤바 ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 4px; }

/* ── 반응형 ── */
@media (max-width: 640px) {
    #top-nav    { display: none !important; }
    #bottom-nav { display: flex !important; }
    #content    { padding-bottom: calc(var(--nav-h) + 16px); }
}
@media (min-width: 641px) {
    #top-nav    { display: flex !important; }
    #bottom-nav { display: none !important; }
    #content    { padding-bottom: 32px; }
    #toast      { bottom: 24px; }
    .viewfinder { height: 300px; }
    .scan-box   { width: 200px; height: 200px; }
    @keyframes scanMove {
        0%,100% { top: 8px; }
        50%      { top: 186px; }
    }
}
