:root {
    --bg: #f5f5f7;
    --card: #ffffff;
    --card-2: #fbfbfd;
    --text: #1d1d1f;
    --text-2: #6e6e73;
    --text-3: #86868b;
    --border: rgba(0, 0, 0, 0.08);
    --border-strong: rgba(0, 0, 0, 0.12);
    --accent: #007aff;
    --accent-hover: #0066d6;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
    --radius: 16px;
    --radius-sm: 10px;
    --blur-bg: rgba(255, 255, 255, 0.72);
    --checker-1: #e9e9ee;
    --checker-2: #f5f5f7;
    --dropdown-hover-bg: #e5e5ea;
}

html[data-theme="dark"] {
    --bg: #1c1c1e;
    --card: #2c2c2e;
    --card-2: #3a3a3c;
    --text: #f5f5f7;
    --text-2: #aeaeb2;
    --text-3: #8e8e93;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.15);
    --accent: #0a84ff;
    --accent-hover: #409cff;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --blur-bg: rgba(28, 28, 30, 0.72);
    --checker-1: #2a2a2c;
    --checker-2: #1c1c1e;
    --dropdown-hover-bg: #4a4a4c;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    transition: background 0.4s cubic-bezier(0.4, 0, 0.2, 1), color 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
}

input,
select {
    font-family: inherit;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--blur-bg);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid var(--border);
    z-index: 100;
    flex-shrink: 0;
    position: relative;
}

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

.logo {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: linear-gradient(135deg, #007aff, #5856d6);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 16px;
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.4);
}

.title {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.02em;
    white-space: nowrap;
}

.actions {
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 101;
}

.btn {
    padding: 8px 16px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
}

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

.btn-primary:active {
    transform: translateY(0);
}

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

.btn-ghost:hover {
    background: var(--card-2);
}

.btn-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
}

.btn-icon:hover {
    background: var(--card-2);
    transform: translateY(-1px);
}

.btn-icon svg {
    width: 18px;
    height: 18px;
    pointer-events: none;
}

.dropdown {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--blur-bg);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 6px;
    min-width: 160px;
    box-shadow: var(--shadow);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px) scale(0.96);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 200;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.dropdown.open .dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.dropdown-menu button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 12px;
    border-radius: 9px;
    font-size: 14px;
    color: var(--text);
    text-align: left;
    transition: background 0.2s, color 0.2s;
    background: transparent;
    border: none;
    cursor: pointer;
}

.dropdown-menu button:hover {
    background: var(--dropdown-hover-bg);
}

/* 当前选中项 – 排它状态 */
.dropdown-menu button.active {
    background: var(--accent);
    color: #fff;
    cursor: default;
    pointer-events: none;
    opacity: 0.85;
}

.dropdown-menu button.active:hover {
    background: var(--accent);
}

.dropdown-menu button svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    pointer-events: none;
}

.dropdown-arrow {
    flex-shrink: 0;
    margin-left: 2px;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.dropdown.open .dropdown-arrow {
    transform: rotate(180deg);
}

.workspace {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

.sidebar {
    width: 340px;
    background: var(--blur-bg);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    flex-shrink: 0;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 3px;
}

.panel {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.panel-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-2);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 12px;
}

.upload-area {
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--card-2);
    position: relative;
    z-index: 5;
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--accent);
    background: rgba(0, 122, 255, 0.06);
}

.upload-area .icon {
    width: 40px;
    height: 40px;
    margin: 0 auto 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    border-radius: 12px;
    color: var(--accent);
    pointer-events: none;
}

.upload-area .icon svg {
    width: 22px;
    height: 22px;
}

.upload-area .text {
    font-size: 13px;
    color: var(--text-2);
    pointer-events: none;
}

.upload-area .text strong {
    color: var(--accent);
    font-weight: 600;
}

.upload-area .hint {
    font-size: 11px;
    color: var(--text-3);
    margin-top: 4px;
    pointer-events: none;
}

.file-info {
    display: none;
    background: var(--card-2);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 13px;
    margin-bottom: 10px;
    align-items: center;
    gap: 10px;
}

