/* story-mode.css — 스토리 모드 챕터/스테이지 선택 화면 */

/* ============================
   헤더 영역
   ============================ */
.story-header {
    text-align: center;
    margin-bottom: 20px;
}

.total-stars {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 215, 0, 0.15);
    border: 1px solid rgba(255, 215, 0, 0.4);
    border-radius: 20px;
    padding: 6px 16px;
    font-family: 'Fredoka One', cursive;
    font-size: 16px;
    color: #ffd700;
    margin-top: 8px;
}

.total-stars .star-icon {
    font-size: 18px;
}

/* ============================
   챕터 탭
   ============================ */
.chapter-tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 8px;
    margin-bottom: 16px;
    /* 스크롤바 숨기기 */
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.chapter-tabs::-webkit-scrollbar {
    display: none;
}

.chapter-tab {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    background: rgba(255, 255, 255, 0.12);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    padding: 8px 16px;
    cursor: pointer;
    font-family: 'Noto Sans KR', sans-serif;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.75);
    transition: all 0.2s ease;
    white-space: nowrap;
    user-select: none;
}

.chapter-tab:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
    color: #fff;
    transform: translateY(-1px);
}

.chapter-tab.active {
    background: linear-gradient(135deg, #6ab04c, #44bd32);
    border-color: #6ab04c;
    color: #fff;
    box-shadow: 0 4px 14px rgba(106, 176, 76, 0.45);
}

.chapter-tab .tab-name {
    font-weight: 700;
    font-size: 13px;
}

.chapter-tab .tab-emoji {
    font-size: 16px;
}

.chapter-tab .tab-stars {
    font-size: 10px;
    opacity: 0.85;
    letter-spacing: 1px;
}

/* ============================
   챕터 정보 영역
   ============================ */
.chapter-info {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 12px 16px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.chapter-info .chapter-emoji {
    font-size: 28px;
    flex-shrink: 0;
}

.chapter-info .chapter-desc {
    font-family: 'Noto Sans KR', sans-serif;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.85);
    line-height: 1.5;
}

.chapter-info .chapter-title {
    font-weight: 700;
    font-size: 14px;
    color: #fff;
    margin-bottom: 2px;
}

/* ============================
   스테이지 그리드
   ============================ */
.stage-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

/* ============================
   스테이지 카드
   ============================ */
.stage-card {
    position: relative;
    aspect-ratio: 1 / 1.05;
    background: rgba(255, 255, 255, 0.13);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
    user-select: none;
    overflow: hidden;
}

.stage-card:hover:not(.locked) {
    transform: translateY(-3px) scale(1.04);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
    border-color: rgba(255, 255, 255, 0.45);
}

.stage-card:active:not(.locked) {
    transform: scale(0.96);
}

/* 잠긴 스테이지 */
.stage-card.locked {
    filter: grayscale(0.6);
    opacity: 0.55;
    cursor: not-allowed;
}

/* 클리어된 스테이지 */
.stage-card.cleared {
    border-color: rgba(106, 176, 76, 0.7);
    box-shadow: 0 0 10px rgba(106, 176, 76, 0.3);
    background: rgba(106, 176, 76, 0.15);
}

/* 현재 (도전 가능한) 스테이지 */
.stage-card.current {
    border-color: #ffd700;
    animation: pulse-border 1.8s ease-in-out infinite;
}

@keyframes pulse-border {
    0%, 100% {
        box-shadow: 0 0 6px rgba(255, 215, 0, 0.4);
        border-color: #ffd700;
    }
    50% {
        box-shadow: 0 0 18px rgba(255, 215, 0, 0.75);
        border-color: #ffe44d;
    }
}

/* 스테이지 번호 */
.stage-card .stage-num {
    font-family: 'Fredoka One', cursive;
    font-size: 20px;
    color: #fff;
    line-height: 1;
}

/* 별 표시 */
.stage-card .stage-stars {
    font-size: 10px;
    letter-spacing: 1px;
    color: #ffd700;
    line-height: 1;
}

/* 잠금 아이콘 */
.stage-card .lock-icon {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 10px;
}

/* 클리어 체크 배지 */
.stage-card .clear-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    font-size: 12px;
    line-height: 1;
}

/* ============================
   모바일 반응형
   ============================ */
