* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.main-layout {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

.left-col {
    flex: 1 1 540px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.side-panel {
    width: 320px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

@media (max-width: 900px) {
    .main-layout {
        flex-direction: column;
        align-items: center;
    }
    .side-panel {
        width: 100%;
    }
}

body {
    font-family: 'Arial', '微軟正黑體', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.container {
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    padding: 30px;
    max-width: 1100px;
    width: 100%;
}

.header {
    text-align: center;
    margin-bottom: 30px;
}

.header h1 {
    color: #333;
    margin-bottom: 10px;
    font-size: 2em;
}

.instruction {
    color: #666;
    font-size: 0.95em;
    line-height: 1.6;
    margin-bottom: 15px;
}

.game-area {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 16px;
    margin-bottom: 10px;
    background: #f5f5f5;
    padding: 20px;
    border-radius: 10px;
    overflow: hidden;
}

.canvas-container {
    width: 540px;
    height: 540px;
    background: #000;
    border-radius: 5px;
    position: relative;
    overflow: hidden;
}

.canvas-container canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.controls {
    text-align: center;
    margin-bottom: 10px;
    padding: 20px;
    background: #f9f9f9;
    border-radius: 10px;
}

.control-info {
    color: #666;
    margin-bottom: 15px;
    font-size: 0.9em;
}

.mobile-menu-btn, .close-menu-btn {
    display: none;
}

/* 虛擬方向鍵控制 */
.virtual-controls-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
}

.virtual-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    padding: 15px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 300px;
}

.btn-row {
    display: flex;
    gap: 10px;
}

.btn-arrow {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 1.2em;
    cursor: pointer;
    transition: all 0.1s;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    touch-action: none;
}

.btn-arrow:hover {
    transform: scale(1.1);
    box-shadow: 0 3px 10px rgba(102, 126, 234, 0.3);
}

.btn-arrow:active {
    transform: scale(0.95);
}

.btn-up {
    margin-bottom: 10px;
}

.btn-left {
    margin-right: 10px;
}

.btn-right {
    margin-left: 10px;
}

.seed-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.timer-display {
    margin: 10px 0 5px;
    font-weight: bold;
    color: #333;
    font-size: 1.05em;
}

.seed-controls label {
    color: #555;
    font-weight: bold;
}

.seed-controls input {
    padding: 8px 12px;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 0.95em;
    width: 200px;
    transition: border-color 0.2s;
}

.seed-controls input:focus {
    outline: none;
    border-color: #667eea;
}

.btn-generate {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    color: white;
    border: none;
    padding: 8px 20px;
    font-size: 0.95em;
    border-radius: 20px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    font-weight: bold;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.btn-generate:hover {
    transform: translateY(-2px);
    box-shadow: 0 3px 15px rgba(17, 153, 142, 0.4);
}

.btn-generate:active {
    transform: translateY(0);
}

.btn-new-game {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 30px;
    font-size: 1em;
    border-radius: 25px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    font-weight: bold;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.btn-new-game:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}

.btn-new-game:active {
    transform: translateY(0);
}

.stats {
    background: #f0f0f0;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 20px;
}

.stats h2 {
    color: #333;
    font-size: 1.2em;
    margin-bottom: 15px;
}

.time-records {
    background: white;
    padding: 15px;
    border-radius: 8px;
    min-height: 60px;
    color: #666;
    font-size: 0.95em;
    line-height: 1.8;
    white-space: pre-wrap;
    font-family: 'Courier New', monospace;
}

.time-records p {
    color: #999;
}

.time-record-item {
    color: #333;
    padding: 5px 0;
}

.time-record-item .number {
    color: #667eea;
    font-weight: bold;
}

.time-record-item .time {
    color: #764ba2;
    font-weight: bold;
}

.message {
    text-align: center;
    color: #ff6b6b;
    font-size: 1.1em;
    font-weight: bold;
    min-height: 30px;
    padding: 10px;
}

.completion-dialog {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.dialog-content {
    background: white;
    padding: 40px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.dialog-content h2 {
    color: #667eea;
    font-size: 2em;
    margin-bottom: 20px;
}

.completion-text {
    font-size: 1.3em;
    color: #555;
    margin-bottom: 30px;
}

.completion-text span {
    color: #764ba2;
    font-weight: bold;
    font-size: 1.2em;
}

.btn-continue {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 15px 40px;
    font-size: 1.1em;
    border-radius: 30px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    font-weight: bold;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.btn-continue:hover {
    transform: translateY(-3px);
    box-shadow: 0 7px 25px rgba(102, 126, 234, 0.5);
}

.btn-continue:active {
    transform: translateY(-1px);
}


/* 響應式設計 */
@media (max-width: 900px) {
    .canvas-container {
        width: 460px;
        height: 460px;
    }
}

@media (max-width: 700px) {
    .container {
        padding: 15px;
    }

    .header h1 {
        font-size: 1.5em;
    }

    .instruction {
        font-size: 0.85em;
    }

    .game-area {
        flex-direction: column;
        gap: 20px;
    }

    .canvas-container {
        width: 360px;
        height: 360px;
    }

    .btn-arrow {
        width: 45px;
        height: 45px;
        font-size: 1em;
    }
}

@media (max-width: 600px), (max-height: 600px) {
    body {
        align-items: center; /* 恢復居中 */
        padding: 0;
        overflow: hidden; /* 防止滾動 */
    }

    .container {
        padding: 0;
        width: 100vw;
        height: 100vh;
        max-width: none;
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }

    .header, .instruction, .side-panel, .header h1 {
        display: none; /* 在手機全螢幕模式下隱藏非核心元素 */
    }
    
    .main-layout, .left-col {
        width: 100%;
        height: 100%;
        margin: 0;
        gap: 0;
    }

    .game-area {
        width: 100%;
        height: 100%;
        padding: 0;
        border-radius: 0;
        position: relative; /* 為絕對定位做準備 */
        background: black;
    }

    .canvas-container {
        width: 100%;
        height: 100%;
        max-height: none;
    }

    /* 覆蓋式控制介面 */
    .virtual-controls-wrapper {
        position: absolute;
        bottom: 20px;
        left: 0;
        width: 100%;
        pointer-events: none; /* 讓點擊穿透到畫布（如果沒點到按鈕） */
        z-index: 10;
        
        display: flex;
        justify-content: center; /* 預設（直式）置中 */
    }

    /* 橫式螢幕特定調整：按鈕靠右，避免遮擋中央視野 */
    @media (orientation: landscape) {
        .virtual-controls-wrapper {
            justify-content: flex-end; /* 靠右對齊 */
            right: 40px;
            left: auto;
            bottom: 40px;
            width: auto; /* 不再佔滿全寬 */
        }
    }

    .virtual-controls {
        pointer-events: auto; /* 恢復按鈕點擊 */
        background: rgba(255, 255, 255, 0.2);
        backdrop-filter: blur(5px);
        padding: 10px;
        border-radius: 50px;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
        margin: 0 auto;
    }

    .btn-arrow {
        width: 60px;
        height: 60px;
        background: rgba(102, 126, 234, 0.8); /* 半透明按鈕 */
        font-size: 1.5em;
        box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    }
    
    /* 簡易設定按鈕 (覆蓋在右上角) */
    .mobile-menu-btn {
        display: block;
        position: absolute;
        top: 20px;
        right: 20px;
        width: 44px;
        height: 44px;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.8);
        border: none;
        font-size: 1.5em;
        cursor: pointer;
        z-index: 20;
        box-shadow: 0 2px 10px rgba(0,0,0,0.2);
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }

    /* 側邊欄變為全螢幕選單 */
    .side-panel {
        display: none; /* 預設隱藏 */
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: white;
        z-index: 1000;
        padding: 60px 20px 20px;
        overflow-y: auto;
        flex-direction: column;
        align-items: center;
    }

    .side-panel.active {
        display: flex; /* 啟用時顯示 */
        animation: fadeIn 0.3s;
    }

    .close-menu-btn {
        display: block;
        position: absolute;
        top: 20px;
        right: 20px;
        width: 40px;
        height: 40px;
        background: transparent;
        border: none;
        font-size: 1.5em;
        color: #333;
        cursor: pointer;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }

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

    .control-info {
        font-size: 0.8em;
    }
}
