* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body {
    background: linear-gradient(135deg, #0f0f1a 0%, #1a1a2e 100%);
    color: #e0e0e0;
    line-height: 1.6;
}

.container {
    display: flex;
    min-height: 100vh;
}

/* —— 侧边栏 —— */
.sidebar {
    width: 260px;
    background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%);
    padding: 24px;
    padding-right: 16px;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    gap: 24px;
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.2);
    transition: width 0.3s ease, padding 0.3s ease;
}

.sidebar.collapsed {
    width: 60px;
    padding: 16px 8px;
}

.sidebar.collapsed .logo,
.sidebar.collapsed .connect-section span:first-child,
.sidebar.collapsed .sidebar-status,
.sidebar.collapsed #keyboardSelect {
    display: none;
}

.sidebar.collapsed .connect-section {
    justify-content: center;
    margin-top: 30px;
}

.sidebar.collapsed .nav-item {
    padding: 12px 8px;
    justify-content: center;
    margin-top: 40px;
}

.sidebar.collapsed .nav-item:first-of-type {
    margin-top: 45px;
}

.sidebar.collapsed .nav-item span {
    display: none;
}

.sidebar.collapsed .nav-item i {
    display: flex;
    font-size: 1.5rem;
}

/* 默认为收起状态 */
.sidebar {
    width: 60px;
    padding: 16px 8px;
}

.sidebar:not(.collapsed) {
    width: 260px;
    padding: 24px;
    padding-right: 16px;
}

/* 收缩按钮 - 书签风格 */
.collapse-btn {
    position: absolute;
    left: 8px;
    top: 8px;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 0;
    background: transparent;
    color: #a0a0a0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 100;
    padding: 0;
    line-height: 1;
}

.collapse-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.collapse-btn:hover {
    color: #6366f1;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    text-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
    padding-left: 40px;
}

.connect-section {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.connect-icon {
    font-size: 1.5rem;
    cursor: pointer;
    transition: transform 0.2s;
}

.connect-icon:hover {
    transform: scale(1.1);
}

.connect-icon.connected {
    color: #4caf50;
}

.sidebar-status {
    font-size: 0.9rem;
    margin-top: 4px;
}

.sidebar-status.connected {
    color: #10b981;
    text-shadow: 0 0 10px rgba(16, 185, 129, 0.3);
}

.sidebar-status.disconnected {
    color: #f43f5e;
}

.nav {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item {
    padding: 12px 14px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.2s;
    color: #a0a0a0;
    font-weight: 500;
}

.nav-item:hover {
    background: rgba(99, 102, 241, 0.2);
    color: #fff;
    transform: translateX(4px);
}

.nav-item.active {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.nav-item i {
    font-size: 1.2rem;
}

/* 主内容区 */
.main {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}

.page {
    display: none;
}

.page.active {
    display: block;
}

.page-content h2 {
    margin-bottom: 20px;
    font-size: 1.5rem;
    font-weight: 600;
    color: #fff;
}

.keyboard-wrapper {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    margin-bottom: 24px;
}

.placeholder {
    color: #888;
    font-style: italic;
    text-align: center;
    padding: 20px;
}

/* 通用设置网格布局 */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 24px;
}

.setting-card {
    padding: 24px;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
}

.card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.card-icon {
    font-size: 1.8rem;
}

.card-header h4 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
    color: #fff;
}

.card-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.setting-row label {
    flex: 1;
    font-weight: 500;
    color: #e0e0e0;
    font-size: 0.95rem;
}

.setting-slider {
    flex: 2;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.setting-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

.setting-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

.setting-value {
    min-width: 60px;
    text-align: right;
    font-family: 'Courier New', monospace;
    color: #6366f1;
    font-weight: 700;
    font-size: 1rem;
}

/* 灯光设置 - 颜色按钮 */
.color-presets {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.color-btn {
    height: 40px;
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.75rem;
    color: white;
    font-weight: 600;
}

.color-btn:hover {
    transform: scale(1.05);
    border-color: rgba(99, 102, 241, 0.5);
}

.color-btn.active {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.3);
}

.color-picker {
    width: 60px;
    height: 40px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    cursor: pointer;
    background: none;
}

/* 层设置 */
.layer-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
}

.layer-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.layer-item:hover {
    background: rgba(99, 102, 241, 0.1);
    border-color: rgba(99, 102, 241, 0.3);
}

.layer-item.active {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(139, 92, 246, 0.2));
    border-color: #6366f1;
}

