/* -------------------------------------------------------------------------- */
/* Design Tokens & Theme Variables                                            */
/* -------------------------------------------------------------------------- */
:root {
    --bg-main: #0b0f19;
    --bg-workspace: #0f172a;
    --bg-panel: rgba(22, 28, 45, 0.7);
    --bg-editor: #090d16;
    --border-color: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(255, 255, 255, 0.16);
    
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    
    --accent-primary: #6366f1;         /* Indigo */
    --accent-primary-hover: #4f46e5;
    --accent-secondary: #06b6d4;       /* Cyan */
    --accent-success: #10b981;         /* Emerald */
    --accent-success-hover: #059669;
    --accent-danger: #f43f5e;          /* Rose */
    --accent-danger-hover: #e11d48;
    --bg-accent-dim: rgba(99, 102, 241, 0.1);
    
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'Fira Code', 'JetBrains Mono', monospace;
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.1);
    --shadow-glow: 0 0 15px rgba(99, 102, 241, 0.25);
    
    --border-radius-sm: 6px;
    --border-radius-md: 10px;
    --border-radius-lg: 16px;
    
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* -------------------------------------------------------------------------- */
/* Reset & Core Page Layout                                                   */
/* -------------------------------------------------------------------------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: var(--font-sans);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-main);
}
::-webkit-scrollbar-thumb {
    background: var(--border-hover);
    border-radius: var(--border-radius-sm);
}
::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}

/* Base Headings */
h1, h2, h3, h4 {
    font-weight: 600;
    letter-spacing: -0.025em;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 500;
    padding: 8px 14px;
    border-radius: var(--border-radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: var(--transition-fast);
    outline: none;
    user-select: none;
    white-space: nowrap;
}

.btn-primary {
    background-color: var(--accent-success);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2);
}
.btn-primary:hover {
    background-color: var(--accent-success-hover);
    transform: translateY(-1px);
}
.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.05);
    border-color: var(--border-color);
    color: var(--text-secondary);
}
.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: var(--border-hover);
    color: var(--text-primary);
}

.btn-danger {
    background-color: rgba(244, 63, 94, 0.1);
    border: 1px solid rgba(244, 63, 94, 0.2);
    color: var(--accent-danger);
}
.btn-danger:hover {
    background-color: var(--accent-danger);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(244, 63, 94, 0.2);
}

.btn-icon-only {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.1rem;
    transition: var(--transition-fast);
}
.btn-icon-only:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

/* Focus Indicator */
button:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* -------------------------------------------------------------------------- */
/* Ad Placements (SEO/CLS Safe Design)                                        */
/* -------------------------------------------------------------------------- */
.ad-container-top,
.ad-container-bottom {
    width: 100%;
    max-width: 100%;
    margin: 10px auto;
    padding: 0 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.ad-container-sidebar {
    width: 320px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    border-left: 1px solid var(--border-color);
    background-color: var(--bg-panel);
}

.ad-label {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.1em;
    margin-bottom: 4px;
    text-align: center;
    width: 100%;
}

/* Box reservation preventing CLS */
.ad-placeholder-box {
    background: radial-gradient(circle at top left, rgba(99, 102, 241, 0.08), transparent), 
                rgba(255, 255, 255, 0.02);
    border: 1px dashed rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius-md);
    width: 100%;
    max-width: 728px; /* Leaderboard limit */
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
    box-shadow: inset 0 0 12px rgba(0,0,0,0.2);
}

.ad-container-sidebar .ad-placeholder-box {
    max-width: 300px;
}

.ad-placeholder-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px;
    text-align: center;
}

.ad-icon {
    font-size: 1.5rem;
    color: var(--accent-primary);
    animation: pulseAd 3s infinite ease-in-out;
    margin-bottom: 6px;
}

