/* FILE: css/magic-app.css */
/* --- MAGICAL THEME VARIABLES --- */
:root {
    --primary: #6366f1;
    --primary-glow: rgba(99, 102, 241, 0.4);
    --secondary: #ec4899;
    --accent: #f59e0b;
    --bg-gradient: linear-gradient(135deg, #fdfbfb 0%, #ebedee 100%);
    --glass: rgba(255, 255, 255, 0.95);
    --glass-border: rgba(255, 255, 255, 0.9);
    --text-dark: #1e293b;
    --text-light: #64748b;
    --radius-xl: 32px;
    --radius-md: 20px;
    --shadow-float: 0 20px 50px -10px rgba(99, 102, 241, 0.15);
    --header-height: 60px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    /* overflow-x: hidden; Removed global hidden to allow mobile sticky tricks */
}

body {
    font-family: 'Nunito', sans-serif;
    background: #f0f4ff;
    color: var(--text-dark);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    overscroll-behavior-y: none;
}

/* --- BACKGROUND MAGIC --- */
.orb {
    position: fixed; 
    border-radius: 50%;
    filter: blur(80px);
    z-index: -1;
    animation: float 10s infinite ease-in-out;
    pointer-events: none;
}

.orb-1 {
    width: 300px;
    height: 300px;
    background: #c7d2fe;
    top: -50px;
    left: -50px;
}

.orb-2 {
    width: 400px;
    height: 400px;
    background: #fbcfe8;
    bottom: -100px;
    right: -100px;
    animation-delay: 2s;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(30px, 50px); }
}

/* --- CONTAINER & GLASS CARD --- */
.container {
    width: 100%;
    max-width: 600px;
    padding: 20px;
    position: relative;
    z-index: 10;
    display: flex;
    flex-direction: column;
    height: 100%;
    padding-bottom: 20px; 
}

.wizard-card {
    background: var(--glass);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border: 2px solid white;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-float);
    padding: 40px 30px;
    min-height: 650px;
    display: flex;
    flex-direction: column;
    position: relative;
    transition: all 0.3s ease;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    overflow-x: hidden;
}

/* --- TYPOGRAPHY --- */
h1, h2, h3 {
    font-family: 'Quicksand', sans-serif;
    line-height: 1.2;
}

h1 {
    font-size: 2.8rem;
    background: linear-gradient(45deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 10px;
}

h2 {
    font-size: 2rem;
    color: var(--text-dark);
    margin-bottom: 10px;
}

p.subtitle {
    color: var(--text-light);
    font-size: 1.15rem;
    margin-bottom: 25px;
    line-height: 1.6;
}

/* --- NAVIGATION --- */
.header-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-shrink: 0;
}

.back-btn {
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid #e2e8f0;
    padding: 10px 18px;
    border-radius: 20px;
    color: var(--text-light);
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.back-btn:hover {
    background: white;
    color: var(--primary);
    transform: translateX(-3px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

/* --- LANDING PAGE VISUALS --- */
.book-shelf {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin: 40px 0;
    perspective: 1000px;
}

.book-hero-img {
    width: 140px;
    height: auto;
    object-fit: contain;
    border-radius: 6px; 
    box-shadow: 0 12px 24px rgba(0,0,0,0.15); 
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    cursor: pointer;
}

.book-hero-img:hover {
    transform: translateY(-10px) scale(1.1) rotate(-3deg);
    box-shadow: 0 20px 40px rgba(0,0,0,0.25);
    z-index: 10;
}

.book-hero-center {
    width: 160px;
    z-index: 2;
    transform: scale(1.05);
}

.book-hero-center:hover {
    transform: translateY(-10px) scale(1.15);
}

.value-props {
    display: flex;
    justify-content: space-around;
    margin-bottom: auto;
    gap: 10px;
    background: rgba(255,255,255,0.5);
    padding: 15px;
    border-radius: 20px;
}

/* --- CUSTOM INPUTS --- */
.big-input {
    width: 100%;
    font-size: 2rem;
    font-weight: 800;
    text-align: center;
    border: 2px solid transparent;
    background: rgba(255, 255, 255, 0.6);
    border-radius: var(--radius-md);
    padding: 20px;
    font-family: 'Quicksand', sans-serif;
    outline: none;
    margin-bottom: 25px;
    color: var(--primary);
    transition: all 0.3s;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
}

.big-input:focus {
    background: white;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-glow);
}

.big-input::placeholder {
    color: #cbd5e1;
    font-weight: 600;
}

.story-textarea {
    width: 100%;
    height: 150px;
    border: 2px solid transparent;
    background: rgba(255, 255, 255, 0.8);
    border-radius: var(--radius-md);
    padding: 20px;
    font-size: 16px;
    font-family: 'Nunito', sans-serif;
    resize: none;
    outline: none;
    color: var(--text-dark);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
    margin-bottom: 20px;
    transition: all 0.2s;
}

.story-textarea:focus {
    background: white;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-glow);
}

/* --- GENDER SELECTOR --- */
.gender-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 25px;
}

