/* tools/code-playground/code-playground.css */

/* --- Overall Tool Page Layout (consistent with other tools) --- */
.tool-page-main {
    padding: 4rem 0 5rem; 
    background-color: var(--bg-main);
    overflow-x: hidden; 
}

.tool-container {
    max-width: 80vw; /* Consistent with other tools */
    margin: 0 auto;
    padding: 0 var(--space-xl); 
}
@media (min-width: 1600px) { 
    .tool-container {
        max-width: 1280px; 
    }
}


/* --- Tool Header (consistent with other tools) --- */
.tool-header {
    text-align: center;
    margin-top: 2rem; 
    margin-bottom: 4rem; 
}

.tool-icon-title {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.85rem; 
    margin-bottom: 1.2rem; 
}

.tool-icon {
    font-size: 3.5rem; 
    color: var(--accent-color);
}

.tool-header h1 {
    font-size: clamp(2.5rem, 6vw, 4rem); 
    font-weight: 900; 
    color: var(--text-primary);
    line-height: 1.15;
    margin-bottom: 0;
    letter-spacing: -0.03em; 
}

.tool-description {
    font-size: clamp(1rem, 2.5vw, 1.25rem); 
    color: var(--text-secondary);
    line-height: 1.7;
    max-width: 700px;
    margin: 0.8rem auto 0 auto;
}

/* --- Error Message Container (consistent) --- */
.error-message-container {
    background-color: #fef2f2; 
    border: 1px solid #ef4444; 
    color: #b91c1c; 
    padding: 1rem 1.5rem; 
    border-radius: 10px; 
    margin-bottom: 2rem; 
    display: flex;
    align-items: center;
    gap: 0.75rem; 
    font-size: var(--fs-base); 
    box-shadow: 0 4px 10px rgba(0,0,0,0.05); 
    text-align: left; 
}
html[data-theme="dark"] .error-message-container {
    background-color: #3f0f0f;
    border-color: #dc2626;
    color: #ef4444;
}
.error-message-container p { 
    margin: 0;
}


/* --- Main Playground Card (.code-playground-card) --- */
.code-playground-card { 
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 24px; 
    box-shadow: 0 15px 50px rgba(0,0,0,0.1); 
    height: 90vh; /* Taller for code editors */
    display: flex; 
    flex-direction: column; 
    overflow: hidden; 
    margin-bottom: 4rem; 
    max-width: 1200px; /* Wider for playground */
    margin-left: auto;
    margin-right: auto;
    transition: all 0.3s ease-out; 
}
html[data-theme="dark"] .code-playground-card {
    box-shadow: 0 15px 50px rgba(0,0,0,0.25);
}

/* Inner Grid for Editor/Preview Split */
.playground-grid-wrapper {
    flex-grow: 1; 
    display: grid;
    grid-template-columns: 1fr 1fr; /* Two equal columns */
    gap: 0; /* Managed by panel padding/borders */
    overflow: hidden; 
}

/* Code Editors Panel (Left) */
.code-editors-panel {
    display: flex;
    flex-direction: column;
    height: 100%; 
    position: relative;
    border-right: 1px solid var(--border-color); 
    background-color: var(--bg-main); 
    overflow: hidden; /* Contains editors and controls */
}
html[data-theme="dark"] .code-editors-panel {
    border-right-color: var(--border-grid-gray-dark);
    background-color: var(--bg-card); 
}

