:root {
    --bg-color: #f4f1ea;
    --text-color: #333;
    --accent-color: #5d4037;
    --card-bg: #fff;
    --border-color: #d7ccc8;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    background-image: url('assets/background.png');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    color: var(--text-color);
    margin: 0;
    padding: 20px;
    height: 100vh;
    box-sizing: border-box;
}

/* 确保文本在背景上清晰可见 */
body {
    text-shadow: 0 1px 0 rgba(255,255,255,0.4);
}

.container {
    display: flex;
    height: 100%;
    gap: 20px;
    background-color: transparent; /* 完全透明，让column的透明度生效 */
    border-radius: 8px;
    padding: 20px;
}

.column {
    flex: 1;
    /* 三个主卡片统一使用高透明度白色背景 */
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 16px; /* 圆角更大一点 */
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    backdrop-filter: blur(5px); /* 可选：增加一点磨砂感 */
}

/* 3. 优化卡片标题配色 */
h2 {
    color: #fff; /* 改为白色 */
    background: transparent; 
    border-radius: 0;
    padding: 0 0 10px 0;
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 1.4em; 
    border-bottom: 2px solid rgba(255, 255, 255, 0.4); /* 浅色下划线 */
    box-shadow: none;
    text-shadow: 0 1px 2px rgba(0,0,0,0.4); /* 增加文字阴影提高可读性 */
    display: block;
    width: 100%;
}

/* 修正炼药锅标题的特殊样式 */
.cauldron-column h2 {
    color: #fff; 
    background: rgba(93, 64, 55, 0.8); /* 保持半透明深棕色背景，以确保在背景图上可见 */
    padding: 8px 15px;
    border-radius: 20px; 
    display: inline-block;
    width: auto;
    align-self: center; 
    border-bottom: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    text-shadow: none;
}

/* 药材列表样式 */
.ingredient-item {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
    padding: 10px;
    background-color: #fff; /* 不透明白色 */
    border: 1px solid rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.ingredient-icon {
    width: 50px;
    height: 50px;
    background-color: transparent;
    border-radius: 0;
    margin-right: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    /* 1. 药材图标取消羽化效果 */
    /* mask-image: radial-gradient(circle, rgba(0,0,0,1) 60%, rgba(0,0,0,0) 100%); */
    /* -webkit-mask-image: radial-gradient(circle, rgba(0,0,0,1) 60%, rgba(0,0,0,0) 100%); */
}

.ingredient-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.ingredient-info {
    flex-grow: 1;
}

.ingredient-name {
    font-weight: bold;
    display: block;
}

.ingredient-count {
    color: #666;
    font-size: 0.9em;
}

/* 补充丢失的 ingredient-controls button 基础样式 */
.ingredient-controls button {
    margin-left: 5px;
    padding: 5px 8px;
    cursor: pointer;
    min-width: 35px;
}
.ingredient-controls button, #pokedex-btn, #clear-pokedex-btn {
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    border: 1px solid rgba(0,0,0,0.1);
}

.ingredient-controls button:hover, #pokedex-btn:hover, #clear-pokedex-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

/* 炼药锅区域特殊处理：为了让锅融入背景，该列背景透明，但保留标题背景 */
.cauldron-column {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.cauldron-column h2 {
    /* 特别调整：炼药锅标题 */
    margin-bottom: 20px;
}
.cauldron-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    /* 改为顶部对齐，避免下方内容变化影响锅的位置 */
    justify-content: flex-start;
    padding-top: 60px;
    flex-grow: 1;
}