.file-info.show {
    display: flex;
}

.file-info .file-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--accent), #5856d6);
    color: #fff;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.file-info .file-icon svg {
    width: 16px;
    height: 16px;
}

.file-info .file-name {
    flex: 1;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-info .file-meta {
    font-size: 11px;
    color: var(--text-3);
    margin-top: 1px;
}

.file-info .file-remove {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    z-index: 6;
}

.file-info .file-remove:hover {
    background: rgba(255, 59, 48, 0.15);
    color: #ff3b30;
}

.file-info .file-remove svg {
    width: 12px;
    height: 12px;
    pointer-events: none;
}

.tab-switch {
    display: flex;
    background: var(--card-2);
    padding: 3px;
    border-radius: 10px;
}

.tab-switch button {
    flex: 1;
    padding: 7px 12px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-2);
    border-radius: 8px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
}

.tab-switch button.active {
    background: var(--card);
    color: var(--text);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.form-group {
    margin-bottom: 14px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-2);
    margin-bottom: 6px;
}

.form-label .value {
    color: var(--accent);
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    font-size: 12px;
}

.form-input,
.form-select {
    width: 100%;
    padding: 9px 12px;
    background: var(--card-2);
    border: 1px solid var(--border);
    border-radius: 9px;
    color: var(--text);
    font-size: 14px;
    transition: all 0.2s;
    outline: none;
}

.form-input:focus,
.form-select:focus {
    border-color: var(--accent);
    background: var(--card);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15);
}

.form-select {
    appearance: none;
    background-image: url("../resources/img/down_arrow.svg");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 14px;
    padding-right: 32px;
    cursor: pointer;
}

.form-range {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: var(--border-strong);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.form-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid var(--border-strong);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    transition: transform 0.15s;
}

.form-range::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.form-range::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid var(--border-strong);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    cursor: pointer;
}

.color-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.color-input {
    width: 36px;
    height: 36px;
    border-radius: 9px;
    border: 2px solid var(--border);
    cursor: pointer;
    background: none;
    padding: 0;
    overflow: hidden;
    flex-shrink: 0;
}

.color-input::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-input::-webkit-color-swatch {
    border: none;
    border-radius: 7px;
}

.color-input::-moz-color-swatch {
    border: none;
    border-radius: 7px;
}

.color-hex {
    flex: 1;
    text-transform: uppercase;
    font-family: ui-monospace, "SF Mono", monospace;
    font-size: 13px;
}

.color-presets {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

.color-presets button {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid var(--card);
    box-shadow: 0 0 0 1px var(--border);
    cursor: pointer;
    transition: transform 0.2s;
    padding: 0;
}

.color-presets button:hover {
    transform: scale(1.15);
}

.switch {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 24px;
}

.switch input {
    display: none;
}

.switch-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--border-strong);
    border-radius: 12px;
    transition: 0.3s;
}

.switch-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

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

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

.range-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.layout-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.layout-grid button {
    padding: 8px 4px;
    font-size: 12px;
    background: var(--card-2);
    border-radius: 8px;
    color: var(--text-2);
    border: 1px solid var(--border);
    transition: all 0.2s;
    font-weight: 500;
    cursor: pointer;
}

.layout-grid button.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    box-shadow: 0 2px 6px rgba(0, 122, 255, 0.3);
}

.canvas-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    position: relative;
    min-width: 0;
    z-index: 1;
}

.canvas-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    background: var(--blur-bg);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 2;
}

.canvas-toolbar .divider {
    width: 1px;
    height: 20px;
    background: var(--border);
    margin: 0 4px;
}

.canvas-toolbar .spacer {
    flex: 1;
}

.zoom-display {
    font-size: 13px;
    color: var(--text-2);
    font-variant-numeric: tabular-nums;
    min-width: 50px;
    text-align: center;
    font-weight: 500;
}

.page-nav {
    display: flex;
    align-items: center;
    gap: 6px;
}

