#subjects-section {
    flex-direction: column;
}

/* ═══════════════════════════════════════════
   SUBJECTS SECTION
   ═══════════════════════════════════════════ */

/* ── Botón "+" flotante ────────────────────── */
#new-subject-btn {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 100;

    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    cursor: pointer;

    background: linear-gradient(135deg, #0f7a55, #1fa36f 50%, #18bf72);
    color: #fff;
    font-size: 1.2rem;

    display: flex;
    align-items: center;
    justify-content: center;

    box-shadow: 0 4px 20px rgba(18, 132, 92, 0.45);
    transition: transform 200ms ease, box-shadow 200ms ease;
}

#new-subject-btn:hover {
    transform: scale(1.08) rotate(90deg);
    box-shadow: 0 6px 28px rgba(18, 132, 92, 0.55);
}

#new-subject-btn:active {
    transform: scale(0.96) rotate(90deg);
}

/* ── Modal overlay ─────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 500;
    display: flex;

    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);

    align-items: center;
    justify-content: center;
    padding: 1rem;

    opacity: 1;
    transition: opacity 220ms ease;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

/* ── Modal card ────────────────────────────── */
.modal-card {
    width: 100%;
    max-width: 420px;

    background: #0a3d29;
    border: 1px solid rgba(169, 204, 187, 0.18);
    border-radius: 20px;

    box-shadow:
        0 24px 60px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.07);

    overflow: hidden;

    transform: translateY(0) scale(1);
    transition: transform 220ms cubic-bezier(.4,0,.2,1);
}

.modal-overlay.hidden .modal-card {
    transform: translateY(16px) scale(0.97);
}

/* Modal header */
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem 0;
}

.modal-header h2 {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.01em;
    color: #e8efe9;
}

.modal-close-btn {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: none;
    background: rgba(255, 255, 255, 0.07);
    color: rgba(232, 239, 233, 0.6);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: background 150ms ease, color 150ms ease;
}

.modal-close-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #e8efe9;
}

/* Modal body */
.modal-body {
    padding: 1.25rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
}

/* Field groups */
.field-group {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.field-group label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: #7fb89a;
}

.field-group input[type="text"] {
    width: 100%;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid rgba(169, 204, 187, 0.18);
    background: rgba(255, 255, 255, 0.05);
    color: #e8efe9;
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: border-color 160ms ease, background 160ms ease;
}

.field-group input[type="text"]::placeholder {
    color: rgba(169, 204, 187, 0.35);
}

.field-group input[type="text"]:focus {
    border-color: rgba(61, 220, 151, 0.45);
    background: rgba(255, 255, 255, 0.07);
}

/* Color swatches */
.color-picker-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.color-swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    background: var(--swatch);
    cursor: pointer;
    transition: transform 150ms ease, border-color 150ms ease;
    flex-shrink: 0;
    position: relative;
}

.color-swatch:hover {
    transform: scale(1.15);
}

.color-swatch.active {
    border-color: #fff;
    transform: scale(1.15);
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25);
}

/* Custom color picker */
.color-custom-wrap {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px dashed rgba(169, 204, 187, 0.4);
    background: rgba(255, 255, 255, 0.05);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: rgba(169, 204, 187, 0.6);
    transition: border-color 150ms ease, color 150ms ease;
    position: relative;
    flex-shrink: 0;
}

.color-custom-wrap:hover {
    border-color: rgba(169, 204, 187, 0.8);
    color: #a9ccbb;
}

.color-custom-wrap input[type="color"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    border: none;
    padding: 0;
}

/* Preview */
.subject-preview {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(169, 204, 187, 0.1);
}

.preview-color-bar {
    width: 6px;
    height: 36px;
    border-radius: 999px;
    background: #e05c5c;
    flex-shrink: 0;
    transition: background 200ms ease;
}

.subject-preview span {
    font-size: 13.5px;
    font-weight: 500;
    color: rgba(232, 239, 233, 0.6);
    font-style: italic;
    transition: color 200ms ease;
}

/* Modal footer */
.modal-footer {
    display: flex;
    gap: 10px;
    padding: 0 1.5rem 1.5rem;
}

.btn-cancel {
    flex: 1;
    padding: 10px;
    border-radius: 10px;
    border: 1px solid rgba(169, 204, 187, 0.18);
    background: rgba(255, 255, 255, 0.05);
    color: rgba(232, 239, 233, 0.65);
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    transition: background 150ms ease, color 150ms ease;
}

.btn-cancel:hover {
    background: rgba(255, 255, 255, 0.09);
    color: #e8efe9;
}

.btn-add {
    flex: 2;
    padding: 10px 16px;
    border-radius: 10px;
    border: none;
    background: linear-gradient(135deg, #0f7a55, #1fa36f 50%, #18bf72);
    color: #fff;
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    box-shadow: 0 4px 14px rgba(18, 132, 92, 0.3);
    transition: transform 160ms ease, box-shadow 160ms ease;
    position: relative;
    overflow: hidden;
}

.btn-add::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0.12) 0%, transparent 55%);
    pointer-events: none;
}

