/* ============ CSS变量与主题 ============ */
:root {
    --bg-primary: #f0f2f5;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-nav: rgba(255, 255, 255, 0.95);
    --text-primary: #2d3436;
    --text-secondary: #636e72;
    --text-muted: #b2bec3;
    --border-color: #dfe6e9;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.15);
    --primary: #6C5CE7;
    --primary-light: #a29bfe;
    --primary-dark: #5a4bd1;
    --accent: #fd79a8;
    --success: #00b894;
    --warning: #fdcb6e;
    --danger: #e17055;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #1e2a4a;
    --bg-nav: rgba(22, 33, 62, 0.95);
    --text-primary: #edf2f7;
    --text-secondary: #a0aec0;
    --text-muted: #718096;
    --border-color: #2d3748;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
}

/* ============ 基础重置 ============ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    transition: var(--transition);
}

/* ============ Toast通知 ============ */
.toast-container {
    position: fixed;
    top: 80px;
    right: 16px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    color: white;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    animation: toastIn 0.3s ease-out;
    pointer-events: auto;
    max-width: 320px;
    word-break: break-word;
}

.toast.success { background: linear-gradient(135deg, #00b894, #00cec9); }
.toast.error { background: linear-gradient(135deg, #e17055, #d63031); }
.toast.info { background: linear-gradient(135deg, #6C5CE7, #a29bfe); }
.toast.warning { background: linear-gradient(135deg, #fdcb6e, #f39c12); color: #2d3436; }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(40px); }
}

/* ============ 彩纸特效 ============ */
.confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
}

/* ============ 应用容器 ============ */
.app-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 0 16px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ============ 顶部导航 ============ */
.top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-primary);
    backdrop-filter: blur(10px);
}

.nav-title {
    font-size: 1.2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.theme-toggle {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    background: var(--bg-card);
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.theme-toggle:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-sm);
}

/* ============ 按钮样式 ============ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    font-family: var(--font-family);
    text-decoration: none;
    white-space: nowrap;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    box-shadow: 0 4px 12px rgba(108, 92, 231, 0.3);
}
.btn-primary:hover { box-shadow: 0 6px 20px rgba(108, 92, 231, 0.4); }

.btn-outline {
    background: transparent;
    border: 1.5px solid var(--border-color);
    color: var(--text-primary);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

.btn-success {
    background: linear-gradient(135deg, #00b894, #00cec9);
    color: white;
}

.btn-warning {
    background: linear-gradient(135deg, #fdcb6e, #f39c12);
    color: #2d3436;
}

.btn-danger {
    background: linear-gradient(135deg, #e17055, #d63031);
    color: white;
}

.btn-sm { padding: 6px 14px; font-size: 0.8rem; }
.btn-lg { padding: 14px 28px; font-size: 1rem; }

/* ============ 模板选择区域 ============ */
.template-section {
    margin-bottom: 16px;
}

.template-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 500;
}

.template-list {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.template-list::-webkit-scrollbar {
    height: 4px;
}

.template-list::-webkit-scrollbar-track {
    background: transparent;
}

.template-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

.template-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-xl);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    font-family: var(--font-family);
}

.template-tab:hover {
    border-color: var(--primary-light);
    color: var(--primary);
    background: rgba(108, 92, 231, 0.05);
}

.template-tab.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    border-color: transparent;
    box-shadow: 0 4px 12px rgba(108, 92, 231, 0.3);
}

.template-tab .tab-icon {
    font-size: 1rem;
}

/* ============ 转盘主区域 ============ */
.wheel-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 10px 0;
    min-height: 300px;
}

.wheel-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

#wheel-canvas {
    display: block;
    transition: none;
}

/* 中心按钮 */
.wheel-center-btn {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: 4px solid white;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    font-size: 0.95rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(108, 92, 231, 0.4), inset 0 2px 4px rgba(255,255,255,0.3);
    transition: var(--transition);
    z-index: 10;
    font-family: var(--font-family);
    letter-spacing: 2px;
}

.wheel-center-btn:hover {
    transform: translate(-50%, -50%) scale(1.08);
    box-shadow: 0 6px 28px rgba(108, 92, 231, 0.5), inset 0 2px 4px rgba(255,255,255,0.3);
}

.wheel-center-btn:active {
    transform: translate(-50%, -50%) scale(0.96);
}

.wheel-center-btn.spinning {
    pointer-events: none;
    opacity: 0.7;
}

