/* Slate Dark Theme & Modern Mobile UI Stylesheet */

html,
body {
    background-color: #0f172a !important;
    color: #f1f5f9;
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, Roboto, sans-serif;
    margin: 0;
    padding: 0;

    /* 스크롤바는 숨기되 위아래 스크롤 동작 허용 */
    overflow-y: auto;
    overflow-x: hidden;
    -ms-overflow-style: none;
    /* IE, Edge */
    scrollbar-width: none;
    /* Firefox */
}

/* Chrome, Safari, Opera 스크롤바 숨김 */
body::-webkit-scrollbar,
html::-webkit-scrollbar {
    display: none;
}

* {
    box-sizing: border-box;
}

body {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    /* 상단 기준 정렬로 스크롤 가능 구역 확보 */
    min-height: 100vh;
    padding: 16px;
    padding-top: calc(16px + var(--safe-area-inset-top, env(safe-area-inset-top, 0px)));
    padding-bottom: calc(16px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)) + var(--admob-banner-height, 0px));
}

.container {
    background-color: #1e293b;
    padding: 1.8rem 1.2rem;
    border-radius: 20px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
    max-width: 480px;
    width: 100%;
    margin: 0 auto;
    text-align: center;
}

/* Header & Emoji */
h1 {
    font-size: 1.35rem;
    font-weight: 800;
    margin: 0 0 0.3rem 0;
    color: #38bdf8;
    letter-spacing: -0.025em;
    background: linear-gradient(135deg, #ffffff 40%, #cbd5e1 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

h1 .emoji {
    -webkit-text-fill-color: initial;
    background: none;
}

.today-line {
    font-size: 0.85rem;
    color: #38bdf8;
    margin-bottom: 1.2rem;
    min-height: 1.2em;
    display: flex;
    align-items: center;
    justify-content: center;
}

.today-line:empty::before {
    content: "오늘의 행운 한 줄을 불러오는 중...";
    color: #64748b;
}

/* D-Day Timer */
.dday-timer {
    background-color: #0f172a;
    border-radius: 12px;
    padding: 10px 14px;
    margin-bottom: 1.2rem;
    border: 1px solid #334155;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
}

.dday-title {
    color: #94a3b8;
    font-weight: 500;
}

.dday-clock {
    color: #f59e0b;
    font-weight: bold;
    font-family: ui-monospace, monospace;
    text-align: right;
}

/* Info Card */
.info-card {
    background-color: #0f172a;
    border-radius: 14px;
    padding: 1rem 1.1rem;
    margin-bottom: 1.2rem;
    text-align: left;
    border: 1px solid #334155;
}

.info-card h3 {
    font-size: 0.95rem;
    color: #38bdf8;
    margin: 0 0 0.5rem 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.info-card p {
    font-size: 0.825rem;
    color: #cbd5e1;
    line-height: 1.5;
    margin: 0 0 0.6rem 0;
}

.explain-link {
    color: #38bdf8;
    font-size: 0.8rem;
    text-decoration: underline;
    cursor: pointer;
    font-weight: bold;
}

/* Mode Selector */
.mode-selector {
    display: flex;
    gap: 8px;
    margin-bottom: 1.2rem;
}

.mode-btn {
    flex: 1;
    padding: 10px;
    background-color: #0f172a;
    border: 1px solid #334155;
    color: #94a3b8;
    border-radius: 10px;
    font-weight: bold;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-btn.active {
    background-color: #0284c7;
    color: white;
    border-color: #38bdf8;
}

/* Game List & Balls */
.game-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 1.5rem 0;
}

.game-row {
    background-color: #0f172a;
    padding: 10px 14px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 1px solid #334155;
}

.game-label {
    font-weight: bold;
    color: #38bdf8;
    font-size: 0.95rem;
    width: 32px;
    text-align: center;
    margin-right: 4px;
}

.ball-container {
    display: flex;
    align-items: center;
    justify-content: space-evenly;
    flex-grow: 1;
    min-width: 0;
    gap: 6px;
}

/* 공 초기 상태: 보이지 않도록 오파시티 0 설정 */
.ball {
    width: 34px;
    min-width: 0;
    flex-shrink: 1;
    aspect-ratio: 1 / 1;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 700;
    font-size: 0.875rem;
    color: #ffffff;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
    opacity: 0;
    transform: scale(0);
}

/* 하나씩 등장하는 Pop 애니메이션 */
@keyframes popIn {
    0% {
        transform: scale(0);
        opacity: 0;
    }

    60% {
        transform: scale(1.15);
        opacity: 1;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.ball.placeholder {
    opacity: 1;
    transform: scale(1);
    animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 0.55;
    }

    50% {
        opacity: 1;
    }
}

/* Buttons & Rows */
.action-row {
    display: flex;
    gap: clamp(4px, 2vw, 8px);
    flex-wrap: nowrap;
    height: 48px;
    margin-bottom: 12px;
}

.action-row > button {
    min-width: 0;
    white-space: nowrap;
    padding: 0 clamp(2px, calc((100vw - 250px) / 6), 13px);
    font-size: clamp(0.625rem, 3.8vw, 0.875rem);
}

.action-row > #generateBtn {
    flex: 1 1 auto;
    width: auto;
    padding-inline: clamp(2px, calc((100vw - 250px) / 6), 16px);
    font-size: clamp(0.625rem, 4vw, 1rem);
}

.btn {
    background-color: #0284c7;
    color: white;
    border: none;
    padding: 14px 20px;
    font-size: 1rem;
    font-weight: bold;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.3);
}

.btn:hover {
    background-color: #0369a1;
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0) scale(0.98);
}

.btn-secondary {
    background-color: #334155;
    color: #f8fafc;
    border: none;
    padding: 12px 14px;
    font-size: 0.875rem;
    font-weight: bold;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-secondary:hover {
    background-color: #475569;
}

#soundToggleBtn {
    border-radius: 9999px;
    border: 1px solid #334155;
    background: rgba(30, 41, 59, 0.85);
    color: #94a3b8;
    font-weight: 600;
}

/* Log Box */
.log-box {
    margin-top: 1.2rem;
    background-color: #0f172a;
    padding: 0.8rem;
    border-radius: 10px;
    text-align: left;
    white-space: pre-line;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.75rem;
    color: #38bdf8;
    max-height: 90px;
    overflow-y: auto;
    border: 1px solid #1e293b;
    line-height: 1.4;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.88);
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 20px;
}

