:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --bg-dark: #0f172a;
    --glass-bg: rgba(30, 41, 59, 0.9);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-main: #f8fafc;
    --text-secondary: #94a3b8;
    --error: #ef4444;
    --success: #10b981;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Outfit', 'Noto Sans KR', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    line-height: 1.6;
    overflow-x: hidden;
    min-height: 100vh;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 20% 30%, #1e1b4b 0%, transparent 40%),
        radial-gradient(circle at 80% 70%, #312e81 0%, transparent 40%);
    z-index: -1;
}

.screen {
    min-height: 100vh;
    width: 100%;
    display: flex;
    flex-direction: column;
}

.hidden {
    display: none !important;
}

.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 2.5rem;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
}

/* Auth & Brand */
#login-screen {
    justify-content: center;
    align-items: center;
}

.login-card {
    width: 90%;
    max-width: 420px;
    text-align: center;
}

.brand-logo {
    margin-bottom: 2rem;
}

.main-logo {
    width: 80px;
    margin-bottom: 1rem;
    filter: drop-shadow(0 0 10px var(--primary-color));
}

.brand-title {
    font-size: 2.5rem;
    background: linear-gradient(to right, #fff, #a5b4fc);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

/* Navbar */
.navbar {
    padding: 1.25rem 2.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--glass-border);
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(10px);
}

.nav-left {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.nav-logo-img {
    height: 28px;
}

.nav-logo-text {
    font-weight: 700;
    color: #fff;
    font-size: 1.1rem;
}

.nav-btn {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: 0.2s;
    font-size: 0.9rem;
}

.nav-btn:hover {
    border-color: #fff;
    color: #fff;
    background: rgba(255, 255, 255, 0.05);
}

.back-btn {
    border-color: var(--primary-color);
    color: var(--primary-color);
    font-weight: 600;
}

.back-btn:hover {
    background: var(--primary-color);
    color: #fff;
}

/* Inputs & Buttons */
.input-group {
    margin-bottom: 1rem;
    text-align: left;
}

input {
    width: 100%;
    padding: 0.8rem;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    color: #fff;
}

input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.btn-primary {
    width: 100%;
    padding: 1rem;
    background: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-weight: 700;
    cursor: pointer;
    transition: 0.2s;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-2px);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Landing Choice */
.central-content {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.welcome-section {
    text-align: center;
    margin-bottom: 3.5rem;
}

.welcome-section h2 {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
}

.choice-container {
    display: flex;
    justify-content: center;
    gap: 2.5rem;
    width: 100%;
    max-width: 1000px;
}

.choice-card {
    flex: 1;
    max-width: 400px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    padding: 4rem 2rem;
}

.choice-card:hover {
    transform: translateY(-10px);
    border-color: var(--primary-color);
}

.choice-icon {
    font-size: 4rem;
    margin-bottom: 1.5rem;
}

/* Search Area */
.content {
    flex: 1;
    padding: 3rem 2rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.drop-zone {
    border: 2px dashed var(--glass-border);
    border-radius: 20px;
    min-height: 250px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 2rem 0;
    cursor: pointer;
}

.drop-zone:hover {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.05);
}

#preview-img {
    max-width: 90%;
    max-height: 230px;
    border-radius: 10px;
}

/* Results */
.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 2rem;
    margin-top: 2rem;
}

.result-card {
    border-radius: 15px;
    overflow: hidden;
}

.result-img-container {
    height: 200px;
    background: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
}

.result-img-container img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.result-info {
    padding: 1.5rem;
}

.result-source {
    font-weight: 700;
    margin-bottom: 0.5rem;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.result-footer {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.similarity-badge {
    color: var(--primary-color);
    font-weight: 800;
}

/* Dashboard */
.stats-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    margin-top: 2rem;
}

.stat-item {
    background: rgba(0, 0, 0, 0.2);
    padding: 1.5rem;
    border-radius: 15px;
    text-align: center;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    display: block;
    margin-top: 0.5rem;
}

.progress-bar-bg {
    height: 10px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 5px;
    margin-top: 1rem;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: var(--primary-color);
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 12px rgba(99, 102, 241, 0.4);
}

.update-progress-container {
    margin-top: 2.5rem;
    padding: 2rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 20px;
    border: 1px solid var(--glass-border);
}

.progress-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1rem;
    font-size: 0.95rem;
    color: var(--text-secondary);
}

/* 실시간 상세 지표 표 */
.progress-stats-table {
    margin-top: 2rem;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    padding-top: 2rem;
    border-top: 1px solid var(--glass-border);
}

.p-stat {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    text-align: center;
}

.p-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.p-value {
    font-size: 1.4rem;
    color: #818cf8;
    /* 밝은 라벤더색으로 강조 */
    font-weight: 800;
    text-shadow: 0 0 10px rgba(129, 140, 248, 0.3);
}

/* Force show update container when not hidden */
.update-progress-container:not(.hidden) {
    display: block !important;
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.95);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 5px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 2rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* --- 문항 상세 모달 --- */
.result-card.clickable { cursor: pointer; transition: transform .15s ease, box-shadow .15s ease; }
.result-card.clickable:hover { transform: translateY(-4px); box-shadow: 0 16px 40px rgba(99, 102, 241, 0.35); }
.detail-modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.detail-backdrop { position: absolute; inset: 0; background: rgba(5, 10, 25, 0.8); backdrop-filter: blur(4px); }
.detail-panel { position: relative; width: min(1000px, 94vw); max-height: 92vh; overflow-y: auto; padding: 2rem 2.5rem; }
.detail-close { position: absolute; top: 1rem; right: 1rem; background: transparent; border: 1px solid var(--glass-border); color: inherit; border-radius: 50%; width: 36px; height: 36px; cursor: pointer; font-size: 1rem; }
.detail-close:hover { background: rgba(255,255,255,0.1); }
.detail-header h3 { margin: 0 2.5rem 0.3rem 0; font-size: 1.2rem; word-break: break-all; }
.detail-meta { opacity: 0.7; font-size: 0.9rem; margin-bottom: 1.2rem; }
.detail-section { margin-top: 1.5rem; }
.detail-label { font-weight: 600; margin-bottom: 0.6rem; display: flex; align-items: center; gap: 0.8rem; }
.detail-link { font-size: 0.8rem; font-weight: 400; opacity: 0.8; color: #a5b4fc; text-decoration: none; }
.detail-link:hover { text-decoration: underline; }
.detail-img { width: 100%; background: #fff; border-radius: 10px; display: block; margin-bottom: 0.8rem; }
.detail-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.detail-table th { text-align: left; width: 110px; padding: 0.45rem 0.6rem; opacity: 0.7; font-weight: 500; vertical-align: top; }
.detail-table td { padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--glass-border); word-break: break-all; }
.detail-path { font-family: monospace; font-size: 0.8rem; opacity: 0.75; }
.detail-solutions { margin-top: 0.5rem; }
.detail-soltext { white-space: pre-wrap; background: rgba(255,255,255,0.05); padding: 1rem; border-radius: 10px; font-size: 0.9rem; }
.detail-answer { font-weight: 700; color: #fbbf24; margin: 0 0 0.8rem 0; }
.detail-empty { opacity: 0.6; }
.nav-btn.small { padding: 0.3rem 0.8rem; font-size: 0.8rem; }


/* --- 검색 범위 필터 --- */
.filter-panel { margin: 1.5rem 0 0.5rem; padding: 1.2rem 1.4rem; border: 1px solid var(--glass-border); border-radius: 16px; background: rgba(255,255,255,0.03); }
.filter-head { display: flex; justify-content: space-between; align-items: center; font-weight: 600; margin-bottom: 0.8rem; }
.filter-row { display: flex; gap: 0.8rem; align-items: flex-start; margin-bottom: 0.7rem; }
.filter-label { flex: 0 0 52px; font-size: 0.85rem; opacity: 0.7; padding-top: 0.35rem; }
.filter-col { flex: 1; display: flex; flex-direction: column; gap: 0.5rem; }
.filter-col-inline { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.chip-group { display: flex; flex-wrap: wrap; gap: 0.4rem; flex: 1; }
.chip { border: 1px solid var(--glass-border); background: rgba(255,255,255,0.04); color: inherit; border-radius: 999px; padding: 0.3rem 0.8rem; font-size: 0.82rem; cursor: pointer; transition: all .12s; }
.chip:hover { background: rgba(99,102,241,0.2); }
.chip.active { background: #6366f1; border-color: #6366f1; color: #fff; }
.chip-count { opacity: 0.6; font-size: 0.72rem; margin-left: 0.2rem; }
.filter-input { background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border); color: inherit; border-radius: 8px; padding: 0.45rem 0.7rem; font-size: 0.85rem; width: 100%; box-sizing: border-box; }
.filter-input.num { width: 70px; }
.filter-hint { opacity: 0.5; font-size: 0.8rem; }
.filter-summary { margin-top: 0.4rem; font-size: 0.82rem; color: #a5b4fc; }


/* --- 출처 상위분류 배지 --- */
.source-tag { display: inline-block; align-self: flex-start; background: rgba(99,102,241,0.18); border: 1px solid rgba(99,102,241,0.45); color: #a5b4fc; border-radius: 6px; padding: 0.15rem 0.5rem; font-size: 0.74rem; font-weight: 600; margin-bottom: 0.4rem; }
.result-info .result-source { display: block; font-size: 0.85rem; opacity: 0.85; }


/* --- 회원·검색범위 관리 --- */
.member-hint { opacity: 0.75; font-size: 0.9rem; margin: 0.4rem 0 1.4rem; }
.member-row { border: 1px solid var(--glass-border); border-radius: 14px; padding: 1rem 1.2rem; margin-bottom: 1rem; background: rgba(255,255,255,0.03); }
.member-head { display: flex; align-items: center; gap: 0.7rem; margin-bottom: 0.7rem; flex-wrap: wrap; }
.member-role { opacity: 0.55; font-size: 0.8rem; }
.member-state { font-size: 0.78rem; color: #a5b4fc; }
.member-full { opacity: 0.7; font-size: 0.88rem; }
.member-head .danger { border-color: rgba(244,63,94,0.5); color: #fda4af; }
.scope-chips { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.scope-chip { display: inline-flex; align-items: center; gap: 0.35rem; border: 1px solid var(--glass-border); border-radius: 999px; padding: 0.28rem 0.75rem; font-size: 0.82rem; cursor: pointer; user-select: none; }
.scope-chip.on { background: rgba(99,102,241,0.25); border-color: #6366f1; }
.scope-chip input { accent-color: #6366f1; }
.member-add { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.member-add .filter-input { max-width: 200px; }
.member-add .btn-primary { width: auto; padding: 0.55rem 1.6rem; }
.member-add-title { margin-top: 2rem; }


/* --- 세그먼트 + 고급 필터 --- */
.segment-bar { display: flex; align-items: center; gap: 0.8rem; margin: 1.4rem 0 0.6rem; flex-wrap: wrap; }
.segment-row { display: flex; gap: 0.45rem; flex-wrap: wrap; flex: 1; }
.seg-btn { border: 1px solid var(--glass-border); background: rgba(255,255,255,0.05); color: inherit; border-radius: 12px; padding: 0.55rem 1.25rem; font-size: 0.95rem; font-weight: 600; cursor: pointer; transition: all .13s; }
.seg-btn:hover { background: rgba(99,102,241,0.2); }
.seg-btn.active { background: #6366f1; border-color: #6366f1; color: #fff; box-shadow: 0 4px 16px rgba(99,102,241,0.4); }

/* --- 진행 단계 --- */
.progress-card { margin-top: 1.6rem; padding: 1.4rem 2rem; }
.prog-steps { display: flex; align-items: center; gap: 0.7rem; }
.prog-step { display: flex; align-items: center; gap: 0.45rem; font-size: 0.9rem; opacity: 0.45; }
.prog-step .pdot { width: 10px; height: 10px; border-radius: 50%; background: rgba(255,255,255,0.25); }
.prog-step.active { opacity: 1; }
.prog-step.active .pdot { background: #6366f1; animation: pulse 1s infinite; }
.prog-step.done { opacity: 0.85; }
.prog-step.done .pdot { background: #34d399; }
.prog-line { flex: 0 0 34px; height: 1px; background: var(--glass-border); }
.prog-msg { margin-top: 0.7rem; font-size: 0.9rem; color: #a5b4fc; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.5); } }
.ocr-box { margin-top: 1rem; border: 1px solid var(--glass-border); border-radius: 12px; padding: 0.9rem 1.1rem; background: rgba(255,255,255,0.03); }
.ocr-label { font-size: 0.82rem; font-weight: 600; margin-bottom: 0.4rem; opacity: 0.8; }
.ocr-text { font-size: 0.88rem; opacity: 0.85; line-height: 1.5; }

/* --- 결과 태그칩 --- */
.result-tags { display: flex; gap: 0.45rem; flex-wrap: wrap; margin-top: 1rem; }

/* --- 매칭 근거 --- */
.detail-signals { margin: 0.6rem 0 0.4rem; }
.sig-row { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.35rem; }
.sig-name { flex: 0 0 62px; font-size: 0.8rem; opacity: 0.75; }
.sig-bar { flex: 1; height: 7px; border-radius: 4px; background: rgba(255,255,255,0.08); overflow: hidden; }
.sig-fill { height: 100%; border-radius: 4px; background: linear-gradient(90deg, #6366f1, #22d3ee); }
.sig-val { flex: 0 0 40px; font-size: 0.8rem; text-align: right; opacity: 0.8; }
.sig-words { margin-top: 0.5rem; font-size: 0.82rem; opacity: 0.85; }
.sig-word { display: inline-block; background: rgba(34,211,238,0.15); border: 1px solid rgba(34,211,238,0.4); border-radius: 6px; padding: 0.1rem 0.5rem; margin: 0 0.25rem 0.25rem 0; }


/* --- 매칭 등급 배지 --- */
.similarity-badge em { font-style: normal; opacity: 0.6; font-size: 0.72em; margin-left: 0.2rem; }
.similarity-badge.grade-same { background: rgba(52,211,153,0.18) !important; color: #6ee7b7 !important; border: 1px solid rgba(52,211,153,0.5); }
.similarity-badge.grade-twin { background: rgba(99,102,241,0.2) !important; color: #a5b4fc !important; border: 1px solid rgba(99,102,241,0.5); }
.similarity-badge.grade-sim { background: rgba(148,163,184,0.15) !important; color: #cbd5e1 !important; border: 1px solid rgba(148,163,184,0.35); }


/* --- 세그먼트 하위 칩 --- */
.subseg-row { display: flex; gap: 0.4rem; flex-wrap: wrap; margin: 0.15rem 0 0.4rem 0.1rem; }


/* --- 여러 문제 일괄 검색 --- */
.multi-cap { font-size: 0.72rem; font-weight: 600; color: #a5b4fc; border: 1px solid rgba(99,102,241,0.5); border-radius: 999px; padding: 0.15rem 0.6rem; vertical-align: middle; margin-left: 0.5rem; }
.multi-slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.8rem; margin: 1.2rem 0; }
.mslot { position: relative; border: 1px solid var(--glass-border); border-radius: 12px; overflow: hidden; background: rgba(255,255,255,0.04); }
.mslot img { width: 100%; height: 120px; object-fit: contain; background: #fff; display: block; }
.mslot-empty { height: 120px; display: flex; flex-direction: column; align-items: center; justify-content: center; opacity: 0.55; font-size: 1.4rem; gap: 0.2rem; }
.mslot-empty small { font-size: 0.68rem; }
.mslot.addable { cursor: pointer; border-style: dashed; }
.mslot.addable:hover { border-color: #6366f1; }
.mslot-foot { display: flex; justify-content: space-between; align-items: center; padding: 0.35rem 0.6rem; font-size: 0.78rem; }
.mslot-foot em { font-style: normal; color: #a5b4fc; }
.mslot.done .mslot-foot em { color: #6ee7b7; }
.mslot.fail .mslot-foot em { color: #fda4af; }
.mslot-x { position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; border-radius: 50%; border: none; background: rgba(15,23,42,0.75); color: #fff; cursor: pointer; font-size: 0.72rem; }
.multi-actions { display: flex; gap: 0.8rem; align-items: center; }
.multi-actions .btn-primary { flex: 1; }
.multi-results { display: flex; flex-direction: column; gap: 1.4rem; margin-top: 1.6rem; }
.mres { padding: 1.3rem 1.5rem; }
.mres-head { display: flex; gap: 1rem; align-items: center; margin-bottom: 0.9rem; }
.mres-q { width: 140px; max-height: 90px; object-fit: contain; background: #fff; border-radius: 8px; }
.mres-head h3 { margin: 0 0 0.2rem; font-size: 1rem; }
.mres-head p { margin: 0; font-size: 0.82rem; opacity: 0.75; }
.mres-row { display: flex; gap: 0.8rem; overflow-x: auto; padding-bottom: 0.5rem; }
.mres-card { flex: 0 0 210px; border: 1px solid var(--glass-border); border-radius: 10px; padding: 0.55rem; cursor: pointer; background: rgba(255,255,255,0.03); transition: transform .12s; }
.mres-card:hover { transform: translateY(-2px); border-color: #6366f1; }
.mres-img { height: 110px; background: #fff; border-radius: 7px; overflow: hidden; margin-bottom: 0.45rem; }
.mres-img img { width: 100%; height: 100%; object-fit: contain; }
.mres-card .source-tag { margin: 0.3rem 0 0.15rem; }
.mres-title { font-size: 0.72rem; opacity: 0.8; line-height: 1.35; max-height: 2.7em; overflow: hidden; }


/* --- 이미지 크게 보기 --- */
.img-lightbox { position: fixed; inset: 0; z-index: 2000; background: rgba(5,10,25,0.9); display: flex; align-items: center; justify-content: center; cursor: zoom-out; }
.img-lightbox img { max-width: 92vw; max-height: 90vh; background: #fff; border-radius: 10px; box-shadow: 0 24px 80px rgba(0,0,0,0.6); }
.zoomable { cursor: zoom-in; }


/* --- 회원가입 / 회원관리 보안 --- */
.link-btn { background: none; border: none; color: #a5b4fc; font-size: 0.85rem; cursor: pointer; margin-top: 0.9rem; text-decoration: underline; }
.signup-panel { margin-top: 0.9rem; border-top: 1px solid var(--glass-border); padding-top: 1rem; }
.su-row { display: flex; gap: 0.5rem; }
.su-row input { flex: 1; }
.su-row .nav-btn { white-space: nowrap; }
.su-msg { font-size: 0.82rem; color: #a5b4fc; min-height: 1.2em; margin: 0.4rem 0 0; }
.member-email { font-size: 0.78rem; opacity: 0.6; }
.member-pending { font-size: 0.76rem; font-weight: 700; color: #fbbf24; border: 1px solid rgba(251,191,36,0.5); border-radius: 999px; padding: 0.12rem 0.55rem; }
.member-head .approve { border-color: rgba(52,211,153,0.6); color: #6ee7b7; }
