body {
    font-family: 'Roboto Mono', monospace;
    font-weight: 400;
    overflow-y: auto;
    background: #333 url('images/scribbles.jpg') center/cover fixed;
    margin: 0;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

body select, body input, body textarea, body button {
    font-family: 'Roboto Mono', monospace;
    font-weight: 400;
}

#logo {
    max-width: min(100px, 60vw);
    height: 100px;
    margin-bottom: 25px;
}

#inputText, #titleText {
    max-width: 100%;
    box-sizing: border-box;
}

.container {
    background: rgba(255, 255, 255, 0.97);
    border-radius: 12px;
    overflow-y: auto;
    box-shadow: 0px 10px 35px 15px rgba(0, 0, 0, 0.4);
    padding: 30px 40px;
    width: 100%;
    max-width: min(1000px, 90vw);
    max-height: 90vh;
    margin: 20px auto;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

select, input, textarea, button {
    width: 100%;
    padding: 14px;
    margin: 12px 0;
    border: 1px solid #d1d1d1;
    border-radius: 6px;
    outline: none;
    transition: all 0.25s ease;
    box-sizing: border-box;
    font-size: 15px;
}

textarea {
    min-height: 100px;
    resize: vertical;
}

#inputText {
    flex-grow: 1; /* Allow essay box to take more space */
}

select:focus, input:focus, textarea:focus {
    box-shadow: 0 0 10px rgba(70, 130, 180, 0.4);
    border-color: #4682b4;
    transform: translateY(-1px);
}

button {
    background-color: #4682b4;
    color: #fff;
    cursor: pointer;
    font-size: 16px;
    padding: 15px;
    font-weight: 500;
}

button:hover {
    background-color: #3a709b;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

button:active {
    transform: translateY(0);
}

/* Image Upload Styles */
.image-upload-container {
    margin: 15px 0;
    padding: 20px;
    border: 2px dashed #ccc;
    border-radius: 8px;
    background-color: #fafafa;
    text-align: center;
    transition: border-color 0.3s ease;
    box-sizing: border-box;
}

.image-upload-container:hover {
    border-color: #4682b4;
}

.image-upload-label {
    display: block;
    margin-bottom: 12px;
    font-weight: bold;
    color: #444;
    font-size: 15px;
}

.image-upload-input {
    width: auto !important;
    margin: 10px auto;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background-color: white;
    cursor: pointer;
    max-width: 100%;
}

.image-upload-input:hover {
    border-color: #4682b4;
}

.image-preview {
    margin-top: 15px;
    text-align: center;
    max-width: 100%;
    overflow: hidden;
}

.image-preview img {
    max-width: 100%;
    max-height: 220px;
    border-radius: 6px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
    height: auto;
    width: auto;
}

.image-preview p {
    margin: 8px 0;
    font-size: 12px;
    color: #555;
    word-break: break-all;
}

#outputText {
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 20px 25px;
    margin-top: 20px;
}

/* --- Comprehensive Markdown Styles --- */

/* Headings */
#outputText h1, #outputText h2, #outputText h3, #outputText h4, #outputText h5, #outputText h6 {
    font-weight: 600;
    color: #343a40;
    margin-top: 1.5em;
    margin-bottom: 0.8em;
    line-height: 1.2;
}
#outputText h1 { font-size: 1.6em; }
#outputText h2 { font-size: 1.4em; }
#outputText h3 { font-size: 1.2em; border-bottom: 2px solid #dee2e6; padding-bottom: 8px;}
#outputText h4 { font-size: 1.1em; }
#outputText h5 { font-size: 1.0em; }
#outputText h6 { font-size: 0.9em; color: #6c757d; }

/* Paragraphs and Links */
#outputText p {
    margin-bottom: 16px;
}
#outputText a {
    color: #007bff;
    text-decoration: none;
    transition: color 0.2s;
}
#outputText a:hover {
    color: #0056b3;
    text-decoration: underline;
}

/* Lists */
#outputText ul, #outputText ol {
    padding-left: 25px;
    margin-bottom: 16px;
}
#outputText li {
    margin-bottom: 8px;
}
#outputText li > p {
    margin-bottom: 8px; /* For paragraphs inside list items */
}

/* Blockquotes */
#outputText blockquote {
    margin: 0 0 16px 0;
    padding: 10px 20px;
    border-left: 5px solid #007bff;
    background-color: #f0f8ff;
    color: #333;
    font-style: italic;
}
#outputText blockquote p:last-child {
    margin-bottom: 0;
}

/* Code Blocks */
#outputText pre {
    background-color: #2b2b2b;
    color: #f8f8f2;
    padding: 16px;
    border-radius: 6px;
    overflow-x: auto;
    margin-bottom: 16px;
}
#outputText code {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
}
#outputText pre code {
    background: none;
    padding: 0;
}
/* Inline code */
#outputText :not(pre) > code {
    background-color: #e9ecef;
    color: #c7254e;
    padding: 3px 6px;
    border-radius: 4px;
}

