:root {
    --primary-color: #7ED9C3;
    --primary-hover: #6BC7B1;
    --accent-color: #FFB7B2;
    --bg-color: #F9FBFB;
    --card-bg: #FFFFFF;
    --text-main: #4A4A4A;
    --text-light: #9B9B9B;
    --shadow: 0 10px 30px rgba(126, 217, 195, 0.15);
    --radius: 20px;
}

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

body {
    font-family: 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    overflow: hidden;
}

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

/* --- 头部 --- */
.app-header {
    height: 70px;
    background: var(--card-bg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 40px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.02);
    z-index: 100;
}

.logo { display: flex; align-items: center; }
.logo-img { height: 40px; width: auto; object-fit: contain; }
.logo span { color: var(--accent-color); }
.header-tips { font-size: 14px; color: var(--text-light); }

/* --- 主内容区 --- */
.app-main {
    flex: 1;
    display: flex;
    padding: 20px;
    gap: 20px;
    background: linear-gradient(135deg, #f5fcf9 0%, #ffffff 100%);
    overflow: hidden;
}

/* --- 画布区域 (PC) --- */
.canvas-section {
    flex: 1;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.canvas-wrapper {
    width: 800px;
    height: 800px;
    background: white;
    box-shadow: 0 10px 30px rgba(0,0,0,0.05);
    flex-shrink: 0;
}

/* --- 左侧布贴库 (PC) --- */
.sidebar {
    width: 400px;
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

/* --- 右侧操作面板 (PC) --- */
.right-panel {
    width: 130px;
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 20px 12px;
    gap: 10px;
    flex-shrink: 0;
    overflow: visible;
}
.right-panel .canvas-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.right-panel .btn-small {
    width: 100%;
    text-align: center;
    padding: 10px 8px;
    font-size: 13px;
}
.right-panel #finish-btn {
    width: 100%;
    padding: 12px 8px;
    font-size: 13px;
}

.category-selector {
    padding: 20px;
    border-bottom: 1px solid #f9f9f9;
}

.custom-select {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #f0f0f0;
    border-radius: 12px;
    cursor: pointer;
    appearance: none;
    background: #fafafa url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23666' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E") no-repeat right 15px center;
}

.sticker-library {
    flex: 1;
    padding: 12px 16px;
    overflow-y: auto;
}

.sticker-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.sticker-item {
    aspect-ratio: 1;
    background: #fcfcfc;
    border: 2px solid #f5f5f5;
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s;
    padding: 10px;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.sticker-item:hover {
    border-color: var(--primary-color);
    transform: translateY(-3px);
}

.sticker-item img { 
    width: 100%; 
    height: 100%; 
    object-fit: contain; 
}

/* 手机端专属抽屉按钮 (在 PC 默认隐藏) */
.drawer-toggle-btn {
    display: none !important;
}

/* 二级尺寸选择器 (首页) */
.inline-size-selector {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #f9f9f9;
}

.size-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid #f0f0f0;
    background: white;
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.size-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    transform: scale(1.1);
}

/* 颜色选择器 (设计页) */
.color-selector-section {
    padding: 15px 20px;
    border-bottom: 1px solid #f9f9f9;
}

.section-title {
    font-size: 13px;
    font-weight: 600;
    color: #4f5d73;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.color-grid {
    display: flex;
    gap: 12px;
}

.color-dot {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid #fff;
    box-shadow: 0 0 0 1px #eee;
    transition: all 0.3s;
}

.color-dot.active {
    box-shadow: 0 0 0 2px var(--primary-color);
    transform: scale(1.1);
}

/* --- PC: canvas-controls 默认水平排列（移动端覆盖） --- */
.canvas-controls {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
}

.btn {
    padding: 12px 20px;
    border-radius: 50px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 14px;
    text-align: center;
}

.btn-primary { background: var(--primary-color); color: white; width: 100%; }
.btn-outline { background: white; border: 2px solid #f0f0f0; color: var(--text-light); flex: 1; }
.btn-danger { color: #FF8B94 !important; }
.btn-outline:hover { border-color: var(--primary-color); color: var(--primary-color); }

/* --- 载体选择页面 (PC) --- */
.selection-screen {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #f5fdfb 0%, #f0f4ff 50%, #fff9f5 100%);
    z-index: 5000;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* 背景光晕装饰 */
.selection-screen::before, .selection-screen::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    z-index: -1;
    opacity: 0.4;
}

.selection-screen::before {
    width: 400px; height: 400px;
    background: var(--primary-color);
    top: -100px; left: -100px;
    animation: float 15s infinite alternate;
}

.selection-screen::after {
    width: 300px; height: 300px;
    background: #ffd1dc;
    bottom: -50px; right: -50px;
    animation: float 20s infinite alternate-reverse;
}

@keyframes float {
    from { transform: translate(0, 0) scale(1); }
    to { transform: translate(100px, 50px) scale(1.15); }
}

.selection-content {
    width: 100%;
    max-width: 1200px;
    padding: 40px;
    text-align: center;
    z-index: 1;
}

.selection-title {
    font-size: 38px;
    font-weight: 800;
    margin-bottom: 50px;
    color: var(--text-main);
    letter-spacing: -1px;
}

.carrier-options { display: flex; gap: 30px; justify-content: center; }

.carrier-card {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.5);
    padding: 35px;
    border-radius: 35px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.03);
    transition: all 0.5s cubic-bezier(0.23, 1, 0.32, 1);
    flex: 1;
    max-width: 320px;
    min-height: 340px; /* 固定最小高度，保证所有卡片一致 */
    text-align: center;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

.carrier-card:hover {
    transform: translateY(-15px);
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 25px 50px rgba(0,0,0,0.08);
    border-color: var(--primary-color);
}

.carrier-preview {
    background: #fdfdfd;
    border-radius: 20px;
    margin-bottom: 25px;
    height: 200px; /* 固定高度，统一所有载体预览区域 */
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.5s;
    overflow: hidden;
    flex-shrink: 0;
}

.carrier-card:hover .carrier-preview { transform: scale(1.05); }
.carrier-preview img {
    max-width: 85%;
    max-height: 85%;
    width: auto;
    height: auto;
    object-fit: contain;
    filter: drop-shadow(0 5px 15px rgba(0,0,0,0.05));
}

.card-color-dots {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 15px;
    flex-wrap: wrap;
}

.card-color-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.1);
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.05);
}