/* Editor Tabs */
.editor-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-highlight);
    flex-shrink: 0;
}
html[data-theme="dark"] .editor-tabs {
    background-color: var(--bg-main);
}
.editor-tabs .tab {
    flex: 1; /* Distribute space evenly */
    padding: 0.8rem 1.2rem;
    background: transparent;
    border: none;
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    position: relative;
    transition: color 0.2s, background-color 0.2s;
    border-radius: 0; /* No rounded corners for tabs */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.editor-tabs .tab:hover {
    background-color: color-mix(in srgb, var(--accent-color) 8%, var(--bg-highlight) 92%);
    color: var(--text-primary);
}
html[data-theme="dark"] .editor-tabs .tab:hover {
    background-color: color-mix(in srgb, var(--accent-color) 12%, var(--bg-main) 88%);
}
.editor-tabs .tab.active {
    color: var(--accent-color);
    font-weight: 600;
    background-color: var(--bg-main);
    box-shadow: none; /* No shadow for tabs */
    border-bottom: 3px solid var(--accent-color); /* Active indicator */
    margin-bottom: -1px; /* Overlap border */
}
html[data-theme="dark"] .editor-tabs .tab.active {
    background-color: var(--bg-card);
}

/* Code Editor Textareas */
.editor-containers {
    flex-grow: 1; /* Allows textareas to fill remaining height */
    position: relative;
    overflow: hidden; /* Hides scrollbars from inactive textareas */
}
.code-editor {
    position: absolute; /* Stack textareas on top of each other */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none; /* No border for internal editor */
    background-color: transparent; /* Use parent background */
    color: var(--text-primary);
    font-family: 'Fira Code', monospace; /* Monospace font */
    font-size: var(--fs-sm);
    padding: var(--space-md);
    resize: none; /* Disable manual resize */
    box-sizing: border-box;
    display: none; /* Hidden by default, show with .active */
    white-space: pre; /* Preserve whitespace (like indentation) */
    overflow: auto; /* Enable scrolling for content */
    line-height: 1.5; /* Good line height for code */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    scrollbar-width: thin; /* Firefox */
    scrollbar-color: var(--accent-color) var(--bg-highlight); /* Firefox */
}
.code-editor::-webkit-scrollbar {
  width: 8px;
  height: 8px; /* For horizontal scroll */
}
.code-editor::-webkit-scrollbar-track {
  background: var(--bg-highlight);
  border-radius: 10px;
}
.code-editor::-webkit-scrollbar-thumb {
  background: var(--accent-color);
  border-radius: 10px;
}
.code-editor::-webkit-scrollbar-thumb:hover {
  background: var(--btn-primary-hover);
}

.code-editor.active {
    display: block; /* Show active editor */
}

/* Editor Controls (Buttons) */
.editor-controls {
    display: flex;
    gap: 0.75rem;
    padding: var(--space-md);
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-highlight);
    flex-shrink: 0;
    justify-content: flex-end; /* Align buttons to the right */
}
html[data-theme="dark"] .editor-controls {
    background-color: var(--bg-main);
}
.editor-controls .btn {
    font-size: var(--fs-sm);
    padding: 0.6rem 1rem;
    border-radius: 8px;
}

/* Preview & Console Panel (Right) */
.preview-console-panel {
    display: flex;
    flex-direction: column;
    height: 100%; 
    position: relative;
    background-color: var(--bg-card); 
    overflow: hidden; /* Contains preview, console, and actions */
}

/* Live Preview Area */
.preview-area {
    flex-grow: 2; /* Allow preview to take more space */
    display: flex;
    flex-direction: column;
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-color);
    overflow: hidden; /* To contain iframe */
}
html[data-theme="dark"] .preview-area {
    border-bottom-color: var(--border-grid-gray-dark);
}
.preview-area h2 {
    margin-bottom: var(--space-sm);
}
#livePreviewIframe {
    flex-grow: 1; /* Let iframe fill remaining space */
    border: 1px solid var(--border-color);
    border-radius: 8px;
    width: 100%;
    background-color: var(--text-light); /* Ensure light background for preview */
}
html[data-theme="dark"] #livePreviewIframe {
    background-color: #fff; /* Force white background */
}

/* Console Output Area */
.console-area {
    flex-grow: 1; /* Allow console to take less space than preview */
    display: flex;
    flex-direction: column;
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-color); /* Separator from actions */
    background-color: var(--bg-main); /* Darker background for console */
}
html[data-theme="dark"] .console-area {
    background-color: #1b1b1b; /* Even darker for console in dark mode */
}
.console-area h2 {
    margin-bottom: var(--space-sm);
}
.console-output {
    flex-grow: 1;
    background-color: var(--text-primary); /* Dark background for console text */
    color: var(--text-light);
    font-family: 'Fira Code', monospace;
    font-size: var(--fs-xs);
    padding: 0.75rem;
    border-radius: 8px;
    overflow: auto;
    white-space: pre-wrap; /* Preserve line breaks and wrap long lines */
    word-break: break-all;
    min-height: 80px; /* Minimum height for console */
    max-height: 150px; /* Max height before scrolling */
}
html[data-theme="dark"] .console-output {
    background-color: #000;
}
.console-area #clearConsoleBtn {
    align-self: flex-end; /* Align button to bottom right */
    margin-top: 0.75rem;
    font-size: var(--fs-xs);
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
}


