/* ===================== 基础变量 ===================== */
:root {
    --bg: #0f1115;
    --bg-elev: #181b22;
    --bg-elev2: #20242e;
    --panel: #1c1f28;
    --border: #2a2f3a;
    --border-light: #343a48;
    --text: #e8eaf0;
    --text-muted: #9aa3b2;
    --text-dim: #6b7384;
    --primary: #5b8cff;
    --primary-hover: #4a7bf0;
    --primary-soft: rgba(91, 140, 255, 0.15);
    --danger: #ff5b6e;
    --success: #34c759;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    --transition: 0.2s ease;
}

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

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Inter', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
}

.hidden { display: none !important; }

/* ===================== 顶部导航 ===================== */
.topbar {
    height: 64px;
    flex-shrink: 0;
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), #7a5cff);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: #fff;
    box-shadow: 0 4px 12px rgba(91, 140, 255, 0.4);
}

.brand-text h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.3px;
}

.brand-text span {
    font-size: 12px;
    color: var(--text-muted);
}

.topbar-actions {
    display: flex;
    gap: 10px;
}

/* ===================== 按钮 ===================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

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

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

.btn-primary:not(:disabled):hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(91, 140, 255, 0.4);
}

.btn-ghost {
    background: var(--bg-elev2);
    color: var(--text);
    border: 1px solid var(--border-light);
}

.btn-ghost:not(:disabled):hover {
    background: var(--border);
    border-color: var(--primary);
    color: var(--primary);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

/* ===================== 主布局 ===================== */
.layout {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* ===================== 左侧面板 ===================== */
.panel {
    width: 360px;
    flex-shrink: 0;
    background: var(--bg-elev);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.panel::-webkit-scrollbar { width: 6px; }
.panel::-webkit-scrollbar-track { background: transparent; }
.panel::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }

.panel-section {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-title i {
    color: var(--primary);
    font-size: 14px;
}

/* ===================== 上传区 ===================== */
.drop-zone {
    border: 2px dashed var(--border-light);
    border-radius: var(--radius);
    padding: 28px 16px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--bg-elev2);
}

.drop-zone:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
}

.drop-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-soft);
    transform: scale(1.01);
}

.drop-zone-content i {
    font-size: 32px;
    color: var(--primary);
    margin-bottom: 10px;
}

.drop-zone-title {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
}

.drop-zone-hint {
    font-size: 12px;
    color: var(--text-dim);
}

/* ===================== 表单控件 ===================== */
.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.field-row {
    display: flex;
    gap: 12px;
}

.field-row .field { flex: 1; }

.field-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

textarea, select, input[type="text"] {
    width: 100%;
    background: var(--bg-elev2);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color var(--transition);
    resize: vertical;
}

textarea:focus, select:focus, input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239aa3b2' d='M6 8L2 4h8z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

/* ===================== 滑块 ===================== */
.slider-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.slider-value {
    font-size: 12px;
    color: var(--primary);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    background: var(--border-light);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 3px solid var(--bg-elev);
    box-shadow: 0 0 0 1px var(--primary);
    transition: transform var(--transition);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 3px solid var(--bg-elev);
    box-shadow: 0 0 0 1px var(--primary);
}

/* ===================== 模式标签 ===================== */
.mode-tabs {
    display: flex;
    gap: 8px;
    background: var(--bg-elev2);
    padding: 4px;
    border-radius: var(--radius-sm);
}

.mode-tab {
    flex: 1;
    padding: 9px 8px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.mode-tab i { font-size: 16px; }

.mode-tab.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(91, 140, 255, 0.35);
}

.mode-tab:not(.active):hover {
    color: var(--text);
    background: var(--border);
}

/* ===================== 子选项 ===================== */
.sub-options {
    margin-top: 4px;
    padding: 14px;
    background: var(--bg-elev2);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 12px;
    animation: slideDown 0.2s ease;
}

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

/* ===================== 位置网格 ===================== */
.position-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 4px;
}

