/* --- VARIABLES --- */
:root {
    /* Light Mode */
    --bg-body: #ffffff;
    --bg-surface: #f7f7f8; /* Slight contrast for cards */
    --bg-surface-hover: #ffffff;
    --border: #e1e1e6;
    
    --text-main: #1d1d1f;
    --text-sub: #86868b;
    
    --accent: #000000;
    --accent-fg: #ffffff;
    
    --brand-blue: #0071e3;
    --brand-gradient: linear-gradient(135deg, #0071e3 0%, #00c6fb 100%);
    
    --radius-xl: 24px;
    --radius-l: 16px;
    --radius-m: 12px;
    
    --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --shadow-hover: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    
    --font-heading: 'Poppins', sans-serif;
    --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-body: #050505;
        --bg-surface: #121212;
        --bg-surface-hover: #1c1c1e;
        --border: #2d2d2d;
        
        --text-main: #f5f5f7;
        --text-sub: #a1a1a6;
        
        --accent: #ffffff;
        --accent-fg: #000000;
        
        --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
        --shadow-hover: 0 20px 25px -5px rgba(0, 0, 0, 0.6);
    }
}

/* --- RESET & BASE --- */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { scroll-behavior: smooth; }

body {
    background-color: var(--bg-body);
    color: var(--text-main);
    font-family: var(--font-body);
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { text-decoration: none; color: inherit; }
button { border: none; background: none; font-family: inherit; cursor: pointer; }

/* --- HEADER (Minimal) --- */
.studio-header {
    padding: 24px 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-body); /* Solid bg to hide scroll */
    background: rgba(var(--bg-body), 0.8); /* Or blur if you convert hex to rgb */
    backdrop-filter: blur(12px);
    border-bottom: 1px solid transparent;
    transition: border-color 0.3s;
}

.studio-header.scrolled {
    border-color: var(--border);
}

.brand-area {
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 18px;
    cursor: pointer;
}
.brand-logo { width: 28px; height: auto; }
@media (prefers-color-scheme: dark) { .brand-logo { filter: invert(1); } }

.header-actions { display: flex; gap: 16px; }

.theme-btn {
    width: 40px; height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: var(--text-main);
}
.theme-btn:hover { background: var(--bg-surface); }

/* --- HERO SECTION --- */
.studio-hero {
    text-align: center;
    padding: 60px 20px 40px;
    max-width: 800px;
    margin: 0 auto;
    animation: fadeInDown 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

.studio-title {
    font-family: var(--font-heading);
    font-size: 48px;
    font-weight: 600;
    line-height: 1.1;
    margin-bottom: 16px;
    background: linear-gradient(180deg, var(--text-main) 0%, var(--text-sub) 150%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.studio-subtitle {
    font-size: 18px;
    color: var(--text-sub);
    margin-bottom: 40px;
}

/* --- SEARCH BAR (Central Hub) --- */
.search-hub {
    position: relative;
    max-width: 600px;
    margin: 0 auto;
    z-index: 50;
}

.search-input-wrapper {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 50px;
    padding: 8px 8px 8px 24px;
    display: flex;
    align-items: center;
    box-shadow: var(--shadow-card);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.search-input-wrapper:focus-within {
    transform: scale(1.02);
    box-shadow: 0 0 0 2px var(--brand-blue), var(--shadow-hover);
    border-color: transparent;
    background: var(--bg-body);
}

.search-icon { font-size: 20px; color: var(--text-sub); margin-right: 12px; }

.search-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 16px;
    color: var(--text-main);
    outline: none;
    height: 40px;
}

/* Freeform Badge inside search or next to it? Let's keep search clean */

/* --- FILTER PILLS --- */
.filter-rail {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 40px;
    padding-bottom: 20px;
    overflow-x: auto;
    scrollbar-width: none; /* Hide scrollbar */
    padding-left: 20px; padding-right: 20px;
    mask-image: linear-gradient(90deg, transparent 0%, black 5%, black 95%, transparent 100%);
}

.filter-pill {
    padding: 10px 20px;
    border-radius: 30px;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    border: 1px solid var(--border);
    color: var(--text-sub);
    background: var(--bg-body);
    transition: all 0.2s;
}

.filter-pill:hover {
    color: var(--text-main);
    border-color: var(--text-sub);
}

.filter-pill.active {
    background: var(--accent);
    color: var(--accent-fg);
    border-color: var(--accent);
}

/* --- MAIN GRID --- */
.template-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px 40px 80px;
    width: 100%;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 24px;
    padding: 0 10px;
}

.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-sub);
}
.crumb-item.active { color: var(--text-main); font-weight: 600; }
.crumb-sep { opacity: 0.5; }

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 24px;
}

