/**
 * 로또 번호 생성기 스타일시트
 * 모바일 퍼스트 반응형 디자인
 */

/* ===== CSS 변수 정의 ===== */
:root {
    --primary: #6366f1;      /* 주요 색상 (인디고) */
    --primary-hover: #4f46e5;
    --include: #22c55e;      /* 포함 번호 색상 (녹색) */
    --include-bg: rgba(34, 197, 94, 0.2);
    --exclude: #ef4444;      /* 제외 번호 색상 (빨강) */
    --exclude-bg: rgba(239, 68, 68, 0.2);
    --bg: #0f172a;           /* 배경 색상 (어두운 네이비) */
    --card: #1e293b;         /* 카드 배경 색상 */
    --card-hover: #273549;
    --text: #f1f5f9;         /* 텍스트 색상 (밝은 회색) */
    --text-muted: #94a3b8;   /* 보조 텍스트 */
    --border: #334155;       /* 테두리 색상 */
    --warning: #f59e0b;      /* 경고 색상 */
    --warning-bg: rgba(245, 158, 11, 0.1);

    /* 로또볼 색상 */
    --ball-yellow: linear-gradient(135deg, #fbbf24, #f59e0b);
    --ball-blue: linear-gradient(135deg, #3b82f6, #2563eb);
    --ball-red: linear-gradient(135deg, #ef4444, #dc2626);
    --ball-gray: linear-gradient(135deg, #6b7280, #4b5563);
    --ball-green: linear-gradient(135deg, #22c55e, #16a34a);

    /* 유틸리티 변수 */
    --radius: 12px;
    --radius-sm: 8px;
    --radius-full: 9999px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
    --transition: all 0.2s ease;
}

/* ===== CSS 리셋 ===== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    -webkit-tap-highlight-color: transparent;
}

/* ===== Body 스타일 ===== */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
                 'Helvetica Neue', Arial, 'Noto Sans KR', sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    padding-bottom: env(safe-area-inset-bottom);
}

/* ===== 접근성 ===== */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* 포커스 스타일 */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ===== 유틸리티 클래스 ===== */
.hidden {
    display: none !important;
}

/* ===== 헤더 ===== */
.header {
    text-align: center;
    padding: 1.5rem 1rem;
    background: linear-gradient(135deg, var(--card) 0%, var(--bg) 100%);
    border-bottom: 1px solid var(--border);
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.25rem;
}

.header p {
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* ===== 면책 배너 ===== */
.disclaimer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background-color: var(--warning-bg);
    border-bottom: 1px solid rgba(245, 158, 11, 0.3);
    font-size: 0.8rem;
    color: var(--warning);
    text-align: center;
    flex-wrap: wrap;
}

.disclaimer-icon {
    font-size: 1rem;
}

/* ===== 컨테이너 ===== */
.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 1rem;
}

/* ===== 카드 ===== */
.card {
    background-color: var(--card);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

/* ===== 버튼 공통 스타일 ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    font-size: 0.95rem;
    font-weight: 600;
    text-align: center;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    min-height: 44px;
    min-width: 44px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Primary 버튼 */
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: white;
    width: 100%;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

/* 생성 버튼 */
.btn-generate {
    font-size: 1.1rem;
    padding: 1rem;
    margin-top: 1rem;
}

/* 복사 버튼 */
.btn-copy {
    background-color: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}

.btn-copy:hover {
    background-color: var(--card-hover);
    color: var(--text);
}

/* 초기화 버튼 */
.btn-reset {
    background-color: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
}

.btn-reset:hover {
    background-color: var(--exclude-bg);
    border-color: var(--exclude);
    color: var(--exclude);
}

/* 재시도 버튼 */
.btn-retry {
    background-color: var(--primary);
    color: white;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}

/* ===== 모드 선택 버튼 ===== */
.mode-selector {
    display: flex;
    gap: 0.5rem;
}

.mode-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.75rem 0.5rem;
    background-color: rgba(0, 0, 0, 0.2);
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
    min-height: 44px;
}

.mode-btn:hover {
    background-color: rgba(0, 0, 0, 0.3);
    color: var(--text);
}

.mode-btn.active {
    background-color: rgba(99, 102, 241, 0.2);
    border-color: var(--primary);
    color: var(--text);
}

.mode-icon {
    font-size: 1.25rem;
}

.mode-label {
    font-size: 0.75rem;
    font-weight: 500;
}

/* ===== 게임 수 선택 ===== */
.game-count-selector {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1rem;
    padding: 0.75rem;
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-sm);
}

.game-count-selector label {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.game-count-buttons {
    display: flex;
    gap: 0.375rem;
    flex: 1;
}

.game-count-btn {
    flex: 1;
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 500;
    background-color: rgba(0, 0, 0, 0.2);
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
    min-height: 36px;
}

.game-count-btn:hover {
    background-color: rgba(0, 0, 0, 0.3);
    color: var(--text);
}

.game-count-btn.active {
    background-color: rgba(99, 102, 241, 0.2);
    border-color: var(--primary);
    color: var(--text);
}

/* ===== 결과 영역 ===== */
.result-area {
    margin-top: 1.25rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
    text-align: center;
}

/* ===== 다회차 결과 ===== */
.generated-results {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.game-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    background-color: rgba(0, 0, 0, 0.15);
    border-radius: var(--radius-sm);
}

.game-item .number-display {
    flex: 1;
    margin-bottom: 0;
    padding: 0.5rem;
    min-height: auto;
}

.game-label {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: white;
    font-size: 0.85rem;
    font-weight: 700;
    border-radius: 50%;
    flex-shrink: 0;
}

.result-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 1rem;
}

/* ===== 번호 표시 영역 ===== */
.number-display {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
    padding: 1rem;
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius);
    min-height: 70px;
    margin-bottom: 1rem;
}

/* ===== 로또 볼 스타일 ===== */
.lotto-ball {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.15rem;
    color: white;
    box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.3),
                0 2px 4px rgba(0, 0, 0, 0.3);
    animation: popIn 0.3s ease-out backwards;
}

