* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

#constellation-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -3; /* Behind other pseudo-elements */
    pointer-events: none; /* Ensure it doesn't interfere with interactions */
}

body {
    background-color: #eef1f5; /* Slightly richer off-white */
    color: #333;
    line-height: 1.6;
    padding: 20px 0;
    position: relative; /* For pseudo-element positioning */
    overflow-x: hidden; /* Prevent horizontal scroll from animations */
}

body::before {
    pointer-events: none; /* Ensure pseudo-elements don't intercept mouse events */
}

body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -2; /* Behind the grid pseudo-element */
    background-image:
        radial-gradient(circle at 15% 25%, rgba(66, 133, 244, 0.18), transparent 40%), /* Increased opacity and spread */
        radial-gradient(circle at 85% 75%, rgba(120, 150, 255, 0.15), transparent 45%); /* Increased opacity and spread */
    animation: soft-glow-animation 30s ease-in-out infinite alternate;
    pointer-events: none; /* Ensure pseudo-elements don't intercept mouse events */
}

body::before {
    content: '';
    position: fixed; /* Fixed to viewport */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        linear-gradient(rgba(66, 133, 244, 0.12) 1px, transparent 1px), /* Bolder grid lines */
        linear-gradient(90deg, rgba(66, 133, 244, 0.12) 1px, transparent 1px); /* Bolder grid lines */
    background-size: 35px 35px;
    z-index: -1; /* Behind all content */
    animation: subtle-grid-animation 70s linear infinite;
    opacity: 0.75; /* Increased overall opacity of the grid layer */
    transform-style: preserve-3d;
    transform: perspective(600px) rotateX(0deg) translateZ(-150px);
}

.container {
    max-width: 850px;
    margin: 40px auto; /* Added top margin for better spacing with animated bg */
    padding: 30px;
    background-color: white;
    box-shadow: 0 15px 35px rgba(50, 50, 93, 0.08), 0 5px 15px rgba(0, 0, 0, 0.05); /* Softer, more modern shadow */
    border-radius: 12px;
    border-top: 4px solid transparent;
    border-image: linear-gradient(to right, #4a90e2, #50e3c2, #4285f4);
    border-image-slice: 1;
    position: relative; /* Ensure it's above the body's pseudo-element if z-index issues arise */
    z-index: 1;
}

header {
    text-align: center;
    margin-bottom: 30px;
    border-bottom: 2px solid #e1e4e8;
    padding-bottom: 25px;
    position: relative;
}

.print-button-container {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 5;
}

#print-button {
    background-color: #4285f4;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 8px 12px;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: background-color 0.2s;
}

#print-button:hover {
    background-color: #3367d6;
}

#print-button i {
    font-size: 16px;
}

.title-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    margin-bottom: 15px;
    padding: 0 20px;
    position: relative;
    height: 40px;
}

.title {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    width: auto;
}

.title h3 {
    font-size: 24px; /* Slightly larger */
    margin: 0;
    color: #2c3e50; /* A deeper, more modern slate gray */
    font-weight: 600;
    letter-spacing: 0.5px;
}

.token-container {
    display: flex;
    align-items: baseline;
    gap: 5px;
    position: absolute;
    left: 20px;
    z-index: 1;
    white-space: nowrap;
    height: 28px;
}

.token-container label {
    font-weight: 600;
    color: #333;
    font-size: 15px;
    display: inline-block;
    vertical-align: baseline;
    line-height: 1.2;
}

.token-display {
    font-weight: 500;
    color: #333;
    font-size: 16px;
    background-color: #f8f9fa;
    padding: 4px 8px;
    border-radius: 4px;
    display: inline-block;
    vertical-align: baseline;
    line-height: 1.2;
    position: relative;
    top: 1px;
}

.date-container {
    display: flex;
    align-items: baseline;
    gap: 5px;
    position: absolute;
    right: 20px;
    z-index: 1;
    white-space: nowrap;
    height: 28px;
}

.date-container label {
    font-weight: 600;
    color: #333;
    font-size: 15px;
    display: inline-block;
    vertical-align: baseline;
    line-height: 1.2;
}