.modal-content {
    background: #1e293b;
    padding: 1.5rem;
    border-radius: 18px;
    max-width: 440px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    border: 1px solid #334155;
    text-align: left;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.modal-content,
.modal-content * {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.modal-content::-webkit-scrollbar,
.modal-content *::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

/* Keep a neutral background until a server response determines the visible view. */
#remoteControlModal,
.service-status {
    position: fixed;
    inset: 0;
    z-index: 999999;
    background: #0B0F19;
    opacity: 1;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    filter: none;
    isolation: isolate;
}

.service-status {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

#remoteControlModal[hidden],
.service-status[hidden] {
    display: none !important;
}

html[data-service-state]:not([data-service-state="ready"]),
html[data-service-state]:not([data-service-state="ready"]) body {
    background: #0B0F19 !important;
}

html[data-service-state]:not([data-service-state="ready"]) body {
    overflow: hidden;
}

html[data-service-state]:not([data-service-state="ready"]) body > :not(#remoteControlModal):not(#serviceStatus) {
    visibility: hidden;
    pointer-events: none;
}

#remoteControlMessage {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.modal-content h3 {
    margin-top: 0;
    color: #38bdf8;
    font-size: 1.1rem;
    border-bottom: 1px solid #334155;
    padding-bottom: 8px;
}

.explain-item {
    margin-bottom: 1rem;
}

.explain-item h4 {
    margin: 0 0 4px 0;
    font-size: 0.9rem;
    color: #f1f5f9;
}

.explain-item p {
    margin: 0;
    font-size: 0.8rem;
    color: #94a3b8;
    line-height: 1.5;
}

.close-btn {
    width: 100%;
    padding: 10px;
    background: #0284c7;
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    margin-top: 10px;
}

/* Media Queries */
@media (max-width: 400px) {
    .ball {
        width: 30px;
        font-size: 0.8rem;
    }

    .game-row {
        padding: 8px 8px;
    }
}

@media (width < 320px) {
    .game-label {
        width: 20px;
    }

    .ball-container {
        gap: 3px;
    }

    .ball {
        font-size: clamp(0.625rem, 4vw, 0.8rem);
    }
}

.mobile-br {
    display: none;
}

@media (max-width: 480px) {
    .mobile-br {
        display: block;
    }
}

/* Saved number entries restored from the legacy saved-list design */
.saved-entry {
    position: relative;
    margin-bottom: 8px;
    padding: 12px;
    border: 1px solid #1e293b;
    border-radius: 12px;
    background: #0b1120;
    font-size: 0.8rem;
}

.saved-entry time {
    display: block;
    margin-bottom: 6px;
    color: #38bdf8;
    font-weight: 600;
}

.saved-set {
    margin-top: 2px;
    color: #cbd5e1;
    font-family: monospace;
}

.saved-label {
    color: #94a3b8;
    font-weight: 700;
}

.delete-saved-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 2px 6px;
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 4px;
    background: rgba(239, 68, 68, 0.1);
    color: #f87171;
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
}

.empty-saved-message {
    padding: 20px 0;
    color: #94a3b8;
    font-size: 0.85rem;
    text-align: center;
}
.quick-qr-check {
    margin-block: 14px;
    display: grid;
    gap: 9px;
    text-align: left;
    font-size: 0.875rem;
}

.quick-qr-check [hidden] { display: none; }

.qr-latest-card,
.qr-check-entry {
    min-width: 0;
    padding: 12px;
    border: 1px solid #475569;
    border-radius: 12px;
    background: #172338;
}

.qr-latest-heading, .qr-game-heading {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 4px 8px;
}

.qr-latest-card h2 {
    margin: 0;
    color: #f8fafc;
    font-size: 0.95rem;
}

.qr-latest-card time, .qr-check-entry small {
    color: #cbd5e1;
    font-size: 0.74rem;
}

.qr-draw-balls, .qr-game-balls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(3px, 1.4vw, 7px);
    margin-block-start: 10px;
}