.gender-card {
    background: white;
    border: 3px solid transparent;
    border-radius: var(--radius-md);
    padding: 20px;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.03);
    position: relative;
    overflow: hidden;
}

.gender-card:hover {
    transform: translateY(-2px);
    border-color: #e2e8f0;
}

.gender-card.selected {
    border-color: var(--primary);
    background: #eef2ff;
    transform: scale(1.02);
    box-shadow: 0 10px 25px rgba(99, 102, 241, 0.2);
}

.gender-card.selected::after {
    content: '✓';
    position: absolute;
    top: 10px;
    right: 10px;
    background: var(--primary);
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
}

.gender-icon {
    font-size: 3rem;
    display: block;
    margin-bottom: 8px;
}

.gender-label {
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--text-dark);
}

/* --- AGE SLIDER --- */
.age-control {
    background: white;
    padding: 25px;
    border-radius: var(--radius-md);
    text-align: center;
    margin-bottom: 20px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.03);
}

.age-display {
    font-size: 3.5rem;
    font-weight: 800;
    color: var(--secondary);
    font-family: 'Quicksand', sans-serif;
    display: block;
    margin-bottom: 5px;
    line-height: 1;
}

input[type=range] {
    width: 100%;
    -webkit-appearance: none;
    background: transparent;
    margin-top: 15px;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 32px;
    width: 32px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    margin-top: -13px;
    box-shadow: 0 4px 10px rgba(99, 102, 241, 0.4);
    border: 4px solid white;
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 8px;
    cursor: pointer;
    background: #e2e8f0;
    border-radius: 10px;
}

/* --- APPEARANCE MODE CARDS --- */
.mode-card {
    background: white;
    border: 2px solid white;
    padding: 20px;
    border-radius: var(--radius-md);
    margin-bottom: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 20px;
    transition: all 0.3s;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.03);
    position: relative;
    overflow: hidden;
}

.mode-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
    border-color: var(--primary);
}

.mode-icon-box {
    min-width: 60px;
    height: 60px;
    background: #eef2ff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
}

.secure-badge {
    font-size: 0.75rem;
    color: #10b981;
    display: flex;
    align-items: center;
    gap: 4px;
    background: #ecfdf5;
    padding: 4px 10px;
    border-radius: 20px;
    width: fit-content;
    margin-top: 5px;
    font-weight: 700;
}

/* --- BUILDER SWATCHES --- */
.label-sm {
    font-weight: 800;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-light);
    margin-bottom: 12px;
    display: block;
    margin-top: 15px;
}

.swatch-grid {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.color-swatch {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid white;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s;
    position: relative;
}

.color-swatch:hover {
    transform: scale(1.1);
}

.color-swatch.selected {
    transform: scale(1.15);
    border-color: var(--primary);
}

.color-swatch.selected::after {
    content: '✓';
    color: white;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-weight: 900;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.style-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 10px;
}

.style-btn {
    background: white;
    border: 2px solid transparent;
    padding: 12px;
    border-radius: 16px;
    text-align: center;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-dark);
    transition: all 0.2s;
    box-shadow: 0 2px 5px rgba(0,0,0,0.02);
}

