body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}
header {
    background-color: #4CAF50;
    color: white;
    text-align: center;
    padding: 1rem;
    flex-shrink: 0;
}
main {
    display: flex;
    flex: 1;
    overflow: hidden;
    border-top: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
    min-height: 0;
}
.editor-section {
    width: 50%;
    height: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}
.toolbar {
    padding: 0.5rem;
    background: #23272e;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    flex-wrap: wrap; /* Allow wrapping for smaller screens */
}
.toolbar button, .toolbar select {
    margin-right: 0.3rem;
    margin-bottom: 0.3rem; /* Spacing for wrapped items */
    background: #333;
    color: #fff;
    border: none;
    border-radius: 3px;
    padding: 0.3rem 0.7rem;
    cursor: pointer;
    font-size: 0.9rem;
}
.toolbar button:hover, .toolbar select:hover {
    background: #444;
}
.toolbar input {
    flex: 1;
    padding: 0.3rem 0.5rem;
    border-radius: 3px;
    border: none;
    font-size: 1rem;
    background: #2d323c;
    color: #fff;
    outline: none;
    min-width: 100px; /* Prevent search shrinking too much */
    margin-bottom: 0.3rem;
}
.toolbar input[type="color"] {
    width: 30px; /* Smaller size for color input */
    height: 25px;
    padding: 0 2px;
    border: 1px solid #555;
    cursor: pointer;
    margin-bottom: 0.3rem;
    vertical-align: middle; /* Align with buttons */
}
.toolbar .separator {
    width: 1px;
    height: 20px;
    background: #555;
    margin: 0 0.5rem;
}
#editor-container {
    flex: 1;
    position: relative;
    height: calc(100% - 42px);
    overflow: hidden;
}
#editor {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}
#plainTextView {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    display: none;
    font-size: 16px;
    font-family: inherit;
    padding: 1rem;
    border: none;
    outline: none;
    resize: none;
    background: #23272e;
    color: #fff;
    box-sizing: border-box;
    overflow-y: auto;
    white-space: normal;
    /* WYSIWYG styles */
    min-width: 0;
    min-height: 0;
    position: relative; /* Needed for positioning resize handles */
}
#plainTextView * {
    color: #fff !important;
}
#plainTextView h1, #plainTextView h2, #plainTextView h3, #plainTextView h4, #plainTextView h5, #plainTextView h6 {
    color: #4CAF50 !important;
}
#plainTextView .header {
    background-color: #4CAF50 !important;
    color: #fff !important;
    padding: 20px;
    text-align: center;
    border-radius: 5px;
}
#plainTextView .section {
    margin: 20px 0;
    padding: 15px;
    border: 1px solid #ddd;
    border-radius: 5px;
    background: #222;
}
#plainTextView .code {
    background-color: #222 !important;
    color: #ffe066 !important;
    padding: 10px;
    border-radius: 5px;
    font-family: monospace;
}
#plainTextView .benefits {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 15px;
}
#plainTextView .benefit-card {
    background-color: #333 !important;
    color: #fff !important;
    padding: 15px;
    border-radius: 5px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
#plainTextView[contenteditable="true"]:empty:before {
    content: attr(placeholder);
    color: #888;
}
.divider {
    width: 1px;
    background-color: #ccc;
    height: 100%;
}
iframe {
    width: 50%;
    height: 100%;
    border: none;
    padding: 0;
    margin: 0;
}
.CodeMirror {
    height: 100% !important;
    width: 100% !important;
    position: absolute;
}
@media (max-width: 768px) {
    main {
        flex-direction: column;
    }
    .editor-section, iframe {
        width: 100%;
        height: 50%;
        min-height: 0; /* Prevent flex item from exceeding height */
        overflow: hidden; /* Ensure content within doesn't overflow */
    }
    .divider {
        width: 100%;
        height: 1px;
        flex-shrink: 0;
    }
    #editor-container {
        height: 100%; /* Let flex handle the height distribution */
        overflow: visible; /* Allow potential overflow for handles? Reconsider if needed */
    }
    .CodeMirror {
        height: 100% !important;
    }
    #plainTextView {
        height: 100%;
    }
    /* Adjust toolbar for smaller screens */
    .toolbar {
        padding: 0.4rem;
    }
    .toolbar button, .toolbar select, .toolbar input[type="color"] {
        padding: 0.25rem 0.5rem;
        font-size: 0.85rem;
        margin-right: 0.2rem;
    }
    /* Specifically target color inputs for size reduction */
    .toolbar input[type="color"] {
        width: 22px;
        height: 22px;
        padding: 0 1px;
    }
    .toolbar input[type="text"] {
        font-size: 0.9rem;
        padding: 0.25rem 0.4rem;
        min-width: 80px; /* Further reduce min-width */
    }
    #codeSearchToolbar {
        margin-left: 0; /* Don't push search to the right */
        flex-basis: 100%; /* Allow search to take full width if needed */
        justify-content: flex-end; /* Keep search items together */
    }
    #textFormattingToolbar {
        margin-left: 0; /* Remove fixed margin */
        justify-content: flex-start; /* Keep items aligned */
    }
}
/* Styles for image resize handles */
.resize-handle {
    position: absolute;
    width: 8px;
    height: 8px;
    background-color: #4CAF50;
    border: 1px solid #fff;
    cursor: nwse-resize; /* Default resize cursor */
    z-index: 10;
}
.resize-handle.nw { top: -5px; left: -5px; cursor: nwse-resize; }
.resize-handle.ne { top: -5px; right: -5px; cursor: nesw-resize; }
.resize-handle.sw { bottom: -5px; left: -5px; cursor: nesw-resize; }
.resize-handle.se { bottom: -5px; right: -5px; cursor: nwse-resize; }

#plainTextView img.resizable-selected {
    outline: 2px dashed #4CAF50; /* Indicate selection */
}
/* Highlight style for preview elements linked from editor selection */
.preview-highlight {
    background-color: rgba(76, 175, 80, 0.3) !important; /* Semi-transparent green */
    outline: 1px solid #4CAF50 !important;
    box-shadow: 0 0 5px rgba(76, 175, 80, 0.5);
    transition: background-color 0.2s ease, outline 0.2s ease, box-shadow 0.2s ease;
}

/* Custom style for CodeMirror selection */
.CodeMirror-selected {
    background-color: #ffeb3b !important; /* Yellow */
    color: #000000 !important;           /* Black text for contrast */
}
/* Styling for the demo code snippet block */
.code pre {
    background-color: #2d2d2d; /* Darker background for the code block */
    color: #ccc; /* Light gray text color */
    padding: 15px;
    border-radius: 5px;
    overflow-x: auto; /* Add horizontal scroll for long lines */
    margin: 0; /* Remove default pre margins */
}
.code code {
    font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
    display: block; /* Make code take full block width */
    line-height: 1.5;
    white-space: pre; /* Preserve whitespace and line breaks */
}