.date-display {
    font-weight: 500;
    color: #333;
    font-size: 16px;
    background-color: #f8f9fa;
    padding: 4px 8px;
    border-radius: 4px;
    display: inline-block;
    vertical-align: baseline;
    line-height: 1.2;
    position: relative;
    top: 1px;
}

.banner {
    width: 100%;
    text-align: center;
    margin-bottom: 20px;
    max-width: 100%;
    overflow: hidden;
}

#logo-img {
    width: 400px;
    height: auto;
    object-fit: contain;
    border-radius: 0;
    box-shadow: none;
    margin-bottom: 15px;
}

.title h1 {
    font-size: 28px;
    font-weight: bold;
    margin-bottom: 5px;
    color: #4285f4;
    letter-spacing: 1px;
}

.title p {
    font-size: 14px;
    font-weight: 600;
    color: #5f6368;
    letter-spacing: 0.5px;
}

header h2 {
    font-size: 22px;
    margin-top: 10px;
    color: #3c4043;
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

form {
    width: 100%;
}

.section-heading {
    font-size: 18px;
    color: #4285f4;
    margin-top: 25px; /* Increased top margin for better separation */
    margin-bottom: 15px;
    padding-bottom: 8px; /* Adjusted padding for thinner border */
    border-bottom: 1px solid #e0e0e0; /* Lighter and thinner border */
    font-weight: 600;
}

/* Contact fields styling */
.form-group.contact > label {
    display: block;
    margin-bottom: 15px;
}

.contact-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-top: 10px;
}

.contact-field {
    flex: 1 1 300px;
    min-width: 300px;
}

.contact-field input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.form-group {
    margin-bottom: 22px;
    border-bottom: 1px solid #e8eaed;
    padding-bottom: 22px;
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #3c4043;
    font-size: 15px;
}

.required-note {
    font-size: 13px;
    color: #d93025;
    font-weight: normal;
    font-style: italic;
    margin-left: 5px;
}

.optional-note {
    font-size: 12px;
    color: #5f6368;
    font-weight: normal;
    font-style: italic;
    margin-left: 5px;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
textarea {
    display: block;
    width: 100%;
    padding: 10px 12px;
    font-size: 15px;
    line-height: 1.5;
    color: #495057;
    background-color: #fff;
    background-clip: padding-box;
    border: 1px solid #ced4da; /* Standard clearer border */
    border-radius: 6px; /* Slightly more rounded */
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.075);
    transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="tel"]:focus,
input[type="number"]:focus,
textarea:focus {
    border-color: #8ab4f8; /* Lighter blue for focus border */
    outline: 0;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.075), 0 0 0 0.2rem rgba(66, 133, 244, 0.25); /* Standard Bootstrap-like focus */
}

select.form-select {
    display: block;
    width: 100%;
    padding: 10px 12px;
    font-size: 15px;
    line-height: 1.5;
    color: #495057;
    background-color: #fff;
    background-clip: padding-box;
    border: 1px solid #ced4da; /* Standard clearer border */
    border-radius: 6px; /* Slightly more rounded */
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.075);
    transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
}

select.form-select:focus {
    border-color: #8ab4f8; /* Lighter blue for focus border */
    outline: 0;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.075), 0 0 0 0.2rem rgba(66, 133, 244, 0.25); /* Standard Bootstrap-like focus */
}

.contact-fields,
.marks-fields,
.entrance-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.marks-fields-12 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 18px 20px;
    margin-bottom: 10px;
}

.marks-fields-12 > .marks-field {
    min-width: 0;
    width: 100%;
}

/* Optionals row: CS, BIO, ECE in a single row */
.optionals-row {
    grid-column: 1 / span 3;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 18px 20px;
    margin-bottom: 0;
}

@media (max-width: 900px) {
  .marks-fields-12, .optionals-row {
    grid-template-columns: 1fr 1fr;
  }
}
@media (max-width: 600px) {
  .marks-fields-12, .optionals-row {
    grid-template-columns: 1fr;
  }
}