.cauldron-pot {
    width: 200px;
    height: 160px;
    background-color: transparent;
    background-image: url('assets/cauldron.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    border-radius: 0;
    margin-bottom: 20px;
    position: relative;
    /* 1. 加强炼药锅的羽化效果 (Masking)，最外圈完全透明 */
    mask-image: radial-gradient(circle, rgba(0,0,0,1) 40%, rgba(0,0,0,0.8) 60%, rgba(0,0,0,0) 80%);
    -webkit-mask-image: radial-gradient(circle, rgba(0,0,0,1) 40%, rgba(0,0,0,0.8) 60%, rgba(0,0,0,0) 80%);
}

.cauldron-pot::before {
    display: none; /* 移除原来的盖子效果 */
}

#brew-btn {
    padding: 15px 40px;
    font-size: 1.2em;
    background-color: #795548; /* Lighter brown to stand out */
    color: white;
    border: 2px solid #3e2723; /* Darker border */
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

#brew-btn:hover {
    background-color: #8d6e63;
    transform: translateY(-2px);
    box-shadow: 0 6px 8px rgba(0,0,0,0.4);
}

/* 2. 药剂名字和失败结果放入白色卡片 */
#message-area {
    margin-top: 20px;
    text-align: center;
    height: 180px; 
    overflow-y: auto;
    color: #d32f2f;
    flex-shrink: 0; 
    width: 100%;
    box-sizing: border-box;
    /* 默认透明无背景，只有有内容时才显示背景 */
    background: transparent;
    border-radius: 12px;
    padding: 15px;
    box-shadow: none;
    transition: all 0.3s;
}

#message-area.has-message {
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

/* 历史记录样式 */
.search-bar input {
    width: 100%;
    padding: 8px;
    margin-bottom: 15px;
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 4px;
    background-color: #fff;
}

.history-card {
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 5px;
    padding: 10px;
    margin-bottom: 10px;
    background-color: #fafafa;
    border-left: 4px solid var(--accent-color);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.history-card.error {
    border-left-color: #d32f2f;
}

.history-title {
    font-weight: bold;
    margin-bottom: 5px;
}

.history-ingredients {
    font-size: 0.85em;
    color: #666;
    margin-bottom: 5px;
    font-style: italic;
    border-bottom: 1px dashed #eee;
    padding-bottom: 5px;
}

.history-desc {
    font-size: 0.9em;
    color: #555;
}

.history-meta {
    font-size: 0.8em;
    color: #999;
    margin-top: 5px;
}

/* 调试面板 */
#debug-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 15px;
    border-radius: 8px;
    z-index: 1000;
    max-width: 300px;
}

#debug-panel.hidden {
    display: none;
}

#debug-canvas-container canvas {
    border: 1px solid white;
    margin-top: 10px;
    max-width: 100%;
}

.message-title {
    font-size: 1.3em;
    font-weight: bold;
    margin-bottom: 5px;
}

.message-desc {
    font-size: 1.1em;
    color: #555;
    background-color: #f9f9f9;
    padding: 10px;
    border-radius: 5px;
    border: 1px solid #eee;
    margin-top: 5px;
    display: inline-block;
}

/* Success styling */
#message-area.success .message-title {
    color: #388e3c;
}

/* Error styling */
#message-area.error .message-title {
    color: #d32f2f;
}

/* 炼药记录标题栏调整，确保对齐 */
.right-column .title-bar {
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    border-bottom: 2px solid rgba(255, 255, 255, 0.4); 
    padding-bottom: 10px; 
    margin-bottom: 15px;
}

.right-column h2 {
    margin-bottom: 0;
    border-bottom: none;
    padding-bottom: 0;
    width: auto;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.4);
}

/* 图鉴模态框内的标题颜色修正 */
.modal-header h2 {
    color: #4e342e; /* 恢复为深棕色 */
    text-shadow: none; /* 移除阴影 */
    border-bottom: none; /* 模态框标题不需要底边框，因为header已有 */
    padding: 0;
    margin: 0;
}

.modal.hidden {
    display: none;
}

.modal:not(.hidden) {
    display: block;
}

