:root {
    --cell-size: 40px;
    --board-gap: 5px;
    --game-padding: 30px;
    --font-heading: 3rem;
}

body {
    font-family: 'Outfit', 'Inter', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    transition: background 0.5s ease;
    padding: 10px;
    box-sizing: border-box;
}

h1 {
    font-size: var(--font-heading);
    color: #2E7D32;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 20px;
    font-weight: 700;
}

#game-container {
    text-align: center;
    background-color: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    padding: var(--game-padding);
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    border: 1px solid rgba(255, 255, 255, 0.5);
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
}

#menu {
    margin-bottom: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

button {
    padding: 12px 25px;
    margin: 8px;
    background: linear-gradient(135deg, #4CAF50, #2E7D32);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    transition: transform 0.2s, box-shadow 0.2s;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.15);
}

#levels {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 15px;
    max-height: 60vh;
    overflow-y: auto;
    padding: 20px;
    justify-items: center;
}

.level-btn {
    width: 50px;
    height: 50px;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: white;
    color: #333;
    border: 2px solid #ddd;
    border-radius: 50%;
    cursor: pointer;
    font-weight: bold;
    font-size: 16px;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 4px 0 #ddd;
}

.level-btn:hover:not(.locked) {
    transform: scale(1.1) translateY(-2px);
    box-shadow: 0 6px 0 #bbb;
    background-color: #f0f0f0;
}

.level-btn.locked {
    background-color: #eee;
    color: #aaa;
    border-color: #ddd;
    box-shadow: none;
    cursor: not-allowed;
    opacity: 0.7;
}

.level-btn.completed {
    background: linear-gradient(135deg, #FFD700, #FFA500);
    color: white;
    border-color: #FFD700;
    box-shadow: 0 4px 0 #CC8400;
}

#board {
    display: grid;
    /* 由 JS 動態設定 --cols 與 --rows */
    grid-template-columns: repeat(var(--cols, 10), var(--cell-size));
    grid-template-rows: repeat(var(--rows, 10), var(--cell-size));
    gap: var(--board-gap);
    margin: 20px auto;
    border: 2px solid #333;
    padding: 10px;
    background-color: #87CEEB;
    width: fit-content;
    border-radius: 8px;
    overflow: hidden;
}

.island {
    background-color: #8B4513;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 3px solid transparent;
}

.island.selected {
    transform: scale(1.1);
    box-shadow: 0 0 15px #FFD700;
    border-color: #FFD700;
}

.bridge {
    position: relative;
    background-color: transparent; /* 讓背景透明，使用偽元素畫線 */
}

.bridge::before {
    content: '';
    position: absolute;
    background-color: #654321;
    z-index: 1;
}

.bridge.horizontal::before {
    height: 4px;
    width: 100%;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
}

.bridge.vertical::before {
    width: 4px;
    height: 100%;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
}

.bridge.double.horizontal::after {
    content: '';
    position: absolute;
    top: calc(50% - 6px);
    left: 0;
    right: 0;
    height: 4px;
    background-color: #654321;
}

/* 修正原生 horizontal double */
.bridge.double.horizontal::before {
    top: calc(50% + 2px);
}

.bridge.double.vertical::after {
    content: '';
    position: absolute;
    top: 0;
    left: calc(50% - 6px);
    bottom: 0;
    width: 4px;
    background-color: #654321;
}

/* 修正原生 vertical double */
.bridge.double.vertical::before {
    left: calc(50% + 2px);
}

#shop-modal, #how-to-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(15px);
    padding: 30px;
    border-radius: 24px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.2);
    z-index: 1000;
    width: 80%;
    max-width: 500px;
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.modal-content h2 {
    color: #2E7D32;
    margin-top: 0;
}

.instruction-body {
    text-align: left;
    margin: 20px 0;
    line-height: 1.6;
}

.instruction-body ul {
    padding-left: 20px;
}

.instruction-body li {
    margin-bottom: 8px;
}

/* 遊戲開場動畫樣式 */
#intro-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #000;
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-family: 'Outfit', sans-serif;
    overflow: hidden;
}

#intro-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
}

.intro-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 2s ease-in-out;
}

.intro-img.show {
    opacity: 1;
}

#intro-content {
    max-width: 80%;
    text-align: center;
    font-size: 1.8rem;
    line-height: 2;
    letter-spacing: 2px;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    padding: 40px;
    border-radius: 30px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    z-index: 10;
}

.intro-line {
    opacity: 0;
    transform: translateY(20px);
    transition: all 1.5s ease;
    margin-bottom: 20px;
}

.intro-line.show {
    opacity: 1;
    transform: translateY(0);
}

#skip-intro {
    position: absolute;
    bottom: 30px;
    left: 30px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 14px;
    color: #ccc;
    cursor: pointer;
    transition: all 0.3s;
}

#skip-intro:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.shop-item {
    margin: 10px 0;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
}

.shop-item button {
    margin-left: 10px;
}

/* 自定義彈窗 (Modal) 樣式 */
#custom-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
}

#custom-modal-content {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(240, 248, 255, 0.9));
    padding: 30px;
    border-radius: 20px;
    width: 90%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.4);
    animation: modalSlideIn 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

#custom-modal-title {
    margin-top: 0;
    color: #2c5282;
    font-size: 1.5rem;
    margin-bottom: 15px;
    font-weight: 700;
}

#custom-modal-message {
    font-size: 1.1rem;
    color: #4a5568;
    margin-bottom: 30px;
    line-height: 1.5;
}

#custom-modal-buttons {
    display: flex;
    justify-content: center;
    gap: 20px;
}

#custom-modal-buttons button {
    padding: 12px 30px;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    font-weight: 700;
    font-size: 1rem;
    transition: all 0.2s;
}

#custom-modal-ok {
    background: linear-gradient(135deg, #4299e1, #3182ce);
    color: white;
    box-shadow: 0 4px 10px rgba(66, 153, 225, 0.3);
}

#custom-modal-ok:hover {
    box-shadow: 0 6px 15px rgba(66, 153, 225, 0.4);
    transform: translateY(-2px);
}

#custom-modal-cancel {
    background: #edf2f7;
    color: #4a5568;
}

#custom-modal-cancel:hover {
    background: #e2e8f0;
    transform: translateY(-2px);
}

#custom-modal-buttons button:active {
    transform: scale(0.95);
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: scale(0.9) translateY(-20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* RWD Media Queries */
@media (max-width: 768px) {
    :root {
        --font-heading: 2rem;
        --game-padding: 20px;
    }
}

@media (max-width: 480px) {
    :root {
        --cell-size: 30px;
        --board-gap: 3px;
        --font-heading: 1.5rem;
    }
    
    #game-container {
        padding: 15px 10px;
    }

    #board {
        padding: 5px;
    }

    /* 針對 12x12 隱藏關卡在小螢幕進一步縮小 */
    #board[style*="--cols: 12"] {
        --cell-size: 25px;
    }

    #levels {
        grid-template-columns: repeat(4, 1fr);
    }

    #skip-intro {
        bottom: auto;
        top: 20px;
        left: auto;
        right: 20px;
        background: rgba(0, 0, 0, 0.5); /* 提高透明底板辨識度 */
        z-index: 50; /* 確保在 intro-content 之上 */
    }

    .level-btn {
        width: 45px;
        height: 45px;
    }
}

.hidden-forced {
    display: none !important;
}