.pos-btn {
    aspect-ratio: 1;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    background: var(--bg-elev2);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.pos-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.pos-btn.active {
    background: var(--primary-soft);
    border-color: var(--primary);
    color: var(--primary);
}

/* ===================== 颜色控件 ===================== */
.color-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

input[type="color"] {
    width: 40px;
    height: 36px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    cursor: pointer;
    background: var(--bg-elev2);
    padding: 3px;
}

input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 4px; }

.color-presets {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    flex: 1;
}

.color-preset {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid var(--border-light);
    cursor: pointer;
    transition: transform var(--transition);
    padding: 0;
}

.color-preset:hover {
    transform: scale(1.18);
    border-color: var(--primary);
}

.color-chip {
    width: 14px;
    height: 14px;
    border-radius: 4px;
    border: 1px solid var(--border-light);
    display: inline-block;
}

/* ===================== 开关 ===================== */
.switch-row {
    display: flex !important;
    flex-direction: row !important;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}

.switch {
    position: relative;
    width: 40px;
    height: 22px;
    display: inline-block;
}

.switch input { opacity: 0; width: 0; height: 0; }

.switch-slider {
    position: absolute;
    inset: 0;
    background: var(--border-light);
    border-radius: 11px;
    cursor: pointer;
    transition: background var(--transition);
}

.switch-slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform var(--transition);
}

.switch input:checked + .switch-slider {
    background: var(--primary);
}

.switch input:checked + .switch-slider::before {
    transform: translateX(18px);
}

/* ===================== 预览区 ===================== */
.preview-area {
    flex: 1;
    overflow: hidden;
    position: relative;
    background:
        radial-gradient(circle at 50% 0%, rgba(91,140,255,0.06), transparent 60%),
        var(--bg);
    display: flex;
    flex-direction: column;
}

.preview-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px;
    gap: 8px;
}

.empty-illustration {
    width: 120px;
    height: 120px;
    border-radius: 30px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.empty-illustration i {
    font-size: 48px;
    color: var(--text-dim);
}

.preview-empty h2 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 4px;
}

.preview-empty p {
    color: var(--text-muted);
    margin-bottom: 20px;
    line-height: 1.7;
}

.preview-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.preview-toolbar {
    height: 52px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elev);
}

.preview-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
}

.preview-info i {
    color: var(--success);
}

.canvas-stage {
    flex: 1;
    overflow: auto;
    padding: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.canvas-stage::-webkit-scrollbar { width: 8px; height: 8px; }
.canvas-stage::-webkit-scrollbar-track { background: transparent; }
.canvas-stage::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 4px; }

#canvas {
    max-width: 100%;
    max-height: 100%;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    background: #fff;
}

/* 棋盘格背景，显示透明区域 */
.canvas-stage::before {
    content: '';
    position: absolute;
    inset: 52px 0 0 0;
    background-image:
        linear-gradient(45deg, #1a1d25 25%, transparent 25%),
        linear-gradient(-45deg, #1a1d25 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #1a1d25 75%),
        linear-gradient(-45deg, transparent 75%, #1a1d25 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    opacity: 0.3;
    pointer-events: none;
}

/* ===================== Toast ===================== */
.toast {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: var(--bg-elev2);
    border: 1px solid var(--border-light);
    color: var(--text);
    padding: 12px 22px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    box-shadow: var(--shadow);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 100;
    pointer-events: none;
    display: flex;
    align-items: center;
    gap: 10px;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.success { border-color: var(--success); }
.toast.success i { color: var(--success); }
.toast.error { border-color: var(--danger); }
.toast.error i { color: var(--danger); }

/* ===================== 响应式 ===================== */
@media (max-width: 900px) {
    .layout {
        flex-direction: column;
    }

    html, body {
        overflow: auto;
        height: auto;
    }

    .panel {
        width: 100%;
        max-height: none;
        border-right: none;
        border-bottom: 1px solid var(--border);
        order: 2;
    }

    .preview-area {
        order: 1;
        min-height: 50vh;
    }

    .topbar {
        padding: 0 16px;
    }

    .brand-text span { display: none; }

    .topbar-actions .btn span { display: none; }
    .topbar-actions .btn { padding: 9px 12px; }
}

@media (max-width: 480px) {
    .mode-tab span { font-size: 11px; }
    .field-row { flex-direction: column; gap: 8px; }
}
