:root {
    --bg-color: #FFF9E3;
    /* Rice White */
    --panel-bg: #FFF9E3;
    /* Rice White for panels too */
    --text-color: #5D4037;
    /* Dark Brown */
    --border-color: #4B7B52;
    /* Forest Green for borders */
    --accent-color: #4B7B52;
    /* Forest Green */

    /* Ghibli Bento Box Colors */
    --ghibli-wood: #8D6E63;
    --ghibli-wood-light: #A1887F;
    --ghibli-shadow: rgba(93, 64, 55, 0.2);

    /* Nutrient Colors */
    --heat-color: #85C1E9;
    /* Sky Blue */
    --vitamin-color: #a3e635;
    /* Lime Green */
    --protein-color: #E67E22;
    /* Sunset Orange */
    --fat-color: #E74C3C;
    /* Strawberry Red */

    /* Traffic Lights */
    --red-light: #E74C3C;
    --yellow-light: #E67E22;
    --green-light: #4B7B52;

    --font-family: 'Quicksand', sans-serif;
    --handwritten-font: 'Indie Flower', cursive;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 40px 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    box-sizing: border-box;
}

.game-container {
    width: 100%;
    max-width: 1200px;
    background: var(--bg-color);
    border-radius: 25px 15px 30px 20px;
    box-shadow: 0 10px 40px rgba(93, 64, 55, 0.15);
    padding: 40px;
    display: flex;
    flex-direction: column;
    gap: 30px;
    border: 4px double var(--border-color);
}

/* Header */
.game-header {
    display: flex;
    justify-content: center;
    align-items: center;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 20px;
}

.game-title {
    font-family: var(--handwritten-font);
    font-size: 36px;
    font-weight: 700;
    color: var(--text-color);
    margin: 0;
    letter-spacing: 1px;
    transform: rotate(-1deg);
}

.header-decorations {
    display: flex;
    gap: 8px;
    font-size: 24px;
}

.header-decorations.left .fruit-icon {
    animation: bounce 2s infinite ease-in-out;
}

.header-decorations.left .fruit-icon:nth-child(2) {
    animation-delay: 0.2s;
}

.header-decorations.left .fruit-icon:nth-child(3) {
    animation-delay: 0.4s;
}

.header-decorations.left .fruit-icon:nth-child(4) {
    animation-delay: 0.6s;
}

.header-decorations.left .fruit-icon:nth-child(5) {
    animation-delay: 0.8s;
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-5px);
    }
}

/* Main Content */
.game-content {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 30px;
}

.panel {
    background: var(--panel-bg);
    border: 2px solid var(--border-color);
    border-radius: 12px 25px 15px 30px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    transition: all 0.3s ease;
    box-shadow: 0 5px 15px rgba(93, 64, 55, 0.1);
}

.panel:hover {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.panel-title {
    font-family: var(--handwritten-font);
    font-size: 22px;
    font-weight: 700;
    text-align: center;
    color: var(--text-color);
    margin: 0;
    padding-bottom: 12px;
    border-bottom: 2px dashed var(--border-color);
    position: relative;
}

/* Nutrition Panel */
.nutrient-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nutrient-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    color: #475569;
}

.nutrient-info .icon {
    margin-right: 8px;
}

.progress-bar-container {
    height: 16px;
    background: #e2e8f0;
    border-radius: 9999px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    border-radius: 9999px;
    transition: width 0.5s ease-in-out;
}

.bar-heat {
    background-color: var(--heat-color);
}

.bar-vitamin {
    background-color: var(--vitamin-color);
}

.bar-protein {
    background-color: var(--protein-color);
}

.bar-fat {
    background-color: var(--fat-color);
}

.nutrient-meta {
    display: flex;
    justify-content: flex-end;
    font-size: 14px;
    font-weight: 600;
    color: #64748b;
}

.sub-letters {
    justify-content: space-between;
}

.sub-letters span:not(.percentage) {
    color: #94a3b8;
}

/* Interaction Panel */
.traffic-light-container,
.lunchbox-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.traffic-lights {
    display: flex;
    justify-content: center;
    gap: 20px;
    padding: 15px;
    background: #f8fafc;
    border-radius: 12px;
}

.light {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 700;
    color: white;
    opacity: 0.3;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.06);
}

.light.red {
    background-color: var(--red-light);
}

.light.yellow {
    background-color: var(--yellow-light);
}

.light.green {
    background-color: var(--green-light);
}

