@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@300;400;500;700&display=swap');

:root {
    --font-main: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
    --bg-color: #ffffff;
    --text-color: #000000;
    --border-width: 2px;
    --spacing-unit: 1rem;
}

* {
    box-sizing: border-box;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0 auto;
    padding: 0;
    line-height: 1.6;
    font-size: 1rem;
    font-weight: 400;
    max-width: 100%;
    overflow-x: hidden;
}

.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    margin-bottom: 40px;
    border-bottom: var(--border-width) solid var(--text-color);
    padding-bottom: 20px;
}

h1 {
    font-size: 2.5rem;
    margin: 0;
    font-weight: 700;
}

.subtitle {
    font-size: 1rem;
    color: #555;
    font-weight: 300;
    margin-bottom: 5px;
}

.disclaimer {
    font-size: 0.85rem;
    color: #999;
    font-weight: 400;
    margin-top: 5px;
    font-style: italic;
}

/* Form Styles */
.score-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
    border: var(--border-width) solid var(--text-color);
    padding: 20px;
    border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
    /* Sketchy border */
    margin-bottom: 40px;
}

.input-guide {
    text-align: center;
    font-size: 0.9rem;
    color: #555;
    margin: 0 0 10px 0;
    padding: 8px 12px;
    background-color: #f8f9fa;
    border-radius: 8px;
    font-weight: 500;
}

.form-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    /* Allow wrapping for mobile */
}

.input-group {
    display: flex;
    gap: 10px;
    flex: 1.5;
}

label {
    flex: 1;
    min-width: 80px;
    /* Ensure label doesn't get too squished */
}

input[type="number"] {
    flex: 1;
    padding: 8px;
    border: var(--border-width) solid var(--text-color);
    font-family: var(--font-main);
    font-size: 0.95rem;
    text-align: center;
    border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
    outline: none;
    min-width: 0;
    /* Fix flexbox overflow issue */
}

input[type="number"]:focus {
    border-width: 3px;
}

.btn-submit {
    margin-top: 20px;
    padding: 12px;
    background-color: var(--text-color);
    color: var(--bg-color);
    border: none;
    font-family: var(--font-main);
    font-size: 1.1rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 5px;
    transform: rotate(-1deg);
    transition: transform 0.2s;
}

.btn-submit:hover {
    transform: rotate(1deg) scale(1.02);
}

.btn-reset {
    margin-top: 8px;
    padding: 8px;
    background-color: transparent;
    color: #666;
    border: 1px solid #ccc;
    font-family: var(--font-main);
    font-size: 0.9rem;
    font-weight: 400;
    cursor: pointer;
    border-radius: 5px;
    transition: all 0.2s;
    width: 100%;
}

.btn-reset:hover {
    background-color: #f5f5f5;
    color: #333;
    border-color: #999;
}

.btn-share {
    display: block;
    width: 100%;
    margin-top: 20px;
    padding: 15px;
    background-color: #fff;
    color: var(--text-color);
    border: var(--border-width) solid var(--text-color);
    font-family: var(--font-main);
    font-size: 1.3rem;
    cursor: pointer;
    border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
    transition: background-color 0.2s;
}

.btn-share:hover {
    background-color: #f0f0f0;
}

/* Results Styles */
.results-section {
    display: none;
    /* Hidden by default */
}

.result-card {
    border: var(--border-width) solid var(--text-color);
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 15px 255px 15px 225px / 225px 15px 255px 15px;
    position: relative;
}

.result-card h3 {
    margin-top: 0;
    margin-bottom: 10px;
    border-bottom: 1px solid #000;
    display: inline-block;
    font-size: 1.8rem;
}

.tag {
    position: absolute;
    top: -10px;
    left: -10px;
    background: #000;
    color: #fff;
    padding: 2px 8px;
    font-size: 1rem;
    transform: rotate(-5deg);
    z-index: 1;
}

.footer {
    text-align: center;
    margin-top: 50px;
    font-size: 1rem;
    color: #888;
}