.en-title {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-light);
    margin-top: 5px;
    font-weight: 500;
}

.bandana-color-hint {
    margin-top: 24px;
    text-align: center;
}

.bandana-color-hint .section-title {
    margin-bottom: 12px;
}

.bandana-color-dots {
    justify-content: center;
}

/* --- 响应式适配 (移动端) --- */
@media (max-width: 768px) {
    .app-header { display: none; }

    /* 手机端解锁滚动限制 */
    body {
        overflow: hidden;
    }
    .app-container {
        height: 100dvh;
        min-height: 100dvh;
        overflow: hidden;
    }

    /* 主容器：改成网格，画布固定，布贴区吃剩余高度 */
    .app-main {
        display: grid;
        grid-template-rows: auto 100vw auto minmax(0, 1fr);
        padding: 0;
        gap: 0;
        min-height: 0;
        overflow: hidden;
        background: #fdfdfd;
    }

    body.drawer-open {
        overflow: hidden;
    }

    /* sidebar 扁平化，子元素直接参与主容器的 flex 排序 */
    .sidebar { display: contents; }

    /* 手机端工具条：固定在顶部，优先放常用操作 */
    .right-panel {
        order: 1;
        position: static;
        width: 100%;
        padding: 6px 12px 6px;
        background: rgba(255, 255, 255, 0.96);
        backdrop-filter: blur(14px);
        border-radius: 0;
        box-shadow: 0 2px 10px rgba(0,0,0,0.06);
        border-bottom: 1px solid #f0f0f0;
        display: flex;
        flex-direction: column;
        gap: 6px;
        flex-shrink: 0;
        z-index: 20;
    }

    /* 手机端颜色选择器：内嵌在 right-panel 顶部，与按钮合并为一条工具栏 */
    .color-selector-section {
        order: unset;
        padding: 0;
        background: transparent;
        border-bottom: none;
        display: flex;
        align-items: center;
        gap: 10px;
        flex-shrink: 0;
        width: 100%;
        z-index: unset;
    }
    /* 手机端：颜色标题保留，标题与颜色点改为上下排版 */
    .color-selector-section .section-title { display: none; }
    .color-selector-section .color-grid { gap: 8px; flex-wrap: wrap; }
    .color-selector-section .color-dot { width: 22px; height: 22px; }

    .right-panel .canvas-controls {
        flex-direction: row;
        flex: 1;
        gap: 5px;
        width: 100%;
    }
    .right-panel .btn-small { padding: 8px 6px; font-size: 11px; width: auto; flex: 1; min-height: 40px; }
    .right-panel #finish-btn { display: none; }

    /* 画布区域：优先展示，紧跟在工具条下方 */
    .canvas-section {
        order: 3;
        flex-shrink: 0;
        flex-grow: 0;    /* 覆盖PC端 flex:1 的 flex-grow:1，防止扩张 */
        height: 100vw;
        min-height: 0;
        border-radius: 0;
        box-shadow: none;
        padding: 0;
        width: 100%;
        overflow: hidden;
        background: #f7f7f7;
        align-items: center;
        justify-content: center;
        touch-action: none;
    }

    .canvas-wrapper {
        width: 800px !important;
        height: 800px !important;
        background: white;
        box-shadow: 0 10px 30px rgba(0,0,0,0.05) !important;
        transform-origin: top left;
        /* 关键：负 margin-bottom 折叠多余的布局高度 */
        margin-bottom: calc(100vw - 800px);
        touch-action: none;
    }

    .canvas-wrapper canvas {
        touch-action: none;
        -webkit-user-drag: none;
        user-select: none;
    }

    /* 分类选择器：紧跟在画布后面，负责切换素材分类 */
    .category-selector {
        order: 4;
        position: static;
        z-index: 1;
        width: 100%;
        min-height: 0;
        padding: 10px 12px;
        background: white;
        border-top: 1px solid #eee;
        border-bottom: 1px solid #f5f5f5;
        border-radius: 0;
        box-shadow: none;
        display: flex;
        align-items: center;
        gap: 10px;
        flex-shrink: 0;
    }
    .category-selector .custom-select { flex: 1; padding: 10px 12px; font-size: 13px; }

    /* 展开按钮 */
    .drawer-toggle-btn {
        display: flex !important;
        background: var(--primary-color);
        color: white;
        border: none;
        padding: 10px 12px;
        border-radius: 20px;
        font-size: 11px;
        font-weight: bold;
        cursor: pointer;
        white-space: nowrap;
        box-shadow: 0 4px 8px rgba(32, 201, 151, 0.2);
        align-items: center;
        justify-content: center;
    }

    /* 布贴库：正常流，固定高度，内部可滚动 */
    .sticker-library {
        order: 5;
        position: static;
        width: 100%;
        min-height: 0;
        height: auto;
        align-self: stretch;
        padding: 10px 12px 12px;
        background: white;
        overflow-y: auto;
        flex-shrink: 0;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        transition: height 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.1);
    }

    /* 展开状态：布贴库覆盖画布区域 */
    .sidebar.expanded .sticker-library {
        position: fixed;
        left: 0;
        right: 0;
        top: calc(var(--sticker-overlay-top, 0px) + var(--sticker-selector-height, 0px));
        bottom: 0;
        height: auto;
        z-index: 999;
        border-top: 1px solid #ececec;
        border-radius: 12px 12px 0 0;
        box-shadow: 0 -14px 34px rgba(0, 0, 0, 0.14);
    }

    .sidebar.expanded .category-selector {
        position: fixed;
        left: 0;
        right: 0;
        top: var(--sticker-overlay-top, 0px);
        z-index: 1000;
        margin: 0;
        background: rgba(255, 255, 255, 0.98);
        box-shadow: 0 8px 18px rgba(0, 0, 0, 0.08);
        filter: none;
    }

    .sidebar.expanded .canvas-section {
        filter: blur(1px);
    }

    .sidebar.expanded .canvas-section {
        pointer-events: none;
    }

    .sticker-grid { 
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 8px;
    }
    .sticker-item { padding: 5px; border-radius: 12px; }

    .sticker-library::-webkit-scrollbar {
        width: 6px;
    }

    .sticker-library::-webkit-scrollbar-thumb {
        background: rgba(126, 217, 195, 0.55);
        border-radius: 999px;
    }

    /* 首页适配 */
    .selection-screen { display: block; overflow-y: auto; padding: 32px 16px; }
    .carrier-options { flex-direction: column; align-items: center; gap: 20px; }
    .carrier-card { max-width: 100%; width: 100%; }
    .selection-title { font-size: 26px; margin-bottom: 24px; text-align: center; }
    .bandana-color-hint { margin-top: 18px; }
    .color-selector-section {
        padding: 10px 12px 8px;
        background: rgba(255, 255, 255, 0.96);
        border-bottom: 1px solid #f0f0f0;
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    .color-selector-section .section-title {
        display: block;
        margin-bottom: 0;
        font-size: 12px;
        color: #3f4a5d;
    }
    .color-selector-section .color-grid {
        width: 100%;
        gap: 8px;
        flex-wrap: wrap;
    }
    .color-selector-section .color-dot {
        width: 22px;
        height: 22px;
    }
    .right-panel {
        padding: 4px 10px 4px;
        gap: 4px;
    }
    .color-selector-section {
        padding: 2px 0;
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 8px;
        width: 100%;
    }
    .color-selector-section .section-title {
        display: block;
        margin: 0;
        font-size: 11px;
        line-height: 1;
        letter-spacing: .6px;
        color: #3f4a5d;
        white-space: nowrap;
        flex: 0 0 auto;
    }
    .color-selector-section .color-grid {
        width: 100%;
        gap: 6px;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        flex: 1 1 auto;
        min-width: 0;
        padding-bottom: 2px;
    }
    .color-selector-section .color-dot {
        width: 22px;
        height: 22px;
        flex: 0 0 auto;
    }
    .right-panel .canvas-controls {
        gap: 4px;
    }
    .right-panel .btn-small {
        padding: 7px 6px;
        min-height: 38px;
    }
}

/* 动画 */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.8); z-index: 2000; backdrop-filter: blur(5px); }
.modal-content { background: white; margin: 10vh auto; padding: 30px; border-radius: 30px; width: 90%; max-width: 500px; text-align: center; position: relative; }
.preview-image-container img { max-width: 100%; border-radius: 15px; }
.size-badge-overlay {
    position: absolute;
    bottom: 10px;
    right: 15px;
    font-size: 32px;
    font-weight: 900;
    color: var(--primary-color);
    opacity: 0.2;
    pointer-events: none;
}

.carrier-preview {
    position: relative;
    background: #f9f9f9;
    border-radius: 20px;
    margin-bottom: 20px;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.fadeIn {
    animation: fadeIn 0.5s ease forwards;
}

.close-modal { position: absolute; right: 20px; top: 15px; font-size: 24px; cursor: pointer; }

/* 引导层样式 */
.guide-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.5s ease;
}

.guide-content {
    background: white;
    padding: 30px;
    border-radius: 20px;
    text-align: center; /* 确保文字居中 */
    max-width: 80%;
}

.hand-icon {
    font-size: 40px;
    margin-bottom: 10px;
}
