* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #121a2c, #2c3e50);
    color: #ffffff;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    animation: backgroundGradient 20s ease infinite alternate;
}

@keyframes backgroundGradient {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.main-container {
    display: flex;
    width: 100%;
    max-width: 95vw;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
}

.game-container {
    position: relative;
    width: auto;
    max-width: 95vw;
    background-color: #000000;
    box-shadow: 0 15px 35px rgba(0, 191, 255, 0.5);
    border-radius: 15px;
    overflow: hidden;
    transition: transform 0.3s;
    padding: 20px;
    text-align: center;
}

.game-container:hover {
    transform: translateY(-5px);
}

header {
    margin-bottom: 20px;
}

h1 {
    color: #00bfff;
    font-size: 2em;
    text-shadow: 0 0 10px rgba(0, 191, 255, 0.7);
    position: relative;
    display: inline-block;
    padding: 0 10px;
}

h1::before {
    content: "👑";
    position: absolute;
    font-size: 0.8em;
    top: -15px;
    left: 5px;
    animation: floatEffect 3s ease-in-out infinite;
}

h1::after {
    content: "💣";
    position: absolute;
    font-size: 0.8em;
    top: -10px;
    right: 5px;
    animation: bounce 1s ease-in-out infinite alternate;
}

@keyframes bounce {
    0% { transform: translateY(0); }
    100% { transform: translateY(-8px); }
}

#hudOverlay {
    display: flex;
    justify-content: space-around;
    margin-bottom: 20px;
    z-index: 5;
    font-weight: bold;
}

#hudOverlay div {
    color: #00bfff;
    font-size: 18px;
    background-color: rgba(0, 0, 0, 0.5);
    padding: 8px 15px;
    border-radius: 25px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s;
    text-shadow: 1px 1px 2px #000000;
}

#hudOverlay div:hover {
    transform: scale(1.05);
}

#hudOverlay div.audio-control {
    position: relative;
    cursor: pointer;
    transition: all 0.3s;
}

#mute-btn {
    padding: 5px 10px;
    font-size: 18px;
    background: none;
    border: none;
    box-shadow: none;
}

#mute-btn:hover {
    transform: scale(1.1);
}

.game-area {
    margin: 0 auto 20px;
    display: flex;
    justify-content: center;
    max-width: 100%;
    overflow: auto;
    max-height: 80vh;
    position: relative;
}

/* 設置捲動條樣式 */
.game-area::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

.game-area::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 5px;
}

.game-area::-webkit-scrollbar-thumb {
    background: rgba(0, 191, 255, 0.6);
    border-radius: 5px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.game-area::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 191, 255, 0.8);
}

/* 專家模式滑動優化 */
@media (max-width: 768px) {
    .game-area {
        max-height: 65vh;
        overflow-x: auto; /* 確保寬盤（中/高級）可水平捲動 */
        overflow-y: scroll;
        -webkit-overflow-scrolling: touch; /* 提供iOS設備上更流暢的滑動 */
        scroll-behavior: smooth; /* 平滑滾動 */
        /* 手機關鍵修正：盤面比視窗寬時，flex 置中會把左右兩側推到捲動範圍
           之外（scrollLeft origin 卡在中間），導致最左/最右格永遠碰不到。
           改為靠左對齊 → 捲動範圍 0..(scrollWidth-clientWidth)，左右格皆可達。
           桌機（>768px）維持置中不受影響。 */
        justify-content: flex-start;
    }
    
    /* 增強捲動條可見性 */
    .game-area::-webkit-scrollbar {
        width: 16px;
        height: 16px;
    }
    
    .game-area::-webkit-scrollbar-thumb {
        background: rgba(0, 191, 255, 0.8);
        border-radius: 8px;
        border: 2px solid rgba(255, 255, 255, 0.2);
    }
}

/* 針對1024px寬度螢幕的專家模式優化 */
@media (max-width: 1024px) and (min-width: 769px) {
    .game-area {
        max-height: 70vh;
        max-width: 95%;
        overflow: auto;
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
    
    /* 在專家模式下顯示雙向滾動指示器 */
    .game-area::after {
        content: "↕️↔️";
        position: absolute;
        right: 10px;
        bottom: 10px;
        font-size: 20px;
        color: rgba(0, 191, 255, 0.9);
        background: rgba(0, 0, 0, 0.5);
        padding: 5px;
        border-radius: 5px;
        animation: pulseAnimation 2s infinite;
        pointer-events: none;
        z-index: 10;
    }
    
    /* 增強遊戲畫布在專家模式下的易用性 */
    #game-canvas {
        margin: 5px;
        box-shadow: 0 0 15px rgba(0, 191, 255, 0.5);
    }
    
    /* 確保捲動條更容易操作 */
    .game-area::-webkit-scrollbar {
        width: 14px;
        height: 14px;
    }
    
    .game-area::-webkit-scrollbar-thumb {
        background: rgba(0, 191, 255, 0.8);
        border-radius: 7px;
        border: 2px solid rgba(255, 255, 255, 0.2);
    }
}

