/* ========== 색상 (라이트 기본) ========== */
:root {
    --bg-1: #eef2ff;
    --bg-2: #fdf2f8;
    --card: rgba(255, 255, 255, 0.85);
    --surface: #f3f4f6;
    --raised: #ffffff;
    --text: #1e1b4b;
    --muted: #6b7280;
    --line: #e5e7eb;
    --accent-1: #6366f1;
    --accent-2: #ec4899;
    --fixed: #6366f1;
    --excluded: #9ca3af;
    --shadow: rgba(79, 70, 229, 0.15);
    color-scheme: light;
}

/* 다크: 자동 모드에서 시스템이 다크일 때 */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg-1: #0f172a;
        --bg-2: #1e1b4b;
        --card: rgba(30, 41, 59, 0.8);
        --surface: #334155;
        --raised: #475569;
        --text: #f1f5f9;
        --muted: #94a3b8;
        --line: #334155;
        --fixed: #818cf8;
        --excluded: #64748b;
        --shadow: rgba(0, 0, 0, 0.35);
        color-scheme: dark;
    }
}

/* 다크: 직접 선택했을 때 */
:root[data-theme="dark"] {
    --bg-1: #0f172a;
    --bg-2: #1e1b4b;
    --card: rgba(30, 41, 59, 0.8);
    --surface: #334155;
    --raised: #475569;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --line: #334155;
    --fixed: #818cf8;
    --excluded: #64748b;
    --shadow: rgba(0, 0, 0, 0.35);
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

/* 배경 그라데이션은 html에 (긴 페이지·모바일에서도 끝까지 이어지게) */
html {
    min-height: 100%;
    background: linear-gradient(135deg, var(--bg-1), var(--bg-2)) no-repeat;
    background-color: var(--bg-1);
}

body {
    font-family: "Noto Sans KR", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
    color: var(--text);
    background: transparent;
    min-height: 100vh;
    margin: 0;
    padding: 0 16px 40px;
    transition: background 0.3s, color 0.3s;
}

h1, h2 {
    margin: 0;
    letter-spacing: -0.02em;
}

/* ========== 상단 바 ========== */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    max-width: 1180px;
    margin: 0 auto;
    padding: 14px 0;
    backdrop-filter: blur(12px);
}