.ad-text {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

@keyframes pulseAd {
    0%, 100% { opacity: 0.6; transform: scale(1); filter: drop-shadow(0 0 0px var(--accent-primary)); }
    50% { opacity: 1; transform: scale(1.1); filter: drop-shadow(0 0 6px var(--accent-primary)); }
}

/* -------------------------------------------------------------------------- */
/* Application Header                                                         */
/* -------------------------------------------------------------------------- */
.app-header {
    background: rgba(11, 15, 25, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-icon {
    font-size: 1.5rem;
    color: var(--accent-secondary);
    filter: drop-shadow(0 0 4px var(--accent-secondary));
}

.header-logo h1 {
    font-size: 1.25rem;
    color: var(--text-primary);
    background: linear-gradient(135deg, var(--text-primary) 30%, var(--text-muted));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-badge {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--accent-primary);
    background-color: var(--bg-accent-dim);
    border: 1px solid rgba(99, 102, 241, 0.2);
    padding: 2px 6px;
    border-radius: 9999px;
    letter-spacing: 0.05em;
}

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

.divider {
    width: 1px;
    height: 24px;
    background-color: var(--border-color);
    margin: 0 4px;
}

/* Dropdown Menu styling */
.dropdown-wrapper {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background-color: var(--bg-workspace);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    padding: 6px;
    min-width: 180px;
    display: none;
    flex-direction: column;
    gap: 2px;
    box-shadow: var(--shadow-lg);
    z-index: 110;
    animation: dropdownShow 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

.dropdown-menu.active {
    display: flex;
}

.dropdown-item {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 8px 12px;
    text-align: left;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: var(--transition-fast);
}

.dropdown-item:hover {
    background-color: var(--bg-accent-dim);
    color: var(--accent-secondary);
}

@keyframes dropdownShow {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* -------------------------------------------------------------------------- */
/* WorkSpace (Split Screen Editor & Preview)                                  */
/* -------------------------------------------------------------------------- */
.app-workspace {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr 320px;
    background-color: var(--bg-workspace);
    height: calc(100vh - 63px - 110px); /* header height and top ad height offsets */
    min-height: 500px;
}

.workspace-panel {
    display: flex;
    flex-direction: column;
    background-color: var(--bg-panel);
    overflow: hidden;
}

.editor-panel {
    border-right: 1px solid var(--border-color);
}

.panel-header {
    background-color: rgba(9, 13, 22, 0.4);
    border-bottom: 1px solid var(--border-color);
    padding: 0 16px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
}

.panel-indicator {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

/* Tabs */
.editor-tabs {
    display: flex;
    gap: 4px;
    height: 100%;
    align-items: flex-end;
}

.tab-btn {
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 500;
    padding: 12px 16px;
    cursor: pointer;
    transition: var(--transition-fast);
    height: 100%;
}
.tab-btn:hover {
    color: var(--text-primary);
    background-color: rgba(255,255,255,0.02);
}
.tab-btn.active {
    color: var(--accent-secondary);
    border-bottom-color: var(--accent-secondary);
    background-color: rgba(255,255,255,0.04);
}

/* Editor Body */
.editor-body {
    flex: 1;
    position: relative;
    background-color: var(--bg-editor);
}

.editor-textarea-wrapper {
    position: absolute;
    inset: 0;
    display: none;
    grid-template-columns: 48px 1fr;
    overflow: hidden;
}

.editor-textarea-wrapper.active {
    display: grid;
}

.line-numbers {
    background-color: rgba(9, 13, 22, 0.8);
    border-right: 1px solid var(--border-color);
    padding: 16px 0;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.6;
    color: var(--text-muted);
    text-align: right;
    padding-right: 12px;
    user-select: none;
    overflow: hidden;
}

.code-textarea {
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    resize: none;
    outline: none;
    color: #e2e8f0;
    font-family: var(--font-mono);
    font-size: 14px; /* Dynamically adjusted */
    line-height: 1.6;
    padding: 16px;
    tab-size: 2;
    -moz-tab-size: 2;
    white-space: pre;
    overflow: auto;
}

/* Preview controls & screen emulation */
.preview-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.preview-mode-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1rem;
    cursor: pointer;
    padding: 4px;
    border-radius: var(--border-radius-sm);
    transition: var(--transition-fast);
}
.preview-mode-btn:hover {
    color: var(--text-primary);
    background-color: rgba(255,255,255,0.05);
}
.preview-mode-btn.active {
    color: var(--accent-primary);
    background-color: var(--bg-accent-dim);
}

.size-indicator {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    margin-left: 6px;
}

.preview-body {
    flex: 1;
    background-color: #f1f5f9;
    padding: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    position: relative;
    transition: background-color var(--transition-normal);
}

#preview-frame {
    width: 100%;
    height: 100%;
    background-color: #ffffff;
    border: none;
    box-shadow: var(--shadow-lg);
    border-radius: var(--border-radius-sm);
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Responsiveness modes applied to iframe */
.preview-body.tablet #preview-frame {
    width: 768px;
    height: 1024px;
    max-height: 100%;
}

.preview-body.mobile #preview-frame {
    width: 375px;
    height: 667px;
    max-height: 100%;
}

/* -------------------------------------------------------------------------- */
/* Modal Overlay                                                              */
/* -------------------------------------------------------------------------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(2, 6, 23, 0.85);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background-color: var(--bg-workspace);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    width: 90%;
    max-width: 460px;
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    overflow: hidden;
    animation: modalSlide 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-size: 1.1rem;
    color: var(--text-primary);
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    transition: var(--transition-fast);
}
.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.setting-row label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.setting-row select {
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: var(--border-radius-sm);
    outline: none;
    cursor: pointer;
    font-family: var(--font-sans);
}

/* Switch styling */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}
.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: rgba(255,255,255,0.1);
    transition: .4s;
    border-radius: 24px;
    border: 1px solid var(--border-color);
}
.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: var(--text-secondary);
    transition: .4s;
    border-radius: 50%;
}
input:checked + .slider {
    background-color: var(--accent-primary);
}
input:checked + .slider:before {
    transform: translateX(20px);
    background-color: #ffffff;
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
}

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