.preference-instruction {
    margin-bottom: 15px;
    color: #5f6368;
    font-size: 14px;
    background-color: #e8f0fe;
    padding: 10px 15px;
    border-radius: 6px;
    border-left: 4px solid #4285f4;
}

.preference-instruction i {
    margin-right: 5px;
    color: #4285f4;
}

.draggable-list {
    list-style: none;
    padding: 0;
    margin: 0;
    background-color: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e8eaed;
    overflow: hidden;
}

.draggable-item {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    background-color: white;
    border-bottom: 1px solid #e8eaed;
    cursor: move;
    user-select: none;
    position: relative;
    transition: all 0.2s ease;
}

.draggable-item:last-child {
    border-bottom: none;
}

.draggable-item:hover {
    background-color: #f8f9fa;
}

.draggable-item.dragging {
    opacity: 0.5;
    background-color: #e8f0fe;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    z-index: 999;
}

.drag-handle {
    margin-right: 10px;
    color: #5f6368;
    cursor: grab;
}

.draggable-item.dragging .drag-handle {
    cursor: grabbing;
}

.preference-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background-color: #4285f4;
    color: white;
    border-radius: 50%;
    font-size: 12px;
    font-weight: bold;
    margin-right: 15px;
}

.course-name {
    flex-grow: 1;
    font-weight: 500;
    color: #3c4043;
}

.course-selection-list {
    margin: 15px 0;
}

.course-option {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    background-color: #f8f9fa;
    border: 1px solid #e1e4e8;
    border-radius: 4px;
    margin-bottom: 8px;
    position: relative;
}

.course-option:hover {
    background-color: #f1f3f5;
}

.course-checkbox {
    margin-right: 10px;
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.preference-indicator {
    display: inline-block;
    width: 24px;
    height: 24px;
    margin-right: 12px;
    border-radius: 50%;
    background-color: #e9ecef;
    color: #495057;
    text-align: center;
    line-height: 24px;
    font-weight: bold;
    font-size: 14px;
}

.preference-indicator.active {
    background-color: #4285f4;
    color: white;
}

.course-option label {
    flex-grow: 1;
    cursor: pointer;
    margin-bottom: 0;
}

.signatures {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.signature-box {
    width: 100%;
    height: 80px;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-top: 5px;
    position: relative;
    background-color: #f9f9f9;
    cursor: crosshair;
}

.signature-box canvas {
    width: 100%;
    height: 100%;
}

.form-actions {
    display: flex;
    justify-content: center;
    gap: 25px;
    margin-top: 35px;
}

button {
    padding: 12px 24px; /* Adjusted padding */
    background-color: #4285f4;
    color: white;
    border: none;
    border-radius: 6px; /* Reduced border-radius */
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.5px;
    min-width: 150px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* Consolidated box-shadow */
    transition: background-color 0.2s ease-in-out, border-color 0.2s ease-in-out, color 0.2s ease-in-out, box-shadow 0.2s ease-in-out, transform 0.1s ease-in-out; /* Consolidated transition */
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15); /* Adjusted generic hover shadow */
}

button[type="submit"]:hover {
    background-color: #3367d6; /* Specific hover for submit button */
}

button:active {
    transform: translateY(1px);
}

#resetBtn {
    background-color: #ffffff;
    color: #4285f4;
    border: 1px solid #4285f4; /* Refined border */
}

#resetBtn:hover {
    background-color: #e8f0fe; /* Light blue background */
    color: #3367d6; /* Darker blue text */
    border-color: #3367d6; /* Darker blue border */
}

.modal {
    display: none;
    position: fixed;
    z-index: 1;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.4);
}

