:root {
    /* --- Woodland Theme (Light) --- */
    --bg: #e6e0d0; /* parchment */
    --card-bg: #f9f4e6; /* cream */
    --header-bg: #8a6b52; /* warm oak */
    --header-text: #fdf8f0; /* linen */
    --text: #433628; /* cocoa */
    --text-muted: #7a6d5c;
    --border: #d6cabc;
    --shadow: 0 4px 10px rgba(67, 54, 40, 0.12);
    --seed-opacity: 0.06;
    

    --modal-bg: #f8f5e6;
    --input-bg: #fffdf5;
    --input-border: #d1c7b7;
    
    --bg-finished: #dbe4ce; /* Muted sage green */
    --lock-btn-bg: #ebe7da;
    --lock-btn-text: #9c8e7e;
    --btn-secondary-bg: #fdfcf5;
    --btn-secondary-text: #4a3b2a;
    
    /* Status Colors (Muted earthy tones) */
    --danger: #b56b54; /* Rusty red/orange */
    --success: #7a8b4f; /* Mossy green */
    
    /* Dynamic Project Color (Default Rust) */
    --project-color: #b56b54;
}

/* --- Woodland Theme (Dark) --- */
body.dark-mode {
    --bg: #2c3327; /* Deep forest background */
    --card-bg: #3b342c; /* Dark wood card */
    --header-bg: #4b3829; /* Darker wood header */
    --header-text: #e9e4d7;
    --text: #e9e4d7; /* Cream text */
    --text-muted: #b5aa9b;
    --border: #5f5245;
    --shadow: 0 4px 10px rgba(0,0,0,0.45);
    
    --modal-bg: #3d362d;
    --input-bg: #2c2720;
    --input-border: #594e3f;
    
    --bg-finished: #2a382a; /* Dark moss */
    --lock-btn-bg: #4a4238;
    --lock-btn-text: #8c8276;
    --btn-secondary-bg: #4a4238;
    --btn-secondary-text: #d1c7b7;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
    font-family: 'Quicksand', "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg);
    min-height: 100vh;
    color: var(--text);
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    scrollbar-gutter: stable; /* Prevent layout shift when scrollbar appears/disappears */
    transition: background-color 0.3s, color 0.3s;
}

body.theme-animating { animation: themeSwap 0.7s ease-in-out; }
@keyframes themeSwap {
    0% { filter: brightness(1.08) saturate(1.06); opacity: 0.85; }
    45% { filter: brightness(1.03) saturate(1.12) contrast(1.04); opacity: 0.92; }
    75% { filter: brightness(0.98) saturate(1.04); opacity: 0.97; }
    100% { filter: brightness(1) saturate(1); opacity: 1; }
}

header {
    background-color: var(--header-bg);
    color: var(--header-text);
    padding: 0.8rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 2px solid rgba(0,0,0,0.05);
    transition: background-color 0.3s;
}

h1 {
    margin: 0;
    font-size: 1.3rem;
    font-weight: 800;
    letter-spacing: 0.5px;
    color: var(--header-text);
    text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
    font-family: 'Cormorant Garamond', Georgia, serif;
    cursor: pointer;
    user-select: none;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-icon {
    width: 52px; height: 52px; border-radius: 8px;
    object-fit: contain; display: block;
    background: rgba(255,255,255,0.12); padding: 4px;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.08);
}

.header-controls { display: flex; gap: 10px; }

.header-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--header-text);
    transition: transform 0.18s ease, box-shadow 0.18s ease, background-color 0.2s;
    transform: translateY(0);
    font-family: inherit;
}
.header-btn:hover { transform: translateY(-1px) scale(1.03); box-shadow: 0 6px 14px rgba(0,0,0,0.12); }
.header-btn:active { transform: translateY(0) scale(0.96); box-shadow: none; }

.header-btn.is-active { background: var(--header-text); color: var(--header-bg); }
.hidden { display: none !important; }
.hidden-input { display: none; }

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem calc(120px + env(safe-area-inset-bottom, 0px));
    position: relative;
    z-index: 1; /* Keep cards above background but below flying effects */
    flex: 1;
}

.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
    align-items: start; /* Prevent shorter cards from stretching to tallest row mate */
}

@media (min-width: 1280px) {
    .projects-grid {
        grid-template-columns: repeat(3, minmax(320px, 1fr));
    }
}

