:root {
    --primary: #FF512F;
    --secondary: #DD2476;
    --bg-gradient: linear-gradient(135deg, #FF512F 0%, #DD2476 100%);
    --bg-dark: #121212;
    --text-main: #ffffff;
    --text-muted: #b3b3b3;
    --card-bg: rgba(25, 25, 25, 0.7);
    --card-border: rgba(255, 255, 255, 0.1);
    --glass-blur: blur(20px);
    --accent: #FEE140;
    --success: #38ef7d;
    --info: #00f2fe;
}

[data-theme="light"] {
    --bg-dark: #f0f2f5;
    --text-main: #1a1a1a;
    --text-muted: #666;
    --card-bg: rgba(255, 255, 255, 0.8);
    --card-border: rgba(0, 0, 0, 0.1);
    --accent: #ff8c00;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Prompt', sans-serif;
}

body {
    background: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    overflow-x: hidden;
    position: relative;
}

body::before,
body::after {
    content: '';
    position: absolute;
    width: 300px;
    height: 300px;
    border-radius: 50%;
    filter: blur(100px);
    z-index: -1;
    animation: float 10s infinite alternate cubic-bezier(0.45, 0.05, 0.55, 0.95);
}

body::before {
    background: var(--primary);
    top: -5%;
    left: -10%;
    opacity: 0.6;
}

body::after {
    background: var(--secondary);
    bottom: -5%;
    right: -10%;
    opacity: 0.6;
    animation-delay: -5s;
    animation-duration: 12s;
}

@keyframes float {
    0% {
        transform: translateY(0) scale(1);
    }

    100% {
        transform: translateY(-50px) scale(1.2);
    }
}

.container {
    width: 100%;
    max-width: 480px;
    text-align: center;
    z-index: 1;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

header h1 {
    font-size: 2.2rem;
    font-weight: 800;
    background: linear-gradient(90deg, #FA709A 0%, #FEE140 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0px 4px 20px rgba(250, 112, 154, 0.3);
}

.btn-icon {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    font-size: 1.5rem;
    padding: 8px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(15deg);
}

header p {
    font-size: 1.1rem;
    color: var(--text-muted);
    margin-bottom: 20px;
}

.main-nav {
    display: flex;
    background: rgba(0, 0, 0, 0.2);
    padding: 5px;
    border-radius: 16px;
    gap: 5px;
    margin-bottom: 25px;
}

.nav-tab {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 10px 5px;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.nav-tab.active {
    background: var(--card-bg);
    color: var(--text-main);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.tab-content.hidden {
    display: none !important;
}

.glass-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-radius: 24px;
    padding: 30px 25px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.4);
    transition: all 0.4s ease;
}

/* Result Box styles (Restored and Polished) */

/* Category Selector */
.category-selector {
    margin-bottom: 20px;
    text-align: center;
}

.category-title {
    font-size: 0.95rem;
    color: var(--accent);
    margin-bottom: 12px;
}

.category-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

.btn-cat {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #ccc;
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    white-space: nowrap;
    /* ป้องกันข้อความในปุ่มหักบรรทัด */
    flex: 1 1 auto;
    /* ให้ปุ่มยืดหดตามพื้นที่ */
    max-width: max-content;
}

.btn-cat:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    transform: translateY(-2px);
}

.btn-cat.active {
    background: linear-gradient(135deg, #FF512F 0%, #DD2476 100%);
    border-color: transparent;
    color: #fff;
    font-weight: 600;
    box-shadow: 0 4px 10px rgba(221, 36, 118, 0.4);
    transform: scale(1.05);
}

/* Budget Button */
.btn-budget {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #ccc;
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    white-space: nowrap;
    flex: 1 1 auto;
    max-width: max-content;
}

.btn-budget:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    transform: translateY(-2px);
}

.btn-budget.active {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    border-color: transparent;
    color: #fff;
    font-weight: 600;
    box-shadow: 0 4px 10px rgba(56, 239, 125, 0.4);
    transform: scale(1.05);
}

.result-box {
    min-height: 180px;
    /* ลดความสูงลงนิดหน่อยสำหรับมือถือ */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 20px;
    padding: 20px 10px;
    /* ลด padding ด้านข้าง */
    border: 2px dashed rgba(255, 255, 255, 0.15);
    transition: all 0.3s ease;
    width: 100%;
    /* ให้เต็มพื้นพี่ container */
}

.food-emoji {
    font-size: 4rem;
    /* ลดขนาดอิโมจิลงนืดหนึ่ง */
    margin-bottom: 10px;
    filter: drop-shadow(0 10px 10px rgba(0, 0, 0, 0.3));
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.food-name {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.4;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    padding: 0 5px;
    word-break: break-word;
}

.controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin-bottom: 25px;
    width: 100%;
    /* บังคับปุ่มกว้างเต็มที่ */
}

.btn-random {
    background: linear-gradient(135deg, #FF512F 0%, #DD2476 100%);
    border: none;
    border-radius: 50px;
    padding: 16px 20px;
    /* ปรับ padding ให้สมส่วน */
    font-size: 1.3rem;
    font-weight: 800;
    color: #fff;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(221, 36, 118, 0.5);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    overflow: hidden;
    width: 100%;
}

.btn-random::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    transition: all 0.5s;
}

.btn-random:hover {
    transform: scale(1.05) translateY(-2px);
    box-shadow: 0 15px 35px rgba(221, 36, 118, 0.7);
}

.btn-random:hover::after {
    left: 100%;
}

.btn-random:active {
    transform: scale(0.95);
}

.btn-random:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: scale(1);
    background: linear-gradient(135deg, #666, #444);
    box-shadow: none;
}

.action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    width: 100%;
}

.btn-recipe,
.btn-map,
.btn-share {
    flex: 1 1 calc(50% - 10px);
    min-width: 130px;
    border: none;
    border-radius: 50px;
    padding: 12px 10px;
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.btn-recipe {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    box-shadow: 0 8px 20px rgba(56, 239, 125, 0.4);
}

.btn-recipe:hover {
    transform: scale(1.05) translateY(-2px);
    box-shadow: 0 12px 25px rgba(56, 239, 125, 0.6);
}

.btn-recipe:active {
    transform: scale(0.95);
}

.btn-share {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    box-shadow: 0 8px 20px rgba(79, 172, 254, 0.4);
}

.btn-share:hover {
    transform: scale(1.05) translateY(-2px);
    box-shadow: 0 12px 25px rgba(79, 172, 254, 0.6);
}

.btn-share:active {
    transform: scale(0.95);
}

.btn-favorite {
    background: linear-gradient(135deg, #FF9A9E 0%, #FAD0C4 100%);
    box-shadow: 0 8px 20px rgba(255, 154, 158, 0.4);
    flex: 1 1 calc(50% - 10px);
    min-width: 130px;
    border: none;
    border-radius: 50px;
    padding: 12px 10px;
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.btn-favorite.active {
    background: linear-gradient(135deg, #ff0844 0%, #ffb199 100%);
}

.btn-favorite:hover {
    transform: scale(1.05) translateY(-2px);
    box-shadow: 0 12px 25px rgba(255, 154, 158, 0.6);
}

.btn-map {
    background: linear-gradient(135deg, #f2994a 0%, #f2c94c 100%);
    box-shadow: 0 8px 20px rgba(242, 201, 76, 0.4);
}

.btn-map:hover {
    transform: scale(1.05) translateY(-2px);
    box-shadow: 0 12px 25px rgba(242, 201, 76, 0.6);
}

.btn-map:active {
    transform: scale(0.95);
}

.hidden {
    display: none !important;
}

@keyframes popIn {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }

    60% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.animate-result {
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.animate-spin {
    animation: shakePulse 0.15s linear infinite;
}

@keyframes shakePulse {
    0% {
        transform: scale(1) rotate(-10deg);
    }

    50% {
        transform: scale(1.15) rotate(10deg);
    }

    100% {
        transform: scale(1) rotate(-10deg);
    }
}

.glow-effect {
    box-shadow: 0 0 30px rgba(255, 81, 47, 0.4), inset 0 0 20px rgba(221, 36, 118, 0.2);
    border: 2px solid rgba(255, 81, 47, 0.5);
    background: rgba(255, 81, 47, 0.1);
}

.history-section {
    text-align: left;
    background: rgba(0, 0, 0, 0.2);
    padding: 15px;
    border-radius: 16px;
}

.history-section h3 {
    font-size: 1rem;
    color: var(--accent);
    margin: 0;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-text-only {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    text-decoration: underline;
}

#historyList {
    list-style: none;
    max-height: 120px;
    overflow-y: auto;
    padding-right: 5px;
    margin: 0;
}

#historyList li {
    font-size: 0.9rem;
    color: var(--text-main);
    padding: 8px 0;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    gap: 8px;
}

#historyList::-webkit-scrollbar {
    width: 5px;
}

#historyList::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
}

#historyList::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 10px;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: flex-end;
    /* เลื่อนให้ Modal มาอยู่ขอบล่างบนมือถือ จะปิดง่ายกว่า */
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal.show {
    opacity: 1;
    pointer-events: auto;
}

.modal .modal-content {
    width: 100%;
    /* ให้กว้างเต็มท */
    max-width: 500px;
    max-height: 85vh;
    overflow-y: auto;
    border-radius: 24px 24px 0 0;
    /* ทำมุมโค้งเฉพาะด้านบน เหมือน Sheet ใน iOS */
    transform: translateY(100%);
    /* แอนิเมทจากด้านล่างขึ้นมา */
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1);
    text-align: left;
    padding-bottom: 50px;
    /* เว้นที่ว่างให้ Safe Area */
    margin-bottom: 0;
}

.modal.show .modal-content {
    transform: translateY(0);
}

.close-btn {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 2rem;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    transition: color 0.2s;
    line-height: 1;
    background: rgba(0, 0, 0, 0.5);
    /* เพิ่มพื้นหลังปุ่มปิดให้กดง่าย */
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.close-btn:hover {
    color: #fff;
    background: rgba(0, 0, 0, 0.8);
}

.recipe-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-emoji {
    font-size: 2.5rem;
}

.modal-title {
    font-size: 1.3rem;
    color: #fff;
    line-height: 1.3;
}

.recipe-body h3 {
    font-size: 1.1rem;
    color: var(--accent);
    margin-top: 20px;
    margin-bottom: 10px;
}

.recipe-body ul,
.recipe-body ol {
    padding-left: 20px;
    color: var(--text-main);
    font-size: 0.95rem;
    line-height: 1.6;
}

.recipe-body li {
    margin-bottom: 8px;
}

/* Meal Plan Grid */
.meal-plan-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-top: 20px;
}

.meal-day-card {
    display: flex;
    align-items: center;
    background: rgba(0, 0, 0, 0.3);
    padding: 12px 15px;
    border-radius: 16px;
    gap: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.day-label {
    font-weight: 800;
    color: var(--accent);
    min-width: 40px;
}

.meal-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
}

.meal-name {
    font-size: 0.95rem;
}

.btn-generate {
    background: var(--bg-gradient);
    border: none;
    color: white;
    padding: 8px 15px;
    border-radius: 50px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
}

/* Forms */
.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    font-size: 0.9rem;
    margin-bottom: 5px;
    color: var(--accent);
}

.form-group input,
.form-group select {
    width: 100%;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 12px;
    border-radius: 12px;
    color: #fff;
    font-size: 1rem;
}

.form-row {
    display: flex;
    gap: 10px;
}

.fav-list {
    list-style: none;
    padding: 0;
}

.fav-item {
    display: flex;
    align-items: center;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    margin-bottom: 8px;
    gap: 10px;
}

.btn-remove {
    margin-left: auto;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
}

.modal-content::-webkit-scrollbar {
    width: 6px;
}

.modal-content::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
}

.modal-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 10px;
}

footer {
    margin-top: 20px;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.4);
    text-align: center;
}

/* 📱 Media Queries เล็กน้อยสำหรับจอใหญ่ เพื่อให้ Card ยืดหยุ่นขึ้น */
@media (min-width: 600px) {
    .glass-card {
        padding: 35px;
    }

    .modal {
        align-items: center;
        /* ตรงกลางสำหรับจอใหญ่ */
    }

    .modal .modal-content {
        width: 90%;
        border-radius: 24px;
        /* โค้งทุกมุมบน PC */
        transform: scale(0.9);
        padding-bottom: 30px;
    }

    .modal.show .modal-content {
        transform: scale(1);
    }
}