@media (max-width: 480px) {
    .stage-grid {
        gap: 7px;
    }

    .stage-card {
        border-radius: 9px;
    }

    .stage-card .stage-num {
        font-size: 17px;
    }

    .stage-card .stage-stars {
        font-size: 9px;
        letter-spacing: 0.5px;
    }

    .chapter-tab {
        padding: 6px 12px;
        font-size: 12px;
    }

    .chapter-tab .tab-emoji {
        font-size: 14px;
    }

    .chapter-tab .tab-stars {
        font-size: 9px;
    }

    .total-stars {
        font-size: 14px;
    }

    .chapter-info {
        padding: 10px 12px;
    }

    .chapter-info .chapter-emoji {
        font-size: 22px;
    }

    .chapter-info .chapter-title {
        font-size: 13px;
    }

    .chapter-info .chapter-desc {
        font-size: 12px;
    }
}

@media (max-width: 360px) {
    .stage-grid {
        gap: 5px;
    }

    .stage-card {
        border-radius: 7px;
        border-width: 1px;
    }

    .stage-card .stage-num {
        font-size: 14px;
    }

    .stage-card .stage-stars {
        font-size: 8px;
        letter-spacing: 0;
    }

    .stage-card .lock-icon {
        font-size: 18px;
    }

    .chapter-tab {
        padding: 5px 10px;
        font-size: 11px;
        border-radius: 16px;
    }

    .chapter-info {
        padding: 8px 10px;
    }
}

/* ============================
   컷신 오버레이
   ============================ */
.cutscene-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: #000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    animation: cutsceneFadeIn 0.5s ease;
}

.cutscene-overlay.hidden {
    display: none;
}

@keyframes cutsceneFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* 배경 이미지 */
.cutscene-bg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    opacity: 0.85;
}

/* 이미지 로드 실패 시 fallback */
.cutscene-bg-fallback {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 120px;
    background: linear-gradient(135deg, var(--fallback-color1, #1a3a5c), var(--fallback-color2, #0a1628));
}

/* 건너뛰기 버튼 */
.cutscene-skip {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 10;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 20px;
    padding: 8px 18px;
    color: rgba(255, 255, 255, 0.8);
    font-family: 'Noto Sans KR', sans-serif;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(4px);
}

.cutscene-skip:hover {
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.6);
}

/* 하단 대사창 */
.cutscene-dialogue-box {
    position: relative;
    z-index: 5;
    width: 100%;
    max-width: 600px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.9), rgba(0, 0, 0, 0.7));
    backdrop-filter: blur(8px);
    border-top: 2px solid rgba(255, 255, 255, 0.15);
    padding: 20px 24px 24px;
    margin-bottom: 0;
}

/* 화자 이름 */
.cutscene-speaker {
    display: inline-block;
    background: linear-gradient(135deg, #6ab04c, #44bd32);
    color: #fff;
    font-family: 'Fredoka One', cursive;
    font-size: 14px;
    padding: 4px 14px;
    border-radius: 12px;
    margin-bottom: 10px;
}

/* 대사 텍스트 */
.cutscene-text {
    font-family: 'Noto Sans KR', sans-serif;
    font-size: 16px;
    color: #fff;
    line-height: 1.7;
    min-height: 52px;
    word-break: keep-all;
}

/* 탭 안내 */
.cutscene-tap-hint {
    text-align: center;
    margin-top: 14px;
    font-family: 'Noto Sans KR', sans-serif;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.4);
    animation: tapBlink 1.5s ease-in-out infinite;
}

@keyframes tapBlink {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 0.8; }
}

/* ============================
   컷신 모바일 반응형
   ============================ */
@media (max-width: 480px) {
    .cutscene-dialogue-box {
        padding: 16px 18px 20px;
    }

    .cutscene-speaker {
        font-size: 12px;
        padding: 3px 12px;
    }

    .cutscene-text {
        font-size: 14px;
        min-height: 44px;
    }

    .cutscene-skip {
        top: 12px;
        right: 12px;
        font-size: 12px;
        padding: 6px 14px;
    }

    .cutscene-tap-hint {
        font-size: 11px;
        margin-top: 10px;
    }

    .cutscene-bg-fallback {
        font-size: 80px;
    }
}

@media (max-width: 360px) {
    .cutscene-dialogue-box {
        padding: 12px 14px 16px;
    }

    .cutscene-text {
        font-size: 13px;
        line-height: 1.6;
    }

    .cutscene-skip {
        font-size: 11px;
        padding: 5px 12px;
    }
}

