:root {
    --bg-color: #0a0a0a;
    --text-main: #f0f0f0;
    --text-dim: #aaa;
    --type-default: #2a2825;
    --type-vege: #2d3524;
    --type-fish: #242d35;
    --accent-gold: #c5a059;
    --header-h: 52px;
}

* {
    -webkit-tap-highlight-color: transparent;
}

button:focus,
.ingredient-chip:focus,
summary:focus {
    outline: none;
}

html, body {
    overscroll-behavior: none;
    background-color: var(--bg-color);
}

body {
    margin: 0;
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: 'Lato', sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    user-select: none;
}

/* --- BODY LOCK --- */

.svg-icon {
    width: 1.6em;
    height: 1.6em;
    stroke: currentColor;
    fill: none;
    display: block;
    flex-shrink: 0;
}

/* Opcjonalnie: Specyficzny kolor dla serca */
.icon-energy {
    color: #ff4d4d;
}

.app-layout {
    display: block;
    width: 100%;
}

.main-wrapper {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    height: 100vh;
    height: 100dvh;
    width: 100%;
}

/* --- HEADER --- */
header {
    background: #111;
    border-bottom: 1px solid #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    
    /* Gwarancja stałej wysokości */
    min-height: var(--header-h); 
    box-sizing: border-box;
}

header h1, header h2 {
    margin: 0;
    font-size: 1.1rem;
    letter-spacing: 2px;
    color: var(--accent-gold);
}

.filter-toggle {
    cursor: pointer;
    user-select: none;
    padding: 5px;
    color: var(--text-dim);
    transition: color 0.2s;
}

.close-filter {
    cursor: pointer;
    user-select: none;
    padding: 5px;
    color: var(--text-dim);
    transition: color 0.2s;
}

.filter-toggle:hover,
.close-filter:hover {
    color: var(--accent-gold);
}

main {
    flex: 1;
    overflow-y: auto;
}

/* --- FILTER PANEL --- */

.filter-panel {
    position: fixed;
    top: 0;
    right: -100%; /* Ukryty modal */
    width: 100%;
    height: 100dvh;
    background-color: var(--bg-color);
    z-index: 2000;
    transition: right 0.3s ease-in-out;
    display: flex;
    flex-direction: column;
}

.filter-panel.active {
    right: 0; /* Pokazujemy modal */
}

.sort-section {
    padding: 15px;
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-shrink: 0;
}

.sort-btn {
    background: #222;
    border: none;
    color: #bbb;
    padding: 6px 12px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.8rem;
}

.sort-btn.active {
    background: var(--accent-gold);
    color: #111;
}

.filter-scroll-area {
    flex-grow: 1;      /* Zajmuje całą dostępną przestrzeń */
    overflow-y: auto;  /* Tylko tu pojawia się pasek przewijania */
    -webkit-overflow-scrolling: touch; /* Gładki scroll na iOS */
}

details {
    width: 100%;
    background: #161616;
    margin-bottom: 2px;
}

/* Ukrywamy domyślny trójkącik w różnych przeglądarkach */
summary::-webkit-details-marker {
    display: none;
}

summary {
    padding: 12px;
    cursor: pointer;
    color: var(--accent-gold);
    font-weight: bold;
    list-style: none; /* Ukrywa domyślny marker */
    font-size: 0.9rem;
    user-select: none;
    
    /* Flexbox do ustawienia tekstu i ikonki */
    display: flex;
    justify-content: space-between;
    align-items: center;
}

details summary .svg-icon {
    transition: transform 200ms ease;
}

details[open] summary .svg-icon {
    transform: rotate(180deg);
}

.category-container {
    padding: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.ingredient-chip {
    padding: 6px 12px;
    background: #222;
    border-radius: 20px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: 0.2s;
    text-transform: capitalize;
}

.ingredient-chip.active {
    background: var(--accent-gold);
    color: #111;
}

.ingredient-chip.tool-active {
    background: var(--accent-gold);
    color: #111;
}

.filter-footer {
    flex-shrink: 0;    /* Nie pozwala się zgniatać */
    padding: 20px;
    background: #1a1a1a; /* Nieco ciemniejszy, żeby odciąć od listy */
    border-top: 1px solid #333;
    
    /* Obsługa safe-area na dole (paski nawigacyjne iOS/Android) */
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* --- RECIPE GRID --- */
#recipe-list {
    width: 100%;
    padding: 20px 15px 40px 15px;
    box-sizing: border-box;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

.recipe-card {
    border: 2px solid #444;
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-shadow: 0 4px 15px rgba(0,0,0,0.6);
    height: fit-content;
    background-image: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.1));
}

.card-header { padding: 12px; text-align: center; }
.recipe-name { font-size: 1.1rem; color: var(--accent-gold); }
.result-icon { font-size: 4rem; height: 85px; display: flex; align-items: center; justify-content: center; }
.ingredients-row { 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    flex-wrap: wrap; 
    gap: 6px; 
    font-size: 1.6rem; 
    padding: 8px 16px; 
}
.plus { font-size: 0.8rem; color: var(--text-dim); }

