/* Bootstrap과 함께 사용하는 커스텀 CSS */

:root {
    --primary-color: #6366f1;
    --secondary-color: #8b5cf6;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --dark-bg: #0f172a;
    --light-bg: #f8fafc;
    --border-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
}

/* 모바일 안전 영역 */
.container-fluid {
    padding-right: 15px;
    padding-left: 15px;
}

@media (max-width: 576px) {
    .container-fluid {
        padding-right: 10px;
        padding-left: 10px;
    }
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Noto Sans KR', sans-serif;
    background: linear-gradient(135deg, var(--dark-bg) 0%, #1e3a8a 100%);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* 모든 요소 overflow 방지 */
* {
    max-width: 100%;
    box-sizing: border-box;
}

img {
    max-width: 100%;
    height: auto;
}

table {
    width: 100%;
    overflow-x: auto;
    display: block;
}

/* 헤더 스타일 */
.header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    padding: 60px 30px;
    border-radius: 0;
    margin-bottom: 40px;
    box-shadow: 0 10px 40px rgba(99, 102, 241, 0.3);
}

.header h1 {
    font-size: 3em;
    margin-bottom: 15px;
    font-weight: 700;
}

.subtitle {
    font-size: 1.2em;
    opacity: 0.95;
    margin-bottom: 0;
}

/* 메인 콘텐츠 */
.main-content {
    background: white;
    border-radius: 15px;
    padding: 40px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    margin-bottom: 30px;
}

.main-content h2 {
    color: var(--primary-color);
    font-weight: 600;
}

/* 입력 섹션 */
.input-section,
.info-section {
    margin-bottom: 40px;
}

/* 카드 호버 효과 */
.card {
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: 1px solid rgba(99, 102, 241, 0.1);
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.type-btn .icon {
    font-size: 1.3em;
}

/* 폼 그룹 */
.form-group {
    margin-bottom: 25px;
}

.form-group label {
    display: block;
    margin-bottom: 10px;
    font-weight: 600;
    color: var(--text-primary);
}

.input-field {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1em;
    transition: all 0.3s ease;
    font-family: inherit;
}

.input-field:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.form-hint {
    color: var(--text-secondary);
    font-size: 0.9em;
    margin-top: 8px;
}

.bit-input-group {
    display: flex;
    gap: 10px;
    align-items: center;
}

.bit-input-group .input-field {
    flex: 1;
}

.bit-default {
    color: var(--text-secondary);
    font-size: 0.9em;
    white-space: nowrap;
}

.input-form.hidden {
    display: none;
}

/* 계산 버튼 */
.calculate-btn {
    width: 100%;
    padding: 15px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1.1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 5px 20px rgba(99, 102, 241, 0.3);
}

.calculate-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(99, 102, 241, 0.4);
}

.calculate-btn:active {
    transform: translateY(0);
}

/* 결과 섹션 */
.result-section {
    margin-top: 40px;
    padding-top: 40px;
    border-top: 2px solid var(--border-color);
}

.result-item {
    margin-bottom: 25px;
    padding: 15px;
    background: var(--light-bg);
    border-radius: 8px;
}

.result-label {
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 0.85em;
    margin-bottom: 8px;
}

.result-value {
    font-size: 1.2em;
    color: var(--text-primary);
    font-weight: 500;
    word-break: break-all;
}

.result-value.unicode {
    font-family: 'Courier New', monospace;
    font-size: 0.95em;
    color: var(--primary-color);
}

/* 결과 그리드 */
.result-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.result-box {
    padding: 25px;
    border-radius: 8px;
    text-align: center;
    background: var(--light-bg);
    border-left: 4px solid var(--border-color);
}

.result-box.max {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.1), rgba(16, 185, 129, 0.05));
    border-left-color: var(--success-color);
}

.result-box.min {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.1), rgba(245, 158, 11, 0.05));
    border-left-color: var(--warning-color);
}

.result-box.diff {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(99, 102, 241, 0.05));
    border-left-color: var(--primary-color);
}