/* Download/Reset Actions */
.download-reset-actions {
    display: flex;
    gap: 0.75rem;
    padding: var(--space-md);
    background-color: var(--bg-highlight); /* Footer background */
    flex-shrink: 0;
    justify-content: flex-end; /* Align buttons to the right */
}
html[data-theme="dark"] .download-reset-actions {
    background-color: var(--bg-main);
}
.download-reset-actions .btn {
    font-size: var(--fs-sm);
    padding: 0.6rem 1rem;
    border-radius: 8px;
}


/* --- Info, FAQ, CTA sections (consistent) --- */
.info-section, .faq-section, .support-tool-cta { 
    padding: var(--space-xxl); 
    margin-top: 4rem;
    margin-bottom: 4rem;
    border-radius: 20px; 
    box-shadow: 0 10px 30px rgba(0,0,0,0.08); 
}

.info-section .column-title, .faq-section .column-title, .support-tool-cta h3 { 
    font-size: var(--fs-xl); 
    font-weight: 700;
    margin-bottom: 1rem; 
    text-align: left;
}
.info-section p, .faq-section p, .support-tool-cta p { 
    font-size: var(--fs-base);
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 0.75rem; 
    padding: 0 0.5rem; 
}
.info-section p:last-of-type { 
    margin-bottom: 0;
}
.info-section .info-list {
    list-style: none;
    padding-left: 0;
    margin-bottom: 1.5rem;
}
.info-section .info-list li {
    font-size: var(--fs-base);
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    position: relative;
    padding-left: 1.5rem;
    padding-right: 0.5rem;
}
.info-section .info-list li::before {
    content: '•';
    color: var(--accent-color);
    position: absolute;
    left: 0;
    font-weight: bold;
}

.how-to-list { 
    list-style-type: decimal;
    padding-left: 1.5rem;
    margin-top: 1rem;
}
.how-to-list li {
    font-size: var(--fs-base);
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    line-height: 1.6;
    padding-right: 0.5rem;
}
.how-to-list li strong {
    color: var(--text-primary);
}


/* Support Tool CTA (consistent) */
.support-tool-cta { 
    text-align: center;
}
.support-tool-cta .tool-icon { /* Corrected from .support-tool-cta .support-tool-icon to .tool-icon as per provided HTML */
    font-size: 4rem; 
    color: var(--accent-color);
    margin-bottom: 1.5rem; 
}
.support-tool-cta p {
    max-width: 600px; 
    margin-left: auto;
    margin-right: auto;
}
.support-tool-cta .coffee-btn-small {
    font-size: var(--fs-base); 
    padding: 0.9rem 1.8rem; 
    border-radius: 10px; 
}

/* --- Responsive Adjustments --- */
@media (max-width: 992px) { 
    .tool-page-main { padding: 2.5rem 0 3.5rem; }
    .tool-header { margin-bottom: 2.5rem; }
    .tool-icon { font-size: 2.5rem; }
    .tool-header h1 { font-size: clamp(1.8rem, 4.5vw, 2.5rem); }
    .tool-description { font-size: var(--fs-base); }

    .code-playground-card { 
        padding: var(--space-lg); 
        height: auto; 
        min-height: 70vh; 
    }
    .playground-grid-wrapper {
        grid-template-columns: 1fr; /* Stack panels on mobile */
        gap: var(--space-xl); 
        padding: var(--space-md); 
    }
    .code-editors-panel {
        border-right: none; 
        border-bottom: 1px solid var(--border-color); /* Separator when stacked */
        padding-bottom: var(--space-lg);
    }
    html[data-theme="dark"] .code-editors-panel { border-bottom-color: var(--border-grid-gray-dark); }
    .preview-console-panel {
        padding-top: var(--space-lg);
    }

    .editor-tabs { margin-bottom: var(--space-md); }
    .code-editor { min-height: 250px; } /* More height for editor on mobile */
    .editor-controls {
        padding: var(--space-md) 0; /* Adjust padding */
        justify-content: center; /* Center buttons */
    }

    .preview-area {
        min-height: 200px;
        padding: 0; /* Remove padding, handled by parent */
    }
    #livePreviewIframe {
        min-height: 200px;
    }

    .console-area {
        padding: var(--space-md) 0;
        min-height: 100px;
    }
    .console-output {
        min-height: 80px;
        max-height: 120px;
    }
    .console-area #clearConsoleBtn {
        font-size: var(--fs-xs);
        padding: 0.5rem 0.8rem;
    }

    .download-reset-actions {
        padding: var(--space-md) 0;
        justify-content: center;
    }

    .info-section, .faq-section, .support-tool-cta {
        padding: 2.5rem; 
        margin-top: 3rem;
        margin-bottom: 3rem;
    }
    .info-section .column-title, .faq-section .column-title, .support-tool-cta h3 { font-size: var(--fs-lg); }
    .info-section p, .faq-section p, .support-tool-cta p { font-size: var(--fs-sm); }
    .how-to-list li { font-size: var(--fs-sm); }
    .support-tool-cta .tool-icon { font-size: 3rem; } 
    .support-tool-cta .coffee-btn-small { font-size: var(--fs-sm); }
}