.btn-guide {
    display: inline-block;
    margin: 20px auto 15px;
    padding: 12px 30px;
    background-color: #fff;
    color: var(--text-color);
    border: var(--border-width) solid var(--text-color);
    font-family: var(--font-main);
    font-size: 1.1rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-guide:hover {
    background-color: #000;
    color: #fff;
    transform: translateY(-2px);
}

.ad-banner {
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    margin: 10px auto;
    max-width: 100%;
    overflow: hidden;
}

.ad-banner-top,
.ad-banner-bottom {
    width: 100%;
    max-width: 680px;
    min-height: 80px;
    margin: 10px auto;
}

.ad-banner-left {
    display: none;
}

/* 광고 배너 내부 요소 제한 */
.ad-banner * {
    max-width: 100%;
}

/* Stick figure placeholder */
.stick-figure {
    text-align: center;
    margin: 20px 0;
}

.character-img {
    max-width: 200px;
    width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
}

/* Mobile Responsiveness */
@media (max-width: 600px) {
    h1 {
        font-size: 2rem;
    }

    .form-group {
        flex-direction: column;
        align-items: flex-start;
    }

    label {
        margin-bottom: 5px;
    }

    input[type="number"] {
        width: 100%;
    }

    .container {
        padding: 10px;
    }

    .character-img {
        max-width: 150px;
    }

    /* 모바일에서 결과 카드 패딩 조정 */
    .result-card {
        padding: 20px 15px 15px 15px;
    }

    .result-card h3 {
        font-size: 1.4rem;
        margin-top: 10px;
        padding-right: 80px; /* 카테고리 배지 공간 확보 */
    }

    /* 태그 위치 조정 */
    .tag {
        top: -8px;
        left: -8px;
        font-size: 0.85rem;
        padding: 2px 6px;
    }

    /* 카테고리 배지 위치 조정 */
    .result-card .category-badge {
        top: 8px;
        right: 8px;
        font-size: 0.75rem;
        padding: 3px 8px;
    }

    /* 필터 버튼 크기 조정 */
    .filter-btn {
        padding: 8px 15px;
        font-size: 0.9rem;
    }

    /* 광고 배너 크기 조정 */
    .ad-banner-top,
    .ad-banner-bottom {
        min-height: 60px;
        margin: 10px auto;
        max-width: 100%;
        width: 100%;
    }

    .ad-banner {
        margin: 10px auto;
        padding: 0;
        width: 100%;
    }

    /* 광고 스크립트 크기 제한 */
    .ad-banner > div,
    .ad-banner > script + div,
    .ad-banner iframe,
    .ad-banner img {
        max-width: 100% !important;
        width: 100% !important;
        height: auto !important;
    }

    /* 쿠팡 광고 특정 조정 */
    .ad-banner [id^="coupang"] {
        max-width: 100% !important;
        width: 100% !important;
    }

    /* 분석 결과 섹션 */
    .results-section {
        margin-top: 20px;
    }

    .results-section h2 {
        font-size: 1.5rem;
        margin-bottom: 15px;
    }
}

/* Error Message */
.error-message {
    color: red;
    font-weight: bold;
    text-align: center;
    margin-top: 10px;
    font-family: var(--font-main);
}

.data-error-banner {
    margin-top: 10px;
    margin-bottom: 10px;
    padding: 10px 12px;
    border: 2px solid #ff5252;
    background-color: #ffecec;
    color: #b00020;
    font-size: 0.95rem;
    text-align: center;
    font-family: var(--font-main);
}

/* Detail Button */
.btn-detail {
    margin-top: 10px;
    padding: 8px 15px;
    background-color: #fff;
    color: var(--text-color);
    border: var(--border-width) solid var(--text-color);
    font-family: var(--font-main);
    font-size: 1.1rem;
    cursor: pointer;
    border-radius: 5px;
    transition: background-color 0.2s;
}

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

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

.modal-content {
    background: white;
    border: 3px solid black;
    border-radius: 15px 255px 15px 225px / 225px 15px 255px 15px;
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 30px;
    position: relative;
    font-family: var(--font-main);
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    font-size: 2.5rem;
    cursor: pointer;
    font-family: Arial, sans-serif;
    line-height: 1;
}

.modal-close:hover {
    color: #ff0000;
}

.modal-content h2 {
    margin-top: 0;
    border-bottom: 2px solid black;
    padding-bottom: 10px;
    font-size: 2rem;
}

.modal-subtitle {
    font-size: 1.2rem;
    color: #666;
    margin-top: -10px;
    margin-bottom: 20px;
}

.modal-section {
    margin: 20px 0;
    padding: 15px;
    border: 2px solid #ddd;
    border-radius: 8px;
}

.modal-section h3 {
    margin-top: 0;
    font-size: 1.5rem;
    border-bottom: 1px solid #000;
    display: inline-block;
}

.modal-section p {
    margin: 8px 0;
    font-size: 1.2rem;
}

.modal-note {
    font-size: 1rem !important;
    color: #666 !important;
    font-style: italic;
}

.cut-scores-list,
.subject-scores-list {
    list-style: none;
    padding-left: 0;
    margin: 10px 0;
}

.cut-scores-list li,
.subject-scores-list li {
    margin: 8px 0;
    font-size: 1.2rem;
    padding: 5px 0;
}

.cut-scores-list li.primary-cut {
    background: #fff3cd;
    padding: 8px;
    border-radius: 5px;
    border-left: 4px solid #ffc107;
}

.badge {
    background: #ffc107;
    color: #000;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 0.9rem;
    margin-left: 10px;
}

/* Mobile Modal Fixes */
@media (max-width: 600px) {
    .modal-content {
        padding: 20px;
        max-height: 95vh;
    }

    .modal-content h2 {
        font-size: 1.6rem;
    }

    .modal-section h3 {
        font-size: 1.3rem;
    }

    .modal-section p,
    .cut-scores-list li,
    .subject-scores-list li {
        font-size: 1.1rem;
    }
}

/* Live Chat Box */
.chat-box {
    position: fixed;
    right: 20px;
    top: 100px;
    width: 320px;
    max-height: 500px;
    background: white;
    border: 3px solid black;
    border-radius: 15px 255px 15px 225px / 225px 15px 255px 15px;
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    font-family: var(--font-main);
    transition: max-height 0.3s ease;
}

/* Desktop: Reserve space for chat */
@media (min-width: 1200px) {
    body {
        padding-right: 360px;
        /* Reserve space for chat */
        padding-left: 220px;
    }

    .container {
        max-width: 600px;
        margin: 0 auto;
        /* Center in the remaining space */
    }

    .ad-banner-top,
    .ad-banner-bottom {
        min-height: 120px;
    }

    .ad-banner-left {
        display: flex;
        position: fixed;
        left: 20px;
        top: 120px;
        width: 160px;
        height: 600px;
        z-index: 900;
    }
}

/* Tablet/Laptop (600px - 1199px): Move to bottom right to avoid overlap */
@media (max-width: 1199px) and (min-width: 601px) {
    .chat-box {
        top: auto;
        bottom: 20px;
    }
}

.chat-box.minimized {
    max-height: 60px;
}

.chat-header {
    padding: 12px 15px;
    border-bottom: 2px solid black;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f9f9f9;
    border-radius: 12px 12px 0 0;
}

.chat-header h4 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 500;
}