/* --- PROJECT CONTAINER --- */
.project-container {
    background: var(--card-bg);
    border-radius: 18px;
    padding: 5px 15px 15px 15px;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
    transition: background-color 0.3s;
    border: 1px solid var(--border);
}

.project-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 15px 5px; margin-bottom: 10px; gap: 10px;
}

.project-title-group { display: flex; align-items: center; gap: 10px; }

.project-title {
    font-size: 1.4rem; font-weight: 800; color: var(--project-color);
    text-transform: uppercase; letter-spacing: 1px;
    font-family: 'Cormorant Garamond', Georgia, serif;
}

.btn-toggle-project {
    background: none; border: none; color: var(--project-color);
    font-size: 1.2rem; cursor: pointer; transition: transform 0.2s; padding: 5px;
}
.part-list { max-height: 2000px; opacity: 1; transition: max-height 0.35s ease, opacity 0.3s ease; overflow: hidden; }
.project-collapsed .btn-toggle-project { transform: rotate(-90deg); }
.project-collapsed .part-list { max-height: 0; opacity: 0; pointer-events: none; }
.project-collapsed { margin-bottom: 1rem; opacity: 0.8; box-shadow: none; }

.project-actions { display: flex; gap: 8px; align-items: center; }

.btn-add-part {
    background: var(--project-color); color: var(--card-bg); border: none;
    border-radius: 20px; padding: 6px 16px; font-size: 0.9rem; font-weight: bold;
    cursor: pointer; box-shadow: 0 3px 8px rgba(0,0,0,0.1); transition: transform 0.1s;
}
.btn-add-part:active { transform: scale(0.95); }

.btn-delete-project {
    background: none; border: none; color: var(--text-muted); font-size: 1.2rem; cursor: pointer; padding: 5px;
}
.btn-delete-project:hover { color: var(--danger); }

.btn-rename-project {
    background: none; border: none; color: var(--text-muted);
    padding: 5px 8px; border-radius: 8px; font-size: 1rem; cursor: pointer;
}
.btn-rename-project:hover { color: var(--project-color); }
.icon-pencil { display: inline-block; transform: scaleX(-1); }

.btn-color {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--project-color);
    cursor: pointer;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 0 0 2px var(--card-bg);
}
.btn-color:hover { box-shadow: inset 0 0 0 2px var(--project-color); }
.color-input { display: none; }

