:root {
    --bg-color: #1e1e1e;
    --panel-bg: rgba(30, 30, 30, 0.85);
    --text-color: #ffffff;
    --primary-color: #007bff;
    --accent-color: #00bcd4;
    --border-radius: 12px;
}

body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #111;
    color: var(--text-color);
}

#container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

#ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Let clicks pass through to 3D canvas */
    z-index: 2;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    /* 从顶部开始排列 */
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
}

.panel {
    background: var(--panel-bg);
    backdrop-filter: blur(10px);
    padding: 15px 20px;
    border-radius: var(--border-radius);
    pointer-events: auto;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    max-width: 500px;
    margin: 0 auto;
    transition: all 0.3s ease;
}

/* 填色向导面板 - 移至右侧不遮挡 */
.wizard-panel {
    position: absolute;
    right: 30px;
    top: 50%;
    transform: translateY(-50%);
    width: 300px;
    background: rgba(40, 40, 40, 0.95);
    /* 稍微深一点，避免干扰 */
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.header-panel {
    display: none;
    /* 隐藏标题 */
    text-align: center;
    margin-top: 10px;
}

.header-panel h1 {
    margin: 0 0 5px 0;
    font-size: 1.5rem;
    font-weight: 600;
}

.header-panel p {
    margin: 0;
    font-size: 0.9rem;
    color: #aaa;
}

.controls-panel {
    margin-top: 10px;
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.solution-panel {
    margin-bottom: 20px;
    text-align: center;
}

/* 教学面板样式 */
.tutorial-panel {
    position: fixed;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    width: 320px;
    text-align: left;
    z-index: 100;
}

.tutorial-header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    padding-bottom: 10px;
    margin-bottom: 15px;
}

.tutorial-header span {
    font-size: 0.8rem;
    color: var(--accent-color);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.tutorial-header h3 {
    margin: 5px 0 0 0;
    font-size: 1.3rem;
    font-weight: 600;
}

.tutorial-content {
    margin-bottom: 15px;
}

.tutorial-content p {
    font-size: 0.9rem;
    line-height: 1.5;
    color: #ccc;
    margin: 0 0 12px 0;
}

.formula-box {
    background: rgba(0, 0, 0, 0.4);
    border-radius: 8px;
    padding: 12px;
    margin-top: 10px;
}

.formula-label {
    font-size: 0.75rem;
    color: #888;
    display: block;
    margin-bottom: 5px;
}

.formula-box code {
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 1.1rem;
    color: var(--accent-color);
    letter-spacing: 2px;
}

.tutorial-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.tutorial-actions button {
    flex: 1;
}

.tutorial-nav {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.tutorial-nav button {
    flex: 1;
}

#btn-tutorial-exit {
    width: 100%;
    margin-top: 5px;
}

#color-palette {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.color-option {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.2s;
}

.color-option:hover {
    transform: scale(1.1);
}

.color-option.selected {
    border-color: #fff;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
    transform: scale(1.2);
}

.buttons {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

button {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
    background: #444;
    color: #fff;
}

button:hover {
    background: #555;
    transform: translateY(-1px);
}

button.primary {
    background: var(--primary-color);
}

button.primary:hover {
    background: #0056b3;
}

button.secondary {
    background: transparent;
    border: 1px solid #555;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.step-display {
    margin-bottom: 15px;
}

#step-count {
    display: block;
    font-size: 0.8rem;
    color: #888;
    margin-bottom: 5px;
}

#step-instruction {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--accent-color);
    margin: 0;
}

/* ========== 视角旋转控制条 ========== */

#rotation-controls {
    pointer-events: none;
}

/* 通用旋转条样式 */
.rotation-bar {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.7);
    padding: 8px 12px;
    border-radius: 25px;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
}

/* 水平旋转条 - 靠近魔方底部 */
.rotation-bar.horizontal-bar {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
}

/* 垂直旋转条 - 靠近魔方左侧 */
.rotation-bar.vertical-bar {
    position: fixed;
    left: 300px;
    top: 55%;
    transform: translateY(-50%);
    flex-direction: column;
    padding: 12px 8px;
}

/* 旋转按钮 */
.rotate-btn {
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: 50%;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    transition: all 0.2s ease;
}

.rotate-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.rotate-btn:active {
    transform: scale(0.95);
}

