body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(to right, #6a11cb 0%, #2575fc 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    padding: 20px;
    box-sizing: border-box;
    color: #333;
}

.container {
    background-color: rgba(255, 255, 255, 0.95);
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 650px;
    text-align: center;
    box-sizing: border-box;
}

h1 {
    color: #333;
    margin-bottom: 15px;
    font-size: 2.2em;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
}

.author-signature {
    font-size: 0.9em;
    color: #888;
    margin-top: -10px;
    margin-bottom: 20px;
    font-style: italic;
}

p {
    color: #666;
    margin-bottom: 30px;
    font-size: 1.1em;
}

label {
    display: block;
    margin-top: 20px;
    margin-bottom: 8px;
    font-weight: bold;
    text-align: left;
    color: #444;
    font-size: 1.05em;
}

input[type="text"],
input[type="number"],
select {
    width: calc(100% - 22px);
    padding: 12px;
    margin-bottom: 20px;
    border: 1px solid #c0d0e0;
    border-radius: 6px;
    font-size: 1.05em;
    box-sizing: border-box;
    transition: all 0.3s ease;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
    border-color: #2575fc;
    box-shadow: 0 0 8px rgba(37, 117, 252, 0.3);
    outline: none;
}

/* Validation feedback styles */
input.invalid {
    border-color: #dc3545;
    box-shadow: 0 0 5px rgba(220, 53, 69, 0.5);
}

.error-message {
    color: #dc3545;
    font-size: 0.9em;
    margin-top: -15px;
    margin-bottom: 15px;
    text-align: left;
    display: block;
}


select {
    background-color: #f8f8f8;
    background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http://www.w3.org/2000/svg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%20viewBox%3D%220%200%20292.4%22%3E%3Cpath%20fill%3D%22%232575fc%22%20d%3D%22M287%2C114.3L159.2%2C22.6c-3.1-2.3-7.5-2.3-10.6%2C0L5.4%2C114.3c-3.1%2C2.3-3.1%2C6.9%2C0%2C9.2l137.8%2C91.7c3.1%2C2.3%2C7.5%2C2.3%2C10.6%2C0l137.8-91.7C290.1%2C121.2%2C290.1%2C116.6%2C287%2C114.3z%22/%3E%3C/svg%3E');
    background-repeat: no-repeat;
    background-position: right 10px top 50%;
    background-size: 12px;
    padding-right: 30px;
}


/* Styling for general subject rows (for classes 1-10) */
.marks-input > div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding: 8px 0;
    border-bottom: 1px dashed #e0e0e0;
    position: relative;
    flex-wrap: wrap;
    gap: 10px;
}
.marks-input > div:last-child {
    border-bottom: none;
}

.marks-input > div label {
    margin: 0;
    width: auto;
    text-align: left;
    font-weight: normal;
    font-size: 1em;
    color: #555;
    flex-shrink: 0;
    padding-right: 5px;
    flex-basis: auto;
}

.marks-input > div input {
    width: auto;
    flex-grow: 1;
    max-width: 80px;
    min-width: 60px;
    margin-bottom: 0;
    padding: 8px;
    text-align: center;
}


/* Refined Styles for Stream Subjects (Class 11/12) */

#streamSubjects {
    display: flex;
    flex-wrap: wrap; /* Allow subjects to wrap to next line */
    justify-content: center; /* Center subjects if space allows */
    gap: 25px; /* Space between individual subject blocks */
    margin-top: 25px;
    padding: 10px 0;
    border-top: 1px solid #e0e0e0;
    border-bottom: 1px solid #e0e0e0;
}

#streamSubjects .subject-block {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    /* Adjust flex-basis to allow 2 columns on wider screens, single column on narrow */
    flex-basis: calc(50% - 15px); /* Adjusted to account for gap (25px / 2 = 12.5, rounded to 15) */
    max-width: calc(50% - 15px);
    min-width: fit-content; /* Increased min-width to ensure space for internal layout */
    background-color: #fefefe;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
    box-sizing: border-box; /* Crucial for correct width calculation */
}

.subject-name {
    font-weight: bold;
    font-size: 1.2em;
    color: #0056b3;
    margin-bottom: 10px;
    text-align: center;
    width: 100%;
    border-bottom: 1px dotted #bbddee;
    padding-bottom: 6px;
}

/* This is the container for Marks, Max, Pass fields within a subject block */
.marks-input-group {
    display: flex;
    flex-direction: column; /* Stack Marks/Max row and Pass row vertically */
    width: 100%;
    gap: 10px; /* Space between each row (Marks/Max, Pass) */
    margin-top: 8px;
}

/* This is for individual 'Marks: input', 'Max: input', 'Pass: input' rows */
.mark-field {
    display: flex;
    align-items: center; /* Vertically align label and input */
    justify-content: flex-start; /* Align from the start of the row */
    gap: 8px; /* Space between label and input */
    width: 100%; /* Take full width within the marks-input-group column */
    margin-bottom: 0; /* No external margin for these internal rows */
    position: relative; /* For positioning error messages */
    padding: 0; /* Remove internal padding, use gap instead */
    border-bottom: 1px dotted #e0e0e0; /* Add back dotted border */
    padding-bottom: 5px; /* Padding for border effect */
    box-sizing: border-box;
}
.mark-field:last-of-type { /* Remove border for the last one */
    border-bottom: none;
    padding-bottom: 0;
}


.mark-field > label { /* Direct child label */
    flex-shrink: 0; /* Prevent label from shrinking */
    min-width: 45px; /* Give labels consistent width */
    text-align: left; /* Align label text to the left */
    font-weight: normal;
    color: #555;
    font-size: 1em;
}