.modal-content {
    background-color: rgba(255, 255, 255, 0.9); /* 高透明度白色，与主卡片一致 */
    margin: 5% auto;
    padding: 20px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    width: 80%;
    max-width: 900px;
    border-radius: 16px; /* 统一圆角 */
    box-shadow: 0 8px 16px rgba(0,0,0,0.2);
    height: 80vh;
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(10px); /* 磨砂效果 */
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid rgba(62, 39, 35, 0.2);
    padding-bottom: 10px;
    margin-bottom: 15px;
    flex-shrink: 0;
}

.modal-header h2 {
    margin: 0;
    border: none;
    padding: 0;
}

.modal-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.close-modal {
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close-modal:hover,
.close-modal:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

#clear-pokedex-btn {
    padding: 8px 15px; /* 增加内边距 */
    background-color: #d32f2f;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1.1em; /* 增大字体 */
    white-space: nowrap; /* 确保不换行 */
}

#clear-pokedex-btn:hover {
    background-color: #b71c1c;
}

/* Pokedex Filter */
.pokedex-filter-item {
    display: flex;
    align-items: center;
    background: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid #ddd;
}

.pokedex-filter-icon {
    width: 20px;
    height: 20px;
    margin-right: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pokedex-filter-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.pokedex-filter-input {
    width: 40px;
    border: none;
    background: transparent;
    font-size: 0.9em;
    text-align: center;
    outline: none;
}

/* Chrome, Safari, Edge, Opera - Hide arrows/spinners */
.pokedex-filter-input::-webkit-outer-spin-button,
.pokedex-filter-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Firefox */
.pokedex-filter-input {
  -moz-appearance: textfield;
}

/* Pokedex Grid */
.pokedex-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    overflow-y: auto;
    padding-right: 5px;
}

.pokedex-search-area {
    margin-bottom: 15px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 8px;
    border: 1px solid rgba(0,0,0,0.05);
}

.pokedex-hint {
    font-size: 0.9em;
    color: #6d4c41;
    margin-bottom: 10px;
    font-weight: bold;
    text-align: center;
}

.pokedex-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.pokedex-search-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.95em;
    box-sizing: border-box;
}

.ingredient-filter {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
    font-size: 0.9em;
}

.filter-label {
    font-weight: bold;
    color: #5d4037;
}

.ingredient-filter label {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
}

.pokedex-card {
    border: 1px solid #eee;
    border-radius: 8px;
    padding: 12px;
    background-color: #fafafa;
    display: flex;
    flex-direction: column;
    min-height: 100px;
    height: auto;
    /* max-height: 300px;  Remove max-height to avoid overlap */
    transition: all 0.2s;
    cursor: pointer;
    position: relative; /* Ensure z-index works if needed */
}

.pokedex-card.locked {
    background-color: #f0f0f0;
    color: #999;
    border-color: #ddd;
    cursor: default;
}

.pokedex-card.unlocked {
    background-color: #fff;
    border-left: 4px solid var(--accent-color);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.pokedex-card.unlocked:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    z-index: 2;
}

.pokedex-card.expanded {
    box-shadow: 0 8px 16px rgba(0,0,0,0.15);
    border-color: #ccc;
    z-index: 5;
}

.pokedex-card-title {
    font-weight: bold;
    margin-bottom: 8px;
    font-size: 1em;
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
}

.pokedex-card-desc {
    font-size: 0.9em;
    color: #555;
    margin-bottom: 10px;
}

.pokedex-card.locked .pokedex-card-desc {
    display: none;
}

.pokedex-recipes {
    margin-top: 10px;
    background-color: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 10px;
    display: none; /* Hidden by default */
    max-height: 150px;
    overflow-y: auto;
}

.pokedex-card.expanded .pokedex-recipes {
    display: block;
}

.recipe-title {
    font-size: 0.8em;
    font-weight: bold;
    color: #795548;
    margin-bottom: 5px;
}

.recipe-list {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 0.8em;
    color: #666;
}

.recipe-item {
    margin-bottom: 3px;
    padding-left: 10px;
    position: relative;
}

.recipe-item::before {
    content: "•";
    position: absolute;
    left: 0;
    color: #8d6e63;
}