.btn-add:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(18, 132, 92, 0.4);
}

.btn-add:active {
    transform: translateY(0);
}

/* ═══════════════════════════════════════════
   SUBJECTS GRID
   ═══════════════════════════════════════════ */

#subjects-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 14px;
    margin-top: 1.5rem;
}

/* ── Subject card ──────────────────────────
   Toda la magia de colores relativos vive aquí.
   --subject-clr se setea inline desde JS.
   El resto de propiedades derivan de él.
   ────────────────────────────────────────── */
.subject-card {
    --subject-clr: #3daa6e; /* fallback, JS lo sobreescribe */

    color: var(--subject-clr);
    border-radius: 16px;
    border: 1px solid color-mix(in srgb, var(--subject-clr) 30%, transparent);
    background: color-mix(in srgb, var(--subject-clr) 12%, #0a3d29);

    overflow: hidden;
    transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
    box-shadow:
        0 2px 14px color-mix(in srgb, var(--subject-clr) 15%, transparent),
        inset 0 1px 0 rgba(255,255,255,0.06);
}

.subject-card:hover {
    transform: translateY(-3px);
    border-color: color-mix(in srgb, var(--subject-clr) 55%, transparent);
    box-shadow:
        0 8px 28px color-mix(in srgb, var(--subject-clr) 25%, transparent),
        inset 0 1px 0 rgba(255,255,255,0.08);
}

/* Franja de color sólido arriba */
.subject-info {
    background: var(--subject-clr);
    padding: 18px 16px 14px;
    position: relative;
    overflow: hidden;
}

/* Brillo interno en la franja */
.subject-info::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 50%;
    background: linear-gradient(180deg, rgba(255,255,255,0.18) 0%, transparent 100%);
    pointer-events: none;
}

.subject-info h3 {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.01em;
    /* Color legible sobre el background: blanco o negro relativo */
    color: color-mix(in srgb, var(--subject-clr) 0%, white);
    text-shadow: 0 1px 3px rgba(0,0,0,0.25);
    position: relative;
    z-index: 1;
}

/* Acciones */
.subject-actions {
    padding: 10px 12px;
    display: flex;
    gap: 8px;
}

.open-subject-btn,
.delete-btn {
    border: none;
    border-radius: 8px;
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    padding: 6px 12px;
    transition: background 150ms ease, color 150ms ease, transform 120ms ease;
}

.open-subject-btn {
    flex: 1;
    /* Fondo relativo al color de la materia */
    background: color-mix(in srgb, var(--subject-clr) 22%, transparent);
    color: color-mix(in srgb, var(--subject-clr) 85%, white);
    border: 1px solid color-mix(in srgb, var(--subject-clr) 35%, transparent);
}

.open-subject-btn:hover {
    background: color-mix(in srgb, var(--subject-clr) 35%, transparent);
    color: white;
    transform: scale(1.02);
}

.delete-btn {
    background: rgba(255, 80, 80, 0.1);
    color: #ff9090;
    border: 1px solid rgba(255, 80, 80, 0.2);
    padding: 6px 10px;
}

.delete-btn:hover {
    background: rgba(255, 80, 80, 0.2);
    transform: scale(1.02);
}

/* ═══════════════════════════════════════════
   SUBJECT DETAIL
   ═══════════════════════════════════════════ */

.subject-detail {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(169, 204, 187, 0.12);
}

.subject-detail.hidden {
    display: none;
}

.detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 1.25rem;
}

.detail-header h2 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: #e8efe9;
}

.final-average-badge {
    padding: 5px 14px;
    border-radius: 999px;
    background: rgba(61, 220, 151, 0.1);
    border: 1px solid rgba(61, 220, 151, 0.2);
    color: #7affc5;
    font-size: 13px;
    font-weight: 500;
}

.final-average-badge strong {
    font-weight: 800;
}

.btn-add-category {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 18px;
    border-radius: 10px;
    border: 1px dashed rgba(169, 204, 187, 0.3);
    background: rgba(255, 255, 255, 0.03);
    color: #a9ccbb;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
    margin-bottom: 1rem;
}

.btn-add-category:hover {
    background: rgba(61, 220, 151, 0.07);
    border-color: rgba(61, 220, 151, 0.35);
    color: #3ddc97;
}

.subject-card.selected {
    border-color: color-mix(in srgb, var(--subject-clr) 70%, transparent);
    box-shadow:
        0 0 0 2px color-mix(in srgb, var(--subject-clr) 35%, transparent),
        0 8px 28px color-mix(in srgb, var(--subject-clr) 25%, transparent);
}

/* ── Mobile ────────────────────────────────── */
@media (max-width: 800px) {
    #new-subject-btn {
        bottom: 1.25rem;
        right: 1.25rem;
        width: 48px;
        height: 48px;
    }

    #subjects-container {
        grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
        gap: 10px;
    }

    .modal-card {
        border-radius: 16px;
    }
}