/* --- PART CARD --- */
.part-card {
    background: var(--card-bg);
    border-radius: 14px;
    padding: 1rem;
    margin-bottom: 0.8rem;
    box-shadow: var(--shadow);
    position: relative;
    transition: background-color 0.3s;
    overflow: hidden;
    border-left: 7px solid var(--project-color);
    border-top: 1px solid var(--border);
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.part-card.is-locked { background-color: var(--bg); opacity: 0.9; }

.part-card.is-finished { 
    background-color: var(--bg-finished); 
    border-left-color: var(--success);
    opacity: 0.9;
}
.finish-shimmer { animation: finishShimmer 0.8s ease; }
@keyframes finishShimmer {
    0% { box-shadow: var(--shadow), 0 0 0 0 rgba(122, 139, 79, 0.32); }
    60% { box-shadow: var(--shadow), 0 0 0 16px rgba(122, 139, 79, 0); }
    100% { box-shadow: var(--shadow), 0 0 0 0 rgba(122, 139, 79, 0); }
}

.part-card.is-minimized { padding: 0.8rem 1rem; }
.part-card.is-minimized .count-display,
.part-card.is-minimized .controls { display: none; }
.part-card.is-minimized .part-mini-count { display: inline-block; }
.part-card.is-minimized .btn-toggle-part { transform: rotate(-90deg); }
.part-card.is-minimized .count-subtext,
.part-card.is-minimized .btn-reset-part,
.part-card.is-minimized .btn-delete-part { display: none; }

.part-header { display: flex; justify-content: space-between; align-items: center; }
.part-card:not(.is-minimized) .part-header { margin-bottom: 15px; }

.part-name-group { display: flex; align-items: center; gap: 12px; flex-grow: 1; }

.check-container { position: relative; cursor: pointer; width: 26px; height: 26px; flex-shrink: 0; }
.check-container input { opacity: 0; cursor: pointer; height: 0; width: 0; }
.checkmark {
    position: absolute; top: 0; left: 0; height: 26px; width: 26px;
    background-color: var(--card-bg); border-radius: 50%; border: 2px solid var(--text-muted); transition: all 0.2s;
}
.check-container input:checked ~ .checkmark { background-color: var(--success); border-color: var(--success); }
.checkmark:after { content: ""; position: absolute; display: none; }
.check-container input:checked ~ .checkmark:after { display: block; }
.check-container .checkmark:after {
    left: 9px; top: 5px; width: 6px; height: 12px;
    border: solid var(--card-bg); border-width: 0 2px 2px 0; transform: rotate(45deg);
}

.part-name {
    font-size: 1.1rem; font-weight: 700; color: var(--text);
    border-bottom: 2px dashed var(--project-color); /* Dashed looks more like stitching */
    cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px;
}

.part-mini-count {
    display: none; font-weight: 800; color: var(--project-color); margin-left: 8px; font-size: 1.2rem;
}

.is-finished .part-name { text-decoration: line-through; color: var(--success); border-bottom: none; }
.is-finished .part-mini-count { color: var(--success); }

.part-actions { display: flex; gap: 8px; align-items: center; }
.part-actions { justify-content: flex-end; min-width: 120px; }
.icon-btn {
    background: none; border: none; font-size: 1.3rem; padding: 5px; color: var(--text-muted);
    cursor: pointer; transition: color 0.2s;
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px;
}
.icon-btn:disabled { opacity: 0.4; pointer-events: none; }
.btn-delete-part:hover { color: var(--danger); }
.btn-toggle-part { transition: transform 0.2s; }

.count-display {
    font-size: 3.5rem; font-weight: 800; text-align: center; color: var(--project-color); margin: 0.5rem 0 0.4rem 0; touch-action: manipulation;
     text-shadow: 1px 1px 0px var(--card-bg);
}
.is-locked .count-display { color: var(--lock-btn-text); pointer-events: none; }
.is-finished .count-display { color: var(--success); pointer-events: none; }

.count-subtext {
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-muted);
    margin: 0 0 0.6rem 0;
}
.count-subtext strong { color: var(--project-color); }
.count-bump-up { animation: countUp 0.26s ease; }
.count-bump-down { animation: countDown 0.26s ease; }
@keyframes countUp {
    0% { transform: scale(0.95); color: var(--btn-secondary-text); }
    60% { transform: scale(1.08); color: var(--project-color); }
    100% { transform: scale(1); color: var(--project-color); }
}
@keyframes countDown {
    0% { transform: scale(1.05); color: var(--project-color); }
    60% { transform: scale(0.9); color: var(--text-muted); }
    100% { transform: scale(1); color: var(--project-color); }
}

.note-toggle {
    background: none; border: 1px dashed var(--border); color: var(--text-muted);
    padding: 4px 10px; border-radius: 10px; cursor: pointer; font-size: 0.9rem;
    margin: 12px auto 6px;
    display: block;
}
.note-toggle:hover { color: var(--project-color); border-color: var(--project-color); }

.note-area {
    display: none;
    margin-top: 10px;
}
.note-area.show { display: block; }
.note-area textarea {
    width: 100%;
    min-height: 90px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text);
    padding: 10px;
    font-size: 0.95rem;
    resize: vertical;
}
.controls { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; padding: 0 5px; }

button.action-btn {
    border: none; border-radius: 12px; padding: 12px 0; font-size: 1.5rem;
    cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.1s;
    box-shadow: 0 3px 6px rgba(0,0,0,0.05);
}

.btn-minus { background-color: var(--btn-secondary-bg); color: var(--btn-secondary-text); border: 1px solid var(--border); }
.btn-plus { background-color: var(--project-color); color: var(--card-bg); }
.btn-lock { background-color: var(--lock-btn-bg); color: var(--lock-btn-text); font-size: 1.1rem; }
.btn-lock.locked-active { background-color: var(--border); color: var(--text-muted); border: 2px solid var(--text-muted); box-shadow: none;}

.hidden-controls { visibility: hidden; pointer-events: none; }
.dimmed { opacity: 0.4; pointer-events: none; }
button:active { transform: scale(0.97); box-shadow: none; }