.modal-content {
    background-color: #ffffff;
    margin: 10% auto;
    padding: 30px;
    border: none;
    width: 85%;
    max-width: 500px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    animation: modalFadeIn 0.4s ease-out;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.close {
    color: #dadce0;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s;
}

.close:hover,
.close:focus {
    color: #5f6368;
    text-decoration: none;
}

.modal-content h2 {
    color: #4285f4;
    margin-bottom: 15px;
    font-size: 24px;
}

.modal-content p {
    margin-bottom: 15px;
    color: #3c4043;
}

#tokenNumber {
    font-weight: bold;
    color: #4285f4;
    font-size: 18px;
    display: inline-block;
    background-color: #e8f0fe;
    padding: 8px 15px;
    border-radius: 30px;
    margin: 10px 0;
}

#printFormBtn {
    margin-top: 25px;
    background-color: #34a853;
}

#printFormBtn:hover {
    background-color: #2e8644;
}

@media print {
    .container {
        box-shadow: none;
        margin: 0;
        padding: 15px;
    }
    
    .form-actions,
    #resetBtn,
    #submitBtn {
        display: none;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 20px;
        margin: 15px;
        border-radius: 8px;
    }
    
    .logo-container {
        flex-direction: column;
        text-align: center;
    }
    
    .logo {
        margin-right: 0;
        margin-bottom: 15px;
    }
    
    .contact-fields,
    .marks-fields,
    .entrance-fields {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .form-actions {
        flex-direction: column;
        gap: 15px;
    }
    
    button {
        width: 100%;
        padding: 12px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 15px;
        margin: 10px;
    }
    
    header h2 {
        font-size: 18px;
    }
    
    .title h1 {
        font-size: 24px;
    }
    
    .title p {
        font-size: 12px;
    }
    
    .form-group {
        margin-bottom: 18px;
        padding-bottom: 18px;
    }
    
    label {
        font-size: 14px;
    }
    
    input[type="text"],
    input[type="tel"],
    input[type="number"],
    textarea {
        padding: 10px;
        font-size: 14px;
    }
}

