* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    /* 드래그 방지 */
    -webkit-user-select: none;
}

body {
    background-color: #2c3e50;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    overflow: hidden;
    /* 모바일 브라우저 기본 제스처 완벽 차단은 body 전체보단 캔버스에 집중 */
    overscroll-behavior: none;
    font-family: 'Arial', sans-serif;
    touch-action: pan-x pan-y;
}

/* 게임 캔버스 컨테이너 */
#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-container canvas {
    display: block;
    touch-action: none;
    /* 게임화면 터치시 스크롤 방지 */
}

/* UI 오버레이 (상점 등) */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* 기본적으로 클릭 패스, 필요한 UI 요소만 pointer-events: auto 부여 */
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* --- 공통 팝업 스타일 --- */
.popup-box {
    background-color: rgba(255, 255, 255, 0.95);
    border: 8px solid #FFD700;
    border-radius: 20px;
    padding: 30px;
    text-align: center;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    width: min(500px, 95vw);
    box-sizing: border-box;
}

@media screen and (max-width: 500px) {
    .popup-box {
        padding: 10px;
        border-width: 3px;
        border-radius: 12px;
    }

    .quiz-question {
        font-size: 28px;
    }

    .choice-btn {
        font-size: 18px;
        padding: 8px 4px;
    }

    /* 우측 상단 상시 UI 과감하게 축소 */
    #persistent-ui {
        top: 10px;
        right: 10px;
        gap: 6px;
    }

    #gold-display {
        font-size: 12px;
        padding: 3px 8px;
        border-width: 2px;
    }

    #shop-open-btn,
    .persistent-btn {
        font-size: 12px;
        padding: 4px 8px;
        border-width: 2px;
        box-shadow: 0 2px 0 #cc7000;
    }

    .buy-btn {
        font-size: 13px;
        padding: 5px 10px;
    }

    .upgrade-item {
        padding: 8px;
        gap: 5px;
    }

    .up-info h3 {
        font-size: 16px;
        margin-bottom: 2px;
    }

    .up-info p {
        font-size: 12px;
    }

    .up-icon {
        font-size: 20px;
        width: 30px;
    }

    .npc-avatar {
        font-size: 40px;
    }

    .npc-bubble {
        font-size: 14px;
        padding: 8px;
    }

    /* 상점 레이아웃 최적화 */
    .shop-content {
        flex-direction: column !important;
        gap: 10px;
        min-height: 0;
    }

    .upgrade-list {
        min-height: 0;
        overflow-y: auto;
    }

    #shop-popup {
        padding: 15px;
    }

    .shop-npc {
        flex: none;
        padding: 10px;
    }

    .npc-avatar {
        font-size: 40px;
        margin-bottom: 5px;
    }

    .encyclopedia-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 8px;
    }

    .fish-card h3 {
        font-size: 14px;
    }

    .shop-header h2 {
        font-size: 20px;
    }

    .shop-gold {
        font-size: 14px;
    }

    #shop-close-btn {
        font-size: 14px;
        padding: 5px 10px;
    }
}

/* --- 퀴즈 전용 스타일 --- */
#quiz-popup h2 {
    color: #FF4500;
    font-size: 32px;
    margin-bottom: 20px;
}

.quiz-question {
    font-size: 64px;
    font-weight: bold;
    color: #333;
    margin-bottom: 30px;
}

.quiz-choices {
    display: flex;
    justify-content: space-around;
    gap: 15px;
}

.choice-btn {
    flex: 1;
    font-size: 40px;
    font-weight: bold;
    padding: 20px 10px;
    border: none;
    border-radius: 15px;
    background-color: #4CAF50;
    color: white;
    cursor: pointer;
    box-shadow: 0 8px 0 #2E8B57;
    transition: transform 0.1s, box-shadow 0.1s;
}

.choice-btn:active {
    transform: translateY(8px);
    box-shadow: none;
}

/* 정답/오답 피드백 클래스 */
.choice-btn.correct {
    background-color: #00BFFF;
    box-shadow: 0 8px 0 #008080;
}

.choice-btn.wrong {
    background-color: #DC143C;
    box-shadow: 0 8px 0 #8B0000;
}

.praise-text {
    margin-top: 20px;
    font-size: 28px;
    font-weight: bold;
    color: #FF1493;
    animation: popUp 0.5s ease-out;
}

.penalty-text {
    margin-top: 20px;
    font-size: 28px;
    font-weight: bold;
    color: #8B0000;
    animation: popUp 0.5s ease-out;
}

/* 애니메이션 */
@keyframes popUp {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }

    80% {
        transform: scale(1.1);
        opacity: 1;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.quiz-shake {
    animation: popupShake 0.4s;
}

@keyframes popupShake {
    0% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-10px);
    }

    50% {
        transform: translateX(10px);
    }

    75% {
        transform: translateX(-10px);
    }

    100% {
        transform: translateX(0);
    }
}