/* Floating Add Project Button */
.fab {
    position: fixed; bottom: 30px; right: 30px;
    background-color: var(--text); color: var(--bg); /* Adapts to mode */
    width: 65px; height: 65px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 2.2rem; box-shadow: 0 6px 15px rgba(74, 59, 42, 0.3);
    border: none; z-index: 3; transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.fab:hover { transform: translateY(-3px) scale(1.04) rotate(-2deg); box-shadow: 0 10px 24px rgba(0,0,0,0.18); }
.fab:active { transform: translateY(0) scale(0.94); box-shadow: 0 3px 8px rgba(0,0,0,0.2); }
.fab { z-index: 2; }

/* --- MODAL --- */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(44, 35, 25, 0.6); z-index: 200; align-items: center; justify-content: center; backdrop-filter: blur(2px);
    display: flex; opacity: 0; visibility: hidden; pointer-events: none;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}
.modal-overlay.active { opacity: 1; visibility: visible; pointer-events: auto; }
.modal-content {
    background: var(--modal-bg); color: var(--text);
    padding: 25px; border-radius: 20px; width: 85%; max-width: 400px; 
    animation: none; box-shadow: var(--shadow); border: 1px solid var(--border);
    transform-origin: center;
}
.modal-overlay.active .modal-content { animation: modalIn 0.32s ease; }
@keyframes modalIn { 
    0% { transform: translateY(10px) scale(0.96); opacity: 0; } 
    60% { transform: translateY(-4px) scale(1.02); opacity: 1; } 
    100% { transform: translateY(0) scale(1); opacity: 1; } 
}
.modal-title { margin: 0 0 15px 0; font-size: 1.3rem; color: var(--text); font-weight: 800; }
.modal-input {
    width: 100%; padding: 15px; font-size: 1.2rem;
    background: var(--input-bg); color: var(--text);
    border: 2px solid var(--input-border); border-radius: 12px; margin-bottom: 25px; outline: none; transition: border-color 0.2s;
}
.modal-input:focus { border-color: var(--project-color); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.modal-btn { padding: 12px 24px; border: none; border-radius: 10px; font-size: 1rem; font-weight: 600; cursor: pointer; }
.btn-cancel { background: var(--lock-btn-bg); color: var(--text-muted); }
.btn-save { background: var(--text); color: var(--bg); }

.empty-state { text-align: center; color: var(--text-muted); margin-top: 80px; font-size: 1.2rem; font-style: italic;}

.footer-bg {
    position: fixed;
    left: 0;
    right: 0;
    bottom: -180px;
    height: clamp(760px, 1200px, 1200px);
    background: url('textures/mushroom.svg') no-repeat center bottom;
    background-size: cover;
    opacity: 1;
    width: 125vw;
    pointer-events: none;
    z-index: 0;
}

.firefly-wrap {
    position: fixed;
    left: -12vw;
    width: 28px;
    height: 28px;
    animation: fireflyGlide var(--fly-duration, 14s) linear forwards;
    z-index: 5; /* Float above content but below header */
    pointer-events: none;
}
.firefly {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255,245,200,0.9) 0%, rgba(255,245,200,0.4) 45%, rgba(255,245,200,0.1) 70%, rgba(255,245,200,0) 85%);
    opacity: 0.9;
    mix-blend-mode: screen;
    filter: blur(1px) drop-shadow(0 0 14px rgba(255, 245, 200, 0.8)) brightness(1.15);
    animation: fireflyFlutter 1.6s ease-in-out infinite alternate, fireflyFlicker 1.1s ease-in-out infinite alternate;
}

.seed-wrap {
    position: fixed;
    width: 36px;
    height: 36px;
    animation: seedGlide var(--seed-duration, 16s) linear forwards;
    z-index: 5;
    pointer-events: none;
}
.seed {
    width: 200px;
    height: 200px;
    background: url('textures/seed.svg') no-repeat center/contain;
    opacity: var(--seed-opacity, 0.07);
    mix-blend-mode: screen;
    filter: drop-shadow(0 4px 10px rgba(200, 190, 160, 0.55));
    animation: seedDrift 2.6s ease-in-out infinite alternate, seedFlicker 1.4s ease-in-out infinite alternate;
}
@keyframes fireflyGlide {
    0% { transform: translate3d(-10vw, 0, 0) scale(var(--fly-scale, 1)); opacity: 0; }
    12% { opacity: 0.55; }
    35% { transform: translate3d(25vw, -6px, 0) scale(var(--fly-scale, 1)); opacity: 0.65; }
    65% { transform: translate3d(65vw, 6px, 0) scale(var(--fly-scale, 1)); opacity: 0.55; }
    90% { opacity: 0.35; }
    100% { transform: translate3d(110vw, 0, 0) scale(var(--fly-scale, 1)); opacity: 0; }
}
@keyframes fireflyFlutter {
    0% { transform: translateY(-2px) translateX(-3px) scale(0.95); }
    50% { transform: translateY(3px) translateX(2px) scale(1.05); }
    100% { transform: translateY(-2px) translateX(1px) scale(0.97); }
}
@keyframes fireflyFlicker {
    0% { opacity: 0.65; filter: blur(1px) drop-shadow(0 0 10px rgba(255,245,200,0.65)); }
    50% { opacity: 1; filter: blur(0.5px) drop-shadow(0 0 16px rgba(255,245,200,1)); }
    100% { opacity: 0.75; filter: blur(1px) drop-shadow(0 0 12px rgba(255,245,200,0.75)); }
}