.chat-toggle {
    background: none;
    border: 2px solid black;
    width: 30px;
    height: 30px;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    border-radius: 50%;
    font-family: Arial, sans-serif;
}

.chat-toggle:hover {
    background: #f0f0f0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    min-height: 350px;
    max-height: 400px;
    background: #fafafa;
}

.chat-box.minimized .chat-messages,
.chat-box.minimized .chat-input-area,
.chat-box.minimized .chat-info {
    display: none;
}

.chat-message {
    margin-bottom: 8px;
    padding: 6px 8px;
    background: white;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 0.9rem;
    word-wrap: break-word;
}

.chat-message-content {
    margin-bottom: 3px;
    line-height: 1.3;
}

.chat-message-time {
    font-size: 0.75rem;
    color: #888;
    text-align: right;
}

.chat-loading {
    text-align: center;
    padding: 40px 20px;
    color: #999;
    font-size: 1rem;
}

.chat-input-area {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 2px solid black;
    background: white;
}

.chat-input-area input {
    flex: 1;
    padding: 8px;
    border: 2px solid black;
    font-family: var(--font-main);
    font-size: 0.9rem;
    border-radius: 5px;
}

.chat-input-area input:focus {
    outline: none;
    border-width: 3px;
}

.btn-chat-send {
    padding: 8px 15px;
    background: black;
    color: white;
    border: none;
    font-family: var(--font-main);
    font-size: 1.1rem;
    cursor: pointer;
    border-radius: 5px;
    transition: transform 0.1s;
}

.btn-chat-send:hover {
    transform: scale(1.05);
}

.btn-chat-send:active {
    transform: scale(0.95);
}

.chat-info {
    padding: 8px 12px;
    font-size: 0.9rem;
    color: #666;
    text-align: center;
    border-top: 1px solid #eee;
    background: #f9f9f9;
}

/* Mobile responsiveness */
@media (max-width: 600px) {
    .chat-box {
        position: static;
        width: 100%;
        max-width: 600px;
        margin: 20px auto 40px auto;
        right: auto;
        left: auto;
        bottom: auto;
        top: auto;
        max-height: 400px;
        box-shadow: none;
    }

    .chat-messages {
        min-height: 280px;
        max-height: 320px;
    }

    /* 분석 결과 섹션과 충분한 간격 확보 */
    .results-section {
        margin-top: 60px;
        padding-top: 20px;
        clear: both;
    }

    /* 채팅 인포 텍스트 줄바꿈 방지 */
    .chat-info {
        font-size: 0.8rem;
        padding: 10px 12px;
        line-height: 1.4;
        word-break: keep-all;
    }
}

/* Custom scrollbar for chat */
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Chat message header with user ID */
.chat-message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    font-size: 0.9rem;
}

.chat-user-id {
    color: #666;
    font-weight: bold;
    font-family: monospace;
}

.chat-message-time {
    font-size: 0.85rem;
    color: #888;
}

.chat-message-content {
    line-height: 1.4;
    color: #000;
}

/* Category Filter Styles */
.category-filter {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 20px 0;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 10px 20px;
    border: 2px solid var(--text-color);
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-main);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 25px;
    transition: all 0.2s;
}

.filter-btn:hover {
    background-color: var(--text-color);
    color: var(--bg-color);
    transform: translateY(-2px);
}

.filter-btn.active {
    background-color: var(--text-color);
    color: var(--bg-color);
    font-weight: 700;
}

.result-card {
    position: relative;
}

.result-card .category-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 4px 10px;
    font-size: 0.85rem;
    border-radius: 12px;
    font-weight: 500;
    background-color: #f0f0f0;
    color: #666;
    z-index: 2;
}

.result-card .category-badge.이과 {
    background-color: #e3f2fd;
    color: #1976d2;
}

.result-card .category-badge.문과 {
    background-color: #fff3e0;
    color: #f57c00;
}

.result-card .category-badge.예체능 {
    background-color: #f3e5f5;
    color: #7b1fa2;
}