/* 在更小螢幕上進一步優化 */
@media (max-width: 480px) {
    .game-area {
        max-height: 60vh;
    }
    
    /* 捲動提示指示器 */
    .game-area::after {
        content: "↕️";
        position: absolute;
        right: 5px;
        bottom: 5px;
        font-size: 24px;
        color: rgba(0, 191, 255, 0.8);
        animation: pulseAnimation 2s infinite;
        pointer-events: none;
        z-index: 10;
    }
    
    @keyframes pulseAnimation {
        0% { opacity: 0.4; transform: scale(0.8); }
        50% { opacity: 1; transform: scale(1.2); }
        100% { opacity: 0.4; transform: scale(0.8); }
    }
}

#game-canvas {
    border: 2px solid #333;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(0, 191, 255, 0.3);
    border-radius: 5px;
}

.controls {
    display: flex;
    justify-content: center;
    margin-top: 20px;
}

.control-btn {
    background-color: rgba(0, 191, 255, 0.3);
    color: white;
    border: none;
    padding: 10px 20px;
    text-align: center;
    text-decoration: none;
    font-size: 16px;
    margin: 5px;
    cursor: pointer;
    border-radius: 5px;
    transition: all 0.3s;
    border: 1px solid rgba(0, 191, 255, 0.5);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.control-btn:hover {
    background-color: rgba(0, 191, 255, 0.5);
    transform: translateY(-3px);
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.4);
}

.control-btn:active {
    transform: translateY(0) scale(0.98);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

/* 右下角遊戲說明 */
.game-info-corner {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: rgba(0, 0, 0, 0.7);
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(0, 191, 255, 0.3);
    color: #00bfff;
    max-width: 250px;
    text-align: left;
    z-index: 100;
    transition: transform 0.3s, box-shadow 0.3s;
}

.game-info-corner:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 30px rgba(0, 191, 255, 0.4);
}

.game-info-content {
    display: flex;
    flex-direction: column;
}

.game-info-content h3 {
    color: #4CA6B0;
    margin-bottom: 15px;
    font-size: 22px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.game-info-content p {
    margin-bottom: 10px;
    font-size: 16px;
    line-height: 1.6;
}

/* 大魏老師資訊課程按鈕樣式 */
.course-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 20px;
    padding: 10px 15px;
    background-color: rgba(0, 191, 255, 0.3);
    color: #fff;
    text-decoration: none;
    border-radius: 8px;
    font-size: 16px;
    transition: all 0.3s ease;
    border: 1px solid rgba(0, 191, 255, 0.5);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    text-align: center;
    width: 100%;
    overflow: visible;
    white-space: nowrap;
}

.course-btn:hover {
    background-color: rgba(0, 191, 255, 0.5);
    transform: translateY(-3px);
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.4);
}

.course-btn:active {
    transform: translateY(0) scale(0.98);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.teacher-icon {
    font-size: 18px;
    margin-right: 8px;
    display: inline-block;
    animation: floatEffect 3s ease-in-out infinite;
}

.teacher-text {
    display: inline-block;
    vertical-align: middle;
    white-space: nowrap;
    overflow: visible;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.7);
}

/* 模態對話框樣式 */
.modal {
    display: none;
    position: fixed;
    z-index: 1;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.7);
}

.modal-content {
    background-color: #1a2639;
    margin: 15% auto;
    padding: 20px;
    border: 1px solid rgba(0, 191, 255, 0.5);
    width: 80%;
    max-width: 500px;
    border-radius: 10px;
    box-shadow: 0 5px 25px rgba(0, 191, 255, 0.3);
    color: #ffffff;
}

.close-btn {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close-btn:hover,
.close-btn:focus {
    color: #00bfff;
    text-decoration: none;
}

.difficulty-options {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 20px;
}

.difficulty-options button {
    width: 100%;
    margin: 5px;
    background-color: rgba(0, 191, 255, 0.3);
    color: white;
    border: 1px solid rgba(0, 191, 255, 0.5);
    padding: 10px;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s;
}

.difficulty-options button:hover {
    background-color: rgba(0, 191, 255, 0.5);
}

.selected {
    background-color: rgba(0, 191, 255, 0.7) !important;
    font-weight: bold;
}

/* 遊戲結束畫面 */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 10;
    border-radius: 15px;
}