.layer-name {
    font-weight: 600;
    color: #e0e0e0;
}

.layer-badge {
    padding: 4px 10px;
    background: rgba(99, 102, 241, 0.3);
    color: #fff;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.add-layer-btn {
    width: 100%;
    padding: 12px;
    background: rgba(99, 102, 241, 0.2);
    border: 1px dashed rgba(99, 102, 241, 0.5);
    border-radius: 8px;
    color: #6366f1;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.add-layer-btn:hover {
    background: rgba(99, 102, 241, 0.3);
    border-style: solid;
}

.mapping-info {
    text-align: center;
    padding: 20px;
}

.mapping-info p {
    color: rgba(224, 224, 224, 0.7);
    margin-bottom: 16px;
}

.mapping-status {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
    padding: 12px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
}

.status-dot {
    width: 10px;
    height: 10px;
    background: #f59e0b;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.status-text {
    color: rgba(224, 224, 224, 0.7);
    font-size: 0.9rem;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* 高级键 - 宏命令 */
.macro-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
}

.macro-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
}

.macro-name {
    font-weight: 600;
    color: #e0e0e0;
    font-family: 'Courier New', monospace;
}

.macro-edit {
    padding: 6px 16px;
    background: rgba(99, 102, 241, 0.2);
    border: 1px solid rgba(99, 102, 241, 0.4);
    border-radius: 6px;
    color: #6366f1;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.macro-edit:hover {
    background: rgba(99, 102, 241, 0.3);
}

.add-macro-btn {
    width: 100%;
    padding: 12px;
    background: rgba(99, 102, 241, 0.2);
    border: 1px dashed rgba(99, 102, 241, 0.5);
    border-radius: 8px;
    color: #6366f1;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.add-macro-btn:hover {
    background: rgba(99, 102, 241, 0.3);
    border-style: solid;
}

/* 系统设置 */
.setting-select {
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: #e0e0e0;
    font-size: 0.9rem;
    cursor: pointer;
    outline: none;
    transition: all 0.2s;
}

.setting-select:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(99, 102, 241, 0.5);
}

.setting-select option {
    background: #1a1a2e;
    color: #e0e0e0;
}

/* Toggle 开关 */
.toggle-switch {
    display: flex;
    align-items: center;
    cursor: pointer;
}

.toggle-switch input {
    display: none;
}

.toggle-slider {
    position: relative;
    width: 50px;
    height: 26px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 13px;
    transition: all 0.3s;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    transition: all 0.3s;
}

.toggle-switch input:checked + .toggle-slider {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(24px);
}

.apply-all-btn {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border: none;
    border-radius: 8px;
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.apply-all-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.6);
}

.apply-all-btn:active {
    transform: translateY(0);
}

/* 日志区域 */
.log-section {
    position: fixed;
    bottom: 0;
    right: 0;
    left: 60px;
    background: rgba(0, 0, 0, 0.8);
    padding: 16px 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    max-height: 200px;
    overflow-y: auto;
}

.log-section h2 {
    font-size: 1rem;
    margin-bottom: 12px;
    color: #6366f1;
}

#log {
    width: 100%;
    height: 150px;
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.4);
    color: #a0a0a0;
    font-family: 'Courier New', monospace;
    overflow-y: auto;
    white-space: pre-wrap;
    font-size: 0.85rem;
}

select, button {
    padding: 10px 14px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    color: #e0e0e0;
    font-size: 0.9rem;
    outline: none;
    transition: all 0.2s;
}

select {
    cursor: pointer;
}

select:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(99, 102, 241, 0.5);
}

select option {
    background: #1a1a2e;
    color: #e0e0e0;
}

button {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
    cursor: pointer;
    border: none;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.5);
}

button:active {
    transform: translateY(0);
}