/* Horizontal Rule */
#outputText hr {
    border: 0;
    height: 2px;
    background-color: #dee2e6;
    margin: 32px 0;
}

/* Tables */
#outputText table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
    display: block;
    overflow-x: auto;
}
#outputText th, #outputText td {
    border: 1px solid #dee2e6;
    padding: 10px 14px;
    text-align: left;
}
#outputText th {
    background-color: #f8f9fa;
    font-weight: 600;
}
#outputText tr:nth-child(even) {
    background-color: #f8f9fa;
}

/* Strong and Emphasis */
#outputText strong {
    font-weight: 600;
    color: #000;
}
#outputText em {
    font-style: italic;
}

#outputText h3 {
    font-size: 1.2em;
    font-weight: 600;
    color: #343a40;
    margin-top: 24px;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid #dee2e6;
}

#outputText strong {
    font-weight: 600;
    color: #000;
}

#outputText hr {
    border: 0;
    height: 1px;
    background-color: #ced4da;
    margin: 24px 0;
}

#outputText p, #outputText li {
    margin-bottom: 12px;
}

#outputText ol, #outputText ul {
    padding-left: 20px;
}

.toggle-buttons {
    display: flex;
    justify-content: space-between;
    margin-bottom: 25px;
    gap: 15px;
}

.toggle-btn {
    flex: 1;
    background-color: #e0e0e0;
    transition: background-color 0.3s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 48px;
    font-size: 15px;
    font-weight: 500;
    color: #333;
}

.toggle-btn.active {
    background-color: #4682b4;
    color: #fff;
}

.typewritten::after {
    content: "|";
    color: #4682b4;
    animation: blink 1.0s step-end infinite;
}

@keyframes blink {
    0%, 100% { opacity: 0; }
    50% { opacity: 1; }
}

/* Modal and Overlay Styles */
.auth-links {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1001;
    font-size: clamp(16px, 4vw, 24px);
}

.auth-link {
    cursor: pointer;
    color: #ffffff;
    text-decoration: none;
}

.auth-link:hover {
    text-decoration: underline;
    text-underline-offset: 8px;
}

.modal {
    display: block;
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.65);
    z-index: 1000;
    padding: 20px;
    box-sizing: border-box;
    backdrop-filter: blur(4px);
}

#keyenter {
    width: 100%;
    box-sizing: border-box;
}

.modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #fefefe;
    padding: 35px;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.4);
    width: 90%;
    max-width: 450px;
    box-sizing: border-box;
}

.close {
    display: none;
}

.loading-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
    backdrop-filter: blur(4px);
}

.loading-overlay p {
    font-size: clamp(1.4em, 4vw, 2em);
    color: #fff;
    text-align: center;
}

.corrections-left {
    position: fixed;
    bottom: 15px;
    left: 15px;
    font-size: clamp(12px, 3vw, 16px);
    padding: 8px 12px;
    border-radius: 6px;
    color: #fff;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    z-index: 100;
}

a {
    color: #FF5733;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Responsive Design */
@media screen and (max-width: 768px) {
    body {
        padding: 15px;
        justify-content: flex-start;
        padding-top: 25px;
    }
    
    .container {
        padding: 25px;
        max-height: none;
        max-width: 95vw;
        margin-top: 15px;
    }
    
    #logo {
        max-width: 8vw;
    }
    
    .toggle-buttons {
        flex-direction: column;
        gap: 10px;
    }
    
    select, input, textarea, button {
        padding: 14px;
        font-size: 16px;
    }
    
    textarea {
        min-height: 100px;
    }
    
    .modal-content {
        padding: 25px;
        width: calc(100% - 30px);
    }
    
    .corrections-left {
        position: relative;
        align-self: center;
        margin-top: 20px;
        background: rgba(255, 255, 255, 0.1);
    }
}

@media screen and (max-width: 480px) {
    body {
        padding: 10px;
    }
    
    .container {
        padding: 20px;
        max-width: 100%;
    }
    
    .modal-content {
        padding: 20px;
    }
}

/* Large screens */
@media screen and (min-width: 1200px) {
    .container {
        max-width: 1100px;
        padding: 40px 50px;
    }
    
    #logo {
        max-width: 100px;
    }
    
    select, input, textarea, button {
        font-size: 16px;
    }
    
    textarea {
        min-height: 150px;
    }
}

/* Ultrawide screens */
@media screen and (min-width: 1600px) {
    .container {
        max-width: 1200px;
        padding: 50px 60px;
    }
    
    textarea {
        min-height: 180px;
    }
}

/* Landscape orientation on smaller devices */
@media screen and (orientation: landscape) and (max-height: 600px) {
    body {
        justify-content: flex-start;
        padding-top: 15px;
    }
    
    #logo {
        max-height: 8vh;
        margin-bottom: 15px;
    }
    
    .container {
        max-height: 80vh;
        overflow-y: auto;
    }
}
