/* =========================================
   1. 폰트 및 기본 초기화
   ========================================= */
@font-face {
    font-family: 'NanumSquareRound';
    src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/noonfonts_two@1.0/NanumSquareRound.woff') format('woff');
    font-weight: normal; font-style: normal;
}

* {
    margin: 0; padding: 0; box-sizing: border-box;
    font-family: 'NanumSquareRound', -apple-system, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

/* ── 기본: PC와 모바일 공통 ──
   body는 스크롤 없이 뷰포트를 꽉 채움.
   스크롤은 각 .screen 안에서만 발생.
   마우스 휠 → .screen 내부에서 동작 (자연스러운 앱 느낌) */
html, body {
    width: 100%;
    height: 100%;
    background-color: #f0f2f5;
    display: flex;
    justify-content: center;
    overflow: hidden;          /* body 자체는 스크롤 없음 */
    overscroll-behavior-y: none;
}

.app-container {
    width: 100%;
    max-width: 480px;
    height: 100%;              /* 뷰포트 전체 높이 */
    background-color: #ffffff;
    position: relative;
    box-shadow: 0 0 30px rgba(0,0,0,0.10);
    display: flex;
    flex-direction: column;
    overflow: hidden;          /* 자식 screen이 스크롤 담당 */
}

/* =========================================
   2. 공통 스크린 및 모션
   ========================================= */
.screen {
    display: none;
    flex-direction: column;
    width: 100%;
    flex: 1;                   /* app-container 남은 공간 전부 차지 */
    /* overflow는 각 화면(smore-main, q-layout, result-layout)에서 개별 지정 */
}
.screen.active { display: flex; }

/* 스크롤 필요한 화면: 문항·결과 */
.q-layout, .result-layout, .loading-layout {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* is-hidden: 문항 전환 중 깜빡임 방지 */
.is-hidden { opacity: 0; pointer-events: none; }

.fade-in-up    { animation: fadeInUp 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) forwards; }
.fade-out-down { animation: fadeOutDown 0.25s ease forwards; }

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeOutDown {
    from { opacity: 1; transform: translateY(0); }
    to   { opacity: 0; transform: translateY(8px); }
}

/* =========================================
   3. 메인 화면
   전략: space-evenly로 4개 영역을 균등 배치
   height:100% 제거 — 창 높이에 구애받지 않음
   ========================================= */
.smore-main {
    background-color: #ffffff;
    justify-content: space-evenly;  /* 4개 영역 균등 배치 */
    align-items: center;
    min-height: 100%;               /* 최소 전체 높이, 넘으면 자연스럽게 늘어남 */
    overflow-y: auto;               /* 혹시 넘치면 스크롤 */
}

/* 로고 */
.main-logo-area {
    width: 100%;
    padding: 0 20px;
    text-align: center;
    flex-shrink: 0;
    animation: fadeInUp 0.6s ease forwards;
}
.main-header-img {
    width: 100%;
    max-width: 100px;
    height: auto;
    object-fit: contain;
}

/* 썸네일 */
.main-img-area {
    width: 100%;
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0 24px;
    animation: zoomInSoft 0.9s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}
.main-img {
    width: 100%;
    max-width: 340px;
    height: auto;
    max-height: 42vh;
    object-fit: contain;
    border-radius: 12px;
}

/* 카피 */
.main-text-area {
    width: 100%;
    padding: 0 28px;
    text-align: center;
    opacity: 0;
    flex-shrink: 0;
    animation-name: fadeInUp;
    animation-duration: 0.8s;
    animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
    animation-delay: 0.2s;
    animation-fill-mode: forwards;
}
.main-title {
    font-size: 24px;
    font-weight: 800;
    line-height: 1.45;
    color: #111;
    margin-bottom: 8px;
}
.main-desc { font-size: 14px; color: #666; line-height: 1.65; word-break: keep-all; }

/* 버튼 */
.main-btn-area {
    width: 100%;
    padding: 0 20px;
    flex-shrink: 0;
    opacity: 0;
    animation-name: fadeInUp;
    animation-duration: 0.8s;
    animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
    animation-delay: 0.4s;
    animation-fill-mode: forwards;  /* 애니메이션 후 opacity:1 유지 보장 */
}
.btn-smore {
    background: linear-gradient(135deg, #28549e 0%, #1e3f7a 100%);
    color: white;
    font-size: 17px;
    font-weight: 800;
    width: 100%;
    padding: 18px;
    border-radius: 16px;
    border: none;
    cursor: pointer;
    position: relative;
    z-index: 10;            /* 다른 요소에 가려지지 않게 */
    pointer-events: auto;   /* 클릭 항상 허용 */
    box-shadow: 0 8px 24px rgba(40, 84, 158, 0.30);
    transition: transform 0.15s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.15s ease,
                background 0.2s ease;
}
.btn-smore:hover {
    background: linear-gradient(135deg, #3162b8 0%, #28549e 100%);
    box-shadow: 0 10px 28px rgba(40, 84, 158, 0.38);
    transform: translateY(-1px);
}
.btn-smore:active { transform: scale(0.96); box-shadow: 0 4px 12px rgba(40, 84, 158, 0.2); }

@keyframes zoomInSoft {
    from { transform: scale(0.96); opacity: 0; }
    to   { transform: scale(1); opacity: 1; }
}

/* =========================================
   4. 문항 화면
   ========================================= */
.q-layout { padding: 0; background-color: #fff; }

.q-header-box {
    width: 100%;
    padding: 22px 20px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: sticky;
    top: 0;
    background-color: rgba(255,255,255,0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 50;
    flex-shrink: 0;
}

.q-progress-wrap {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.q-back-btn {
    background: none; border: none;
    font-size: 16px; color: #999; font-weight: 800;
    cursor: pointer; padding: 6px 8px; margin-left: -8px;
    border-radius: 8px;
    transition: color 0.2s, background 0.2s;
}
.q-back-btn:hover { color: #333; background: #f5f5f5; }
.q-back-btn:active { color: #111; }
.q-back-btn.hidden { opacity: 0; pointer-events: none; }

.progress-bar-container {
    flex: 1; height: 8px;
    background-color: #eef0f2; border-radius: 10px; overflow: hidden;
}
.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #4facfe 0%, #00c6fb 100%);
    width: 0%;
    transition: width 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
    border-radius: 10px;
}

.q-count { font-size: 13px; font-weight: 700; color: #bbb; width: 38px; text-align: right; white-space: nowrap; }
#current-q { color: #28549e; }

/* 문항 콘텐츠 */
.q-content-box {
    width: 100%;
    padding: 16px 0 0 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.q-title {
    font-size: 20px; font-weight: 800;
    text-align: center; margin-bottom: 20px;
    line-height: 1.55; color: #1a1a1a;
    white-space: pre-wrap; word-break: keep-all;
    padding: 0 24px;
}

/* 문항 이미지 — PNG라 테두리/그림자 없음, full width */
.q-img-wrap {
    width: 100%; max-width: 100%;
    margin-bottom: 0;
    text-align: center; flex-shrink: 0;
}
.q-img-wrap img {
    width: 100%; height: auto;
    max-height: 44vh;
    object-fit: contain;
    border-radius: 0; box-shadow: none;
    display: block;
}

/* 5번 문항: 상반신 클로즈업이라 별도 축소 */
.q-img-wrap img.q-img-small {
    max-height: 32vh;
    max-width: 70%;
    margin: 0 auto;
}

/* 선택지 — 이미지 하단을 살짝 덮음 */
.options-wrap {
    width: 100%;
    display: flex; flex-direction: column;
    gap: 10px;
    padding: 0 20px 32px;
    margin-top: -28px;
    position: relative; z-index: 2;
}

.btn-option {
    width: 100%;
    background-color: rgba(255,255,255,0.97);
    color: #2a2a2a;
    border: 2px solid #eaecef;
    border-radius: 16px;
    padding: 17px 16px;
    font-size: 15px; font-weight: 700;
    line-height: 1.5; word-break: keep-all;
    cursor: pointer;
    text-align: center;
    box-shadow: 0 4px 16px rgba(0,0,0,0.08);
    transition: border-color 0.18s ease, background-color 0.18s ease,
                box-shadow 0.18s ease, transform 0.15s cubic-bezier(0.4,0,0.2,1);
}
.btn-option:hover {
    border-color: #28549e; background-color: #f4f7fd;
    box-shadow: 0 4px 14px rgba(40,84,158,0.14);
    transform: translateY(-1px);
}
.btn-option:active {
    background-color: #eaf0fb; border-color: #28549e;
    transform: scale(0.975); box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}

/* =========================================
   5. 로딩 화면
   ========================================= */
.loading-layout {
    padding: 0;
    background-color: #e9eaec;
    overflow: hidden;
    justify-content: center;
    position: relative;
}
.loading-wrapper {
    position: relative;
    width: 100%; height: 100%;
    max-width: 480px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.l-layer {
    position: absolute; top: 0; left: 0;
    width: 100%; height: 100%;
    object-fit: cover;
}
.l-bg    { z-index: 1; }
.l-copy1 { z-index: 2; animation: floatSlow 3s infinite alternate; }
.l-copy2 { z-index: 3; }
.l-book  { z-index: 4; animation: floatFast 2s infinite alternate ease-in-out; }

/* 로딩 카피 이미지 — 양쪽 여백 주고 상단 영역에 위치 */
.l-copy1, .l-copy2 {
    left: 5%;
    width: 90%;
    height: 100%;
    object-fit: contain;
    object-position: center top;   /* 이미지 상단 기준으로 배치 */
}

/* 스피너 — 카피 이미지 아래, 책 이미지 위 공간 */
.l-spinner-container {
    position: absolute;
    top: 28%;                      /* PC 기준: 카피 아래, 책 위 — 겹치지 않게 */
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: transparent;
    width: 100%;
}
.spinner {
    width: 34px; height: 34px;
    border: 4px solid rgba(40,84,158,0.18);
    border-top: 4px solid #28549e;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 10px;
}
.l-spinner-text {
    font-size: 14px; font-weight: 800;
    color: #28549e;
    text-align: center;
    padding: 0 32px;
    word-break: keep-all;
    line-height: 1.4;
    min-height: 20px;
    transition: opacity 0.2s ease;
}

@keyframes spin      { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
@keyframes floatSlow { from { opacity: 0.8; transform: translateY(0); } to { opacity: 1; transform: translateY(-5px); } }
@keyframes floatFast { from { transform: translateY(0); } to { transform: translateY(-12px); } }

/* =========================================
   6. 결과 화면
   ========================================= */
.result-layout {
    padding: 30px 20px 40px;
    background-color: #fdfdfd;
}
.capture-box {
    width: 100%;
    display: flex; flex-direction: column; align-items: center;
    margin-bottom: 24px;
}
.r-title {
    font-size: 26px; font-weight: 800;
    color: #28549e; margin-bottom: 22px;
    text-align: center; line-height: 1.35;
}

/* 결과 이미지 — 라운드 박스, 머리 잘림 방지 */
.r-img-wrap {
    width: 100%; max-width: 220px;
    margin: 0 auto 20px;
    border-radius: 20px; overflow: hidden;
    background: #f5f7fa;
    box-shadow: 0 6px 20px rgba(0,0,0,0.08);
}
.r-img-wrap img {
    width: 100%; height: auto;
    max-height: 260px;
    object-fit: cover;
    object-position: top;    /* 머리 기준 — 하단이 잘림 */
    display: block;
}

.r-desc-box, .r-solution-box {
    background-color: #ffffff;
    border: 1px solid #ebebeb;
    border-radius: 18px; padding: 20px 18px;
    width: 100%; margin-bottom: 12px;
    box-shadow: 0 3px 12px rgba(0,0,0,0.04);
}
.r-desc-box h3, .r-solution-box h3 {
    font-size: 16px; font-weight: 800;
    margin-bottom: 12px; text-align: center; color: #222;
}
.r-desc-box p, .r-solution-box p {
    font-size: 14px; line-height: 1.75; color: #555;
    white-space: pre-wrap; text-align: center;
    margin: 0; word-break: keep-all;
}

.r-book-wrap { text-align: center; margin: 12px 0 16px; }
.r-book-wrap img {
    width: 110px; border-radius: 8px;
    box-shadow: 0 8px 22px rgba(0,0,0,0.14);
    transition: transform 0.2s ease;
}
.r-book-wrap img:hover { transform: scale(1.04) rotate(-1deg); }

/* 버튼 그룹 */
.r-btn-group { width: 100%; display: flex; flex-direction: column; gap: 12px; margin-bottom: 28px; }

.btn-smore-green, .btn-smore-outline {
    width: 100%; padding: 17px; border-radius: 16px;
    font-size: 15px; font-weight: 800; cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}
.btn-smore-outline {
    background-color: #fff; border: 2px solid #dde0e4 !important;
    color: #444; box-shadow: none;
}
.btn-smore-green {
    background: linear-gradient(135deg, #43b049 0%, #338a38 100%);
    color: white; border: none;
    box-shadow: 0 6px 18px rgba(67,176,73,0.28);
}
.btn-smore-green:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn-smore-outline:hover { background-color: #f5f6f8; border-color: #bbb !important; }
.btn-smore-green:active, .btn-smore-outline:active { transform: scale(0.97); }

.btn-row { display: flex; gap: 12px; }
.btn-row .btn-smore-outline { flex: 1; }

/* 서점 링크 */
.bookstore-box {
    width: 100%; border-top: 1px dashed #ddd;
    padding-top: 24px; text-align: center;
}
.bookstore-box h3 { font-size: 15px; font-weight: 800; margin-bottom: 12px; color: #777; }
.store-links { display: flex; gap: 12px; justify-content: center; }
.store-item {
    flex: 1; border: 1px solid #e4e4e4; border-radius: 12px;
    padding: 13px 5px; display: flex; justify-content: center; align-items: center;
    background: #fff;
    transition: background 0.18s, border-color 0.18s, transform 0.15s; cursor: pointer;
}
.store-item:hover  { background: #f8f9fb; border-color: #c0c4cc; transform: translateY(-1px); }
.store-item:active { background: #f0f1f4; transform: scale(0.97); }
.store-item img { height: 20px; object-fit: contain; }

/* =========================================
   7. 푸터 — 항상 하단에 고정 노출
   ========================================= */
.app-footer {
    width: 100%;
    padding: 10px 20px;
    display: flex;
    justify-content: center; align-items: center;
    gap: 8px;
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;           /* app-container에서 눌리지 않음 */
    background: #fff;
    z-index: 100;
    /* screen과 같은 레벨(app-container 직계 자식)이므로 항상 화면 하단에 보임 */
}
.app-footer img { height: 11px; filter: grayscale(100%) opacity(35%); }
.app-footer p { font-size: 10px; color: #bbb; margin: 0; font-weight: 600; }

/* =========================================
   8. 모달
   ========================================= */
.modal-overlay {
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.65);
    z-index: 999;
    display: flex; align-items: flex-end; justify-content: center;
    opacity: 1; transition: opacity 0.25s ease; cursor: pointer;
}
.modal-overlay.hidden { opacity: 0; pointer-events: none; }

.modal-content {
    background: white; width: 100%; max-width: 480px;
    border-radius: 24px 24px 0 0; padding: 24px 20px 40px;
    max-height: 85vh; overflow-y: auto; position: relative;
    animation: fadeInUp 0.35s cubic-bezier(0.2,0.8,0.2,1); cursor: default;
}
.modal-close {
    position: absolute; top: 18px; right: 18px;
    background: #f0f0f0; border-radius: 50%; width: 32px; height: 32px;
    border: none; font-size: 15px; font-weight: bold; color: #555;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: background 0.2s;
}
.modal-close:hover { background: #e0e0e0; }
.modal-content h3 { text-align: center; font-size: 17px; font-weight: 800; margin-bottom: 18px; color: #222; }

.types-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.type-card {
    background: #f8f9fa; padding: 14px; border-radius: 16px;
    text-align: center; cursor: pointer; border: 1.5px solid #eee; overflow: hidden;
    transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}
.type-card:hover {
    border-color: #28549e;
    box-shadow: 0 4px 14px rgba(40,84,158,0.12);
    transform: translateY(-2px);
}
.type-card:active { transform: scale(0.95); }
.type-card img {
    width: 100%; aspect-ratio: 3/4; border-radius: 10px; margin-bottom: 8px;
    object-fit: cover; object-position: top; display: block;
}
.type-card p { font-size: 13px; font-weight: 800; margin-bottom: 4px; color: #111; word-break: keep-all; }
.type-badge { font-size: 11px; font-weight: 700; color: #28549e; }

/* =========================================
   9. 반응형 (430px 이하 = 모바일)
   — PC와 구조 동일, 크기만 조정
   ========================================= */
@media (max-width: 430px) {
    /* 메인 */
    .main-header-img { max-width: 76px; }
    .main-img        { max-height: 36vh; }
    .main-text-area  { padding: 0 20px; }
    .main-title      { font-size: 21px; margin-bottom: 6px; }
    .main-desc       { font-size: 13px; }
    .main-btn-area   { padding: 0 20px; }
    .btn-smore       { padding: 15px; font-size: 16px; }

    /* 로딩 스피너 — 모바일은 책이 더 크게 보여서 더 위로 */
    .l-spinner-container { top: 22%; }

    /* 문항 */
    .q-header-box  { padding: 18px 16px 10px; }
    .q-content-box { padding: 14px 0 0 0; }
    .q-title       { font-size: 17px; margin-bottom: 14px; }
    .q-img-wrap    { max-width: 100%; }
    .q-img-wrap img { max-height: 40vh; }
    .options-wrap  { gap: 8px; margin-top: -20px; padding: 0 16px 24px; }
    .btn-option    { padding: 14px; font-size: 13px; }

    /* 결과 */
    .r-title   { font-size: 22px; margin-bottom: 16px; }
    .r-img-wrap { max-width: 190px; }
    .r-img-wrap img { max-height: 230px; }
    .r-desc-box p, .r-solution-box p { font-size: 13px; }
    .btn-smore-green, .btn-smore-outline { padding: 15px; font-size: 14px; }

    /* 푸터 */
    .app-footer { padding: 9px 16px; }
}

/* 아주 작은 기기 (320px) */
@media (max-width: 350px) {
    .main-title { font-size: 19px; }
    .q-title    { font-size: 15px; }
    .btn-option { font-size: 12px; padding: 12px 10px; }
}

/* 호버 효과: 마우스 있는 환경에서만 */
@media (hover: none) {
    .btn-smore:hover, .btn-option:hover,
    .btn-smore-green:hover, .btn-smore-outline:hover,
    .store-item:hover, .type-card:hover,
    .r-book-wrap img:hover { transform: none; filter: none; }
}