@media (max-width: 576px) { 
    .tool-page-main { padding: 1.5rem 0 2rem; }
    .tool-header { margin-bottom: 1.5rem; }
    .tool-icon { font-size: 2rem; }
    .tool-header h1 { font-size: clamp(1.5rem, 4vw, 2rem); }
    .tool-description { font-size: var(--fs-sm); }

    /* Mobile: Card 100% width, 5px padding left/right */
    .code-playground-card { 
        width: calc(100% - 10px); /* 100% of viewport width minus 5px left + 5px right padding */
        margin-left: 5px; 
        margin-right: 5px;
        padding: 1rem 10px; /* Adjust internal padding to be consistent and avoid breaking layout */
        border-radius: 16px;
        height: auto; 
        min-height: 60vh; 
        box-sizing: border-box; /* Include padding in the width calculation */
    }
    /* Adjust input and results panels within the tighter card padding */
    .code-editors-panel, .preview-console-panel {
        padding: 0; /* Internal panels are now 0 padding, managed by converter-grid-wrapper */
    }
    .playground-grid-wrapper {
        padding: var(--space-md) var(--space-sm); /* Adjust overall padding for mobile */
    }

    .section-title-within-tab { font-size: 1.3rem; margin-bottom: 1rem; }
    .section-title-within-panel { /* For preview/console titles */
        font-size: var(--fs-base);
        margin-bottom: var(--space-xs);
    }

    .editor-tabs .tab {
        font-size: var(--fs-xs);
        padding: 0.6rem 0.8rem;
    }
    .code-editor {
        font-size: var(--fs-xs);
        min-height: 180px;
        padding: var(--space-sm);
    }
    .editor-controls {
        padding: var(--space-sm) 0;
        gap: 0.5rem;
    }
    .editor-controls .btn {
        font-size: var(--fs-xs);
        padding: 0.5rem 0.8rem;
    }
    
    .preview-area { min-height: 150px; }
    #livePreviewIframe { min-height: 150px; }

    .console-area { min-height: 60px; padding: var(--space-sm) 0;}
    .console-output { font-size: 0.65rem; min-height: 50px; max-height: 80px;}
    .console-area #clearConsoleBtn { font-size: var(--fs-xs); padding: 0.3rem 0.5rem;}


    .download-reset-actions {
        padding: var(--space-sm) 0;
        gap: 0.5rem;
    }
    .download-reset-actions .btn {
        font-size: var(--fs-xs);
        padding: 0.5rem 0.8rem;
    }


    .info-section, .faq-section, .support-tool-cta {
        padding: 1.5rem; 
        margin-top: 1.5rem;
        margin-bottom: 1.5rem;
    }
    .info-section .column-title, .faq-section .column-title, .support-tool-cta h3 { font-size: var(--fs-sm); }
    .info-section p, .faq-section p, .support-tool-cta p { font-size: var(--fs-xs); }
    .how-to-list li { font-size: var(--fs-xs); }
    .support-tool-cta .tool-icon { font-size: 2.2rem; } 
    .support-tool-cta .coffee-btn-small { font-size: var(--fs-xs); }
}