* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #e0f2fe 0%, #e0e7ff 50%, #f3e8ff 100%);
    min-height: 100vh;
    padding: 0.75rem;
}

@media (min-width: 640px) {
    body {
        padding: 1.5rem;
    }
}

@media (min-width: 1024px) {
    body {
        padding: 2rem;
    }
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 1.5rem;
}

@media (min-width: 768px) {
    .header {
        margin-bottom: 2rem;
    }
}

@media (min-width: 1024px) {
    .header {
        margin-bottom: 2.5rem;
    }
}

.header-title {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

@media (min-width: 768px) {
    .header-title {
        gap: 0.75rem;
        margin-bottom: 0.75rem;
    }
}

.header-title h1 {
    font-size: 1.5rem;
    font-weight: 900;
    color: #312e81;
    line-height: 1.2;
}

@media (min-width: 480px) {
    .header-title h1 {
        font-size: 1.875rem;
    }
}

@media (min-width: 640px) {
    .header-title h1 {
        font-size: 2.25rem;
    }
}

@media (min-width: 1024px) {
    .header-title h1 {
        font-size: 3rem;
    }
}

.icon {
    width: 1.75rem;
    height: 1.75rem;
    color: #6366f1;
    flex-shrink: 0;
}

@media (min-width: 640px) {
    .icon {
        width: 2rem;
        height: 2rem;
    }
}

@media (min-width: 1024px) {
    .icon {
        width: 2.5rem;
        height: 2.5rem;
    }
}

.icon-small {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
}

@media (min-width: 768px) {
    .icon-small {
        width: 1.25rem;
        height: 1.25rem;
    }
}

.subtitle {
    font-size: 0.875rem;
    color: #4338ca;
    margin-bottom: 1.25rem;
    padding: 0 0.5rem;
}

@media (min-width: 640px) {
    .subtitle {
        font-size: 1rem;
        margin-bottom: 1.5rem;
    }
}

@media (min-width: 1024px) {
    .subtitle {
        font-size: 1.125rem;
        margin-bottom: 2rem;
    }
}

/* How to Use Section */
.how-to-use {
    max-width: 1000px;
    margin: 0 auto 1.5rem;
    background: white;
    border-radius: 0.875rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    border: 3px solid #c7d2fe;
    padding: 0.875rem;
    text-align: left;
}

@media (min-width: 640px) {
    .how-to-use {
        padding: 1.25rem;
        border-radius: 1rem;
        margin-bottom: 2rem;
    }
}

@media (min-width: 1024px) {
    .how-to-use {
        padding: 1.5rem;
        margin-bottom: 2.5rem;
    }
}

.how-to-use h2 {
    font-size: 1.125rem;
    font-weight: 700;
    color: #312e81;
    margin-bottom: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

@media (min-width: 640px) {
    .how-to-use h2 {
        font-size: 1.25rem;
        margin-bottom: 1rem;
    }
}

@media (min-width: 1024px) {
    .how-to-use h2 {
        font-size: 1.5rem;
    }
}

.instructions {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    color: #4338ca;
}

@media (min-width: 640px) {
    .instructions {
        gap: 1.25rem;
    }
}

@media (min-width: 1024px) {
    .instructions {
        gap: 1.5rem;
    }
}

.instruction-block h3 {
    font-size: 0.9375rem;
    font-weight: 700;
    color: #312e81;
    margin-bottom: 0.5rem;
}

@media (min-width: 640px) {
    .instruction-block h3 {
        font-size: 1rem;
    }
}

@media (min-width: 1024px) {
    .instruction-block h3 {
        font-size: 1.125rem;
    }
}

.instruction-block ol {
    margin-left: 1rem;
    line-height: 1.7;
    font-size: 0.8125rem;
}

@media (min-width: 640px) {
    .instruction-block ol {
        margin-left: 1.5rem;
        line-height: 1.75;
        font-size: 0.9rem;
    }
}

@media (min-width: 1024px) {
    .instruction-block ol {
        margin-left: 2rem;
        line-height: 1.8;
        font-size: 1rem;
    }
}

.instruction-block p {
    line-height: 1.6;
    font-size: 0.8125rem;
}

@media (min-width: 640px) {
    .instruction-block p {
        font-size: 0.9rem;
    }
}

@media (min-width: 1024px) {
    .instruction-block p {
        font-size: 1rem;
    }
}

.example {
    margin-top: 0.75rem;
    font-size: 0.75rem;
    font-style: italic;
    background: #eef2ff;
    padding: 0.625rem;
    border-radius: 0.5rem;
}

@media (min-width: 640px) {
    .example {
        font-size: 0.8125rem;
        padding: 0.75rem;
    }
}

@media (min-width: 1024px) {
    .example {
        font-size: 0.875rem;
    }
}

/* Main Content Layout */
.main-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

@media (min-width: 640px) {
    .main-content {
        gap: 1.5rem;
        margin-bottom: 2rem;
    }
}

@media (min-width: 1024px) {
    .main-content {
        grid-template-columns: 280px 1fr;
        margin-bottom: 2.5rem;
    }
}

@media (min-width: 1280px) {
    .main-content {
        grid-template-columns: 320px 1fr;
    }
}

.sidebar {
    order: 2;
}

@media (min-width: 1024px) {
    .sidebar {
        position: sticky;
        top: 1.5rem;
        height: fit-content;
        order: 1;
    }
}

.calculator-section {
    order: 1;
}

@media (min-width: 1024px) {
    .calculator-section {
        order: 2;
    }
}

/* Sidebar */
.grade-scale-card {
    background: white;
    border-radius: 0.875rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    border: 3px solid #c7d2fe;
    padding: 0.875rem;
}

@media (min-width: 640px) {
    .grade-scale-card {
        padding: 1.25rem;
        border-radius: 1rem;
    }
}

@media (min-width: 1024px) {
    .grade-scale-card {
        padding: 1.5rem;
    }
}

.grade-scale-card h3 {
    font-size: 1rem;
    font-weight: 700;
    color: #312e81;
    text-align: center;
    margin-bottom: 0.875rem;
}

@media (min-width: 640px) {
    .grade-scale-card h3 {
        font-size: 1.125rem;
        margin-bottom: 1rem;
    }
}

@media (min-width: 1024px) {
    .grade-scale-card h3 {
        font-size: 1.25rem;
        margin-bottom: 1.25rem;
    }
}

.grade-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.grade-badge {
    width: 2.75rem;
    height: 2rem;
    background: linear-gradient(135deg, #c7d2fe 0%, #ddd6fe 100%);
    border-radius: 0.625rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #312e81;
    border: 2px solid #a5b4fc;
    font-size: 0.8125rem;
    flex-shrink: 0;
}

@media (min-width: 640px) {
    .grade-badge {
        width: 3rem;
        height: 2.25rem;
        font-size: 0.875rem;
        border-radius: 0.75rem;
    }
}

@media (min-width: 1024px) {
    .grade-badge {
        width: 3.5rem;
        height: 2.5rem;
    }
}

.grade-item input {
    flex: 1;
    padding: 0.5rem;
    background: #eef2ff;
    border: 2px solid #c7d2fe;
    border-radius: 0.625rem;
    color: #312e81;
    font-weight: 600;
    font-size: 0.8125rem;
    min-width: 0;
}

@media (min-width: 640px) {
    .grade-item input {
        padding: 0.5rem 0.625rem;
        font-size: 0.875rem;
        border-radius: 0.75rem;
    }
}

@media (min-width: 1024px) {
    .grade-item input {
        padding: 0.5rem 0.75rem;
    }
}

.grade-item input:focus {
    outline: none;
    border-color: #6366f1;
}

.grade-note {
    color: #4338ca;
    font-size: 0.6875rem;
    text-align: center;
    margin-top: 0.875rem;
    line-height: 1.4;
}

@media (min-width: 640px) {
    .grade-note {
        font-size: 0.75rem;
        margin-top: 1rem;
    }
}

@media (min-width: 1024px) {
    .grade-note {
        margin-top: 1.25rem;
    }
}

/* Cards */
.calculator-section {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

@media (min-width: 640px) {
    .calculator-section {
        gap: 1.5rem;
    }
}

.card {
    background: white;
    border-radius: 0.875rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    border: 3px solid #c7d2fe;
    overflow: hidden;
}

@media (min-width: 640px) {
    .card {
        border-radius: 1rem;
    }
}

.card-header {
    background: linear-gradient(90deg, #ddd6fe 0%, #e9d5ff 100%);
    padding: 0.875rem 1rem;
    border-bottom: 3px solid #c7d2fe;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
}

@media (min-width: 640px) {
    .card-header {
        padding: 1rem 1.25rem;
    }
}

@media (min-width: 1024px) {
    .card-header {
        padding: 1.25rem 1.5rem;
        flex-wrap: nowrap;
    }
}

.cgpa-header {
    background: linear-gradient(90deg, #e9d5ff 0%, #dbeafe 100%);
}

.card-header h2 {
    font-size: 1.0625rem;
    font-weight: 700;
    color: #312e81;
}

@media (min-width: 640px) {
    .card-header h2 {
        font-size: 1.25rem;
    }
}

@media (min-width: 1024px) {
    .card-header h2 {
        font-size: 1.5rem;
    }
}

.btn-add {
    padding: 0.5rem 0.75rem;
    background: #6366f1;
    color: white;
    border: none;
    border-radius: 9999px;
    font-weight: 600;
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: background 0.3s, transform 0.1s;
    white-space: nowrap;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
}

@media (min-width: 640px) {
    .btn-add {
        padding: 0.5rem 0.875rem;
        font-size: 0.8125rem;
        gap: 0.5rem;
    }
}

@media (min-width: 1024px) {
    .btn-add {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
    }
}

.btn-add:hover {
    background: #4f46e5;
}

.btn-add:active {
    transform: scale(0.98);
}

@media (max-width: 639px) {
    .btn-add {
        width: 100%;
        justify-content: center;
    }
}

.card-body {
    padding: 0.875rem;
}

@media (min-width: 640px) {
    .card-body {
        padding: 1.25rem;
    }
}

@media (min-width: 1024px) {
    .card-body {
        padding: 1.5rem;
    }
}

/* Table - FIXED FOR MOBILE */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.course-table {
    width: 100%;
    border-collapse: collapse;
    display: block;
}

@media (min-width: 640px) {
    .course-table {
        display: table;
    }
}

/* Hide table header on mobile */
.course-table thead {
    display: none;
}

@media (min-width: 640px) {
    .course-table thead {
        display: table-header-group;
    }
}

.course-table thead tr {
    border-bottom: 2px solid #c7d2fe;
}

.course-table th {
    text-align: left;
    padding: 0.625rem 0.5rem;
    color: #312e81;
    font-weight: 700;
    font-size: 0.75rem;
    white-space: nowrap;
}

@media (min-width: 768px) {
    .course-table th {
        padding: 0.75rem;
        font-size: 0.875rem;
    }
}

.col-credits {
    width: 5.5rem;
}

@media (min-width: 768px) {
    .col-credits {
        width: 7rem;
    }
}

@media (min-width: 1024px) {
    .col-credits {
        width: 8rem;
    }
}

.col-grade {
    width: 5.5rem;
}

@media (min-width: 768px) {
    .col-grade {
        width: 7rem;
    }
}

@media (min-width: 1024px) {
    .col-grade {
        width: 8rem;
    }
}

.col-actions {
    width: 2.5rem;
}

@media (min-width: 1024px) {
    .col-actions {
        width: 3rem;
    }
}

.course-table tbody tr {
    border-bottom: 1px solid #e0e7ff;
}

.course-table td {
    padding: 0.625rem 0.5rem;
}

@media (min-width: 768px) {
    .course-table td {
        padding: 0.75rem;
    }
}

.course-table input,
.course-table select {
    width: 100%;
    padding: 0.5rem;
    background: #eef2ff;
    border: 2px solid #c7d2fe;
    border-radius: 0.625rem;
    color: #312e81;
    font-size: 0.75rem;
}

@media (min-width: 640px) {
    .course-table input,
    .course-table select {
        font-size: 0.8125rem;
        border-radius: 0.75rem;
    }
}

@media (min-width: 1024px) {
    .course-table input,
    .course-table select {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }
}

.course-table select {
    font-weight: 600;
}

.course-table input:focus,
.course-table select:focus {
    outline: none;
    border-color: #6366f1;
}

.course-table input[type="number"]::-webkit-inner-spin-button,
.course-table input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
}

.course-table input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

/* Mobile Course Cards - FIXED */
#coursesTableBody {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

@media (min-width: 640px) {
    #coursesTableBody {
        display: table-row-group;
    }
}

/* Mobile course row styling - FIXED */
@media (max-width: 639px) {
    .course-table tbody {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }
    
    .course-table tbody tr {
        display: flex;
        flex-direction: column;
        background: #f9fafb;
        padding: 1rem;
        border-radius: 0.75rem;
        border: 2px solid #e0e7ff;
        margin-bottom: 0;
    }
    
    .course-table tbody td {
        display: block;
        width: 100%;
        padding: 0;
        border: none;
    }
    
    .course-table tbody td:not(:last-child) {
        margin-bottom: 0.75rem;
    }
    
    .course-table tbody td::before {
        content: attr(data-label);
        display: block;
        font-weight: 700;
        color: #312e81;
        font-size: 0.8125rem;
        margin-bottom: 0.375rem;
    }
    
    /* Hide label for delete button */
    .course-table tbody td:last-child::before {
        content: '';
        display: none;
    }
    
    .course-table input,
    .course-table select {
        font-size: 0.875rem;
        padding: 0.625rem 0.75rem;
    }
}

.btn-delete {
    padding: 0.375rem;
    background: #ddd6fe;
    color: #4338ca;
    border: none;
    border-radius: 9999px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s, transform 0.1s;
    width: 1.875rem;
    height: 1.875rem;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

@media (min-width: 640px) {
    .btn-delete {
        padding: 0.4rem;
        width: 2rem;
        height: 2rem;
    }
}

@media (min-width: 1024px) {
    .btn-delete {
        padding: 0.5rem;
        width: 2.25rem;
        height: 2.25rem;
    }
}

@media (max-width: 639px) {
    .btn-delete {
        width: 100%;
        max-width: 120px;
        height: 2.5rem;
        margin: 0.5rem auto 0;
        font-size: 1.125rem;
    }
}

.btn-delete:hover:not(:disabled) {
    background: #c7d2fe;
}

.btn-delete:active:not(:disabled) {
    transform: scale(0.95);
}

.btn-delete:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Result Cards */
.result-card {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: 0.875rem;
    border: 2px solid #c7d2fe;
}

@media (min-width: 640px) {
    .result-card {
        padding: 1.25rem;
        border-radius: 1rem;
    }
}

@media (min-width: 1024px) {
    .result-card {
        margin-top: 1.25rem;
        padding: 1.5rem;
    }
}

.sgpa-result {
    background: linear-gradient(90deg, #ddd6fe 0%, #e9d5ff 100%);
}

.result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.result-label {
    font-size: 0.875rem;
    font-weight: 700;
    color: #312e81;
}

@media (min-width: 640px) {
    .result-label {
        font-size: 1rem;
    }
}

@media (min-width: 1024px) {
    .result-label {
        font-size: 1.25rem;
    }
}

.result-value {
    font-size: 1.75rem;
    font-weight: 900;
    color: #4338ca;
}

@media (min-width: 480px) {
    .result-value {
        font-size: 2rem;
    }
}

@media (min-width: 640px) {
    .result-value {
        font-size: 2.5rem;
    }
}

@media (min-width: 1024px) {
    .result-value {
        font-size: 3rem;
    }
}

.result-details {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: #4338ca;
}

@media (min-width: 480px) {
    .result-details {
        flex-direction: row;
        gap: 1rem;
        font-size: 0.8125rem;
    }
}

@media (min-width: 640px) {
    .result-details {
        gap: 1.5rem;
        font-size: 0.875rem;
    }
}

/* CGPA Section */
.cgpa-inputs {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.875rem;
    margin-bottom: 1.25rem;
}

@media (min-width: 640px) {
    .cgpa-inputs {
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
        margin-bottom: 1.5rem;
    }
}

.input-group label {
    display: block;
    color: #312e81;
    margin-bottom: 0.5rem;
    font-weight: 700;
    font-size: 0.75rem;
}

@media (min-width: 640px) {
    .input-group label {
        font-size: 0.8125rem;
    }
}

@media (min-width: 1024px) {
    .input-group label {
        font-size: 0.875rem;
    }
}

.input-group input {
    width: 100%;
    padding: 0.625rem 0.75rem;
    background: #eef2ff;
    border: 2px solid #c7d2fe;
    border-radius: 0.625rem;
    color: #312e81;
    font-weight: 600;
    font-size: 0.875rem;
}

@media (min-width: 640px) {
    .input-group input {
        padding: 0.75rem;
        font-size: 0.9375rem;
        border-radius: 0.75rem;
    }
}

@media (min-width: 1024px) {
    .input-group input {
        padding: 0.75rem 1rem;
        font-size: 1rem;
    }
}

.input-group input:focus {
    outline: none;
    border-color: #6366f1;
}

.input-group input[type="number"]::-webkit-inner-spin-button,
.input-group input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
}

.input-group input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

.cgpa-result {
    background: linear-gradient(90deg, #ddd6fe 0%, #dbeafe 100%);
    padding: 1.25rem;
}

@media (min-width: 640px) {
    .cgpa-result {
        padding: 1.5rem;
    }
}

@media (min-width: 1024px) {
    .cgpa-result {
        padding: 2rem;
    }
}

.cgpa-display {
    text-align: center;
}

.cgpa-display h3 {
    font-size: 1.125rem;
    font-weight: 700;
    color: #312e81;
    margin-bottom: 0.625rem;
}

@media (min-width: 640px) {
    .cgpa-display h3 {
        font-size: 1.25rem;
        margin-bottom: 0.75rem;
    }
}

@media (min-width: 1024px) {
    .cgpa-display h3 {
        font-size: 1.5rem;
    }
}

.cgpa-value {
    font-size: 2.5rem;
    font-weight: 900;
    color: #312e81;
    margin-bottom: 0.875rem;
}

@media (min-width: 480px) {
    .cgpa-value {
        font-size: 3rem;
        margin-bottom: 1rem;
    }
}

@media (min-width: 640px) {
    .cgpa-value {
        font-size: 3.5rem;
    }
}

@media (min-width: 1024px) {
    .cgpa-value {
        font-size: 4.5rem;
    }
}

.cgpa-breakdown {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 0.625rem;
    padding: 0.875rem;
    font-size: 0.75rem;
    color: #312e81;
}

@media (min-width: 640px) {
    .cgpa-breakdown {
        gap: 1rem;
        padding: 1rem;
        font-size: 0.8125rem;
        border-radius: 0.75rem;
    }
}

@media (min-width: 1024px) {
    .cgpa-breakdown {
        font-size: 0.875rem;
    }
}

.breakdown-label {
    font-weight: 600;
    font-size: 0.6875rem;
}

@media (min-width: 640px) {
    .breakdown-label {
        font-size: 0.75rem;
    }
}

@media (min-width: 1024px) {
    .breakdown-label {
        font-size: 0.875rem;
    }
}

.breakdown-value {
    font-size: 1.125rem;
    font-weight: 700;
    margin-top: 0.25rem;
}

@media (min-width: 640px) {
    .breakdown-value {
        font-size: 1.25rem;
    }
}

@media (min-width: 1024px) {
    .breakdown-value {
        font-size: 1.5rem;
    }
}

/* Footer */
.footer {
    text-align: center;
    margin-top: 1.5rem;
    color: #4338ca;
    font-size: 0.75rem;
}

@media (min-width: 640px) {
    .footer {
        margin-top: 2rem;
        font-size: 0.8125rem;
    }
}

@media (min-width: 1024px) {
    .footer {
        margin-top: 2.5rem;
        font-size: 0.875rem;
    }
}

/* Accessibility */
button:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 2px solid #6366f1;
    outline-offset: 2px;
}

/* Print styles */
@media print {
    body {
        background: white;
    }
    .btn-add,
    .btn-delete {
        display: none;
    }
}