*::before,
*::after {
  box-sizing: border-box;
}

:root {
    --primary-color: #6366f1;
    --primary-hover: #5856eb;
    --accent-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --dark-bg: #0f172a;
    --text-primary: #f1f5f9;
    --text-secondary: #080909;
    --gradient-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
    --shadow-hover: 0 20px 40px -10px rgba(0, 0, 0, 0.4);
    --input-border: #8b8a8b;
}


.demo-container {
    position: relative;
    background: cornflowerblue;
    margin: 0 auto;
    padding: 20px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    grid-template-areas:
        "header header"
        "help help"
        "editor preview"
        "actions actions"
        "cta cta";
    overflow: hidden;    
}

.demo-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0; 
    height: 100%;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grid" width="10" height="10" patternUnits="userSpaceOnUse"><path d="M 10 0 L 0 0 0 10" fill="none" stroke="rgba(255,255,255,0.05)" stroke-width="1"/></pattern></defs><rect width="100" height="100" fill="url(%23grid)"/></svg>');
    opacity: 1;
    z-index: 0;
    pointer-events: none; /* allow clicking through */
}

/* placing child elements above the pseudo-element */
.demo-container > * {
    position: relative;
    z-index: 1;
}

.demo-header {
    grid-area: header;
    text-align: center;
    margin-bottom: 2rem;
    padding: 2rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 10px;
}

.demo-subtitle {
    font-size: 1.2rem;
    opacity: 0.9;
    margin-bottom: 1.5rem;
}

.demo-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.help-panel {
    grid-area: help;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.help-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.help-item {
    background: white;
    padding: 1rem;
    border-radius: 6px;
    border-left: 4px solid #4CAF50;
}

.editor-preview-split {
    grid-area: editor;
    display: flex;
    flex-direction: column;
    min-height: 600px;
    min-width: 0;
}

.preview-section {
    grid-area: preview;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid #e9ecef;
}

.word-count {
    font-size: 0.9rem;
    color: #666;
    background: #f8f9fa;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

#markdownEditor {
    flex: 1;
    width: 100%;
    padding: 1rem;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.5;
    resize: vertical;
    min-height: 400px;
}

#markdownEditor:focus {
    border-color: #4CAF50;
    outline: none;
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
}

.editor-actions {
    grid-area: actions;
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.html-preview {
    flex: 1;
    padding: 1.5rem;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    background: white;
    overflow-y: auto;
    overflow-x: auto; /* recheck */
    min-height: 400px;
}

.raw-html {
    flex: 1; /* review */
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    overflow: auto;
}

.raw-html pre {
    margin: 0;
    padding: 1rem;
    background: #2d3748;
    color: #e2e8f0;
    border-radius: 6px;
}

.demo-cta {
    grid-area: cta;
    background: linear-gradient(135deg, #4CAF50, #45a049);
    color: white;
    padding: 3rem 2rem;
    text-align: center;
    margin-top: 2px;
}

.cta-content h3 {
    margin-top: 0;
    font-size: 1.5rem;
}

.cta-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.form-group {
    text-align: center;
    margin-bottom: 5px;
}

/* text input styling */

input[type="text"] {
    transition: 180ms box-shadow ease-in-out;
    font-size: 16px;
    font-size: max(16px, 1em);
    font-family: inherit;
    padding: 0.25em 0.5em;
    background-color: #fff;
    border: 2px solid var(--input-border);
    border-radius: 4px;
}

input[type="text"]:focus {
    box-shadow: 0 0 0 3px #e7e309cb;    
    outline: 3px solid transparent;
}

/* button Styles */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-primary {
    background: yellow;
    color: black;
}

.btn-primary:hover {
    background: black;
    transform: translateY(-1px);
    color: white;
}

.btn-secondary, .btn-outline {
    background: yellow;
    color: black;
}

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

.btn-outline:hover {
    background: black;
    color: white;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

/* loading states */
.loading {
    text-align: center;
    padding: 2rem;
    color: #666;
    font-style: italic;
}

.error {
    background: #ffebee;
    border: 1px solid #f44336;
    border-radius: 6px;
    padding: 1rem;
    color: #c62828;
}

.error h3 {
    margin-top: 0;
    color: #d32f2f;
}

/* preview image styling - need review  */
img {
    width: 96%;
    object-fit: fill;
    border-radius: 10px;
}

p:has(> img) {
    text-align: center;
    padding: 15px;
}

@media (max-width: 968px) {
    .demo-container {
        grid-template-columns: 1fr;
        grid-template-areas:
            "header"
            "help"
            "editor"
            "preview"
            "actions"
            "cta";
    }
}

@media (min-width: 969px) {
    .demo-container::before {
        left: 50%;
        transform: translateX(-50%);
        width: 100vw;
    }
}