.page-info {
    font-size: 13px;
    color: var(--text-2);
    font-variant-numeric: tabular-nums;
    min-width: 40px;
    text-align: center;
}

.canvas-container {
    flex: 1;
    overflow: hidden;
    position: relative;
    cursor: grab;
    background-image: linear-gradient(45deg, var(--checker-1) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker-1) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker-1) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker-1) 75%);
    background-size: 24px 24px;
    background-position: 0 0, 0 12px, 12px -12px, -12px 0px;
    background-color: var(--checker-2);
    z-index: 1;
}

.canvas-container.dragging {
    cursor: grabbing;
}

.canvas-container canvas {
    position: absolute;
    top: 50%;
    left: 50%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
    border-radius: 2px;
    transform-origin: center center;
    pointer-events: none;
}

.canvas-empty {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    color: var(--text-3);
    text-align: center;
    pointer-events: none;
    z-index: 0;
}

.canvas-empty .big-icon {
    width: 72px;
    height: 72px;
    background: var(--card);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
    color: var(--accent);
}

.canvas-empty .big-icon svg {
    width: 32px;
    height: 32px;
}

.canvas-empty h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-2);
}

.canvas-empty p {
    font-size: 13px;
    max-width: 280px;
    line-height: 1.5;
}

.mobile-toggle {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #5856d6);
    color: #fff;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(0, 122, 255, 0.4);
    z-index: 90;
    transition: transform 0.3s;
    cursor: pointer;
}

.mobile-toggle:active {
    transform: scale(0.9);
}

.mobile-toggle svg {
    width: 24px;
    height: 24px;
    pointer-events: none;
}

.toast-container {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    pointer-events: none;
}

.toast {
    padding: 12px 20px;
    background: var(--blur-bg);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    font-size: 14px;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
    animation: toastIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    max-width: 90vw;
}

.toast .icon {
    font-weight: 700;
    font-size: 16px;
}

.toast.success .icon {
    color: #34c759;
}

.toast.error .icon {
    color: #ff3b30;
}

.toast.info .icon {
    color: var(--accent);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 999;
}

.loading-overlay.show {
    display: flex;
}

.loading-card {
    background: var(--card);
    padding: 28px 36px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow);
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
}

.spinner {
    width: 26px;
    height: 26px;
    border: 3px solid var(--border-strong);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@media (max-width: 1024px) {
    .sidebar {
        width: 300px;
        padding: 16px;
        gap: 12px;
    }
}

@media (max-width: 768px) {
    .topbar {
        padding: 10px 14px;
    }

    .title {
        font-size: 15px;
    }

    .actions .btn {
        padding: 7px 12px;
        font-size: 13px;
    }

    .sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 78vh;
        border-right: none;
        border-top: 1px solid var(--border);
        border-radius: 20px 20px 0 0;
        transform: translateY(100%);
        z-index: 95;
        box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.18);
        padding: 12px 16px 30px;
    }

    .sidebar.open {
        transform: translateY(0);
    }

    .sidebar::before {
        content: '';
        display: block;
        width: 40px;
        height: 4px;
        background: var(--border-strong);
        border-radius: 2px;
        margin: 0 auto 14px;
    }

    .mobile-toggle {
        display: flex;
    }

    .canvas-toolbar {
        padding: 8px 12px;
        gap: 4px;
        flex-wrap: wrap;
    }

    .canvas-toolbar .btn-icon {
        width: 32px;
        height: 32px;
    }

    .canvas-toolbar .btn-icon svg {
        width: 16px;
        height: 16px;
    }

    .dropdown-menu {
        min-width: 140px;
    }

    .canvas-empty .big-icon {
        width: 60px;
        height: 60px;
    }

    .canvas-empty h3 {
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .actions .btn-text {
        display: none;
    }

    .actions .btn {
        padding: 7px 10px;
    }

    .logo {
        width: 28px;
        height: 28px;
    }

    /* 移动端下拉菜单右对齐更舒服 */
    .dropdown-menu {
        right: 0;
        left: auto;
        min-width: 140px;
    }
}

.hidden {
    display: none !important;
}