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

/* 字体导入 */
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&family=Roboto:wght@300;400;500&display=swap');

/* 根变量 */
:root {
    --primary-color: #4a90e2;
    --secondary-color: #f39c12;
    --accent-color: #e74c3c;
    --background-gradient: linear-gradient(135deg, #1e3c72 0%, #2a5298 50%, #1e3c72 100%);
    --glass-bg: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.2);
    --shadow-color: rgba(0, 0, 0, 0.3);
    --text-light: #ffffff;
    --text-dark: #333333;
    --border-radius: 15px;
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --glow-color: rgba(74, 144, 226, 0.6);
}

/* 主体样式 */
body {
    font-family: 'Roboto', sans-serif;
    background: var(--background-gradient);
    background-attachment: fixed;
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
}

/* 背景动画 */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 20% 80%, rgba(120, 119, 198, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(255, 119, 48, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 40% 40%, rgba(120, 119, 198, 0.2) 0%, transparent 50%);
    animation: backgroundFlow 20s ease-in-out infinite;
    z-index: -1;
}

@keyframes backgroundFlow {
    0%, 100% { opacity: 1; transform: translateY(0px); }
    50% { opacity: 0.8; transform: translateY(-10px); }
}

/* 游戏容器 */
#gameContainer {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* 画布样式 */
#canvas {
    border-radius: var(--border-radius);
    box-shadow: 
        0 20px 40px var(--shadow-color),
        0 0 20px rgba(74, 144, 226, 0.3);
    background: transparent;
    transition: var(--transition-smooth);
}

#canvas:hover {
    box-shadow: 
        0 25px 50px var(--shadow-color),
        0 0 30px rgba(74, 144, 226, 0.5);
}

/* 控制面板 */
.controls {
    position: absolute;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 20px;
    z-index: 100;
    padding: 20px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 25px;
    box-shadow: 0 10px 30px var(--shadow-color);
    transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1), 
                transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.selectors-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.settings-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}

/* 骰子类型选择器 */
.dice-type-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-light);
    font-family: 'Orbitron', monospace;
    font-size: 14px;
    font-weight: 500;
}

.dice-type-selector label {
    white-space: nowrap;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.dice-type-selector select {
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-light);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    font-family: 'Orbitron', monospace;
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition-smooth);
    backdrop-filter: blur(10px);
    min-width: 120px;
}

.dice-type-selector select:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--secondary-color);
    box-shadow: 0 0 10px rgba(243, 156, 18, 0.3);
}

.dice-type-selector select:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.2);
    border-color: var(--secondary-color);
    box-shadow: 0 0 15px rgba(243, 156, 18, 0.5);
}

.dice-type-selector option {
    background: rgba(30, 60, 114, 0.95);
    color: var(--text-light);
    padding: 5px;
}

/* 骰子数量选择器 */
.dice-count-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-light);
    font-family: 'Orbitron', monospace;
    font-size: 14px;
    font-weight: 500;
}

.dice-count-selector label {
    white-space: nowrap;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.dice-count-selector select {
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-light);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    font-family: 'Orbitron', monospace;
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition-smooth);
    backdrop-filter: blur(10px);
    min-width: 100px;
}

.dice-count-selector select:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--primary-color);
    box-shadow: 0 0 10px rgba(74, 144, 226, 0.3);
}

.dice-count-selector select:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.2);
    border-color: var(--primary-color);
    box-shadow: 0 0 15px rgba(74, 144, 226, 0.5);
}

/* 开关样式 */
.toggle-switch {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-light);
    font-family: 'Orbitron', monospace;
    font-size: 14px;
    font-weight: 500;
}

.toggle-switch label {
    white-space: nowrap;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.toggle-switch input[type="checkbox"] {
    position: relative;
    width: 50px;
    height: 26px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(0, 0, 0, 0.3);
    outline: none;
    border-radius: 13px;
    cursor: pointer;
    transition: var(--transition-smooth);
    border: 1px solid var(--glass-border);
}

.toggle-switch input[type="checkbox"]::before {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    top: 2px;
    left: 3px;
    background: var(--text-light);
    transition: var(--transition-smooth);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.toggle-switch input[type="checkbox"]:checked {
    background: var(--primary-color);
}

.toggle-switch input[type="checkbox"]:checked::before {
    transform: translateX(23px);
    background: white;
}

.dice-count-selector option {
    background: rgba(30, 60, 114, 0.95);
    color: var(--text-light);
    padding: 5px;
}

/* 按钮样式 */
.btn {
    position: relative;
    padding: 15px 30px;
    color: var(--text-light);
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    font-family: 'Orbitron', monospace;
    letter-spacing: 1px;
    transition: var(--transition-smooth);
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.5s;
}

.btn:hover::before {
    left: 100%;
}

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

/* 投掷按钮样式 */
#rollBtn {
    background: linear-gradient(45deg, var(--primary-color), #2980b9);
    box-shadow: 
        0 4px 15px rgba(74, 144, 226, 0.4),
        inset 0 1px 2px rgba(255, 255, 255, 0.2);
}

#rollBtn:hover {
    transform: translateY(-3px);
    box-shadow: 
        0 8px 25px rgba(74, 144, 226, 0.6),
        0 0 20px rgba(74, 144, 226, 0.4);
}

/* 重置按钮样式 */
#resetBtn {
    background: linear-gradient(45deg, var(--accent-color), #c0392b);
    box-shadow: 
        0 4px 15px rgba(231, 76, 60, 0.4),
        inset 0 1px 2px rgba(255, 255, 255, 0.2);
}

#resetBtn:hover {
    transform: translateY(-3px);
    box-shadow: 
        0 8px 25px rgba(231, 76, 60, 0.6),
        0 0 20px rgba(231, 76, 60, 0.4);
}