.light.active {
    opacity: 1;
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
}

.lunchbox-flow {
    display: flex;
    justify-content: space-between;
    padding: 0 10px;
    font-weight: 700;
    color: #64748b;
    font-size: 18px;
}

.flow-arrow {
    animation: pulse 2s infinite ease-in-out;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

/* 便当盒外壳 */
.bento-box {
    width: 100%;
    height: 250px;
    background-color: var(--ghibli-wood);
    padding: 15px;
    border-radius: 25px 35px 20px 40px;
    border: 4px solid var(--text-color);
    box-shadow: 12px 12px 0px var(--ghibli-shadow);
    display: grid;
    grid-template-columns: 1fr 1.5fr 1.5fr;
    grid-template-rows: 1fr 1fr;
    gap: 10px;
    box-sizing: border-box;
    position: relative;
}

/* 内部格子通用样式 */
.grid-item {
    background-color: #FDFEFE;
    border: 2px solid var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
    background-image: radial-gradient(rgba(141, 110, 99, 0.05) 1px, transparent 1px);
    background-size: 10px 10px;
}

/* 左侧上方：正方形居中 */
.square-grid {
    border-radius: 12px 15px 10px 14px;
}

.square-content {
    width: 60%;
    height: 60%;
    border-radius: 8px;
}

/* 左侧下方：圆形居中 */
.circle-grid {
    border-radius: 15px 12px 18px 10px;
}

.circle-content {
    width: 70px;
    height: 70px;
    border: 2px dashed #D7CCC8;
    border-radius: 50%;
}

/* 右上方区域：两个并排小长方形 */
.right-top-1 {
    grid-column: 2;
    grid-row: 1;
    border-radius: 10px 20px 8px 15px;
}

.right-top-2 {
    grid-column: 3;
    grid-row: 1;
    border-radius: 20px 12px 15px 10px;
}

/* 右下方区域：大长方形跨两列 */
.right-bottom-large {
    grid-column: 2 / span 2;
    grid-row: 2;
    border-radius: 10px 10px 25px 15px;
}

/* 装饰：木纹感 */
.bento-box::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(45deg,
            rgba(255, 255, 255, 0.02) 0px,
            rgba(255, 255, 255, 0.02) 2px,
            transparent 2px,
            transparent 10px);
    pointer-events: none;
    border-radius: inherit;
}

/* Foods Panel */
.foods-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 700px;
    overflow-y: auto;
    padding-right: 8px;
}

.food-item {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    gap: 20px;
    padding: 12px 16px;
    background: var(--panel-bg);
    border: 2px solid var(--border-color);
    border-radius: 12px 25px 15px 30px;
    transition: all 0.3s ease;
    cursor: pointer;
    box-shadow: 0 3px 6px rgba(93, 64, 55, 0.05);
}

.food-item:nth-child(even) {
    background: #e8f5e9;
}

/* Nutrients Layout with Large Icons */
.nutrient-item {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 10px 20px;
    align-items: center;
    padding: 15px 0;
    border-bottom: 1px dashed rgba(75, 123, 82, 0.3);
}

.nutrient-info {
    display: contents;
    /* Make children part of parent grid */
}

.icon {
    grid-column: 1;
    grid-row: 1 / span 3;
}

.name {
    grid-column: 2;
    grid-row: 1;
    font-weight: bold;
}

.value {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
}

.progress-bar-container {
    grid-column: 2;
    grid-row: 2;
}

.nutrient-meta {
    grid-column: 2;
    grid-row: 3;
}

.icon img {
    height: clamp(40px, 4vw, 60px);
    width: auto;
    object-fit: contain;
}

.food-icon img {
    height: clamp(48px, 6vw, 90px);
    width: auto;
    object-fit: contain;
}

.food-item:hover {
    transform: scale(1.02) translateY(-2px);
    box-shadow: 0 5px 15px rgba(93, 64, 55, 0.1);
    background: #e0f2f1;
}

.food-icon {
    font-size: 24px;
}

.food-name {
    flex: 1;
    margin-left: 15px;
    font-weight: 600;
    color: #334155;
}

.food-count {
    font-weight: 700;
    background: #e0f2f1;
    color: #14b8a6;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 14px;
}

/* Footer */
.game-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 2px solid var(--border-color);
    padding-top: 20px;
}

.footer-tags {
    display: flex;
    gap: 20px;
    color: #64748b;
    font-weight: 600;
    font-size: 14px;
}