/* safe area for notch devices */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .cutscene-dialogue-box {
        padding-bottom: calc(24px + env(safe-area-inset-bottom));
    }
}

/* ============================
   스테이지 상세 모달
   ============================ */
.stage-detail-overlay {
    position: fixed;
    inset: 0;
    z-index: 8000;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.stage-detail-overlay.hidden {
    display: none;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.stage-detail-modal {
    background: linear-gradient(135deg, #1a2a3a, #0d1b2a);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    padding: 24px;
    width: 90%;
    max-width: 380px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    animation: modalSlideUp 0.3s ease;
}

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

.stage-detail-header {
    text-align: center;
    margin-bottom: 16px;
}

.stage-detail-num {
    font-family: 'Fredoka One', cursive;
    font-size: 36px;
    color: #ffd700;
    line-height: 1;
}

.stage-detail-title {
    font-family: 'Noto Sans KR', sans-serif;
    font-weight: 700;
    font-size: 18px;
    color: #fff;
    margin-top: 6px;
}

.stage-detail-desc {
    font-family: 'Noto Sans KR', sans-serif;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.7);
    margin-top: 6px;
    line-height: 1.5;
    word-break: keep-all;
}

/* 별 미션 목록 */
.star-missions {
    margin: 18px 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.star-mission {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 10px 12px;
    transition: border-color 0.2s;
}

.star-mission.achieved {
    border-color: rgba(106, 176, 76, 0.5);
    background: rgba(106, 176, 76, 0.1);
}

.star-mission-icon {
    flex-shrink: 0;
    font-size: 18px;
    line-height: 1.2;
    min-width: 28px;
    text-align: center;
}

.star-mission-text {
    font-family: 'Noto Sans KR', sans-serif;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.9);
    line-height: 1.4;
    word-break: keep-all;
}

.star-mission.achieved .star-mission-text {
    color: rgba(255, 255, 255, 0.6);
    text-decoration: line-through;
}

/* 버튼 영역 */
.stage-detail-buttons {
    display: flex;
    gap: 10px;
    margin-top: 18px;
}

.stage-detail-play {
    flex: 1;
    background: linear-gradient(135deg, #6ab04c, #44bd32);
    border: none;
    border-radius: 12px;
    padding: 14px;
    color: #fff;
    font-family: 'Fredoka One', cursive;
    font-size: 16px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 4px 14px rgba(106, 176, 76, 0.4);
}

.stage-detail-play:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(106, 176, 76, 0.6);
}

.stage-detail-play:active {
    transform: scale(0.97);
}

.stage-detail-close {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    padding: 14px 18px;
    color: rgba(255, 255, 255, 0.7);
    font-family: 'Noto Sans KR', sans-serif;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s;
}

.stage-detail-close:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

/* 모바일 반응형 */
@media (max-width: 480px) {
    .stage-detail-modal {
        padding: 20px;
        max-width: 340px;
    }

    .stage-detail-num {
        font-size: 30px;
    }

    .stage-detail-title {
        font-size: 16px;
    }

    .stage-detail-desc {
        font-size: 12px;
    }

    .star-mission {
        padding: 8px 10px;
        gap: 8px;
    }

    .star-mission-icon {
        font-size: 16px;
    }

    .star-mission-text {
        font-size: 12px;
    }

    .stage-detail-play {
        font-size: 14px;
        padding: 12px;
    }
}

@media (max-width: 360px) {
    .stage-detail-modal {
        padding: 16px;
    }

    .star-mission-text {
        font-size: 11px;
    }
}

/* ============================
   챕터 배경 이미지
   ============================ */
.chapter-bg {
    position: fixed;
    inset: 0;
    z-index: -1;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    transition: opacity 0.5s ease;
    opacity: 0.15;
}

.chapter-bg::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(0,0,0,0.3), rgba(0,0,0,0.5));
}

/* ============================
   스토리 모드 페이지 커스텀
   ============================ */

/* 컨테이너 내부 챕터 배경 이미지 */
.container-chapter-bg {
    position: absolute;
    inset: 0;
    z-index: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0.12;
    transition: background-image 0.5s ease;
    pointer-events: none;
    border-radius: inherit;
}

/* 컨테이너 내부 콘텐츠를 배경 위에 표시 */
.page-body .container-wide > *:not(.container-chapter-bg) {
    position: relative;
    z-index: 1;
}

.page-body .container-wide {
    background: rgba(255, 255, 255, 0.92);
}

