/* CSS 变量定义 */
:root {
    --primary-color: #ff6b6b;
    --secondary-color: #4ecdc4;
    --accent-color: #45b7d1;
    --background-color: #f8f9fa;
    --text-color: #2c3e50;
    --success-color: #27ae60;
    --warning-color: #f39c12;
    --error-color: #e74c3c;
    --border-color: #dee2e6;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --wheel-bg: #ffffff;
    --pointer-color: #e74c3c;
}

/* 基础重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Microsoft YaHei', '微软雅黑', Arial, sans-serif;
    background: linear-gradient(135deg, var(--background-color) 0%, #e3f2fd 100%);
    color: var(--text-color);
    line-height: 1.6;
    min-height: 100vh;
}

/* 应用容器 */
.app-container {
    display: grid;
    grid-template-areas: 
        "header header"
        "main sidebar";
    grid-template-columns: 1fr 300px;
    grid-template-rows: auto 1fr;
    min-height: 100vh;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    gap: 20px;
}

/* 头部 */
.app-header {
    grid-area: header;
    text-align: center;
    padding: 20px 0;
    background: var(--wheel-bg);
    border-radius: 15px;
    box-shadow: 0 4px 20px var(--shadow-color);
}

.app-header h1 {
    font-size: 2.5rem;
    color: var(--primary-color);
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

.subtitle {
    color: var(--text-color);
    font-size: 1.1rem;
    opacity: 0.8;
}

/* 主要内容区域 */
.main-content {
    grid-area: main;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--wheel-bg);
    border-radius: 15px;
    box-shadow: 0 4px 20px var(--shadow-color);
    padding: 40px 20px;
    position: relative;
}

/* 转盘容器 */
.wheel-container {
    position: relative;
    margin-bottom: 30px;
}

#wheelCanvas {
    border-radius: 50%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    background: var(--wheel-bg);
    transition: transform 0.3s ease;
}

#wheelCanvas:hover {
    transform: scale(1.02);
}

/* 转盘指针 */
.wheel-pointer {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 15px solid transparent;
    border-right: 15px solid transparent;
    border-top: 30px solid var(--pointer-color);
    z-index: 10;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

/* 控制按钮 */
.controls {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
}

.spin-btn, .spin-again-btn {
    padding: 15px 30px;
    font-size: 1.2rem;
    font-weight: bold;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.spin-btn {
    background: linear-gradient(45deg, var(--primary-color), var(--warning-color));
    color: white;
}

.spin-again-btn {
    background: linear-gradient(45deg, var(--secondary-color), var(--accent-color));
    color: white;
}

.spin-btn:hover, .spin-again-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.spin-btn:active, .spin-again-btn:active {
    transform: translateY(0);
}

.spin-btn:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
    transform: none;
}

/* 结果显示 */
.result-display {
    text-align: center;
    padding: 20px;
    background: linear-gradient(135deg, var(--success-color), var(--secondary-color));
    border-radius: 15px;
    color: white;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    animation: fadeInUp 0.5s ease;
}

.result-display h2 {
    margin-bottom: 15px;
    font-size: 1.5rem;
}

.selected-food {
    font-size: 2rem;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

/* 侧边栏 */
.sidebar {
    grid-area: sidebar;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.panel {
    background: var(--wheel-bg);
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 4px 20px var(--shadow-color);
}

.panel h3 {
    margin-bottom: 15px;
    color: var(--primary-color);
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 8px;
}

.panel-btn {
    width: 100%;
    padding: 12px;
    background: linear-gradient(45deg, var(--accent-color), var(--secondary-color));
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.panel-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(69, 183, 209, 0.3);
}

/* 菜品编辑器 */
.food-editor {
    margin-top: 15px;
}

.food-list {
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 15px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
}

.food-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    margin: 5px 0;
    background: var(--background-color);
    border-radius: 6px;
    transition: all 0.2s ease;
}

.food-item:hover {
    background: var(--border-color);
}

.food-name {
    flex-grow: 1;
}

.delete-food {
    background: var(--error-color);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 0.8rem;
}

.add-food {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

#newFoodInput {
    flex-grow: 1;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
}

#addFoodBtn {
    padding: 10px 15px;
    background: var(--success-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

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

.editor-actions button {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

#resetFoodsBtn {
    background: var(--warning-color);
    color: white;
}

#closeFoodEditorBtn {
    background: var(--text-color);
    color: white;
}

/* 历史记录面板 */
.history-panel {
    margin-top: 15px;
}

.history-list {
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 15px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
}

.history-item {
    padding: 10px;
    margin: 5px 0;
    background: var(--background-color);
    border-radius: 6px;
    border-left: 4px solid var(--primary-color);
}

.history-food {
    font-weight: bold;
    color: var(--primary-color);
    margin-bottom: 2px;
}

.history-time {
    font-size: 0.85rem;
    color: #666;
}

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

.history-actions button {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

#clearHistoryBtn {
    background: var(--error-color);
    color: white;
}

#closeHistoryBtn {
    background: var(--text-color);
    color: white;
}

/* 加载提示 */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    color: white;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid transparent;
    border-top: 5px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

/* 错误提示 */
.error-message {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1001;
    animation: slideInRight 0.3s ease;
}

.error-content {
    background: var(--error-color);
    color: white;
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    gap: 15px;
    max-width: 300px;
}

.close-error {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 动画定义 */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* 响应式设计 */
@media (max-width: 768px) {
    .app-container {
        grid-template-areas: 
            "header"
            "main"
            "sidebar";
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        padding: 10px;
        gap: 15px;
    }
    
    .app-header h1 {
        font-size: 2rem;
    }
    
    .main-content {
        padding: 20px 15px;
    }
    
    #wheelCanvas {
        width: 300px;
        height: 300px;
    }
    
    .controls {
        flex-direction: column;
        width: 100%;
    }
    
    .spin-btn, .spin-again-btn {
        width: 100%;
        padding: 12px 20px;
        font-size: 1.1rem;
    }
    
    .sidebar {
        order: 3;
    }
    
    .food-list, .history-list {
        max-height: 200px;
    }
}

@media (max-width: 480px) {
    .app-container {
        padding: 5px;
        gap: 10px;
    }
    
    .app-header {
        padding: 15px 10px;
    }
    
    .app-header h1 {
        font-size: 1.8rem;
    }
    
    .subtitle {
        font-size: 1rem;
    }
    
    #wheelCanvas {
        width: 250px;
        height: 250px;
    }
    
    .main-content {
        padding: 15px 10px;
    }
    
    .panel {
        padding: 15px;
    }
    
    .selected-food {
        font-size: 1.5rem;
    }
}