/* -------------------------------------------------------------------------- */
/* SEO Explanatory Content & FAQ Section                                      */
/* -------------------------------------------------------------------------- */
.app-info-footer {
    background-color: var(--bg-main);
    border-top: 1px solid var(--border-color);
    padding: 48px 24px 24px 24px;
    margin-top: auto;
}

.seo-rich-content {
    max-width: 1000px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 32px;
}

.seo-intro h2,
.seo-features h3,
.seo-faq h3 {
    color: var(--text-primary);
    margin-bottom: 12px;
}

.seo-intro h2 {
    font-size: 1.5rem;
    background: linear-gradient(135deg, var(--text-primary) 30%, var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.seo-intro p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 12px;
    line-height: 1.7;
}

.seo-features h3,
.seo-faq h3 {
    font-size: 1.25rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
}

.seo-features ul {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    margin-top: 16px;
}

.seo-features li {
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    padding: 16px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    transition: var(--transition-fast);
}

.seo-features li:hover {
    border-color: var(--accent-primary);
    transform: translateY(-2px);
}

.seo-features li strong {
    color: var(--text-primary);
    display: block;
    margin-bottom: 4px;
}

/* FAQ Accordion Details Styles */
.seo-faq {
    margin-top: 8px;
}

.faq-item {
    margin-bottom: 12px;
}

.faq-item details {
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    transition: var(--transition-fast);
    overflow: hidden;
}

.faq-item details[open] {
    border-color: var(--accent-secondary);
}

.faq-item summary {
    padding: 16px 20px;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
    list-style-type: none; /* Hide default arrow in some browsers */
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.faq-item summary::-webkit-details-marker {
    display: none; /* Hide default arrow in WebKit */
}

.faq-item summary::after {
    content: '+';
    font-size: 1.2rem;
    color: var(--accent-secondary);
    transition: transform var(--transition-fast);
}

.faq-item details[open] summary::after {
    content: '−';
    transform: rotate(180deg);
}

.faq-answer {
    padding: 0 20px 16px 20px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.6;
    border-top: 1px dashed var(--border-color);
    padding-top: 12px;
}

.faq-answer code {
    background-color: var(--bg-main);
    color: var(--accent-secondary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
}

.footer-bottom {
    text-align: center;
    margin-top: 48px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

.footer-bottom p {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* -------------------------------------------------------------------------- */
/* Responsive Adaptation                                                      */
/* -------------------------------------------------------------------------- */
@media (max-width: 1200px) {
    .app-workspace {
        grid-template-columns: 1fr 1fr;
        height: auto;
        min-height: 600px;
    }
    
    .ad-container-sidebar {
        display: none; /* Hide sidebar ad unit to conserve developer space */
    }
}

@media (max-width: 768px) {
    html {
        font-size: 14px;
    }
    
    .app-header {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }
    
    .header-actions {
        justify-content: space-between;
    }
    
    .app-workspace {
        grid-template-columns: 1fr;
        grid-template-rows: 400px 400px;
        height: auto;
    }
    
    .editor-panel {
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    
    .preview-body {
        padding: 12px;
    }
    
    .preview-body.tablet #preview-frame,
    .preview-body.mobile #preview-frame {
        width: 100%;
        height: 100%;
    }
    
    .ad-placeholder-box {
        aspect-ratio: auto !important;
        height: 50px;
    }
    
    .ad-text {
        font-size: 0.65rem;
    }
}