/* Print Specific Styles */
@media print {
    @page {
        size: A4;
        margin: 8mm 10mm; /* Reduced page margins */
    }

    body {
        background-color: #fff !important;
        color: #000 !important;
        padding: 0 !important;
        margin: 0 !important;
        font-size: 8pt !important; /* Aggressively reduced base font */
        line-height: 1.1 !important; /* Aggressively reduced line height */
        -webkit-print-color-adjust: exact !important; /* Ensures background colors/images print in Chrome/Safari */
        print-color-adjust: exact !important;
    }

    .loader-container,
    header .banner, /* Hides the main logo banner */
    .print-button-container,
    #successModal,
    .modal, /* Hide all modals */
    .preference-instruction i, /* Hide info icon in preferences */
    .preference-instruction p, /* Hide the whole instruction paragraph */
    .optional-note, /* Hide (Optional) text */
    .required-note, /* Hide (Required) text */
    .loader-floor, /* Hide loader floor */
    .loader-content .loader-logo, /* Hide loader logo specifically if not covered by .loader-container */
    .loader-spinner, /* Hide spinner specifically */
    .progress-dots /* Hide progress dots */
    {
        display: none !important;
    }

    .container {
        max-width: 100% !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 2mm !important; /* Minimal container padding within @page margins */
        box-shadow: none !important;
        border-radius: 0 !important;
        border-top: none !important;
        border: none !important; /* Remove any container border */
    }

    header {
        text-align: left !important; /* Align header content to left */
        margin-bottom: 6px !important; /* Minimal margin */
        padding-bottom: 2px !important; /* Minimal padding */
        border-bottom: 1px solid #ccc !important;
    }

    .title-container {
        margin-top: 0 !important;
        margin-bottom: 6px !important; /* Minimal margin */
        padding: 0 !important; /* Remove padding */
        height: auto !important;
        display: flex !important; /* Ensure flex for alignment */
        justify-content: space-between !important;
        align-items: center !important; /* Vertically align items */
    }

    .title {
        position: static !important; /* Remove absolute positioning */
        transform: none !important;
        text-align: center !important; /* Center title text */
        flex-grow: 1; /* Allow title to take available space */
    }
    
    .title h3 {
        font-size: 11pt !important; /* Minimal title size */
        font-weight: bold !important;
    }

    .token-container,
    .date-container {
        position: static !important; /* Remove absolute positioning */
        font-size: 8pt !important; /* Reduced */
        gap: 3px !important;
        height: auto !important;
        padding: 2px 0;
    }

    .token-container label,
    .date-container label,
    .token-display,
    .date-display {
        font-size: 8pt !important; /* Reduced */
        padding: 2px 4px !important;
        background-color: #fff !important; /* Ensure no background color for print */
        border: 1px solid #ddd !important; /* Light border for clarity */
    }

    .form-group {
        margin-bottom: 1px !important; /* Barely any space */
        padding: 0 !important;
        border-bottom: none !important; /* Remove any bottom border for print */
    }

    label {
        font-size: 7pt !important; /* Aggressively reduced label font */
        margin-bottom: 0px !important; /* Minimal space */
        line-height: 1.0 !important; /* Minimal line height */
        font-weight: bold !important;
    }

    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    select,
    textarea {
        font-size: 7pt !important; /* Aggressively reduced input font */
        padding: 1px 2px !important; /* Minimal padding */
        line-height: 1.0 !important; /* Minimal line height */
        margin-bottom: 0 !important; /* Remove margin from inputs themselves */
        border: 1px solid #bbb !important; /* Ensure borders are visible */
        background-color: #fff !important; /* Ensure white background */
        box-shadow: none !important;
        border-radius: 2px !important; /* Slight radius for print */
    }
    
    select {
        -webkit-appearance: none !important; /* Remove default select styling for Chrome/Safari */
        -moz-appearance: none !important; /* Remove default select styling for Firefox */
        appearance: none !important;
        padding-right: 20px !important; /* Add space for custom arrow if needed */
        background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23000000%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E') !important;
        background-repeat: no-repeat !important;
        background-position: right 5px center !important;
        background-size: 8px 8px !important; /* Smaller arrow */
    }

    textarea {
        min-height: 12px !important; /* Extremely reduced textarea height */
        resize: none !important; /* Disable resizing for print */
        line-height: 1.3 !important;
    }

    .marks-fields {
        gap: 2px !important; /* Aggressively reduce gap */
        grid-template-columns: repeat(auto-fill, minmax(75px, 1fr)) !important; /* Aggressively compact */
    }

    .marks-field label {
        font-size: 5pt !important; /* Barely legible, last resort */
        line-height: 1.0 !important;
    }

    .marks-field input[type="number"] {
        padding: 0px 1px !important; /* Almost no padding */
        font-size: 5pt !important; /* Barely legible, last resort */
    }

    .course-preference-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)) !important; /* Adjusted for legibility */
        gap: 3px !important; /* Reduced */
    }

    .course-checkbox-label {
        font-size: 6pt !important; /* Aggressively reduced */
        padding: 1px 2px !important; /* Minimal padding */
        line-height: 1.1 !important;
        border: 1px solid #ddd !important;
    }
    
    .course-checkbox-label .preference-indicator {
        display: inline-block !important; /* Ensure indicator is visible */
        font-size: 6pt !important; /* Reduced */
        width: 14px !important; /* Reduced */
        height: 14px !important; /* Reduced */
        line-height: 14px !important; /* Reduced */
        margin-left: 3px !important; /* Reduced */
        background-color: #eee !important;
        color: #000 !important;
        border-radius: 50% !important;
    }

    button[type="submit"],
    button[type="reset"] {
        display: none !important; /* Hide submit and reset buttons */
    }

    /* Ensure all content is visible */
    * {
        overflow: visible !important;
        box-shadow: none !important; /* Remove all shadows for print */
    }

    /* Attempt to keep sections from breaking across pages if it were longer */
    .form-group, .section-heading {
        page-break-inside: avoid !important;
    }

    .section-heading {
        font-size: 8pt !important; /* Aggressively Reduced */
        margin-top: 2px !important; /* Minimal margin */
        margin-bottom: 1px !important; /* Minimal margin */
        padding-bottom: 0px !important; /* No padding */
        border-bottom: 0.5pt solid #f0f0f0 !important; /* Very faint border or none */
    }
}