/* 번호 범위별 색상 */
.ball-yellow { background: var(--ball-yellow); }
.ball-blue { background: var(--ball-blue); }
.ball-red { background: var(--ball-red); }
.ball-gray { background: var(--ball-gray); }
.ball-green { background: var(--ball-green); }

/* 보너스볼 */
.lotto-ball.bonus {
    position: relative;
    border: 2px solid var(--warning);
}

.lotto-ball.bonus::after {
    content: '+';
    position: absolute;
    top: -8px;
    right: -8px;
    width: 18px;
    height: 18px;
    background-color: var(--warning);
    border-radius: 50%;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 작은 볼 (그리드용) */
.lotto-ball.small {
    width: 36px;
    height: 36px;
    font-size: 0.9rem;
}

/* ===== 번호 그리드 ===== */
.number-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 6px;
    margin: 1rem 0;
}

.grid-number {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    background-color: rgba(0, 0, 0, 0.2);
    border: 2px solid transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
    min-height: 36px;
    min-width: 36px;
    user-select: none;
}

.grid-number:hover {
    background-color: rgba(0, 0, 0, 0.3);
    color: var(--text);
}

.grid-number.include {
    background-color: var(--include-bg);
    border-color: var(--include);
    color: var(--include);
}

.grid-number.exclude {
    background-color: var(--exclude-bg);
    border-color: var(--exclude);
    color: var(--exclude);
    text-decoration: line-through;
}

/* ===== 범례 ===== */
.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.legend-item.hint {
    font-size: 0.75rem;
    opacity: 0.7;
}

.legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.legend-dot.include {
    background-color: var(--include);
}

.legend-dot.exclude {
    background-color: var(--exclude);
}

/* ===== 선택 현황 ===== */
.selection-status {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    font-size: 0.85rem;
}

.status-item {
    color: var(--text-muted);
}

.status-item.include strong {
    color: var(--include);
}

.status-item.exclude strong {
    color: var(--exclude);
}

.selection-status .btn-reset {
    margin-left: auto;
}

/* ===== 로딩 스피너 ===== */
.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 2rem;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ===== 에러 메시지 ===== */
.error-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 1.5rem;
    color: var(--text-muted);
    font-size: 0.875rem;
    text-align: center;
}

/* ===== 당첨번호 리스트 ===== */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-sm);
}

.history-round {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary);
    min-width: 60px;
}

.history-numbers {
    display: flex;
    gap: 0.375rem;
    flex-wrap: wrap;
    flex: 1;
}

.history-numbers .lotto-ball {
    width: 32px;
    height: 32px;
    font-size: 0.75rem;
}

.bonus-separator {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin: 0 0.25rem;
}

/* ===== 통계 컨트롤 ===== */
.stats-controls {
    margin-bottom: 1rem;
}