.style-btn:hover {
    transform: translateY(-2px);
    border-color: #e2e8f0;
}

.style-btn.selected {
    background: #eef2ff;
    color: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.15);
}

/* --- BIG BUTTON --- */
.button-container {
    margin-top: auto;
    padding-top: 20px;
    width: 100%;
}

.magic-btn {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border: none;
    padding: 20px;
    width: 100%;
    border-radius: 50px;
    font-size: 1.25rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 10px 25px -5px rgba(99, 102, 241, 0.4);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    letter-spacing: 0.5px;
    z-index: 100;
}

.magic-btn:hover {
    transform: scale(1.02) translateY(-2px);
    box-shadow: 0 15px 30px -5px rgba(99, 102, 241, 0.5);
}

.magic-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
    background: #cbd5e1;
}

.magic-btn::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(rgba(255, 255, 255, 0.2), transparent);
    transform: rotate(45deg);
    animation: shimmer 3s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%) rotate(45deg); }
    100% { transform: translateX(100%) rotate(45deg); }
}

/* --- TOAST NOTIFICATION --- */
.toast-notification {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #ef4444; 
    color: white;
    padding: 12px 24px;
    border-radius: 50px;
    font-weight: 700;
    box-shadow: 0 10px 30px rgba(239, 68, 68, 0.4);
    z-index: 9999;
    animation: shake 0.5s cubic-bezier(.36,.07,.19,.97) both;
    display: flex;
    align-items: center;
    gap: 8px;
}

@keyframes shake {
  10%, 90% { transform: translate3d(-51%, 0, 0); }
  20%, 80% { transform: translate3d(-49%, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-52%, 0, 0); }
  40%, 60% { transform: translate3d(-48%, 0, 0); }
}

/* --- INTEREST TAGS --- */
.tag-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
}

.tag-pill {
    background: white;
    border: 2px solid transparent;
    padding: 12px 20px;
    border-radius: 30px;
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-light);
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.02);
    display: flex;
    align-items: center;
    gap: 8px;
}

.tag-pill:hover {
    transform: translateY(-2px);
    color: var(--primary);
}

.tag-pill.selected {
    background: var(--primary);
    color: white;
    box-shadow: 0 8px 15px rgba(99, 102, 241, 0.3);
    border-color: var(--primary);
}

.add-tag-group {
    margin-top: 10px;
    display: flex;
    gap: 10px;
    width: 100%;
}

.add-btn {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 15px;
    width: 54px;
    font-size: 1.5rem;
    cursor: pointer;
    transition: 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.add-btn:hover {
    background: var(--secondary);
}

/* --- CARDS (GENRES) --- */
.selection-card {
    background: white;
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 140px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.02);
}

.selection-card:hover {
    transform: translateY(-5px);
    border-color: var(--primary);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.05);
}

.selection-card.selected {
    background: #eef2ff;
    border-color: var(--primary);
    transform: scale(0.98); 
}

.selection-card.custom-card {
    border: 2px dashed var(--primary);
    background: #eff6ff;
    min-height: unset;
    height: auto;
    padding: 15px 20px;
    margin-bottom: 20px;
    display: flex;
    flex-direction: row; 
    align-items: center;
    justify-content: flex-start;
    text-align: left;
    gap: 15px;
}

.custom-card:hover {
    background: #e0e7ff;
    border-style: solid;
}

.lesson-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

/* --- STORY RESULT CARDS --- */
.story-result-card {
    background: white;
    border-radius: 20px;
    padding: 20px;
    margin-bottom: 20px;
    border: 3px solid transparent; 
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    transition: all 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    cursor: pointer;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 10px;
    position: relative;
    overflow: hidden;
}

.story-result-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 15px 30px rgba(99, 102, 241, 0.1);
}

.story-result-card.selected {
    border-color: var(--primary);
    background: #f5f7ff;
    box-shadow: 0 15px 40px rgba(99, 102, 241, 0.2);
    transform: scale(1.01);
}