/* 指针 */
.wheel-pointer {
    position: absolute;
    top: -5px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    filter: drop-shadow(0 3px 6px rgba(0,0,0,0.3));
}

.pointer-arrow {
    width: 0;
    height: 0;
    border-left: 16px solid transparent;
    border-right: 16px solid transparent;
    border-top: 36px solid #e74c3c;
    position: relative;
}

.pointer-arrow::after {
    content: '';
    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%);
    width: 14px;
    height: 14px;
    background: #e74c3c;
    border-radius: 50%;
    border: 3px solid #c0392b;
}

/* ============ 抽奖历史 ============ */
.history-section {
    margin: 12px 0;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 12px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.history-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-height: 120px;
    overflow-y: auto;
}

.history-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    background: linear-gradient(135deg, rgba(108, 92, 231, 0.1), rgba(253, 121, 168, 0.1));
    border-radius: var(--radius-xl);
    font-size: 0.8rem;
    color: var(--text-secondary);
    border: 1px solid rgba(108, 92, 231, 0.15);
    animation: fadeInScale 0.3s ease-out;
}

.history-item .history-num {
    font-weight: 700;
    color: var(--primary);
    font-size: 0.75rem;
}

@keyframes fadeInScale {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

/* ============ 底部操作栏 ============ */
.bottom-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-top: 1px solid var(--border-color);
    margin-top: auto;
    gap: 8px;
}

.bottom-left, .bottom-right {
    display: flex;
    gap: 6px;
    align-items: center;
}

.bottom-center {
    flex: 1;
    text-align: center;
}

.item-count {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.shortcuts-hint {
    display: flex;
    justify-content: center;
    gap: 16px;
    padding: 8px 0;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.shortcuts-hint kbd {
    display: inline-block;
    padding: 2px 6px;
    font-size: 0.7rem;
    font-family: monospace;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* ============ 弹窗基础 ============ */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
    animation: fadeIn 0.2s ease-out;
    backdrop-filter: blur(4px);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s ease-out;
}

.modal-content.modal-lg {
    max-width: 640px;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--bg-primary);
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: var(--transition);
}

.modal-close:hover {
    background: var(--danger);
    color: white;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
}

/* ============ 结果弹窗 ============ */
.modal-result {
    text-align: center;
}

.result-icon {
    font-size: 4rem;
    margin: 24px 0 8px;
    animation: bounceIn 0.5s ease-out;
}

@keyframes bounceIn {
    0% { opacity: 0; transform: scale(0.3); }
    50% { transform: scale(1.1); }
    70% { transform: scale(0.95); }
    100% { opacity: 1; transform: scale(1); }
}

.result-title {
    font-size: 1.2rem;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.result-display {
    margin: 16px 0 24px;
    padding: 20px;
    background: linear-gradient(135deg, rgba(108, 92, 231, 0.08), rgba(253, 121, 168, 0.08));
    border-radius: var(--radius-md);
    border: 2px solid rgba(108, 92, 231, 0.2);
}

.result-text {
    font-size: 1.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    word-break: break-word;
}

.result-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    padding-bottom: 16px;
}

/* ============ 编辑器 ============ */
.editor-section h3 {
    font-size: 0.95rem;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.content-input-area textarea {
    width: 100%;
    padding: 12px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: var(--font-family);
    resize: vertical;
    transition: var(--transition);
    line-height: 1.6;
}

.content-input-area textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.15);
}

.content-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.item-count-display {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.quick-add {
    display: flex;
    gap: 8px;
}

.quick-add input {
    flex: 1;
    padding: 8px 12px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: var(--font-family);
}

.quick-add input:focus {
    outline: none;
    border-color: var(--primary);
}

/* ============ 设置 ============ */
.setting-item {
    margin-bottom: 16px;
}

.setting-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 0.9rem;
    font-weight: 600;
}

.setting-value {
    font-size: 0.8rem;
    color: var(--primary);
    font-weight: 500;
}

.setting-item input[type="range"] {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border-color);
    border-radius: 3px;
    outline: none;
}

.setting-item input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(108, 92, 231, 0.3);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    color: var(--text-secondary);
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    cursor: pointer;
}

/* 配色方案选择 */
.color-scheme-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.color-scheme-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    font-family: var(--font-family);
}

.color-scheme-btn:hover {
    border-color: var(--primary-light);
}

.color-scheme-btn.active {
    border-color: var(--primary);
    background: rgba(108, 92, 231, 0.08);
    color: var(--primary);
}