/* 制作方法询问按钮 */
.ask-cooking-btn {
    margin-top: 15px;
    padding: 10px 20px;
    background: linear-gradient(45deg, var(--warning-color), #e67e22);
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.3s ease;
    box-shadow: 0 3px 10px rgba(243, 156, 18, 0.3);
}

.ask-cooking-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(243, 156, 18, 0.4);
}

/* AI功能设置面板 */
.ai-settings {
    margin-top: 15px;
}

.api-key-input {
    margin-bottom: 15px;
}

.api-key-input label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: var(--text-color);
}

#apiKeyInput {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.9rem;
    margin-bottom: 10px;
}

#testApiBtn {
    padding: 8px 15px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

#testApiBtn:hover {
    background: #3498db;
}

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

.ai-actions button {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

#generateFoodsBtn {
    background: var(--success-color);
    color: white;
}

#generateFoodsBtn:hover {
    background: #229954;
}

#closeAiSettingsBtn {
    background: var(--text-color);
    color: white;
}

/* 模态对话框样式 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    max-width: 600px;
    max-height: 80vh;
    width: 90%;
    display: flex;
    flex-direction: column;
    animation: slideIn 0.3s ease;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border-radius: 15px 15px 0 0;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.3rem;
}

.modal-close {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    text-align: right;
    background: var(--background-color);
    border-radius: 0 0 15px 15px;
}

.modal-footer button {
    padding: 10px 20px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s ease;
}

.modal-footer button:hover {
    background: #e55656;
}

/* 制作方法内容样式 */
.cooking-content {
    line-height: 1.8;
    color: var(--text-color);
}

.cooking-content h3 {
    color: var(--primary-color);
    margin: 20px 0 10px 0;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border-color);
}

.cooking-content h3:first-child {
    margin-top: 0;
}

.cooking-content p {
    margin-bottom: 15px;
}

.cooking-content ul, .cooking-content ol {
    margin: 15px 0;
    padding-left: 25px;
}

.cooking-content li {
    margin-bottom: 8px;
}

.loading-text {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-color);
    font-size: 1.1rem;
}

.loading-text::after {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top: 2px solid var(--primary-color);
    border-radius: 50%;
    margin-left: 10px;
    animation: spin 1s linear infinite;
}

/* 模态框动画 */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-50px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* 移动端模态框适配 */
@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        max-height: 85vh;
        margin: 20px;
    }
    
    .modal-header, .modal-body, .modal-footer {
        padding: 15px;
    }
    
    .modal-header h3 {
        font-size: 1.1rem;
    }
    
    .cooking-content {
        font-size: 0.95rem;
    }
}