:root {
    --bg-dark: #0f0f1b;
    --panel-bg: rgba(26, 26, 46, 0.7);
    --panel-border: rgba(255, 255, 255, 0.1);
    --text-main: #e2e2e2;
    --accent: #4ecca3;
    --accent-hover: #45b38f;
    --danger: #e94560;
    --danger-hover: #d13d56;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow: hidden;
    /* 防止滾動 */
    width: 100vw;
    height: 100vh;
}

#game-container {
    position: relative;
    width: 100%;
    height: 100%;
}

#canvas-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

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

/* UI 覆蓋層 */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
    /* 讓點擊穿透到 3D 畫布 */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 20px;
}

/* 讓 UI 元素本身可以接收點擊 */
#ui-layer header,
#ui-layer #controls-panel,
#ui-layer #history-panel {
    pointer-events: auto;
}

.modal {
    pointer-events: auto;
}

/* 玻璃擬態樣式 */
.glass-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
}

h1 {
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: 1px;
    background: linear-gradient(90deg, #fff, #4ecca3);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.status-panel {
    font-size: 1.2rem;
    font-weight: bold;
}

#ai-thinking {
    color: var(--accent);
    margin-left: 10px;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        opacity: 0.5;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.5;
    }
}

#controls-panel {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 20px;
}

/* 側邊走步歷史 */
#history-panel {
    position: absolute;
    right: 20px;
    top: 80px;
    width: 200px;
    max-height: calc(100% - 180px);
    overflow-y: auto;
    padding: 15px;
}

#history-panel h3 {
    font-size: 1rem;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--panel-border);
    padding-bottom: 5px;
}

#move-history {
    list-style-position: inside;
    font-size: 0.9rem;
}

#move-history li {
    padding: 4px 0;
    font-family: monospace;
}

/* 按鈕樣式 */
.btn {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    border: 1px solid var(--panel-border);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    backdrop-filter: blur(5px);
}

.btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.btn:active:not(:disabled) {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn.primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.btn.primary:hover {
    background: var(--accent-hover);
}

/* 模態框 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    padding: 30px;
    width: 90%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.modal h2 {
    text-align: center;
    margin-bottom: 10px;
    font-size: 1.5rem;
}

.setting-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

select {
    background: rgba(0, 0, 0, 0.5);
    color: var(--text-main);
    border: 1px solid var(--panel-border);
    padding: 8px;
    border-radius: 4px;
    outline: none;
}

/* 存檔欄位 */
.save-slot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    margin-bottom: 10px;
}

.save-slot .slot-info {
    font-size: 0.9rem;
}

.save-slot .slot-actions {
    display: flex;
    gap: 5px;
}

.hidden {
    display: none !important;
}

/* 手機響應式設計 */
@media (max-width: 768px) {
    #history-panel {
        display: none;
        /* 手機隱藏歷史面板以節省空間 */
    }

    header {
        flex-direction: column;
        gap: 10px;
    }

    h1 {
        font-size: 1.2rem;
    }

    .status-panel {
        font-size: 1rem;
    }

    #controls-panel {
        margin-bottom: 30px;
    }
}