.mark-field input {
    flex-grow: 1; /* Allow input to take remaining space */
    max-width: 120px; /* Max width to prevent overly wide inputs, but allows expansion */
    min-width: 80px; /* Ensure a decent min-width */
    margin-bottom: 0;
    padding: 8px;
    text-align: left; /* Align text left as they are now wider */
    background-color: #eef4f9;
    border: 1px solid #a3c1e3;
    border-radius: 4px; /* Slightly rounder corners */
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
}

/* Error messages directly after input fields, positioned relative to their .mark-field parent */
.mark-field .error-message {
    position: absolute; /* Position relative to .mark-field */
    top: 100%; /* Below the input line */
    left: 0;
    right: 0;
    text-align: left;
    margin-top: 2px; /* Small space below input */
    white-space: normal; /* Allow message to wrap */
    font-size: 0.85em;
    width: 100%; /* Take full width of parent */
    padding: 0; /* Remove padding */
}


/* Button Group Styling */
.button-group {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 20px;
}

button {
    background: linear-gradient(to right, #28a745 0%, #218838 100%);
    color: white;
    padding: 12px 20px;
    border: none;
    border-radius: 30px;
    cursor: pointer;
    font-size: 1.1em;
    transition: all 0.3s ease;
    letter-spacing: 0.5px;
    box-shadow: 0 4px 15px rgba(0, 123, 255, 0.2);
    flex-grow: 1;
    max-width: 180px;
}

button:hover {
    background: linear-gradient(to right, #218838 0%, #1e7e34 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 123, 255, 0.3);
}

.reset-button {
    background: linear-gradient(to right, #6c757d 0%, #5a6268 100%);
    box-shadow: 0 4px 15px rgba(108, 117, 125, 0.2);
}

.reset-button:hover {
    background: linear-gradient(to right, #5a6268 0%, #4e555b 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(108, 117, 125, 0.3);
}


.result {
    margin-top: 25px;
    padding: 15px;
    border-radius: 8px;
    background-color: #f9f9f9;
    text-align: left;
    font-size: 1em;
    line-height: 1.5;
    border: 1px solid #eee;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.result.pass {
    background-color: #e6ffe6;
    color: #28a745;
    border-color: #a3e0a3;
    animation: fadeIn 0.5s ease-out;
}

.result.fail {
    background-color: #ffe6e6;
    color: #dc3545;
    border-color: #e0a3a3;
    animation: shake 0.5s ease-out;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-3px); }
    40%, 80% { transform: translateX(3px); }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .container {
        padding: 20px;
        max-width: 98%;
    }
    h1 {
        font-size: 1.6em;
        margin-bottom: 10px;
    }
    .author-signature {
        font-size: 0.8em;
        margin-top: -8px;
        margin-bottom: 15px;
    }
    p {
        font-size: 1em;
        margin-bottom: 20px;
    }
    .button-group {
        flex-direction: column;
        gap: 10px;
        margin-top: 20px;
    }
    button, .reset-button {
        padding: 10px 15px;
        font-size: 1em;
        max-width: 100%;
    }

    /* **CRITICAL MOBILE FIXES FOR STREAM SUBJECTS (CLASS 11/12)** */
    #streamSubjects {
        gap: 15px; /* Reduce gap between subject blocks on smaller screens */
    }

    #streamSubjects .subject-block {
        flex-basis: calc(100% - 10px); /* Make subject blocks take full width minus padding/gap */
        max-width: calc(100% - 10px);
        min-width: 290px; /* Remove min-width to allow shrinking on very small screens */
        padding: 12px; /* Slightly less padding */
        margin: 0 auto; /* Center the blocks when they stack */
    }

    .marks-input-group {
        gap: 8px; /* Slightly less gap between rows */
    }
    .mark-field {
        gap: 5px; /* Less gap in mark-field */
        padding-bottom: 4px;
    }
    .mark-field > label {
        min-width: 40px; /* Adjusted min-width for labels */
        font-size: 0.95em;
    }
    .mark-field input {
        min-width: 70px; /* Ensure sufficient width */
        max-width: 100%; /* Allow full width */
        font-size: 0.95em;
        padding: 6px;
    }

    /* General marks input adjustment for classes 1-10 */
    .marks-input > div input {
        max-width: 100px;
    }
    .result {
        font-size: 0.9em;
        margin-top: 20px;
        padding: 12px;
    }
}

@media (max-width: 480px) {
    /* For very small screens, stack label and input within mark-field */
    .mark-field {
        flex-direction: column;
        align-items: flex-start;
        gap: 3px;
        padding-bottom: 3px;
    }
    .mark-field > label {
        min-width: unset;
        text-align: left;
        width: 100%;
    }
    .mark-field input {
        width: 100%; /* Full width */
        max-width: 100%;
        text-align: left;
        margin-right: 0;
    }
    /* Adjust error message position for stacked elements */
    .mark-field .error-message {
        position: relative; /* No longer absolute for stacked elements */
        top: auto;
        left: auto;
        margin-top: 0;
        margin-bottom: 0;
        font-size: 0.8em;
        text-align: left;
        width: 100%;
    }

    /* General marks input adjustment for very small screens (classes 1-10) */
    .marks-input > div {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }
    .marks-input > div label {
        width: 100%;
        margin-bottom: 3px;
    }
    .marks-input > div input {
        width: calc(100% - 16px); /* Account for padding */
        max-width: 100%;
        text-align: left;
    }
}