/* 按钮禁用状态 */
.btn:disabled {
    background: linear-gradient(45deg, #666666, #555555) !important;
    cursor: not-allowed !important;
    transform: none !important;
    box-shadow: 
        0 2px 8px rgba(0, 0, 0, 0.3),
        inset 0 1px 2px rgba(255, 255, 255, 0.1) !important;
    opacity: 0.6;
}

.btn:disabled:hover {
    transform: none !important;
    box-shadow: 
        0 2px 8px rgba(0, 0, 0, 0.3),
        inset 0 1px 2px rgba(255, 255, 255, 0.1) !important;
}

.btn:disabled::before {
    display: none;
}

/* 投掷中的动画效果 */
.btn.rolling {
    background: linear-gradient(45deg, #f39c12, #e67e22) !important;
    animation: rollingPulse 1s ease-in-out infinite;
    pointer-events: none;
}

@keyframes rollingPulse {
    0%, 100% { 
        transform: scale(1);
        box-shadow: 0 4px 15px rgba(243, 156, 18, 0.4);
    }
    50% { 
        transform: scale(1.05);
        box-shadow: 0 8px 25px rgba(243, 156, 18, 0.6);
    }
}

/* 结果显示 */
.result {
    position: absolute;
    top: 40px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    padding: 20px 40px;
    border-radius: 30px;
    font-size: 24px;
    font-weight: 700;
    font-family: 'Orbitron', monospace;
    color: var(--text-light);
    border: 1px solid var(--glass-border);
    box-shadow: 
        0 10px 30px var(--shadow-color),
        inset 0 1px 2px rgba(255, 255, 255, 0.1);
    opacity: 0;
    transition: var(--transition-smooth);
    text-shadow: 0 2px 10px var(--shadow-color);
}

.result.show {
    opacity: 1;
    animation: resultPulse 2s ease-in-out;
}

@keyframes resultPulse {
    0%, 100% { transform: translateX(-50%) scale(1); }
    50% { transform: translateX(-50%) scale(1.05); }
}

/* 加载提示 */
.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-light);
    font-size: 20px;
    font-family: 'Orbitron', monospace;
    z-index: 1000;
    text-align: center;
    opacity: 0;
    animation: loadingFade 2s ease-in-out infinite;
}

@keyframes loadingFade {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

.loading::after {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    margin-left: 10px;
    border: 2px solid var(--text-light);
    border-top: 2px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 信息面板 */
.info {
    position: absolute;
    top: 30px;
    right: 30px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    padding: 15px 20px;
    border-radius: var(--border-radius);
    color: var(--text-light);
    font-size: 14px;
    line-height: 1.6;
    border: 1px solid var(--glass-border);
    box-shadow: 0 10px 25px var(--shadow-color);
    transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1), 
                transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                background 0.3s ease-out;
    max-height: 45vh;  
    overflow-y: auto; 
    min-width: 250px; 
    max-width: 350px;  
}

.info:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

/* 自定义滚动条样式以匹配整体设计 */
.info::-webkit-scrollbar {
    width: 8px;
}

.info::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.info::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    transition: var(--transition-smooth);
}

.info::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

.info div {
    margin-bottom: 5px;
}

.info div:last-child {
    margin-bottom: 0;
}

/* 版本信息 */
.version {
    position: absolute;
    bottom: 20px;
    right: 20px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 12px;
    font-family: 'Orbitron', monospace;
}

/* 投掷结果表格样式 */
.results-section {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid var(--glass-border);
}

.results-section h3 {
    color: var(--text-light);
    font-family: 'Orbitron', monospace;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.results-table-container {
    max-height: calc(45vh - 120px); 
    overflow-y: auto;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
    color: var(--text-light);
    font-family: 'Roboto', sans-serif;
}

.results-table th {
    background: rgba(74, 144, 226, 0.3);
    padding: 6px 8px;
    text-align: left;
    font-weight: 600;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--glass-border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.results-table td {
    padding: 6px 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    transition: background-color 0.2s ease;
}

.results-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.05);
}

.results-table .no-results td {
    text-align: center;
    font-style: italic;
    color: rgba(255, 255, 255, 0.6);
    padding: 15px;
}

.results-table .roll-number {
    font-weight: 600;
    color: var(--secondary-color);
}