/* 맥박(Pulse) 애니메이션 */
@keyframes pulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }

    100% {
        transform: scale(1);
    }
}

.pulse-anim {
    animation: pulse 2s infinite ease-in-out;
}

/* --- 상시 유지 UI (오른쪽 상단) --- */
#persistent-ui {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 5px;
    align-items: center;
    z-index: 20;
}

#gold-display {
    background: rgba(0, 0, 0, 0.6);
    color: #FFD700;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: bold;
    border: 2px solid #FFD700;
}

#shop-open-btn {
    background: #FF8C00;
    color: white;
    border: 2px solid #ffba66;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 2px 0 #cc7000;
    transition: transform 0.1s, box-shadow 0.1s;
}

#shop-open-btn:active {
    transform: translateY(4px);
    box-shadow: none;
}

/* --- 상점 팝업 전용 스타일 --- */
#shop-popup {
    width: min(800px, 95vw);
    max-height: 95vh;
    display: flex;
    flex-direction: column;
    padding: 15px;
    /* Reduced from 30px */
}

.shop-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
    /* Reduced */
    padding-bottom: 5px;
    border-bottom: 2px dashed #CCC;
    flex-wrap: wrap;
    gap: 5px;
}

.shop-header h2 {
    color: #4169E1;
    font-size: 20px;
    /* Reduced from 28px */
    margin: 0;
}

.shop-gold {
    font-size: 16px;
    /* Reduced */
    font-weight: bold;
    color: #DAA520;
}

#shop-close-btn {
    background: #FF6347;
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
}

.shop-content {
    display: flex;
    gap: 10px;
    flex: 1;
    flex-direction: column !important;
    min-height: 0;
}

/* NPC 영역 (상단) */
.shop-npc {
    background: #F0F8FF;
    border: 2px solid #87CEFA;
    border-radius: 10px;
    padding: 5px 10px;
    /* Reduced padding */
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 10px;
    /* Reduced gap */
    flex-shrink: 0;
}

.npc-avatar {
    font-size: 32px;
    /* Halved from ~60px equivalent */
    margin-bottom: 0;
    animation: float 3s ease-in-out infinite;
}

.npc-bubble {
    background: white;
    border: 2px solid #333;
    border-radius: 10px;
    padding: 5px 10px;
    /* Reduced padding */
    font-size: 14px;
    /* Reduced font */
    font-weight: bold;
    position: relative;
    max-width: 80%;
}

/* 말풍선 꼬리 (왼쪽으로 변경) */
.npc-bubble::after {
    content: '';
    position: absolute;
    top: 50%;
    left: -10px;
    margin-top: -6px;
    border-width: 6px;
    border-style: solid;
    border-color: transparent #333 transparent transparent;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

/* 업그레이드 리스트 영역 */
.upgrade-list {
    flex: 2;
    display: flex;
    flex-direction: column;
    gap: 8px;
    /* Reduced gap */
    overflow-y: auto;
    padding-right: 5px;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}

.upgrade-item {
    display: flex;
    align-items: center;
    background: #FFF8DC;
    border: 2px solid #DEB887;
    border-radius: 8px;
    padding: 6px 10px;
    /* Reduced padding */
    text-align: left;
}

.up-icon {
    font-size: 28px;
    width: 40px;
    text-align: center;
}

.up-info {
    flex: 1;
    padding: 0 10px;
}

.up-info h3 {
    color: #8B4513;
    font-size: 16px;
    margin-bottom: 3px;
}

.up-info p {
    color: #666;
    font-size: 13px;
    margin: 0;
}

.buy-btn {
    background: #32CD32;
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 3px 0 #228B22;
    transition: all 0.1s;
}

.buy-btn:active {
    transform: translateY(5px);
    box-shadow: none;
}

/* --- 도감(Encyclopedia) 전용 스타일 --- */
#encyclopedia-popup {
    width: min(800px, 95vw);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

#book-close-btn {
    background: #FF6347;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
}

.encyclopedia-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    overflow-y: auto;
    padding: 10px;
    /* 모바일 스크롤 지원 */
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}