.card-footer {
    display: grid;
    grid-template-columns: 1fr 1.2fr 1fr;
    align-items: center;
    padding: 10px 12px;
    background: rgba(0,0,0,0.1);
    border-top: 1px solid rgba(255,255,255,0.05);
    font-size: 0.75rem;
}

.footer-center { display: flex; justify-content: center; align-items: center; color: var(--text-dim); font-weight: bold; }
.footer-center .svg-icon { margin-right: 4px; font-size: 0.5rem; }
.card-vege { background-color: var(--type-vege); border-color: #4a5d23; }
.card-fish { background-color: var(--type-fish); border-color: #3b5a6b; }
.card-default { background-color: var(--type-default); border-color: #444; }
.energy-val, .diff-val { display: flex; align-items: center; gap: 2px; font-size: 0.5rem; }
.energy-val { justify-content: flex-end; color: #ff5f5f; }
.diff-val { justify-content: flex-start; color: #ffd700; font-size: 0.6rem; }

/* Scena - określa perspektywę */
.card-scene {
    perspective: 1200px;
    width: 90%;
    max-width: 400px;
    height: 80vh;
    min-height: 400px;
    max-height: 420px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0 auto;
    user-select: none;
    -webkit-user-select: none;
}

/* Kontener obrotowy */
.card-inner {
    position: relative;
    width: 100%;
    height: 100%; /* Teraz wypełni rodzica */
    /* transition: transform 0.6s cubic-bezier(0.23, 1, 0.32, 1); */
    transform-style: preserve-3d;
    will-change: transform;
}

/* Wspólne style dla obu stron */
.card-face {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    margin: 0 !important;
    border: 2px solid var(--accent-gold);
    cursor: pointer;
}

/* Strona tylna - startuje obrócona o 180 stopni */
.card-back {
    transform: rotateY(180deg);
    /* display: flex;
    flex-direction: column; */
}

/* Poprawka dla Modala: upewnij się, że backdrop nie ucina 3D */
.modal-card {
    background: transparent !important;
    box-shadow: none !important;
    border: none !important;
}

.flip-hint {
    position: absolute;
    z-index: 1;
    left: 0;
    right: 0;
    bottom: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    margin-bottom: 15px;
    color: var(--text-dim);
    font-size: 0.85rem;
    letter-spacing: 1px;
    opacity: 0.7;
    animation: fadeIn 0.5s ease-out;
    transition: opacity 300ms ease;
}

.flip-hint.hidden {
    opacity: 0;
}

.hint-icon {
    animation: handSwipe 2s infinite ease-in-out;
}

@keyframes handSwipe {
    0%, 100% { transform: rotate(-10deg) translateX(-5px); }
    50% { transform: rotate(10deg) translateX(5px); }
}

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

#apply-filters {
    padding: 10px 25px;
    background: var(--accent-gold);
    border: none;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    color: #111;
}

/* --- EMPTY STATE --- */
.empty-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: var(--text-dim);
}

.empty-state-icons {
    font-size: 2.5rem;
    margin: 20px 0;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    opacity: 0.6;
}

.reset-btn {
    margin-top: 20px;
    padding: 12px 30px;
    background: transparent;
    border: 2px solid var(--accent-gold);
    color: var(--accent-gold);
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    text-transform: uppercase;
    transition: 0.3s;
}

.reset-btn:hover {
    background: var(--accent-gold);
    color: black;
}

/* --- TOGGLE SWITCH --- */
.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
    margin-right: 10px;
}

.switch input { 
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #333;
    transition: .4s;
    border-radius: 20px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--accent-gold);
}

input:checked + .slider:before {
    transform: translateX(20px);
}

/* Poprawka dla labela vege w footerze panelu */
label.vege-toggle {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 0.9rem;
    user-select: none;
}

/* --- MODAL SYSTEM --- */
.modal-backdrop {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 200;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-backdrop.active {
    display: flex;
    opacity: 1;
}

.modal-card {
    width: 100%;
    max-width: 360px; /* Bardziej pionowe proporcje */
    transform: translateY(50px);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-backdrop.active .modal-card {
    transform: translateY(0);
}

.close-modal-btn {
    position: fixed;
    top: 10px;
    right: 10px;
    z-index: 210;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 40px;
    height: 40px;
    font-size: 2rem;
    color: white;
    cursor: pointer;
    line-height: 1;
    opacity: 0.5;
}

/* --- MODAL INGREDIENTS LIST --- */
.modal-ing-container {
    width: 85%;
    margin: 0 auto 20px auto;
}

.modal-ing-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.95rem;
    padding: 10px;
}

.modal-ing-row:not(:last-child) {
    border-bottom: 1px solid rgba(255,255,255,0.075);
}

.modal-ing-name {
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-ing-value {
    color: var(--accent-gold);
    font-weight: bold;
}

/* --- DESKTOP (od 1024px) --- */
@media (min-width: 1024px) {
    .app-layout {
        display: flex;
        height: 100vh;
        height: 100dvh;
        overflow: hidden;
    }

    .filter-panel {
        position: static;
        width: 360px;
        min-width: 360px;
        height: 100%;
        border-left: 1px solid #444;
        right: 0;
    }

    .close-filter,
    .filter-toggle {
        display: none;
    }
}