.screen h1 {
    font-size: 36px;
    margin-bottom: 20px;
    color: #00bfff;
    text-shadow: 0 0 10px rgba(0, 191, 255, 0.7);
}

.screen p {
    font-size: 20px;
    margin: 10px 0;
    color: #ffffff;
}

@keyframes floatEffect {
    0% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
    100% { transform: translateY(0); }
}

/* 移動設備適配 */
@media (max-width: 768px) {
    .game-container {
        padding: 10px;
    }
    
    h1 {
        font-size: 1.5em;
    }
    
    #hudOverlay div {
        font-size: 14px;
        padding: 5px 10px;
    }
    
    .game-info-corner {
        padding: 15px;
        bottom: 10px;
        right: 10px;
        max-width: 200px;
    }
    
    .game-info-content h3 {
        font-size: 18px;
    }
    
    .game-info-content p {
        font-size: 14px;
    }
    
    .course-btn {
        font-size: 14px;
    }
    
    .modal-content {
        width: 90%;
        margin: 30% auto;
    }
    
    #mute-btn {
        font-size: 16px;
        padding: 3px 8px;
    }
    
    .floating-text {
        font-size: 18px;
    }
}

@media (max-width: 480px) {
    .game-info-corner {
        max-width: 160px;
    }
    
    .teacher-text {
        font-size: 12px;
        white-space: nowrap;
        line-height: 1.2;
    }
}

/* 飄動文字樣式 */
.floating-text {
    position: absolute;
    font-size: 24px;
    font-weight: bold;
    text-shadow: 0 0 10px rgba(0, 0, 0, 0.8), 0 0 5px rgba(255, 255, 255, 0.5);
    pointer-events: none;
    z-index: 50;
    white-space: nowrap;
    opacity: 0;
    animation: floatingTextAnimation 3s ease-in-out forwards;
    letter-spacing: 1px;
    font-family: 'Arial', 'Microsoft JhengHei', sans-serif;
}

@keyframes floatingTextAnimation {
    0% {
        transform: translateY(0) scale(0.5) rotate(-5deg);
        opacity: 0;
    }
    10% {
        opacity: 1;
    }
    50% {
        transform: translateY(-40px) scale(1.3) rotate(5deg);
        opacity: 1;
    }
    90% {
        opacity: 0.9;
    }
    100% {
        transform: translateY(-80px) scale(1) rotate(-2deg);
        opacity: 0;
    }
}

/* 專家模式特定樣式 */
.expert-mode {
    /* 增加滾動提示的箭頭 */
    position: relative;
    -webkit-overflow-scrolling: touch; /* 確保iOS上滾動流暢 */
    scroll-behavior: smooth; /* 平滑滾動 */
    scrollbar-width: auto; /* 確保Firefox上滾動條可見 */
    scrollbar-color: rgba(0, 191, 255, 0.7) rgba(0, 0, 0, 0.3); /* Firefox滾動條顏色 */
    max-height: 70vh !important; /* 確保在所有設備上都能看到適當的內容 */
    max-width: 95vw !important; /* 確保可以水平捲動查看所有內容 */
    overflow: auto !important; /* 強制啟用所有方向的捲動 */
}

.expert-mode::before {
    content: "";
    position: absolute;
    width: 100%;
    height: 30px;
    bottom: 0;
    left: 0;
    background: linear-gradient(transparent, rgba(0, 191, 255, 0.2));
    pointer-events: none;
    z-index: 5;
}

.expert-mode::after {
    content: ""; 
    position: absolute;
    width: 30px;
    height: 100%;
    right: 0;
    top: 0;
    background: linear-gradient(to left, rgba(0, 191, 255, 0.2), transparent);
    pointer-events: none;
    z-index: 5;
}