.fish-card {
    background: #FFF8DC;
    border: 4px solid #DEB887;
    border-radius: 15px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.fish-card h3 {
    margin: 10px 0 5px 0;
    font-size: 20px;
    color: #333;
}

.fish-grade {
    font-weight: bold;
    margin-bottom: 5px;
}

.grade-N {
    color: #888888;
}

.grade-R {
    color: #4169E1;
}

.grade-SR {
    color: #8A2BE2;
}

.grade-SSR {
    color: #FFD700;
    text-shadow: 1px 1px 2px #000;
}

.fish-count {
    font-size: 14px;
    color: #555;
}

.fish-reward {
    font-size: 14px;
    color: #DAA520;
    font-weight: bold;
    margin-top: 5px;
}

/* 진짜 이미지 스프라이트 표시 */
.fish-img-container {
    width: 100px;
    height: 80px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    margin-bottom: 10px;
    overflow: hidden;
}

.fish-img-sprite {
    max-width: 90%;
    max-height: 90%;
    width: auto;
    height: auto;
    image-rendering: crisp-edges;
    image-rendering: pixelated;
    /* 레트로 감성 도트 유지 */
}

/* 미발견 실루엣 처리 */
.undiscovered {
    background: #E0E0E0;
    border-color: #999;
}

.undiscovered h3,
.undiscovered p {
    color: #777;
}

.silhouette-img {
    filter: brightness(0);
    opacity: 0.5;
}

/* 공통 버튼 추가 스타일 */
.persistent-btn {
    background: #FF8C00;
    color: white;
    border: 2px solid #ffba66;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 2px 0 #cc7000;
    transition: transform 0.1s, box-shadow 0.1s;
}

.persistent-btn:active {
    transform: translateY(4px);
    box-shadow: none;
}

/* --- 모바일 기기 세로 모드(Portrait) 방지 경고창 --- */
#orientation-warning {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    color: white;
    z-index: 9999;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    font-weight: bold;
    text-align: center;
}

/* 폭이 좁은 기기(모바일)에서 세로 방향일 때만 플렉스로 표시 */
/* Portrait mode is now allowed — warning only shown on tablets/desktop narrowed accidentally */
@media screen and (max-width: 500px) and (orientation: portrait) {

    /* portrait phones: hide warning, play normally */
    #orientation-warning {
        display: none !important;
    }
}

/* --- 퀴즈 도상학 물고기 아이콘 시각화 --- */
.quiz-icon-area {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin: 15px 0;
    flex-wrap: wrap;
}

.quiz-fish-group {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    max-width: 200px;
    justify-content: center;
    background: rgba(30, 144, 255, 0.1);
    border: 2px dashed #87CEEB;
    border-radius: 12px;
    padding: 10px;
}

.quiz-fish-icon {
    font-size: 24px;
    animation: fishBounce 0.6s ease-in-out infinite alternate;
}

.quiz-fish-icon:nth-child(even) {
    animation-delay: 0.3s;
}

@keyframes fishBounce {
    0% {
        transform: translateY(0);
    }

    100% {
        transform: translateY(-4px);
    }
}

.quiz-operator {
    font-size: 48px;
    font-weight: bold;
    color: #FF4500;
}

.quiz-answer-mark {
    font-size: 48px;
    font-weight: bold;
    color: #FFD700;
    background: rgba(255, 215, 0, 0.2);
    border: 3px solid #FFD700;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }
}

/* --- 타이핑 퀴즈 전용 스타일 --- */
.typing-word-area {
    background: #fff;
    border: 4px solid #FF1493;
    border-radius: 15px;
    padding: 20px;
    margin: 20px 0;
}

.typing-target {
    font-size: 48px;
    font-weight: bold;
    color: #333;
    letter-spacing: 5px;
}

.quiz-input-area {
    margin: 20px 0;
}

.quiz-input {
    width: 80%;
    font-size: 32px;
    padding: 10px;
    border: 4px solid #4169E1;
    border-radius: 10px;
    text-align: center;
    outline: none;
}

.quiz-input:focus {
    border-color: #FFD700;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.correct-input {
    border-color: #32CD32 !important;
    background-color: #f0fff0;
}

.wrong-input {
    border-color: #DC143C !important;
    background-color: #fff0f0;
}

/* NPC 콧수염 이모지 */
.npc-mustache {
    font-size: 60px;
    margin-top: -30px;
    margin-bottom: 10px;
}

/* --- Phase 4 새로 추가된 애니메이션 --- */
@keyframes magic-circle-spin {
    from {
        transform: translate(-50%, -50%) rotate(0deg) scale(0.8);
        opacity: 0;
    }

    50% {
        opacity: 0.8;
    }

    to {
        transform: translate(-50%, -50%) rotate(360deg) scale(1.5);
        opacity: 0;
    }
}

.magic-circle-anim {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 200px;
    height: 200px;
    border: 5px dashed #FF69B4;
    border-radius: 50%;
    box-shadow: 0 0 20px #FF1493, inset 0 0 20px #FF1493;
    animation: magic-circle-spin 1.5s ease-out forwards;
    pointer-events: none;
    z-index: 100;
}

@keyframes shake-screen {
    0% {
        transform: translate(0, 0) rotate(0deg);
    }

    25% {
        transform: translate(-5px, 5px) rotate(-1deg);
    }

    50% {
        transform: translate(5px, -5px) rotate(1deg);
    }

    75% {
        transform: translate(-5px, -5px) rotate(-1deg);
    }

    100% {
        transform: translate(0, 0) rotate(0deg);
    }
}

.screen-shake-anim {
    animation: shake-screen 0.3s ease-in-out infinite;
}