.result-title {
    font-size: 0.9em;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 600;
    margin-bottom: 10px;
}

.result-box .result-value {
    font-size: 1.8em;
    font-family: 'Courier New', monospace;
    font-weight: 700;
}

/* 계산 결과들 */
.calculation-results {
    display: grid;
    gap: 15px;
    margin-top: 20px;
}

.calculation-item {
    padding: 20px;
    background: var(--light-bg);
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
}

.calc-header {
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 15px;
    text-transform: uppercase;
    font-size: 0.9em;
}

.calc-results {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
}

.calc-result {
    padding: 10px;
    background: white;
    border-radius: 6px;
    text-align: center;
    border: 1px solid var(--border-color);
}

.calc-result-label {
    font-size: 0.85em;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.calc-result-value {
    font-size: 1.3em;
    font-weight: 600;
    font-family: 'Courier New', monospace;
    color: var(--primary-color);
}

/* 에러 메시지 */
.result-error {
    padding: 15px;
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.1), rgba(239, 68, 68, 0.05));
    border-left: 4px solid var(--danger-color);
    border-radius: 8px;
    color: var(--danger-color);
    font-weight: 500;
}

/* 정보 섹션 */
.info-section {
    background: white;
    border-radius: 12px;
    padding: 40px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

.guide-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 25px;
}

.guide-item {
    padding: 20px;
    background: var(--light-bg);
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
}

.guide-item h3 {
    color: var(--primary-color);
    margin-bottom: 10px;
    font-size: 1.1em;
}

.guide-item p {
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-size: 0.95em;
}

.example {
    font-family: 'Courier New', monospace;
    color: var(--primary-color);
    font-weight: 500;
    font-size: 0.9em;
}

/* 위키 스타일 */
.wiki-section {
    background: linear-gradient(135deg, #f8fafc 0%, #e0e7ff 100%);
    border-top: 4px solid var(--primary-color);
    padding-top: 50px;
    padding-bottom: 50px;
}

.wiki-toc {
    background: white;
    border-left: 4px solid var(--primary-color);
    padding: 25px;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.08);
}

.wiki-toc .nav-link {
    color: var(--text-primary);
    padding: 10px 15px;
    border-radius: 6px;
    transition: all 0.2s ease;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.wiki-toc .nav-link:hover {
    background: var(--light-bg);
    color: var(--primary-color);
    transform: translateX(5px);
}

.wiki-toc .nav-link.active {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
}

.code-block {
    background: #1e293b;
    color: #e2e8f0;
    padding: 20px;
    border-radius: 8px;
    overflow-x: auto;
    overflow-wrap: break-word;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    line-height: 1.5;
    margin: 15px 0;
    border-left: 4px solid var(--primary-color);
    max-width: 100%;
    word-break: break-all;
}

.wiki-list {
    list-style: none;
    padding-left: 0;
}

.wiki-list li {
    padding: 8px 0;
    padding-left: 25px;
    position: relative;
    color: var(--text-secondary);
}

.wiki-list li::before {
    content: "▸";
    position: absolute;
    left: 0;
    color: var(--primary-color);
    font-weight: bold;
}

.wiki-flow {
    background: linear-gradient(135deg, #e0e7ff 0%, #ddd6fe 100%);
    padding: 20px;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    line-height: 2;
    white-space: pre;
    overflow-x: auto;
    overflow-wrap: break-word;
    border: 2px dashed var(--secondary-color);
    margin: 15px 0;
    max-width: 100%;
}

.wiki-example {
    background: #f0fdf4;
    padding: 20px;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    line-height: 1.8;
    white-space: pre;
    overflow-x: auto;
    overflow-wrap: break-word;
    border-left: 4px solid var(--success-color);
    margin: 15px 0;
    max-width: 100%;
}

.guide-content h4 {
    color: var(--secondary-color);
    margin: 20px 0 10px 0;
    font-size: 1em;
    font-weight: 600;
}

#wiki h3 {
    color: var(--primary-color);
    margin-top: 30px;
    margin-bottom: 15px;
    font-size: 1.3em;
    padding-bottom: 10px;
    border-bottom: 2px solid rgba(99, 102, 241, 0.2);
}

#wiki .guide-content {
    background: white;
    padding: 25px;
    border-radius: 8px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

#wiki .guide-item {
    margin-bottom: 0;
}