#pokedex-btn {
    background-color: transparent; 
    color: #fff; /* 改为白色 */
    border: 1px solid rgba(255, 255, 255, 0.6); /* 浅色边框 */
    border-radius: 4px;
    padding: 6px 15px; 
    cursor: pointer;
    font-size: 1.0em; 
    white-space: nowrap;
    transition: all 0.2s;
    height: auto;
    margin-left: 10px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

#pokedex-btn:hover {
    background-color: rgba(255, 255, 255, 0.2); /* 悬停时浅色背景 */
    border-color: #fff;
}

/* Default desktop state */
.mobile-history-collapsed,
.mobile-only {
    display: none;
}

/* --- Mobile Adaptation --- */
@media (max-width: 768px) {
    body {
        padding: 0;
        overflow: hidden; /* Prevent body scroll, handle in containers */
    }

    .container {
        display: block; /* Break flex layout */
        position: relative;
        padding: 0;
        margin: 0;
        width: 100vw;
        height: 100vh;
        gap: 0;
    }

    /* 1. Cauldron (Main View) */
    .cauldron-column {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 1;
        justify-content: center;
        padding: 20px 60px; /* Space for sidebars */
        box-sizing: border-box;
        pointer-events: none; /* Let clicks pass through to sidebars if needed, but buttons need pointer-events: auto */
    }

    .cauldron-column > * {
        pointer-events: auto;
    }

    .cauldron-area {
        padding-top: 0;
        justify-content: center;
        transform: translateY(-10%); /* Move up 10% */
    }

    .cauldron-pot {
        width: 180px;
        height: 140px;
    }

    /* 2. Ingredient Library (Left Sidebar) */
    .left-column {
        position: fixed;
        top: 60px; /* Move up further */
        left: 10px;
        transform: none; /* Remove centering */
        width: auto;
        height: auto;
        background: transparent;
        border: none;
        box-shadow: none;
        padding: 0;
        overflow: visible;
        z-index: 10;
        backdrop-filter: none;
    }

    .left-column h2 {
        display: none;
    }

    #ingredient-list {
        display: flex;
        flex-direction: column;
        gap: 25px; /* Increase gap slightly */
    }

    .ingredient-item {
        margin: 0;
        padding: 0;
        background: transparent;
        border: none;
        box-shadow: none;
        position: relative;
        width: 65px; /* Enlarged */
        height: 65px; /* Enlarged */
        overflow: visible;
    }

    .ingredient-icon {
        width: 65px; /* Enlarged */
        height: 65px; /* Enlarged */
        margin: 0;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.8);
        box-shadow: 0 2px 5px rgba(0,0,0,0.2);
        position: relative;
        cursor: pointer;
        transition: transform 0.2s;
    }
    
    .ingredient-icon:active {
        transform: scale(0.95);
    }

    .ingredient-info {
        position: absolute;
        top: -5px; 
        right: -5px; 
        background: #fff; /* White background */
        color: #d32f2f; /* Red text for visibility */
        border: 1px solid #eee;
        border-radius: 50%; /* Circle */
        width: 20px;
        height: 20px;
        min-width: 20px;
        min-height: 20px;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 11px;
        font-weight: bold;
        z-index: 2;
        box-shadow: 0 2px 4px rgba(0,0,0,0.2);
        pointer-events: none;
        flex-grow: 0;
        line-height: 1;
        aspect-ratio: 1 / 1;
    }
    
    /* Hide the text parts of info */
    .ingredient-name {
        display: none;
    }
    
    /* We only want the number inside .ingredient-count to be visible/styled as badge */
    /* But structure is .ingredient-info > .ingredient-name + .ingredient-count */
    /* So we hide .ingredient-info by default and show a specific badge? */
    /* Better: Use the existing structure. */
    .ingredient-info {
        /* Override previous .ingredient-info styles for mobile badge */
        display: block;
        flex-grow: 0;
        width: auto;
        height: auto;
        line-height: 1;
    }
    
    .ingredient-count {
        font-size: 0; /* Hide text "当前: ... 份" */
        width: 100%;
        height: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    
    /* Use span inside ingredient-count for the number? ID is count-{name} */
    .ingredient-count span {
        font-size: 11px;
        display: block;
        line-height: 1;
    }

    .ingredient-controls {
        display: none;
        position: absolute;
        left: 60px;
        top: 50%;
        transform: translateY(-50%);
        background: rgba(255, 255, 255, 0.95);
        padding: 8px;
        border-radius: 8px;
        box-shadow: 0 4px 10px rgba(0,0,0,0.2);
        flex-direction: row;
        gap: 5px;
        z-index: 100;
        white-space: nowrap;
    }

    /* Show controls when expanded class is present */
    .ingredient-item.mobile-expanded .ingredient-controls {
        display: flex;
        animation: fadeIn 0.2s ease-out;
    }

    /* 3. History (Right Sidebar) */
    .right-column {
        position: fixed;
        top: 0;
        right: 0;
        height: 100%;
        width: 40px; /* Collapsed width */
        background: rgba(255, 255, 255, 0.6);
        border: none;
        border-radius: 16px 0 0 16px;
        padding: 10px 0;
        z-index: 20;
        transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        overflow: hidden;
        backdrop-filter: blur(10px);
        box-shadow: -2px 0 10px rgba(0,0,0,0.1);
    }

    .right-column.expanded {
        width: 85%;
        background: rgba(255, 255, 255, 0.95);
        padding: 20px;
    }

    /* Collapsed View */
    .mobile-history-collapsed {
        display: flex;
        flex-direction: column;
        align-items: center;
        height: 100%;
        width: 40px;
        cursor: pointer;
    }

    .history-label {
        writing-mode: vertical-rl;
        text-orientation: upright;
        font-weight: bold;
        color: #000; /* Black */
        margin-top: 20px;
        letter-spacing: 4px;
        font-size: 1.1em;
    }

    #history-preview {
        margin-top: 20px;
        display: flex;
        flex-direction: column;
        gap: 0; /* Remove gap to use border/margin */
        width: 100%;
        align-items: center;
    }

    .history-preview-item {
        writing-mode: vertical-rl;
        font-size: 12px;
        color: #000; /* Black */
        max-height: 80px;
        overflow: hidden;
        text-overflow: ellipsis;
        padding: 5px 0;
        border-bottom: 1px solid rgba(0,0,0,0.2); /* Separator */
    }
    
    .history-preview-item:last-child {
        border-bottom: none;
    }

    /* Expanded View */
    .history-full-content {
        display: none;
        width: 100%;
        height: 100%;
        flex-direction: column;
    }

    .right-column.expanded .history-full-content {
        display: flex;
    }
    
    /* Change expanded header colors to brown */
    .right-column.expanded h2 {
        color: var(--accent-color);
        border-bottom-color: var(--accent-color);
    }
    
    .right-column.expanded #pokedex-btn {
        color: var(--accent-color);
        border-color: var(--accent-color);
    }
    
    .right-column.expanded #pokedex-btn:hover {
        background-color: rgba(93, 64, 55, 0.1);
    }

    .right-column.expanded .mobile-history-collapsed {
        display: none;
    }

    /* Header actions in expanded view */
    .header-actions {
        display: flex;
        align-items: center;
        gap: 10px;
    }

    .mobile-only {
        display: block;
    }

    #close-history-btn {
        background: transparent;
        border: none;
        font-size: 28px;
        color: #666;
        cursor: pointer;
        padding: 0 10px;
        line-height: 1;
    }

    /* Modal adjustments */
    .modal-content {
        width: 90%;
        height: 90vh;
        margin: 5% auto;
    }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-50%) translateX(-10px); }
    to { opacity: 1; transform: translateY(-50%) translateX(0); }
}