.nav {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.nav a {
    padding: 8px 14px;
    border-radius: 10px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
}

.nav a:hover {
    color: var(--text);
    background: var(--surface);
}

.nav a.current {
    color: var(--text);
    background: var(--raised);
    font-weight: 700;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.settings {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.setting {
    display: flex;
    align-items: center;
    gap: 8px;
}

.setting-label {
    font-size: 13px;
    color: var(--muted);
}

/* ========== 세그먼트 버튼 (공용) ========== */
.segmented {
    display: inline-flex;
    padding: 4px;
    gap: 2px;
    border-radius: 12px;
    background: var(--surface);
}

.segmented button {
    padding: 7px 12px;
    font-size: 13px;
    font-weight: 500;
    color: var(--muted);
    background: transparent;
    border-radius: 9px;
}

.segmented button.active {
    color: var(--text);
    background: var(--raised);
    font-weight: 700;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

#gameSelect button {
    width: 40px;
    padding: 8px 0;
    font-size: 15px;
}

/* ========== 패널 ========== */
.panel {
    padding: 32px 28px;
    background: var(--card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--line);
    border-radius: 28px;
    box-shadow: 0 20px 50px var(--shadow);
}

.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.panel-head h2 {
    font-size: 18px;
}

.panel-desc,
.panel-foot {
    margin: 10px 0 0;
    font-size: 13px;
    line-height: 1.6;
    color: var(--muted);
}

/* ========== 화면 배치: 모바일 ========== */
.app {
    display: grid;
    gap: 20px;
    margin: 8px auto 0;
}

.layout-mobile .app,
.layout-mobile .topbar {
    max-width: 460px;
}

/* ========== 화면 배치: PC ========== */
.layout-pc body {
    min-width: 960px; /* 좁은 화면에서 PC 모드를 고르면 가로 스크롤 */
}

.layout-pc .app {
    max-width: 1180px;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
    grid-template-areas:
        "draw picker"
        "draw history";
    align-items: start;
}

.layout-pc .draw-panel    { grid-area: draw; padding: 44px 40px; }
.layout-pc .picker-panel  { grid-area: picker; }
.layout-pc .history-panel { grid-area: history; }

.layout-pc .draw-panel h1 {
    font-size: 36px;
}

.layout-pc .results {
    min-height: 200px;
}

.layout-pc .ball {
    width: 46px;
    height: 46px;
    font-size: 18px;
}

.layout-pc .balls {
    gap: 8px;
}

/* ========== 뽑기 패널 ========== */
.draw-panel {
    text-align: center;
}

.draw-panel h1 {
    font-size: 30px;
    font-weight: 900;
}

.subtitle {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 15px;
}

.games {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin-top: 24px;
}

.games-label {
    font-size: 14px;
    color: var(--muted);
}

.results {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 12px;
    min-height: 120px;
    margin: 24px 0;
    padding: 20px 14px;
    border-radius: 20px;
    background: var(--surface);
}

.placeholder {
    color: var(--muted);
    font-size: 15px;
}

.game-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.game-label {
    width: 18px;
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
}

.balls {
    display: flex;
    flex: 1;
    justify-content: center;
    align-items: center;
    gap: 6px;
}

.plus {
    color: var(--muted);
    font-weight: 700;
}

/* 분석 */
.stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 20px 0 0;
}

.stats div {
    padding: 12px 8px;
    border: 1px solid var(--line);
    border-radius: 14px;
}

.stats dt {
    font-size: 12px;
    color: var(--muted);
}

.stats dd {
    margin: 4px 0 0;
    font-size: 18px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.hint {
    margin: 16px 0 0;
    color: var(--muted);
    font-size: 12px;
}

/* ========== 로또 공 (실제 로또 색상 구간) ========== */
.ball {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;

    font-size: 16px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    box-shadow: inset -3px -4px 8px rgba(0, 0, 0, 0.2), 0 3px 6px rgba(0, 0, 0, 0.15);

    animation: drop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.ball.c1 { background: radial-gradient(circle at 30% 30%, #fde68a, #f59e0b); }
.ball.c2 { background: radial-gradient(circle at 30% 30%, #93c5fd, #2563eb); }
.ball.c3 { background: radial-gradient(circle at 30% 30%, #fca5a5, #dc2626); }
.ball.c4 { background: radial-gradient(circle at 30% 30%, #d1d5db, #6b7280); }
.ball.c5 { background: radial-gradient(circle at 30% 30%, #86efac, #16a34a); }

/* 고정 번호로 나온 공 표시 */
.ball.is-fixed {
    outline: 3px solid var(--fixed);
    outline-offset: 2px;
}

.layout-pc .ball.small,
.ball.small {
    width: 28px;
    height: 28px;
    font-size: 12px;
    animation: none;
}

@keyframes drop {
    0%   { opacity: 0; transform: translateY(-16px) scale(0.5); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* ========== 버튼 ========== */
.actions {
    display: flex;
    gap: 10px;
}

button {
    font: inherit;
    font-size: 17px;
    font-weight: 700;
    padding: 15px 20px;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.2s, opacity 0.2s, background 0.2s, color 0.2s;
}

button:active {
    transform: scale(0.97);
}

button:focus-visible {
    outline: 3px solid rgba(99, 102, 241, 0.4);
    outline-offset: 2px;
}

button.primary {
    flex: 1;
    color: white;
    background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.35);
}

button.primary:hover {
    box-shadow: 0 10px 26px rgba(99, 102, 241, 0.5);
}

button.primary:disabled {
    opacity: 0.7;
    cursor: wait;
}

button.ghost {
    color: var(--muted);
    background: transparent;
    border: 1px solid var(--line);
}

button.ghost:hover:not(:disabled) {
    color: var(--text);
    background: var(--surface);
}

button.ghost:disabled {
    opacity: 0.4;
    cursor: default;
}

button.link {
    padding: 0;
    font-size: 13px;
    font-weight: 500;
    color: var(--muted);
    background: none;
    text-decoration: underline;
    text-underline-offset: 3px;
}

button.link:hover {
    color: var(--text);
}

/* ========== 번호 고정 / 제외 ========== */
.tag {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    color: white;
}

.tag.fixed    { background: var(--fixed); }
.tag.excluded { background: var(--excluded); }

.number-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 6px;
    margin-top: 16px;
}

.cell {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    aspect-ratio: 1;
    padding: 0;
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    border: 2px solid transparent;
}

.cell:hover {
    border-color: var(--muted);
}

/* 번호 색상 구간을 왼쪽 위 점으로 표시 */
.cell::before {
    content: "";
    position: absolute;
    top: 5px;
    left: 5px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.cell.c1::before { background: #f59e0b; }
.cell.c2::before { background: #2563eb; }
.cell.c3::before { background: #dc2626; }
.cell.c4::before { background: #6b7280; }
.cell.c5::before { background: #16a34a; }

.cell-num {
    font-size: 15px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.cell-freq {
    min-height: 13px;
    font-size: 10px;
    font-weight: 500;
    color: var(--muted);
}

.cell.fixed {
    border-color: var(--fixed);
    background: var(--fixed);
    color: white;
}

.cell.fixed .cell-freq {
    color: rgba(255, 255, 255, 0.85);
}

.cell.excluded {
    color: var(--excluded);
    text-decoration: line-through;
    opacity: 0.55;
}

/* ========== 기록 ========== */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 16px 0 0;
    padding: 0;
    list-style: none;
    counter-reset: game;
}

.history-list li {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 8px 10px;
    border-radius: 12px;
    background: var(--surface);
    counter-increment: game;
}

.history-list li::before {
    content: counter(game);
    width: 22px;
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
}

.history-list li.empty {
    justify-content: center;
    padding: 16px;
    color: var(--muted);
    font-size: 14px;
    background: none;
}

.history-list li.empty::before {
    content: none;
}

/* ========== 알림 ========== */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    z-index: 20;
    transform: translateX(-50%);
    padding: 10px 18px;
    border-radius: 999px;
    background: var(--text);
    color: var(--bg-1);
    font-size: 14px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

/* 아주 좁은 화면 (모바일 모드) */
@media (max-width: 420px) {
    .layout-mobile .panel {
        padding: 28px 16px;
    }

    .layout-mobile .ball {
        width: 34px;
        height: 34px;
        font-size: 14px;
    }

    .layout-mobile .balls {
        gap: 4px;
    }

    .setting-label {
        display: none;
    }
}
