* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    background-color: #020408;
    overflow: hidden;
    touch-action: none;
    /* 防止手機板手勢干擾 */
}

body {
    font-family: 'Outfit', sans-serif;
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
}

.game-container {
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    background: #000;
}

/* 核心容器：嚴格鎖定 600:1066 比例 */
.canvas-container {
    position: relative;
    box-shadow: 0 0 100px rgba(0, 0, 0, 0.8), 0 0 30px rgba(251, 191, 36, 0.15);
    background: #000;
    overflow: hidden;

    /* 預設在手機直屏下填滿寬度 */
    width: 100vw;
    height: calc(100vw * 1066 / 600);
}

/* 當螢幕太長 (如 iPhone) 或太寬 (如平板) 時，根據比例切換縮放模式 */
@media (min-aspect-ratio: 600/1066) {
    .canvas-container {
        height: 100vh;
        width: calc(100vh * 600 / 1066);
    }
}

/* 桌機版上限 */
@media (min-width: 601px) and (min-height: 1067px) {
    .canvas-container {
        width: 600px;
        height: 1066px;
        border-radius: 20px;
        border: 4px solid #1a1a1a;
    }
}

#gameCanvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
    image-rendering: auto;
    /* 保證圖片平滑 */
}

/* 介面蓋板 */
.menu-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 200;
    display: none;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.7);
    animation: fadeIn 0.4s ease-out;
}

#cover-overlay {
    background: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.95)), url('cover_bg.webp');
    background-size: cover;
    background-position: center;
    display: none;
    /* 修改：預設不顯示，由 JS 決定何時顯示 */
}

/* Loading 畫面專屬樣式 */
/* Loading 畫面 (簡化簡潔版) */
.loading-overlay {
    background: #020408;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: opacity 0.5s ease, visibility 0.5s;
}

.loading-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}

.loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 200px;
    /* 縮小寬度使其更精確 */
}

.loading-text {
    font-size: 0.9rem;
    color: rgba(251, 191, 36, 0.8);
    margin-bottom: 12px;
    letter-spacing: 1px;
}

.progress-bar-container {
    width: 100%;
    height: 4px;
    /* 更細的線條 */
    background: rgba(255, 255, 255, 0.05);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-bar-fill {
    width: 0%;
    height: 100%;
    background: #fbbf24;
    box-shadow: 0 0 8px rgba(251, 191, 36, 0.4);
    transition: width 0.3s ease-out;
}

.loading-status {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.4);
    font-family: monospace;
}

.overlay-content {
    width: 100%;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: slideUp 0.5s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.blur-bg {
    backdrop-filter: blur(10px);
    background: rgba(0, 0, 0, 0.8);
}

/* 封面標題與按鈕 */
.game-title {
    font-size: clamp(3rem, 15vw, 6rem);
    font-weight: 900;
    line-height: 0.9;
    text-align: center;
    margin-bottom: 40px;
    background: linear-gradient(to bottom, #fff 30%, #fbbf24);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 15px rgba(251, 191, 36, 0.5));
}

.btn-group {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 250px;
}

.menu-btn {
    width: 100%;
    padding: 16px;
    font-size: 1.2rem;
    font-weight: 700;
    border-radius: 12px;
    cursor: pointer;
    transition: 0.3s;
    border: none;
}

.menu-btn.primary {
    background: #fbbf24;
    color: #000;
    box-shadow: 0 5px 0 #b45309;
}

.menu-btn.secondary {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* 規則容器 */
.rules-container {
    width: 90%;
    max-height: 80%;
    background: rgba(10, 10, 10, 0.95);
    border: 2px solid #fbbf24;
    border-radius: 20px;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.rules-content {
    overflow-y: auto;
    margin: 15px 0;
}

.rules-content h3 {
    color: #fbbf24;
    margin-top: 15px;
    font-size: 1.1rem;
}

.rules-content li {
    color: #ddd;
    margin: 5px 0;
    font-size: 0.9rem;
}

/* 投降按鈕 */
.surrender-btn {
    position: absolute;
    bottom: 30px;
    left: 20px;
    padding: 8px 18px;
    /* 稍微縮小 */
    background: rgba(0, 0, 0, 0.85);
    border: 1.5px solid rgba(239, 68, 68, 0.6);
    color: #ef4444;
    font-size: 0.9rem;
    /* 從 1rem 降到 0.9rem */
    font-weight: 700;
    border-radius: 12px;
    z-index: 210;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(6px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

.surrender-btn:hover {
    background: #000;
    border-color: #ef4444;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.25);
}

.surrender-btn:active {
    transform: translateY(0);
}

/* 結束畫面 */
.game-over-overlay {
    position: absolute;
    inset: 0;
    z-index: 300;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(8px);
}

#result-text {
    font-size: clamp(3.5rem, 18vw, 5.5rem);
    /* 從 6rem 改為響應式，最大 5.5rem */
    font-weight: 900;
    margin-bottom: 30px;
    text-shadow: 0 0 30px rgba(251, 191, 36, 0.6);
    text-align: center;
    width: 90%;
    /* 限制寬度防止溢出 */
}

#confirm-btn {
    width: 125px;
}

/* 低血量警報 */
@keyframes hpBlink {

    0%,
    100% {
        filter: brightness(1);
    }

    50% {
        filter: brightness(1.5) contrast(1.2);
    }
}

.hp-warning {
    animation: hpBlink 0.5s infinite alternate !important;
}

/* 教學畫面 (Tutorial) 樣式 - 手機優化版 */
.tutorial-overlay {
    z-index: 1500 !important;
}

.tutorial-container {
    width: 88%;
    /* 原本 92%，縮小 */
    max-width: 450px;
    /* 原本 500px */
    padding: 30px 20px;
    /* 原本 40px 25px */
    border: 3px solid rgba(251, 191, 36, 0.5);
    border-radius: 32px;
    text-align: center;
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.9), inset 0 0 30px rgba(251, 191, 36, 0.1);
    animation: slideUp 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.tutorial-title {
    color: #fbbf24;
    font-size: 2.1rem;
    /* 原本 2.4rem */
    margin-bottom: 25px;
    /* 原本 35px */
    font-weight: 900;
    text-shadow: 0 0 15px rgba(251, 191, 36, 0.4);
}

.tutorial-steps {
    display: flex;
    flex-direction: column;
    gap: 25px;
    margin-bottom: 40px;
}

.t-step {
    display: flex;
    align-items: center;
    gap: 20px;
    text-align: left;
    background: rgba(255, 255, 255, 0.05);
    padding: 20px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.t-icon-box {
    width: 90px;
    height: 90px;
    flex-shrink: 0;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 18px;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 2px solid rgba(251, 191, 36, 0.3);
}

.t-icon {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    position: relative;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

.ball-normal {
    background-image: url('ball_blue.png');
    filter: drop-shadow(0 0 8px rgba(59, 130, 246, 0.6));
}

.ball-special {
    background-image: url('h_ball_blue.png');
    filter: drop-shadow(0 0 12px rgba(251, 191, 36, 0.7));
}

.t-info h3 {
    font-size: 1.6rem;
    margin-bottom: 5px;
    color: #fff;
    font-weight: 800;
}

.t-info p {
    font-size: 1.1rem;
    /* 原本 1.2rem */
    color: rgba(255, 255, 255, 0.8);
    line-height: 1.4;
}

#tutorial-close-btn {
    width: 100%;
    margin-top: 10px;
    padding: 20px;
    font-size: 1.5rem;
}