body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    line-height: 1.7;
    margin: 0;
    background-color: #282c34; /* Darker Background */
    color: #abb2bf;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

main {
    width: 95%; /* Wider main content */
    max-width: 3200px;
    margin: 2rem auto;
    flex-grow: 1;
}

.container {
    display: grid; /* Use grid for better layout */
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

textarea, #preview {
    padding: 1.5rem;
    border: 1px solid #383e49; /* Softer border */
    border-radius: 8px;
    box-sizing: border-box;
    background-color: #1e2229; /* Darker editor background */
    color: #abb2bf;
    overflow: auto;
    font-size: 1rem; /* Slightly larger font */
    line-height: 1.6;
    resize: vertical; /* Allow vertical resizing */
}

textarea {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

#preview {
    overflow-wrap: break-word;
}

/* Improved Markdown Styling */
#preview h1, #preview h2, #preview h3, #preview h4, #preview h5, #preview h6 {
    font-weight: 600;
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
}
#preview h1 { font-size: 2em; }
#preview h2 { font-size: 1.6em; }
#preview h3 { font-size: 1.4em; }
#preview h4 { font-size: 1.2em; }
#preview h5 { font-size: 1em; }
#preview h6 { font-size: 0.9em; }

#preview a {
    color: #58a6ff;
    text-decoration: none;
}
#preview a:hover {
    text-decoration: underline;
}

#preview blockquote {
    border-left: 0.25rem solid #6a737d;
    padding-left: 1rem;
    margin: 1rem 0;
    color: #8b949e;
}
#preview code {
    background-color: #30363d;
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-size: 0.9em;
}
pre {
    background-color: #30363d;
    padding: 1rem;
    border-radius: 6px;
    overflow-x: auto;
}
pre code {
    padding: 0;
    background-color: transparent;
}
#preview table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}
#preview th, #preview td {
    border: 1px solid #44475a;
    padding: 0.5rem;
    text-align: left;
}
#preview th {
    background-color: #30363d;
    font-weight: 600;
}

/* Responsive */
@media (max-width: 900px) {
    .container {
        grid-template-columns: 1fr; /* Stack on smaller screens */
    }
}

/* Improved Header */
header {
    background-color: #161b22; /* Darker header background */
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #30363d;
}

header h1 {
    margin: 0;
    font-size: 1.5rem;
    color: #c9d1d9;
}

/* Improved Footer */
footer {
    background-color: #161b22;
    padding: 1rem 2rem;
    text-align: center;
    margin-top: auto;
    border-top: 1px solid #30363d;
    color: #8b949e;
    font-size: 0.85rem;
}
#clear-button{
    padding: 0.5rem 1rem; 
    background-color: #21262d; 
    color: #c9d1d9; 
    border: none; 
    border-radius: 5px; 
    cursor: pointer;
    margin-left: auto;
}
header .header-content{
    display: flex;
    width: 100%;
    align-items: center;
}

.toolbar {
    background-color: #1e2229; /* Match editor background */
    padding: 0.5rem;
    border-bottom: 1px solid #30363d;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    display: flex;
    gap: 0.5rem;
}

.toolbar button {
    background-color: #282c34;
    color: #abb2bf;
    border: none;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
}

.toolbar button:hover {
    background-color: #30363d;
}

textarea {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}

.editor-wrapper { /* New wrapper for toolbar and textarea */
    display: flex;
    flex-direction: column; /* Essential for correct sizing */
    flex: 1; /* Allow to take up available space */
}
.container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    flex: 1; /* Make container take available space */
}
main{
    display: flex;
    flex-direction: column;
    flex: 1;
}
.toolbar {
    background-color: #1e2229;
    padding: 0.5rem;
    border-bottom: 1px solid #30363d;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    display: flex;
    gap: 0.5rem;
}

.toolbar button {
    background-color: #282c34;
    color: #abb2bf;
    border: none;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
}

.toolbar button:hover {
    background-color: #30363d;
}

textarea {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    flex: 1; /* Key: Allow textarea to expand */
    resize: vertical;
}
@media (max-width: 900px) {
    .container {
        grid-template-columns: 1fr; /* Stack on smaller screens */
        flex-direction: column;
    }
}