@keyframes seedGlide {
    0% { transform: translate3d(var(--seed-start, -12vw), 0, 0) scale(var(--seed-scale, 1)); opacity: 0; }
    10% { opacity: 0.35; }
    40% { transform: translate3d(calc(var(--seed-mid, 30vw)), -10px, 0) scale(var(--seed-scale, 1)); opacity: 0.5; }
    70% { transform: translate3d(calc(var(--seed-mid, 30vw) * 2), 8px, 0) scale(var(--seed-scale, 1)); opacity: 0.4; }
    100% { transform: translate3d(var(--seed-end, 110vw), -6px, 0) scale(var(--seed-scale, 1)); opacity: 0; }
}
@keyframes seedDrift {
    0% { transform: translateY(-4px) translateX(calc(var(--seed-sway, 6px) * -1)) rotate(calc(var(--seed-tilt, 10deg) * -0.6)) scale(0.94); opacity: 0.65; }
    50% { transform: translateY(5px) translateX(calc(var(--seed-sway, 6px) * 0.8)) rotate(calc(var(--seed-tilt, 10deg))) scale(1.05); opacity: 0.9; }
    100% { transform: translateY(-3px) translateX(calc(var(--seed-sway, 6px) * 0.4)) rotate(calc(var(--seed-tilt, 10deg) * 0.2)) scale(0.97); opacity: 0.7; }
}
@keyframes seedFlicker {
    0% { opacity: 0.65; filter: drop-shadow(0 2px 4px rgba(200,190,160,0.35)); }
    50% { opacity: 0.9; filter: drop-shadow(0 4px 8px rgba(200,190,160,0.5)); }
    100% { opacity: 0.7; filter: drop-shadow(0 3px 6px rgba(200,190,160,0.4)); }
}

@media (max-width: 768px) {
    .footer-bg {
        bottom: -40px;
        height: clamp(260px, 24vh, 450px);
    }
}

@media (max-width: 1024px) and (min-width: 769px) {
    .container {
        padding: 1.5rem 1.25rem calc(140px + env(safe-area-inset-bottom, 0px));
    }
    .footer-bg {
        height: clamp(300px, 28vh, 480px);
        bottom: -180px;
    }
}


/* Sweet-ish alerts */
.swal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(44, 35, 25, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
    padding: 20px;
    animation: overlayFade 0.22s ease;
}

.swal-dialog {
    background: var(--card-bg);
    color: var(--text);
    border-radius: 16px;
    padding: 22px 20px 18px;
    width: min(420px, 90vw);
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
    border: 1px solid var(--border);
    text-align: center;
    position: relative;
    animation: dialogPop 0.28s ease;
}

.swal-title {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-size: 1.4rem;
    margin: 0 0 8px;
}

.swal-text { margin: 0 0 16px; color: var(--text-muted); }

.swal-actions { display: flex; justify-content: center; gap: 10px; }

.swal-btn {
    border: none;
    border-radius: 12px;
    padding: 12px 18px;
    font-weight: 700;
    cursor: pointer;
    min-width: 110px;
    transition: transform 0.08s;
}
.swal-btn:active { transform: scale(0.97); }
.swal-confirm { background: var(--project-color); color: var(--card-bg); }
.swal-cancel { background: var(--lock-btn-bg); color: var(--text); }
.swal-danger { background: var(--danger); color: var(--card-bg); }
@keyframes overlayFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes dialogPop { 
    0% { transform: translateY(8px) scale(0.96); opacity: 0; } 
    60% { transform: translateY(-3px) scale(1.02); opacity: 1; } 
    100% { transform: translateY(0) scale(1); opacity: 1; } 
}