/* --- CARD DESIGN (Studio Style) --- */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 24px;
    position: relative;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    cursor: pointer;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 220px;
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-hover);
    background: var(--bg-surface-hover);
    border-color: var(--brand-blue);
}

/* Special "Freeform" Card */
.card-create-new {
    background: var(--bg-body);
    border: 2px dashed var(--border);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.card-create-new:hover {
    border-color: var(--text-main);
    border-style: solid;
}

.create-icon-circle {
    width: 56px; height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-fg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    margin-bottom: 16px;
    transition: transform 0.3s;
}
.card-create-new:hover .create-icon-circle { transform: rotate(90deg); }

/* Standard Template Card */
.card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
}

.card-icon-box {
    width: 48px; height: 48px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    color: white;
}

.ai-badge {
    font-size: 11px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 20px;
    background: linear-gradient(135deg, #a855f7 0%, #d8b4fe 100%);
    color: white;
    display: flex;
    align-items: center;
    gap: 4px;
}

.card-content { flex: 1; }

.card-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-main);
}

.card-desc {
    font-size: 14px;
    color: var(--text-sub);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-arrow {
    margin-top: 20px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--brand-blue);
    opacity: 0;
    transform: translateX(-10px);
    transition: all 0.3s;
}

.card:hover .card-arrow {
    opacity: 1;
    transform: translateX(0);
}

/* Category Card specific styling */
.card-category .card-icon-box { border-radius: 50%; width: 56px; height: 56px; }
.card-category { align-items: center; text-align: center; justify-content: center; }
.card-category .card-top { justify-content: center; width: 100%; margin-bottom: 16px; }
.card-category .card-title { margin-bottom: 4px; }
.card-category .card-desc { -webkit-line-clamp: 2; margin-bottom: 0; }

/* --- MODAL --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.modal-overlay.show { opacity: 1; pointer-events: all; }

.modal-panel {
    width: 600px;
    max-width: 90vw;
    background: var(--bg-body);
    border-radius: var(--radius-xl);
    padding: 32px;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
    border: 1px solid var(--border);
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    overflow: hidden;
}

.modal-overlay.show .modal-panel { transform: scale(1); }

.modal-close {
    position: absolute;
    top: 20px;
    right: 20px;
    padding: 8px;
    color: var(--text-sub);
    border-radius: 50%;
    transition: 0.2s;
}
.modal-close:hover { background: var(--bg-surface); color: var(--text-main); }

.modal-header-row {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.modal-icon-lg {
    width: 64px; height: 64px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    color: white;
    flex-shrink: 0;
}

.modal-title { font-size: 24px; font-weight: 600; margin-bottom: 4px; }
.modal-subtitle { color: var(--text-sub); font-size: 14px; }

.modal-prompt-area {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-l);
    padding: 16px;
    margin-bottom: 24px;
}

.prompt-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-sub);
    text-transform: uppercase;
    margin-bottom: 8px;
    letter-spacing: 0.5px;
}

.prompt-textarea {
    width: 100%;
    background: transparent;
    border: none;
    font-family: inherit;
    font-size: 15px;
    color: var(--text-main);
    resize: none;
    outline: none;
    min-height: 80px;
}

.modal-btn {
    width: 100%;
    padding: 16px;
    background: var(--accent);
    color: var(--accent-fg);
    border-radius: 50px;
    font-weight: 600;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.2s;
}
.modal-btn:hover { transform: scale(1.02); opacity: 0.95; }
.modal-btn:disabled { opacity: 0.7; cursor: wait; }

/* --- ICON COLORS --- */
.bg-blue { background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%); }
.bg-emerald { background: linear-gradient(135deg, #10b981 0%, #059669 100%); }
.bg-violet { background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%); }
.bg-rose { background: linear-gradient(135deg, #f43f5e 0%, #e11d48 100%); }
.bg-orange { background: linear-gradient(135deg, #f97316 0%, #ea580c 100%); }
.bg-cyan { background: linear-gradient(135deg, #06b6d4 0%, #0891b2 100%); }
.bg-dark { background: linear-gradient(135deg, #333 0%, #000 100%); }

/* --- RESPONSIVE --- */
@media (max-width: 768px) {
    .studio-header { padding: 16px 20px; }
    .studio-title { font-size: 32px; }
    .template-container { padding: 20px; }
    .filter-rail { justify-content: flex-start; }
    .grid { grid-template-columns: 1fr; }
}

/* --- ANIMATIONS --- */
@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#themeToggle {
    display: none;
}