/* 水平滑杆 */
.horizontal-bar input[type="range"] {
    width: 180px;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    cursor: pointer;
    outline: none;
}

.horizontal-bar input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--accent-color);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 188, 212, 0.5);
    transition: transform 0.15s ease;
}

.horizontal-bar input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

/* 垂直滑杆 */
.vertical-bar input[type="range"] {
    writing-mode: vertical-lr;
    direction: rtl;
    width: 6px;
    height: 120px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    cursor: pointer;
    outline: none;
}

.vertical-bar input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--accent-color);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 188, 212, 0.5);
}

/* ========== 移动端响应式布局 ========== */

/* 平板和小屏幕 (max-width: 768px) */
@media screen and (max-width: 768px) {
    #ui-overlay {
        padding: 10px;
    }

    .panel {
        padding: 10px 15px;
        max-width: 100%;
    }

    .header-panel h1 {
        font-size: 1.2rem;
    }

    .header-panel p {
        font-size: 0.8rem;
    }

    /* 向导面板移到底部 */
    .wizard-panel {
        position: fixed;
        right: 10px;
        top: auto;
        bottom: 80px;
        transform: none;
        width: calc(100% - 20px);
        max-width: 350px;
    }

    /* 色板按钮变小 */
    .color-option {
        width: 30px;
        height: 30px;
    }

    /* 按钮变小 */
    button {
        padding: 8px 12px;
        font-size: 0.85rem;
    }

    /* 控制面板固定到底部，不遮挡魔方 */
    .controls-panel {
        position: fixed;
        bottom: 50px;
        left: 10px;
        right: 10px;
        max-width: none;
        margin: 0;
        padding: 10px;
        gap: 8px;
    }

    /* 解法面板也固定到底部 */
    .solution-panel {
        position: fixed;
        bottom: 50px;
        left: 10px;
        right: 10px;
        max-width: none;
        margin: 0;
    }

    /* 水平旋转条 */
    .rotation-bar.horizontal-bar {
        bottom: 10px;
        padding: 6px 10px;
    }

    .horizontal-bar input[type="range"] {
        width: 140px;
    }

    /* 垂直旋转条 */
    .rotation-bar.vertical-bar {
        left: 10px;
        padding: 10px 6px;
    }

    .vertical-bar input[type="range"] {
        height: 100px;
    }

    .rotate-btn {
        width: 26px;
        height: 26px;
        font-size: 10px;
    }
}

/* 手机竖屏 (max-width: 480px) */
@media screen and (max-width: 480px) {
    .header-panel h1 {
        font-size: 1rem;
    }

    /* 色板按钮更小 */
    .color-option {
        width: 26px;
        height: 26px;
    }

    #color-palette {
        gap: 6px;
    }

    /* 按钮堆叠 */
    .buttons {
        gap: 6px;
    }

    button {
        padding: 6px 10px;
        font-size: 0.8rem;
    }

    /* 水平旋转条更紧凑 */
    .horizontal-bar input[type="range"] {
        width: 100px;
    }

    /* 垂直旋转条更紧凑 */
    .vertical-bar input[type="range"] {
        height: 80px;
    }

    .rotate-btn {
        width: 24px;
        height: 24px;
        font-size: 9px;
    }

    /* 向导面板全宽 */
    .wizard-panel {
        right: 5px;
        left: 5px;
        width: auto;
        max-width: none;
        bottom: 70px;
    }

    /* 控制面板 */
    .controls-panel {
        margin-bottom: 10px;
        gap: 10px;
    }

    /* 解法面板 */
    .solution-panel {
        margin-bottom: 10px;
    }

    #step-instruction {
        font-size: 1rem;
    }
}

/* 横屏模式 */
@media screen and (max-height: 500px) and (orientation: landscape) {
    .header-panel {
        display: none;
    }

    .controls-panel,
    .solution-panel {
        position: fixed;
        bottom: 10px;
        right: 10px;
        left: auto;
        width: 280px;
        margin: 0;
    }

    .wizard-panel {
        top: 10px;
        bottom: auto;
        right: 10px;
        width: 250px;
    }

    .rotation-bar.vertical-bar {
        left: 10px;
        top: 50%;
    }

    .rotation-bar.horizontal-bar {
        bottom: 10px;
        left: 50%;
    }
}