.footer-buttons {
    display: flex;
    gap: 12px;
}

.btn {
    font-family: var(--font-family);
    padding: 12px 24px;
    border: 2px solid var(--border-color);
    border-radius: 8px 15px 10px 12px;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 3px 6px rgba(93, 64, 55, 0.1);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(93, 64, 55, 0.15);
}

.btn:active {
    transform: translateY(1px);
    box-shadow: 0 2px 4px rgba(93, 64, 55, 0.1);
}

.btn-primary {
    background-color: var(--green-light);
    color: white;
}

.btn-secondary {
    background-color: #e2e8f0;
    color: #475569;
}

.btn-primary:hover {
    background-color: #059669;
}

.btn-secondary:hover {
    background-color: #cbd5e1;
}

/* Nutrient Status Colors */
.status-green {
    background-color: var(--green-light) !important;
}

.status-yellow {
    background-color: var(--yellow-light) !important;
}

.status-red {
    background-color: var(--red-light) !important;
}

/* Drag and Drop Styles */
.food-item[draggable="true"] {
    cursor: grab;
}

.food-item[draggable="true"]:active {
    cursor: grabbing;
}

.food-item.dragging {
    opacity: 0.5;
    transform: scale(0.95);
}

.drop-target.drag-over {
    background-color: rgba(255, 249, 227, 0.7) !important;
    border: 2px dashed var(--ghibli-wood) !important;
}

.food-item.used {
    opacity: 0.5;
    pointer-events: none;
    filter: grayscale(0.5);
}

/* Placed Food in Bento Box */
.placed-food {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: absolute;
    top: 0;
    left: 0;
}

.placed-food img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
}

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

.modal-content {
    background-color: var(--bg-color);
    margin: 15% auto;
    padding: 30px;
    border: 4px solid var(--border-color);
    border-radius: 20px;
    width: 80%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    position: relative;
}

.close-btn {
    color: var(--text-color);
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close-btn:hover,
.close-btn:focus {
    color: var(--red-light);
    text-decoration: none;
    cursor: pointer;
}

#qrcode img {
    margin: 20px auto;
    border: 2px solid var(--border-color);
    border-radius: 10px;
}

/* Dietary Pagoda Styles */
.dietary-pagoda-container {
    text-align: center;
    margin-top: 5px;
    /* Reduced margin */
    cursor: pointer;
    transition: transform 0.2s ease;
}

.dietary-pagoda-container:hover {
    transform: scale(1.05);
}

#dietary-pagoda-img {
    max-width: 264px;
    max-height: 240px;
    width: auto;
    height: auto;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.1);
    object-fit: contain;
}

.hint-text {
    font-size: 12px;
    color: #64748b;
    margin-top: 5px;
    font-family: var(--font-family);
}

/* Pagoda Modal specific styles */
.pagoda-modal-content {
    max-width: 600px;
    /* Larger than the QR modal */
    width: 90%;
}

.zoomed-img {
    width: 100%;
    height: auto;
    border-radius: 10px;
}

/* 移动端适配 */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .game-container {
        padding: 15px;
        gap: 15px;
        max-width: 450px;
        /* 限制手机端最大宽度，避免过宽 */
        margin: 0 auto;
    }

    .game-title {
        font-size: 24px;
    }

    .game-content {
        grid-template-columns: 1fr;
        /* 变成单列 */
        gap: 15px;
    }

    .panel {
        padding: 15px;
    }

    /* 限制营养素进度条宽度 */
    .progress-bar-container {
        max-width: 120px;
    }

    /* 可选食物分成三行显示，支持横向滚动 */
    .foods-list {
        display: grid;
        grid-template-rows: repeat(3, auto);
        grid-auto-flow: column;
        overflow-x: auto;
        max-height: none;
        gap: 10px;
        padding-bottom: 10px;
    }

    .food-item {
        flex-direction: column;
        min-width: 70px;
        text-align: center;
        gap: 5px;
        padding: 6px;
    }

    .food-icon img {
        height: 35px;
        width: auto;
    }

    .food-name {
        margin-left: 0;
        font-size: 11px;
    }

    .food-count {
        font-size: 11px;
        padding: 2px 4px;
    }

    /* 调整底部按钮 */
    .game-footer {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }

    .footer-tags {
        justify-content: center;
    }

    .footer-buttons {
        width: 100%;
        justify-content: center;
    }

    .btn {
        padding: 10px 20px;
        width: 45%;
    }
}