.story-result-card.selected::before {
    content: '';
    position: absolute;
    top: 0; left: 0; bottom: 0; width: 6px;
    background: var(--primary);
}

.story-badge {
    align-self: flex-start;
    background: var(--accent);
    color: white;
    font-size: 0.75rem;
    font-weight: 800;
    padding: 4px 12px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.story-title {
    font-size: 1.4rem;
    font-family: 'Quicksand', sans-serif;
    font-weight: 700;
    line-height: 1.2;
    color: var(--text-dark);
}

.story-desc {
    color: var(--text-light);
    font-size: 1rem;
    line-height: 1.5;
    margin-bottom: 5px;
}

/* --- ANIMATIONS --- */
.fade-in { animation: fadeIn 0.4s ease-out forwards; }
.slide-up { animation: slideUp 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards; }
.pop-in { animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: translateY(0); } }
@keyframes popIn { from { opacity: 0; transform: scale(0.8); } to { opacity: 1; transform: scale(1); } }

.hidden { display: none; }

/* ------------------------------------------------------------------
   GOD TIER MOBILE FIXES 
   ------------------------------------------------------------------ */
@media (max-width: 640px) {
    /* 1. Viewport Fix: Use Dynamic Height (dvh) to avoid address bar hiding content */
    body {
        height: 100dvh;
        justify-content: flex-start;
        align-items: flex-start;
        background: #fff;
        padding: 0;
        overflow: hidden; /* Prevent body scroll, we scroll the 'card' now */
    }

    /* 2. Container takes full space */
    .container {
        padding: 0;
        max-width: 100%;
        height: 100%;
        padding-bottom: 0; /* Let internal spacing handle this */
    }

    /* 3. Wizard Card becomes the 'Screen' */
    .wizard-card {
        border-radius: 0;
        border: none;
        box-shadow: none;
        min-height: 0; /* Reset desktop minimum */
        height: 100%; /* Fill screen */
        width: 100%;
        margin: 0;
        padding: 20px 20px 0 20px; /* Top/Side padding, bottom handled by footer */
        
        /* This is the MAIN SCROLLABLE AREA for mobile */
        overflow-y: auto; 
        -webkit-overflow-scrolling: touch; /* Momentum scroll */
        display: flex;
        flex-direction: column;
    }

    /* 4. Remove 'ghost' gradient from old code */
    .wizard-card::after {
        display: none;
    }

    /* 5. Fix Internal Scroll Conflicts 
       The JS adds id="scrollable-content" with overflows. 
       We must override this on mobile to allow the window to scroll naturally. 
    */
    #scrollable-content {
        overflow-y: visible !important;
        flex: 0 0 auto !important; /* Allow it to take up its natural height */
        padding-bottom: 0 !important;
    }
    
    /* Make the inner content wrappers (fade-in, slide-up) grow properly */
    .wizard-card > div {
        flex-grow: 1;
        display: flex;
        flex-direction: column;
        min-height: min-content;
    }

    /* 6. Sticky Footer (The "Thumb Zone") 
       This ensures the button is ALWAYS visible at the bottom 
       of the screen (sticky) or at the end of content (static-ish).
    */
    .button-container {
        position: sticky;
        bottom: 0;
        background: linear-gradient(to top, #ffffff 90%, rgba(255,255,255,0));
        padding-top: 30px;
        padding-bottom: calc(20px + env(safe-area-inset-bottom)); /* iPhone Home Bar Safety */
        margin-top: auto;
        z-index: 50;
        width: 100%;
    }

    /* 7. Text & Sizing Tweaks for readability */
    h1 { font-size: 2.2rem; }
    h2 { font-size: 1.8rem; }
    
    .gender-grid { grid-template-columns: 1fr; }
    .big-input { font-size: 1.5rem; }
    .age-display { font-size: 3rem; }
    
    /* Better Grid for Hair/Styles */
    .style-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    /* Adjust Book Images */
    .book-hero-img { width: 110px; }
    .book-hero-center { width: 130px; }
    
    .orb { opacity: 0.5; }
}