.period-select {
    width: 100%;
    padding: 0.625rem 1rem;
    font-size: 0.9rem;
    background-color: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
}

.period-select:focus {
    border-color: var(--primary);
}

/* ===== 탭 네비게이션 ===== */
.stats-tabs {
    display: flex;
    gap: 0.25rem;
    background-color: rgba(0, 0, 0, 0.2);
    padding: 0.25rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
}

.tab-btn {
    flex: 1;
    padding: 0.625rem 0.5rem;
    font-size: 0.8rem;
    font-weight: 500;
    background-color: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
    min-height: 44px;
}

.tab-btn:hover {
    color: var(--text);
}

.tab-btn.active {
    background-color: var(--primary);
    color: white;
}

/* ===== 탭 패널 ===== */
.tab-panel {
    min-height: 100px;
}

.stats-description {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: rgba(99, 102, 241, 0.1);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--primary);
    line-height: 1.5;
}

.stats-numbers {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    padding: 0.5rem;
}

.stats-number {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.stats-number .count {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* ===== 차트 컨테이너 ===== */
.chart-container {
    width: 100%;
    height: 250px;
    position: relative;
}

/* ===== 푸터 ===== */
.footer {
    text-align: center;
    padding: 1.5rem 1rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    border-top: 1px solid var(--border);
}

/* ===== 애니메이션 ===== */
@keyframes popIn {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    70% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.3s ease forwards;
}

/* ===== 반응형: 작은 화면 ===== */
@media (max-width: 400px) {
    .number-grid {
        grid-template-columns: repeat(7, 1fr);
        gap: 4px;
    }

    .grid-number {
        font-size: 0.75rem;
        min-height: 32px;
        min-width: 32px;
    }

    .mode-label {
        font-size: 0.65rem;
    }

    .lotto-ball {
        width: 42px;
        height: 42px;
        font-size: 1rem;
    }

    .game-item .lotto-ball {
        width: 36px;
        height: 36px;
        font-size: 0.9rem;
    }

    .history-numbers .lotto-ball {
        width: 28px;
        height: 28px;
        font-size: 0.7rem;
    }

    .legend {
        font-size: 0.75rem;
    }

    .legend-item.hint {
        width: 100%;
    }

    .game-count-selector {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .game-count-selector label {
        text-align: center;
    }

    .game-count-btn {
        font-size: 0.75rem;
        padding: 0.5rem;
    }

    .game-label {
        width: 24px;
        height: 24px;
        font-size: 0.75rem;
    }

    .result-buttons {
        flex-direction: column;
    }
}

/* ===== 반응형: 태블릿 이상 ===== */
@media (min-width: 768px) {
    .header h1 {
        font-size: 2rem;
    }

    .container {
        padding: 1.5rem;
    }

    .card {
        padding: 1.5rem;
    }

    .lotto-ball {
        width: 56px;
        height: 56px;
        font-size: 1.25rem;
    }

    .chart-container {
        height: 300px;
    }
}

/* ===== 토스트 메시지 ===== */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.875rem 1.25rem;
    background-color: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    font-size: 0.875rem;
    color: var(--text);
    z-index: 1000;
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    max-width: calc(100% - 40px);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

.toast-message {
    line-height: 1.4;
}

.toast-success {
    border-color: var(--include);
}

.toast-success .toast-icon {
    color: var(--include);
}

.toast-error {
    border-color: var(--exclude);
}

.toast-error .toast-icon {
    color: var(--exclude);
}

.toast-warning {
    border-color: var(--warning);
}

.toast-warning .toast-icon {
    color: var(--warning);
}

.toast-info {
    border-color: var(--primary);
}

.toast-info .toast-icon {
    color: var(--primary);
}

/* ===== 복사 버튼 상태 ===== */
.btn-copy.copied {
    background-color: var(--include-bg);
    border-color: var(--include);
    color: var(--include);
}

/* ===== pop-in 애니메이션 ===== */
.pop-in {
    animation: popIn 0.3s ease-out backwards;
}

/* ===== 스크롤바 스타일 ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== 선택 불가 ===== */
.no-select {
    user-select: none;
    -webkit-user-select: none;
}

/* ===== 인쇄 스타일 ===== */
@media print {
    .disclaimer,
    .btn,
    .mode-selector,
    .selection-card,
    .stats-card,
    .toast {
        display: none;
    }

    body {
        background: white;
        color: black;
    }

    .card {
        border: 1px solid #ccc;
        box-shadow: none;
    }
}