.results-table .dice-result {
    font-weight: 600;
    color: #4CAF50;
}

.results-table .total-sum {
    font-weight: bold;
    color: var(--accent-color);
}

/* 当前结果表格样式 */
.current-results {
    /* margin-top: 15px; */
    padding: 2px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    border: 1px solid var(--glass-border);
}

.current-results h4 {
    margin: 0 0 8px 0;
    font-size: 12px;
    font-weight: 600;
    color: #ffffff;
    text-align: center;
    font-family: 'Orbitron', monospace;
}

.current-results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
    color: var(--text-light);
    font-family: 'Roboto', sans-serif;
}

.current-results-table th {
    background: rgba(74, 144, 226, 0.3);
    padding: 6px 8px;
    text-align: center;
    font-weight: 600;
    font-size: 10px;
    border-bottom: 1px solid var(--glass-border);
}

.current-results-table td {
    padding: 6px 8px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    transition: background-color 0.2s ease;
}

.current-results-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.05);
}

.current-results-table .no-results td {
    text-align: center;
    font-style: italic;
    color: rgba(255, 255, 255, 0.6);
    padding: 10px;
}

.current-results-table .dice-number {
    font-weight: 600;
    color: #ffffff;
}

.current-results-table .dice-value {
    font-weight: 600;
    color: #ffffff;
    font-size: 12px;
}

/* 滚动条样式 */
.results-table-container::-webkit-scrollbar {
    width: 6px;
}

.results-table-container::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.results-table-container::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 3px;
}

.results-table-container::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

/* 响应式设计 */
@media (max-width: 768px) {
    .controls {
        bottom: 20px;
        padding: 15px;
        gap: 15px;
        flex-direction: column;
        align-items: center;
    }
    
    .btn {
        padding: 12px 24px;
        font-size: 14px;
        width: 200px;
    }
    
    /* 移动端优化：简化动画和效果 */
    .btn::before {
        display: none; 
    }
    
    .btn:hover {
        transform: none; 
    }
    
    #rollBtn:hover,
    #resetBtn:hover {
        transform: none;
        box-shadow: 
            0 4px 15px rgba(74, 144, 226, 0.4);
    }
    
    /* 简化投掷动画 */
    @keyframes rollingPulse {
        0%, 100% { 
            transform: scale(1);
            box-shadow: 0 2px 10px rgba(243, 156, 18, 0.3);
        }
        50% { 
            transform: scale(1.02);
            box-shadow: 0 4px 15px rgba(243, 156, 18, 0.5);
        }
    }
    
    .result {
        top: 20px;
        font-size: 18px;
        padding: 15px 25px;
    }
    
    .info {
        top: 20px;
        right: 20px;
        font-size: 12px;
        padding: 10px 15px;
    }
    
    /* 禁用背景动画 */
    body::before {
        animation: none;
        opacity: 0.3;
    }
    
    /* 简化阴影效果 */
    #canvas {
        box-shadow: 0 10px 20px var(--shadow-color);
    }
    
    #canvas:hover {
        box-shadow: 0 10px 20px var(--shadow-color);
    }
}

@media (max-width: 480px) {
    .controls {
        left: 50%;
        transform: translateX(-50%);
        width: 90%;
        max-width: 300px;
    }
    
    .result {
        width: 90%;
        max-width: 300px;
        text-align: center;
    }
    
    .info {
        display: none;
    }
    
    /* 移动端性能优化 */
    * {
        transform: translateZ(0); /* 启用硬件加速 */
        backface-visibility: hidden;
    }
    
    /* 禁用所有复杂动画 */
    .btn::before,
    body::before {
        display: none;
    }
    
    /* 简化渐变背景 */
    body {
        background: #2a5298; 
    }
    
    /* 移动设备性能优化 */
    @media (hover: none) and (pointer: coarse) {
        * {
            -webkit-tap-highlight-color: transparent;
            -webkit-touch-callout: none;
            -webkit-user-select: none;
            user-select: none;
        }
        
        /* 禁用所有hover效果 */
        .btn:hover,
        #rollBtn:hover,
        #resetBtn:hover,
        #canvas:hover,
        .info:hover,
        .results-table tbody tr:hover,
        .current-results-table tbody tr:hover {
            transform: none !important;
            box-shadow: inherit !important;
            background: inherit !important;
        }
        
        /* 简化动画 */
        @keyframes rollingPulse {
            0%, 100% { opacity: 1; }
            50% { opacity: 0.8; }
        }
        
        /* 禁用复杂效果 */
        body::before,
        .btn::before {
            display: none !important;
        }
        
        /* 使用transform3d强制硬件加速 */
        .btn,
        .controls,
        .info,
        .result {
            transform: translate3d(0, 0, 0);
            will-change: auto;
        }
    }
}

/* 高对比度模式 */
@media (prefers-contrast: high) {
    :root {
        --glass-bg: rgba(0, 0, 0, 0.8);
        --glass-border: rgba(255, 255, 255, 0.5);
    }
}

/* 减少动画模式 */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