/* 푸터 */
.footer {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    text-align: center;
    padding: 30px 20px;
    margin-top: 50px;
    border-radius: 0;
    backdrop-filter: blur(10px);
}

/* 반응형 디자인 */
@media (max-width: 768px) {
    /* 헤더 모바일 최적화 */
    .header h1 {
        font-size: 1.8em;
    }

    .subtitle {
        font-size: 1em;
    }

    /* 메인 콘텐츠 패딩 조정 */
    .main-content {
        padding: 20px;
        border-radius: 10px;
    }

    .header {
        padding: 30px 15px;
        margin-bottom: 20px;
    }

    /* 코드 블록 모바일 최적화 */
    .code-block {
        font-size: 0.75em;
        padding: 15px;
        white-space: pre-wrap;
        word-break: break-word;
    }

    .wiki-flow {
        font-size: 0.75em;
        padding: 15px;
        white-space: pre-wrap;
        word-break: break-word;
        line-height: 1.5;
    }

    .wiki-example {
        font-size: 0.75em;
        padding: 15px;
        white-space: pre-wrap;
        word-break: break-word;
    }

    /* 위키 목차 모바일에서 숨김 */
    .wiki-toc {
        margin-bottom: 20px;
    }

    /* 위키 섹션 패딩 */
    .wiki-section {
        padding-top: 30px;
        padding-bottom: 30px;
    }

    /* 위키 목차를 상단 고정 해제 */
    .wiki-toc.sticky-top {
        position: relative !important;
        top: 0 !important;
    }

    /* 결과 그리드 1열로 */
    .result-grid {
        grid-template-columns: 1fr;
    }

    /* 카드 타이틀 크기 조정 */
    .card-title {
        font-size: 1em;
    }

    /* 결과 값 크기 조정 */
    .result-box .result-value {
        font-size: 1.4em;
    }

    /* 입력 필드 패딩 조정 */
    .input-field {
        padding: 10px 12px;
        font-size: 16px; /* iOS 줌인 방지 */
    }

    /* Bootstrap form-control도 조정 */
    .form-control,
    .form-control-lg {
        font-size: 16px !important; /* iOS 줌인 방지 */
    }

    /* 버튼 패딩 조정 */
    .calculate-btn {
        padding: 12px 20px;
        font-size: 1em;
    }

    /* pre 태그 overflow */
    pre {
        overflow-x: auto;
        white-space: pre-wrap;
        word-wrap: break-word;
    }
}

@media (max-width: 576px) {
    /* 초소형 화면 추가 최적화 */
    .header h1 {
        font-size: 1.5em;
    }

    .main-content {
        padding: 15px;
    }

    .header {
        padding: 25px 10px;
    }

    /* 위키 섹션 패딩 */
    #wiki .guide-content {
        padding: 15px;
    }

    /* 카드 간격 조정 */
    .row.g-4 {
        gap: 1rem !important;
    }

    /* 코드 블록 더 작게 */
    .code-block,
    .wiki-flow,
    .wiki-example {
        font-size: 0.7em;
        padding: 10px;
    }

    /* 결과 값 크기 */
    .result-box .result-value {
        font-size: 1.2em;
    }

    /* 위키 목차 폰트 크기 */
    .wiki-toc .nav-link {
        font-size: 0.9em;
        padding: 8px 12px;
    }

    /* Container 패딩 더 줄이기 */
    .container,
    .container-fluid {
        padding-right: 5px;
        padding-left: 5px;
    }
}

/* 태블릿 최적화 */
@media (min-width: 769px) and (max-width: 1024px) {
    .header h1 {
        font-size: 2.5em;
    }

    .main-content {
        padding: 30px;
    }
}