.qr-ball {
    display: grid;
    place-items: center;
    min-width: 0;
    flex: 0 1 34px;
    aspect-ratio: 1;
    border-radius: 50%;
    border: 1px solid transparent;
    color: #0f172a;
    font-size: clamp(0.63rem, 3vw, 0.85rem);
    font-weight: 800;
}

.qr-ball-band-1 { background: #fbbf24; }
.qr-ball-band-2 { background: #60a5fa; }
.qr-ball-band-3 { background: #fb7185; }
.qr-ball-band-4 { background: #c4b5fd; }
.qr-ball-band-5 { background: #34d399; }
.qr-ball-match { border-color: #f8fafc; box-shadow: 0 0 0 1px #e2e8f0; }
.qr-ball-bonus { border: 2px dashed #334155; }
.qr-ball-miss { background: #28364d; color: #cbd5e1; }
.qr-bonus-plus { color: #cbd5e1; font-weight: 700; }

.qr-check-entry > summary {
    display: flex;
    align-items: center;
    gap: 10px;
    list-style: none;
}

.qr-check-entry > summary::-webkit-details-marker { display: none; }

.qr-check-entry > summary::after {
    content: '';
    width: 7px;
    height: 7px;
    flex-shrink: 0;
    margin-inline-start: auto;
    border: solid #cbd5e1;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.qr-check-entry[open] > summary::after { transform: rotate(225deg); }
.qr-check-entry > summary small { display: block; margin-top: 3px; }

.qr-entry-icon, .qr-scan-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.qr-entry-icon {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    color: #7dd3fc;
    background: #213752;
    border-radius: 9px;
}

.qr-entry-icon svg, .qr-scan-button svg { width: 21px; height: 21px; }

.quick-qr-check summary {
    cursor: pointer;
    font-weight: 700;
}

.qr-scan-button {
    width: 100%;
    min-height: 48px;
}

.qr-check-body { margin-top: 10px; }
.qr-check-status p { line-height: 1.55; }

.qr-result-list {
    display: grid;
    gap: 8px;
    padding: 0;
    list-style: none;
}

.qr-result-list li {
    padding: 9px;
    border-radius: 9px;
    background: #1e293b;
}

.qr-result-list small { display: block; margin-top: 6px; }
.qr-rank-win { font-weight: 800; color: #86efac; }

.qr-prizes {
    border-top: 1px solid #334155;
    padding-top: 10px;
    margin-top: 10px;
}

.qr-prizes ol {
    display: grid;
    gap: 6px;
    margin: 8px 0 0;
    padding: 0;
    list-style: none;
}

.qr-prizes li {
    padding: 8px;
    background: #1e293b;
    border-radius: 8px;
    overflow-wrap: anywhere;
}

.qr-prize-heading {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 8px;
}

.qr-prize-heading span, .qr-prize-stats dt, .qr-prize-note {
    color: #cbd5e1;
    font-size: 0.72rem;
}

.qr-prize-stats {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
    gap: 6px;
    margin: 6px 0 0;
    font-variant-numeric: tabular-nums;
}

.qr-prize-stats dd { margin: 2px 0 0; font-weight: 700; }
.qr-prize-note, .qr-prize-remarks { margin: 5px 0 0; }
.qr-prize-remarks { color: #bae6fd; font-size: 0.75rem; }

html:has(.qr-check-entry[open], .qr-prizes[open]:not([hidden])) {
    scroll-padding-bottom: calc(24px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)) + var(--admob-banner-height, 0px));
}

body:has(.qr-check-entry[open], .qr-prizes[open]:not([hidden])) {
    padding-bottom: calc(32px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)) + var(--admob-banner-height, 0px));
}

html.lotto-qr-scanning,
html.lotto-qr-scanning body {
    overflow: hidden;
    background-color: transparent !important;
}

html.lotto-qr-scanning body > :not(.qr-scan-overlay) { visibility: hidden !important; }

.qr-scan-overlay {
    position: fixed;
    inset: 0;
    z-index: 20000;
    overflow: hidden;
    overscroll-behavior: none;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    padding: calc(12px + var(--safe-area-inset-top, env(safe-area-inset-top, 0px))) 16px
        calc(12px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)) + var(--admob-banner-height, 0px));
    color: #f8fafc;
}

.qr-scan-controls {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    z-index: 1;
}

.qr-scan-controls button, .qr-scan-target p, .qr-scan-target > span {
    padding: 8px 12px;
    border: 1px solid #94a3b8;
    border-radius: 9px;
    background: #0f172a;
    color: #f8fafc;
    font-size: 0.88rem;
}

.qr-scan-controls button { min-height: 44px; cursor: pointer; }

.qr-scan-target {
    display: grid;
    align-content: center;
    justify-items: center;
    min-height: 0;
    text-align: center;
}

.qr-scan-frame {
    width: min(70vw, 35dvh, 320px);
    aspect-ratio: 1;
    border: 3px solid #67e8f9;
    border-radius: 18px;
    box-shadow: 0 0 0 150vmax #020617a6;
}

.qr-scan-target p, .qr-scan-target > span { position: relative; margin: 8px 0 0; }

@media (orientation: landscape) {
    .qr-scan-target { grid-template-columns: auto minmax(0, 240px); place-content: center; align-items: center; gap: 8px 12px; }
}

@media (max-width: 300px) {
    .qr-latest-card, .qr-check-entry { padding: 8px; }
    .qr-entry-icon { width: 30px; height: 30px; flex-basis: 30px; }
}

.quick-qr-check button:disabled {
    opacity: 0.55;
}

.qr-pass-offer {
    --qr-pass-top: calc(10px + var(--safe-area-inset-top, env(safe-area-inset-top, 0px)));
    --qr-pass-bottom: calc(10px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)) + var(--admob-banner-height, 0px));
    position: fixed;
    inset: var(--qr-pass-top) 0 var(--qr-pass-bottom);
    width: min(calc(100% - 24px), 380px);
    max-height: calc(100dvh - var(--qr-pass-top) - var(--qr-pass-bottom));
    margin: auto;
    padding: 22px clamp(12px, 5vw, 24px) 16px;
    border: 1px solid #37516d;
    border-radius: 18px;
    background: #172338;
    color: #f8fafc;
    text-align: center;
    overflow: auto;
    overscroll-behavior: contain;
}

.qr-pass-offer::backdrop { background: #020617b8; }

.qr-pass-close {
    display: block;
    width: 44px;
    height: 44px;
    margin: -10px -8px 0 auto;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #f8fafc;
    font-size: 1.5rem;
    cursor: pointer;
}

.qr-pass-offer h2 { margin: 0; font-size: clamp(1rem, 5vw, 1.3rem); }
.qr-pass-offer p { margin: 8px 0 0; color: #cbd5e1; line-height: 1.45; }

.qr-pass-visual {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: fit-content;
    margin: 18px auto;
    padding: 10px 16px;
    border-radius: 12px;
    color: #7dd3fc;
    background: #213752;
    font-size: 1.75rem;
    font-weight: 700;
}

.qr-pass-visual svg { width: 28px; height: 28px; }
.qr-pass-watch { width: 100%; min-height: 46px; }
.qr-pass-status:not(:empty) { margin-top: 10px; color: #fde68a; line-height: 1.45; }
.qr-pass-footer { margin-top: 14px; color: #cbd5e1; }
.qr-pass-footer small { display: block; margin-top: 3px; color: #94a3b8; }