/* 專家模式對於大螢幕的優化 */
@media (min-width: 1025px) {
    .expert-mode {
        max-height: 75vh !important; /* 大螢幕上給更多顯示空間 */
        max-width: 85vw !important; /* 大螢幕上控制最大寬度 */
    }
    
    /* 為大螢幕也啟用滾動控制按鈕 */
    .scroll-controls {
        display: flex;
    }
    
    /* 增強滾動條視覺效果在大螢幕上 */
    .game-area::-webkit-scrollbar {
        width: 16px;
        height: 16px;
    }
    
    .game-area::-webkit-scrollbar-thumb {
        background: rgba(0, 191, 255, 0.8);
        border-radius: 8px;
        border: 2px solid rgba(0, 0, 0, 0.3);
    }
    
    /* 調整大螢幕上滾動按鈕的位置 */
    #scroll-left {
        left: 20px;
        bottom: 20px;
    }
    
    #scroll-right {
        left: auto;
        right: 20px;
        bottom: 20px;
    }
    
    #scroll-up {
        right: 20px;
        bottom: 80px;
    }
    
    #scroll-down {
        right: 20px;
        bottom: 140px;
    }
}

.scroll-hint {
    animation: flashHint 1.5s infinite alternate;
    box-shadow: 0 0 10px rgba(0, 191, 255, 0.7);
    font-size: 16px !important; /* 確保提示文字足夠大 */
    padding: 8px 15px !important; /* 增大提示框 */
    background-color: rgba(0, 0, 0, 0.8) !important; /* 加深背景以增強可讀性 */
}

@keyframes flashHint {
    0% { background-color: rgba(0, 0, 0, 0.7); }
    100% { background-color: rgba(0, 191, 255, 0.7); }
}

/* 替代的信息按鈕 - 小螢幕使用 */
.info-icon {
    display: none;
    position: fixed;
    bottom: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
    background-color: rgba(0, 191, 255, 0.7);
    border-radius: 50%;
    text-align: center;
    line-height: 40px;
    font-size: 24px;
    color: white;
    cursor: pointer;
    z-index: 100;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
    animation: pulseAnimation 2s infinite;
}

/* 滾動控制按鈕 - 小螢幕使用 */
.scroll-controls {
    display: none;
    position: fixed;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 110;
    flex-direction: column;
    gap: 10px;
}

.scroll-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: rgba(0, 191, 255, 0.7);
    color: white;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
    border: none;
    transition: all 0.2s;
}

.scroll-btn:active {
    transform: scale(0.95);
    background-color: rgba(0, 191, 255, 0.9);
}

/* 為水平滾動按鈕添加特定樣式 */
#scroll-left, #scroll-right {
    width: 40px;
    height: 40px;
    position: fixed;
    top: auto;
    bottom: 20px;
    z-index: 110;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(0, 191, 255, 0.8);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
}

#scroll-left {
    right: auto;
    left: 20px;
}

#scroll-right {
    right: auto;
    left: 70px;
}

/* 小螢幕適配增強 */
@media (max-width: 768px) {
    /* ... existing code ... */
    
    /* 增強滾動條可見性 */
    .game-area::-webkit-scrollbar {
        width: 18px;
        height: 18px;
    }
    
    .game-area::-webkit-scrollbar-thumb {
        background: rgba(0, 191, 255, 0.9);
        border-radius: 9px;
        border: 2px solid rgba(255, 255, 255, 0.3);
    }

    /* 顯示滾動控制按鈕 */
    .scroll-controls {
        display: flex;
    }
    
    /* 專家模式特別調整 */
    .expert-mode {
        max-height: 70vh !important; /* 確保在小螢幕上有足夠的空間 */
    }
    
    /* 調整按鈕位置以方便操作 */
    #scroll-left {
        bottom: 80px;
        left: 15px;
    }
    
    #scroll-right {
        bottom: 80px;
        left: auto;
        right: 15px;
    }
    
    #scroll-up, #scroll-down {
        width: 45px;
        height: 45px;
        font-size: 24px;
    }
}

/* 更小螢幕適配增強 */
@media (max-width: 480px) {
    /* ... existing code ... */
    
    /* 專家模式特別調整 */
    .expert-mode {
        max-height: 60vh !important; /* 確保在更小螢幕上有足夠的空間 */
    }
    
    /* 強化滾動提示效果 */
    .scroll-hint {
        padding: 10px !important;
        font-size: 18px !important;
        background-color: rgba(0, 0, 0, 0.9) !important;
        border: 1px solid rgba(0, 191, 255, 0.8);
    }
    
    /* 調整所有滾動按鈕位置 */
    #scroll-left {
        left: 10px;
        bottom: 70px;
    }
    
    #scroll-right {
        right: 10px;
        bottom: 70px;
    }
    
    #scroll-up {
        right: 10px;
        bottom: 125px;
    }
    
    #scroll-down {
        right: 10px;
        bottom: 15px;
    }
} 