/* 챕터 정보 영역 - 텍스트 어둡게 */
.chapter-info .chapter-title {
    color: #222;
}

.chapter-info .chapter-desc {
    color: #444;
}

/* 스테이지 카드 숫자 - 검은색 */
.stage-card .stage-num {
    color: #222;
}

/* 챕터 탭 텍스트 - 비활성 탭 어둡게 */
.chapter-tab {
    color: rgba(0, 0, 0, 0.6);
}

.chapter-tab:hover {
    color: #222;
}

.chapter-tab.active {
    color: #fff;
}

.chapter-tab .tab-stars {
    color: rgba(0, 0, 0, 0.5);
}

.chapter-tab.active .tab-stars {
    color: rgba(255, 255, 255, 0.85);
}

/* 총 별 표시 - 어둡게 */
.total-stars {
    color: #b8860b;
    background: rgba(255, 215, 0, 0.2);
    border-color: rgba(255, 215, 0, 0.5);
}

/* 페이지 타이틀 - 검은색 */
.story-header .page-title {
    color: #222;
}

/* 챕터 정보 배경 조정 */
.chapter-info {
    background: rgba(0, 0, 0, 0.06);
    border-color: rgba(0, 0, 0, 0.1);
}

/* 스테이지 카드 배경 조정 */
.stage-card {
    background: rgba(255, 255, 255, 0.5);
    border-color: rgba(0, 0, 0, 0.15);
}

.stage-card.cleared {
    background: rgba(106, 176, 76, 0.2);
    border-color: rgba(106, 176, 76, 0.6);
}

.stage-card.current {
    background: rgba(255, 255, 255, 0.7);
}

.stage-card.locked {
    background: rgba(0, 0, 0, 0.06);
}

/* 메인으로 돌아가기 버튼 */
.page-body .btn-gray {
    color: #333;
}

/* 푸터 링크 어둡게 */
.footer-links a {
    color: #555;
}

.footer-links .divider {
    color: #999;
}

/* ============================
   앱/WebView 반응형 (짧은 화면)
   ============================ */
@media (max-height: 700px) {
    .story-header {
        margin-bottom: 12px;
    }

    .story-header .beluga-icon {
        font-size: 28px;
        margin-bottom: 2px;
    }

    .story-header .page-title {
        font-size: 24px;
        margin-bottom: 4px;
    }

    .total-stars {
        font-size: 13px;
        padding: 4px 12px;
        margin-top: 4px;
    }

    .chapter-tabs {
        margin-bottom: 10px;
        padding-bottom: 6px;
    }

    .chapter-tab {
        padding: 5px 10px;
        font-size: 11px;
        gap: 2px;
    }

    .chapter-tab .tab-emoji {
        font-size: 13px;
    }

    .chapter-tab .tab-stars {
        font-size: 8px;
    }

    .chapter-info {
        padding: 8px 12px;
        margin-bottom: 10px;
    }

    .chapter-info .chapter-emoji {
        font-size: 20px;
    }

    .chapter-info .chapter-title {
        font-size: 12px;
    }

    .chapter-info .chapter-desc {
        font-size: 11px;
    }

    .stage-grid {
        gap: 6px;
        margin-bottom: 12px;
    }

    .stage-card {
        border-radius: 8px;
    }

    .stage-card .stage-num {
        font-size: 15px;
    }

    .stage-card .stage-stars {
        font-size: 8px;
    }
}

@media (max-height: 550px) {
    .story-header .beluga-icon {
        display: none;
    }

    .story-header .page-title {
        font-size: 20px;
    }

    .chapter-info {
        padding: 6px 10px;
        margin-bottom: 8px;
    }

    .chapter-info .chapter-emoji {
        font-size: 16px;
    }

    .stage-grid {
        gap: 4px;
        margin-bottom: 10px;
    }

    .stage-card .stage-num {
        font-size: 13px;
    }
}

/* safe area for notch/status bar devices */
@supports (padding-top: env(safe-area-inset-top)) {
    .page-body .container-wide {
        padding-top: calc(30px + env(safe-area-inset-top));
        padding-bottom: calc(30px + env(safe-area-inset-bottom));
    }

    @media (max-height: 700px) {
        .page-body .container-wide {
            padding-top: calc(15px + env(safe-area-inset-top));
            padding-bottom: calc(15px + env(safe-area-inset-bottom));
        }
    }
}