.scheme-preview {
    display: flex;
    gap: 2px;
    width: 40px;
    height: 16px;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
}

.scheme-preview::before,
.scheme-preview::after {
    content: '';
    flex: 1;
}

#scheme-vibrant::before { background: linear-gradient(90deg, #e74c3c, #f39c12, #2ecc71, #3498db); }
#scheme-vibrant::after { background: linear-gradient(90deg, #9b59b6, #1abc9c, #e91e63, #ff9800); }

#scheme-pastel::before { background: linear-gradient(90deg, #FFB3BA, #FFDFBA, #FFFFBA, #BAFFC9); }
#scheme-pastel::after { background: linear-gradient(90deg, #BAE1FF, #E8BAFF, #FFB3E6, #B3FFE0); }

#scheme-nature::before { background: linear-gradient(90deg, #27ae60, #2ecc71, #1abc9c, #16a085); }
#scheme-nature::after { background: linear-gradient(90deg, #3498db, #2980b9, #8e44ad, #6C5CE7); }

#scheme-warm::before { background: linear-gradient(90deg, #e74c3c, #e67e22, #f39c12, #fdcb6e); }
#scheme-warm::after { background: linear-gradient(90deg, #d63031, #e17055, #fab1a0, #ff7675); }

/* ============ 模板库网格 ============ */
.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
}

.template-card {
    padding: 16px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    cursor: pointer;
    transition: var(--transition);
}

.template-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.template-card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.template-card-icon {
    font-size: 2rem;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
}

.template-card-info h4 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.template-card-info p {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.template-card-items {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
}

.template-card-tag {
    padding: 2px 8px;
    background: rgba(108, 92, 231, 0.08);
    border-radius: var(--radius-xl);
    font-size: 0.7rem;
    color: var(--text-secondary);
}

/* ============ 文本辅助类 ============ */
.text-muted {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ============ 全屏模式 ============ */
:fullscreen .top-nav,
:fullscreen .template-section,
:fullscreen .bottom-bar,
:fullscreen .shortcuts-hint,
:fullscreen .history-section {
    display: none;
}

:fullscreen .wheel-area {
    min-height: 100vh;
}

:fullscreen .wheel-center-btn {
    width: 90px;
    height: 90px;
    font-size: 1.2rem;
}

/* ============ 响应式设计 ============ */
@media (max-width: 768px) {
    .app-container {
        padding: 0 10px;
    }

    .nav-title {
        font-size: 1rem;
    }

    .template-list {
        gap: 6px;
    }

    .template-tab {
        padding: 6px 12px;
        font-size: 0.8rem;
    }

    .wheel-center-btn {
        width: 60px;
        height: 60px;
        font-size: 0.85rem;
    }

    .pointer-arrow {
        border-left-width: 12px;
        border-right-width: 12px;
        border-top-width: 28px;
    }

    .pointer-arrow::after {
        top: -32px;
        width: 10px;
        height: 10px;
    }

    .modal-content {
        margin: 8px;
    }

    .result-text {
        font-size: 1.2rem;
    }

    .result-icon {
        font-size: 3rem;
    }

    .bottom-bar {
        flex-wrap: wrap;
        gap: 6px;
    }

    .bottom-center {
        order: -1;
        width: 100%;
        flex: none;
    }

    .color-scheme-list {
        grid-template-columns: repeat(2, 1fr);
    }

    .template-grid {
        grid-template-columns: 1fr;
    }

    .shortcuts-hint {
        display: none;
    }
}

@media (max-width: 400px) {
    .wheel-center-btn {
        width: 50px;
        height: 50px;
        font-size: 0.75rem;
    }

    .template-tab .tab-name {
        display: none;
    }

    .template-tab .tab-icon {
        font-size: 1.1rem;
    }

    .btn-sm span {
        display: none;
    }
}

@media (min-width: 1200px) {
    .wheel-center-btn {
        width: 80px;
        height: 80px;
        font-size: 1.05rem;
    }
}

/* ============ 动画 ============ */
@keyframes pulse {
    0%, 100% { transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-50%, -50%) scale(1.05); }
}

.wheel-center-btn:not(.spinning) {
    animation: pulse 2s ease-in-out infinite;
}

/* ============ 打印样式 ============ */
@media print {
    .top-nav, .bottom-bar, .shortcuts-hint, .template-section, .history-section {
        display: none;
    }
}