:root {
    --login-ink: #18252d;
    --login-muted: #62717a;
    --login-paper: #f6f8fa;
    --login-surface: rgba(255, 255, 255, 0.94);
    --login-line: #dce3e6;
    --login-teal: #007f6a;
    --login-teal-dark: #006753;
}

body.portal-redesign {
    min-width: 320px;
    color: var(--login-ink);
    background: var(--login-paper);
    overflow-x: hidden;
}

.portal-redesign .noise-overlay,
.portal-redesign .cursor-glow,
.portal-redesign .ambient-glow,
.portal-redesign .bg-video { display: none !important; }

.portal-redesign .visual-canvas {
    background: #172121;
}

.portal-redesign .video-overlay {
    background: rgba(12, 20, 20, 0.2) !important;
}

.portal-redesign .construct-field {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
}

.portal-redesign .construct-field span { position: absolute; display: block; }

.portal-redesign .construct-frame {
    top: 16%;
    left: 7%;
    width: min(54vw, 720px);
    height: min(54vw, 720px);
    border: 1px solid rgba(174, 213, 204, 0.2);
    transform: rotate(-9deg);
}

.portal-redesign .construct-axis {
    background: rgba(194, 225, 217, 0.28);
}

.portal-redesign .construct-axis-x { top: 62%; right: 0; left: 0; height: 1px; }
.portal-redesign .construct-axis-y { top: 0; bottom: 0; left: 45%; width: 1px; }

.portal-redesign .construct-line {
    height: 1px;
    transform-origin: left center;
    background: rgba(87, 176, 157, 0.65);
}

.portal-redesign .construct-line-a { top: 35%; left: 6%; width: 44%; transform: rotate(22deg); }
.portal-redesign .construct-line-b { top: 58%; left: 19%; width: 37%; transform: rotate(-37deg); }
.portal-redesign .construct-line-c { top: 74%; left: 51%; width: 38%; transform: rotate(14deg); background: rgba(219, 164, 78, 0.68); }

.portal-redesign .construct-point {
    width: 10px;
    height: 10px;
    border: 2px solid #dca356;
    border-radius: 50%;
    background: #172121;
}

.portal-redesign .construct-point-a { top: 31%; left: 39%; }
.portal-redesign .construct-point-b { top: 53%; left: 18%; border-color: #78e2c5; }
.portal-redesign .construct-point-c { top: 67%; left: 72%; border-color: #78e2c5; }

.portal-redesign .portal-wrapper {
    width: min(1180px, calc(100% - 64px));
    min-height: 100vh;
    padding: 28px 0 24px;
    margin: 0 auto !important;
}

.portal-redesign .app-header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center;
    min-height: 32px;
    margin: 0;
    padding-bottom: 22px;
    border-bottom: 1px solid rgba(231, 244, 244, 0.22);
}

.portal-redesign .brand-logotype {
    color: #f3fbfa;
    font-family: "Noto Serif SC", serif;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0;
}

.portal-redesign .header-status { color: rgba(237, 249, 248, 0.82); font-size: 13px; font-weight: 600; }
.portal-redesign .status-indicator { background: #5de0bd; box-shadow: none; animation: none; }
.portal-redesign .portal-content { align-items: center; padding: 44px 0; }

.portal-redesign .view-grid {
    grid-template-columns: minmax(0, 1fr) 420px;
    gap: clamp(56px, 10vw, 148px);
    align-items: center;
}

.portal-redesign .branding-panel { min-height: 430px; display: flex; align-items: center; padding: 0 !important; transform: none !important; }
.portal-redesign .brand-content { width: min(520px, 100%); margin: 0 !important; transform: none !important; }

.portal-redesign .brand-eyebrow {
    color: #78e2c5;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 1.6px;
    margin: 0 0 18px;
}

.portal-redesign .main-title {
    color: #f7fffd;
    font-family: "Noto Serif SC", serif;
    font-size: clamp(44px, 5vw, 68px) !important;
    font-weight: 700;
    line-height: 1.13 !important;
    letter-spacing: 0;
    margin: 0 0 22px !important;
    text-shadow: none !important;
}

.portal-redesign .main-desc {
    max-width: 440px;
    color: rgba(234, 247, 246, 0.84);
    font-size: 16px !important;
    line-height: 1.8 !important;
    text-shadow: none;
    margin: 0 0 34px !important;
}

.portal-redesign .system-stats {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: min(430px, 100%);
    gap: 0;
    border-top: 1px solid rgba(231, 244, 244, 0.24);
}

.portal-redesign .stat-item { padding: 16px 14px 2px 0; }
.portal-redesign .stat-item + .stat-item { padding-left: 22px; border-left: 1px solid rgba(231, 244, 244, 0.24); }
.portal-redesign .stat-value { display: block; color: #fff; font-size: 16px !important; font-weight: 800; }
.portal-redesign .stat-label { display: block; margin-top: 5px; color: rgba(233, 247, 245, 0.72); font-size: 12px !important; font-weight: 500; letter-spacing: 0; text-transform: none; }
.portal-redesign .action-panel { width: 100% !important; min-width: 0; margin: 0 !important; padding: 0 !important; transform: none !important; }

.portal-redesign .portal-card {
    box-sizing: border-box;
    width: 100%;
    max-width: 420px !important;
    max-height: none !important;
    min-height: 486px;
    margin: 0;
    padding: 34px 34px 30px;
    background: var(--login-surface);
    border: 1px solid rgba(24, 37, 45, 0.12);
    border-radius: 8px;
    box-shadow: 0 18px 45px rgba(27, 45, 50, 0.12);
}

.portal-redesign .card-progress { margin: 0 0 32px; }
.portal-redesign .step-indicator { justify-content: flex-start; gap: 10px; }
.portal-redesign .step { color: #8b969d; font-size: 12px; font-weight: 700; opacity: 1; }
.portal-redesign .step.active { color: var(--login-teal); }
.portal-redesign .step-line { width: 26px; height: 1px; background: var(--login-line); }
.portal-redesign .stage-header { margin: 0 0 24px; text-align: left; }

.portal-redesign .stage-header h2 {
    color: var(--login-ink);
    font-family: "Noto Serif SC", serif;
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 0;
    margin: 0 0 8px;
}

.portal-redesign .stage-header p { color: var(--login-muted); font-size: 14px; line-height: 1.55; opacity: 1; }
.portal-redesign .auth-tabs { justify-content: flex-start; gap: 22px; margin: 0 0 26px; padding: 0; background: transparent; border: 0; border-radius: 0; }
.portal-redesign .auth-tab { flex: 0 0 auto; position: relative; padding: 0 0 8px; color: var(--login-muted); font-size: 14px; font-weight: 700; border-radius: 0; }
.portal-redesign .auth-tab.active { color: var(--login-ink); background: transparent; box-shadow: none; }
.portal-redesign .auth-tab.active::after { content: ''; position: absolute; right: 0; bottom: 0; left: 0; height: 2px; background: var(--login-teal); }
.portal-redesign .input-group { margin-bottom: 18px; }

.portal-redesign .input-group .field-label {
    position: static;
    display: block;
    margin: 0 0 7px;
    transform: none;
    color: #405057;
    font-size: 13px;
    font-weight: 700;
    pointer-events: auto;
}

.portal-redesign .input-group.input-plain input {
    box-sizing: border-box;
    height: 48px;
    padding: 0 13px;
    color: var(--login-ink);
    background: #fff;
    border: 1px solid #cfd9dd;
    border-radius: 5px;
    font-size: 15px;
}

.portal-redesign .input-group.input-plain input::placeholder { color: #9aa6ac; }
.portal-redesign #userLoginForm .input-group .field-label {
    width: 100%;
    text-align: left;
}
.portal-redesign #userLoginForm .input-group.input-plain input {
    text-align: left;
}
.portal-redesign .input-group.input-plain input:focus { border-color: var(--login-teal); background: #fff; box-shadow: 0 0 0 3px rgba(0, 127, 106, 0.13); }
.portal-redesign .input-group.input-plain input:-webkit-autofill,
.portal-redesign .input-group.input-plain input:-webkit-autofill:hover,
.portal-redesign .input-group.input-plain input:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--login-ink);
    -webkit-box-shadow: 0 0 0 1000px #fff inset;
    box-shadow: 0 0 0 1000px #fff inset;
    transition: background-color 9999s ease-out 0s;
}
.portal-redesign .form-utils { margin: -2px 0 22px; }
.portal-redesign .btn-link-sm { color: var(--login-teal); font-size: 13px; font-weight: 600; opacity: 1; }

.portal-redesign .btn-primary {
    min-height: 48px;
    padding: 0 18px;
    color: #fff;
    background: var(--login-teal);
    border-radius: 5px;
    font-size: 15px;
    font-weight: 800;
    letter-spacing: 0;
}

.portal-redesign #loginSubmitButton {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--login-teal);
    box-shadow: 0 8px 16px rgba(0, 127, 106, 0.16);
}

.portal-redesign .btn-primary:hover { background: var(--login-teal-dark); filter: none; transform: none; }
.portal-redesign #loginSubmitButton:hover { box-shadow: 0 10px 20px rgba(0, 103, 83, 0.2); }
.portal-redesign #loginSubmitButton:active { background: #005d4c; box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.16); }
.portal-redesign .btn-primary:focus-visible, .portal-redesign .auth-tab:focus-visible, .portal-redesign .btn-link:focus-visible, .portal-redesign .btn-link-sm:focus-visible { outline: 3px solid rgba(217, 147, 49, 0.4); outline-offset: 3px; }
.portal-redesign .form-footer { margin-top: 22px; color: var(--login-muted); font-size: 13px; }
.portal-redesign .btn-link { color: var(--login-teal); font-size: 13px; text-decoration: none; }
.portal-redesign .feedback-msg { color: #b34230; font-size: 13px; }

.portal-redesign #userRegisterForm .input-group { margin-bottom: 10px; }
.portal-redesign #userRegisterForm .input-group .field-label { width: 100%; margin-bottom: 5px; font-size: 12px; text-align: left; }
.portal-redesign #userRegisterForm .field-label span { margin-left: 5px; color: #8b979d; font-weight: 500; }
.portal-redesign #userRegisterForm .input-group.input-plain input { height: 44px; }
.portal-redesign #userRegisterForm .btn-primary { margin-top: 8px; }
.portal-redesign #userRegisterForm .form-footer { margin-top: 18px; }

.portal-redesign .portal-card.portal-stage-subjects {
    width: min(520px, 100%) !important;
    max-width: 520px !important;
    min-height: 360px !important;
    height: auto !important;
    padding: 36px !important;
}
.portal-redesign .portal-card.portal-stage-subjects #subjectStage .stage-header { max-width: none; padding: 0; margin: 0 0 24px; }
.portal-redesign .portal-card.portal-stage-subjects #availableSubjectGrid {
    display: block !important;
    width: 100% !important;
}

.portal-redesign .portal-card.portal-stage-subjects .subject-container,
.portal-redesign .portal-card.portal-stage-subjects .subject-grid {
    display: grid !important;
    width: 100% !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 14px !important;
}

.portal-redesign .subject-card, .portal-redesign .subject-card-wide {
    min-height: 104px;
    padding: 14px;
    background: #fff;
    border: 1px solid var(--login-line);
    border-radius: 6px;
    box-shadow: none;
    color: var(--login-ink);
}

.portal-redesign .portal-card.portal-stage-subjects .subject-card,
.portal-redesign .portal-card.portal-stage-subjects .subject-card-wide {
    box-sizing: border-box;
    width: 100% !important;
    min-width: 0 !important;
    min-height: 122px !important;
    height: 122px !important;
    padding: 16px !important;
    justify-content: center;
    grid-column: auto !important;
}

.portal-redesign .portal-card.portal-stage-subjects .subject-card-stage {
    display: flex;
    min-height: 184px !important;
    height: auto !important;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 14px;
}

.portal-redesign .subject-card-heading {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 10px;
}

.portal-redesign .subject-card-stage .card-icon {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    font-size: 18px;
}

.portal-redesign .subject-card-stage .card-title { margin-bottom: 2px; }

.portal-redesign .stage-choice-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
}

.portal-redesign .stage-choice {
    display: flex;
    min-height: 56px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border: 1px solid #cbd9d6;
    border-radius: 5px;
    background: #f7faf9;
    color: var(--login-ink);
    text-decoration: none;
    transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.portal-redesign .stage-choice strong { font-size: 13px; line-height: 1; }
.portal-redesign .stage-choice span { color: var(--login-muted); font-size: 11px; line-height: 1; }
.portal-redesign .stage-choice:hover,
.portal-redesign .stage-choice:focus-visible { border-color: var(--login-teal); background: #eaf6f3; color: var(--login-teal); }
.portal-redesign .stage-choice:focus-visible { outline: 3px solid rgba(217, 147, 49, 0.4); outline-offset: 2px; }

.portal-redesign .portal-wrapper:has(.portal-card.portal-stage-subjects) .view-grid {
    grid-template-columns: minmax(0, 520px) !important;
    justify-content: center;
}

.portal-redesign .portal-wrapper:has(.portal-card.portal-stage-subjects) .branding-panel {
    display: none !important;
}

.portal-redesign .portal-wrapper:has(.portal-card.portal-stage-subjects) .action-panel {
    width: 100% !important;
}

.portal-redesign .subject-card::before, .portal-redesign .subject-card-wide::before { display: none; }
.portal-redesign .subject-card:hover:not(.disabled), .portal-redesign .subject-card-wide:hover:not(.disabled) { background: #f1f8f6; border-color: rgba(0, 127, 106, 0.45); box-shadow: none; transform: none; }
.portal-redesign .card-icon { width: 42px; height: 42px; background: #edf5f3; border: 0; border-radius: 5px; color: var(--login-teal); }
.portal-redesign .card-title { color: var(--login-ink); font-size: 15px; letter-spacing: 0; }
.portal-redesign .card-meta { color: var(--login-muted); font-size: 12px; font-weight: 500; letter-spacing: 0; }
.portal-redesign .card-arrow { opacity: 1; transform: none; background: transparent; color: var(--login-teal); }
.portal-redesign .stage-actions { margin-top: 22px; text-align: left; }
.portal-redesign .app-footer { color: #748188; font-size: 12px; }

@media (max-width: 860px) {
    .portal-redesign .visual-canvas { background: #172121; }
    .portal-redesign .video-overlay { background: rgba(12, 20, 20, 0.2) !important; }
    .portal-redesign .construct-frame { top: 10%; left: -46%; width: 155vw; height: 155vw; }
    .portal-redesign .construct-axis-y { left: 18%; }
    .portal-redesign .construct-line-a { top: 15%; left: -8%; width: 95%; }
    .portal-redesign .construct-line-b { top: 57%; left: 13%; width: 78%; }
    .portal-redesign .construct-line-c { top: 78%; left: 7%; width: 98%; }
    .portal-redesign .construct-point-a { top: 10%; left: 68%; }
    .portal-redesign .construct-point-b { top: 52%; left: 13%; }
    .portal-redesign .construct-point-c { top: 74%; left: 74%; }
    .portal-redesign .portal-wrapper { width: 100%; min-height: 100svh; padding: 0; }
    .portal-redesign .app-header, .portal-redesign .branding-panel, .portal-redesign .app-footer { display: none !important; }
    .portal-redesign .portal-content { min-height: 100svh; padding: 24px 20px; align-items: flex-start; }
    .portal-redesign .view-grid { display: block !important; }
    .portal-redesign .action-panel { width: 100% !important; }
    .portal-redesign .portal-card { width: 100% !important; max-width: 520px !important; min-width: 0 !important; min-height: 0; margin: 0 auto; padding: 28px 24px; }
    .portal-redesign .portal-card.portal-stage-subjects { width: 100% !important; max-width: 520px !important; min-height: 0 !important; padding: 28px 24px !important; }
    .portal-redesign .portal-card.portal-stage-subjects .subject-container, .portal-redesign .portal-card.portal-stage-subjects .subject-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
}

@media (max-width: 480px) {
    .portal-redesign .portal-content { padding: 16px; }
    .portal-redesign .portal-card { padding: 26px 20px; }
    .portal-redesign .portal-card { padding: 24px 20px; }
    .portal-redesign .card-progress { margin-bottom: 26px; }
    .portal-redesign .stage-header h2 { font-size: 25px; }
}

/* Subject selection workspace */
.portal-redesign .portal-wrapper:has(.portal-card.portal-stage-subjects) .view-grid {
    grid-template-columns: minmax(0, 760px) !important;
    justify-content: center !important;
}

.portal-redesign .portal-card.portal-stage-subjects {
    width: min(760px, calc(100vw - 52px)) !important;
    max-width: 760px !important;
    min-height: 0 !important;
    padding: 42px 54px 22px !important;
    border-radius: 8px;
}

.portal-redesign .portal-card.portal-stage-subjects #subjectStage .stage-header {
    margin: 0 0 30px !important;
}

.portal-redesign .portal-card.portal-stage-subjects .stage-header h2 {
    margin-bottom: 7px;
    font-size: 32px;
}

.portal-redesign .portal-card.portal-stage-subjects .stage-header p {
    max-width: 420px;
    font-size: 14px;
}

.portal-redesign .portal-card.portal-stage-subjects .subject-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 18px !important;
}

.portal-redesign .portal-card.portal-stage-subjects .subject-card-stage {
    min-height: 214px !important;
    padding: 22px !important;
    gap: 24px;
    border: 1px solid #d7e1e3;
    border-radius: 8px;
    background: #f9fbfb;
    box-shadow: none;
}

.portal-redesign .portal-card.portal-stage-subjects .subject-card-stage[data-subject-key="physics"] {
    --subject-accent: #007f6a;
    --subject-tint: #eef8f5;
    --subject-line: #b8dcd4;
}

.portal-redesign .portal-card.portal-stage-subjects .subject-card-stage[data-subject-key="math"] {
    --subject-accent: #2d6c9f;
    --subject-tint: #eff5fa;
    --subject-line: #c2d7e7;
}

.portal-redesign .portal-card.portal-stage-subjects .subject-card-stage.card-highlight,
.portal-redesign .portal-card.portal-stage-subjects .subject-card-stage:hover:not(.disabled) {
    border-color: var(--subject-line);
    background: var(--subject-tint);
    box-shadow: none;
    transform: none;
}

.portal-redesign .portal-card.portal-stage-subjects .subject-card-heading {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-align: center;
}

.portal-redesign .portal-card.portal-stage-subjects .subject-card-stage .card-icon {
    width: 48px;
    height: 48px;
    flex-basis: 48px;
    border-radius: 7px;
    background: var(--subject-tint);
    color: var(--subject-accent);
    font-size: 22px;
}

.portal-redesign .portal-card.portal-stage-subjects .subject-card-stage .card-title {
    color: var(--subject-accent);
    font-size: 18px;
    font-weight: 800;
    text-align: center;
}

.portal-redesign .portal-card.portal-stage-subjects .subject-card-stage .card-meta {
    margin-top: 4px;
    color: #71818a;
    font-size: 12px;
    text-align: center;
}

.portal-redesign .portal-card.portal-stage-subjects .stage-choice-row {
    gap: 10px;
}

.portal-redesign .portal-card.portal-stage-subjects .stage-choice {
    min-height: 62px;
    border-color: var(--subject-line);
    border-radius: 6px;
    background: #fff;
    color: #20323b;
}

.portal-redesign .portal-card.portal-stage-subjects .stage-choice strong { font-size: 15px; }
.portal-redesign .portal-card.portal-stage-subjects .stage-choice span { margin-top: 1px; font-size: 11px; }
.portal-redesign .portal-card.portal-stage-subjects .stage-choice:hover,
.portal-redesign .portal-card.portal-stage-subjects .stage-choice:focus-visible {
    border-color: var(--subject-accent);
    background: var(--subject-accent);
    color: #fff;
}
.portal-redesign .portal-card.portal-stage-subjects .stage-choice:hover span,
.portal-redesign .portal-card.portal-stage-subjects .stage-choice:focus-visible span { color: rgba(255, 255, 255, 0.82); }

.portal-redesign .portal-card.portal-stage-subjects .stage-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid #dce5e7;
    text-align: right;
}

.portal-redesign .portal-card.portal-stage-subjects .stage-actions .btn-link {
    font-size: 13px;
    font-weight: 700;
}

@media (max-width: 860px) {
    .portal-redesign .portal-wrapper:has(.portal-card.portal-stage-subjects) .view-grid {
        grid-template-columns: minmax(0, 1fr) !important;
        width: 100% !important;
    }

    .portal-redesign .portal-card.portal-stage-subjects {
        width: calc(100vw - 40px) !important;
        min-width: 0 !important;
        max-width: calc(100vw - 40px) !important;
        padding: 32px 28px 20px !important;
    }
}

@media (max-width: 560px) {
    .portal-redesign .portal-card.portal-stage-subjects {
        padding: 26px 20px 18px !important;
    }

    .portal-redesign .portal-card.portal-stage-subjects .subject-grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    .portal-redesign .portal-card.portal-stage-subjects .subject-card-stage {
        min-height: 0 !important;
        padding: 18px !important;
        gap: 18px;
    }

    .portal-redesign .portal-card.portal-stage-subjects .subject-card-heading {
        flex-direction: row;
        justify-content: center;
    }

    .portal-redesign .portal-card.portal-stage-subjects .subject-card-heading .card-info {
        flex: 0 1 auto;
        align-items: center;
    }

    .portal-redesign .portal-card.portal-stage-subjects .stage-header h2 { font-size: 28px; }
}

/* Password dialogs share the login surface and field system. */
.portal-redesign .portal-modal {
    z-index: 3000;
    padding: 24px;
    overflow-y: auto;
}

.portal-redesign .portal-modal-backdrop {
    background: rgba(12, 27, 27, 0.66);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.portal-redesign .portal-modal-card {
    box-sizing: border-box;
    width: min(100%, 480px);
    max-height: calc(100svh - 48px);
    margin: auto;
    padding: 32px;
    overflow-y: auto;
    scrollbar-width: none;
    border: 1px solid rgba(24, 37, 45, 0.12);
    border-radius: 8px;
    background: #f8fafb;
    box-shadow: 0 22px 56px rgba(5, 20, 20, 0.3);
}

.portal-redesign .portal-modal-card::-webkit-scrollbar { display: none; }

.portal-redesign .portal-modal-header {
    gap: 18px;
    margin-bottom: 26px;
}

.portal-redesign .portal-modal-title {
    color: var(--login-ink);
    font-family: "Noto Serif SC", serif;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: 0;
}

.portal-redesign .portal-modal-subtitle {
    max-width: 360px;
    margin-top: 8px;
    color: var(--login-muted);
    font-size: 14px;
    line-height: 1.6;
}

.portal-redesign .portal-modal-close {
    width: 34px;
    height: 34px;
    border: 1px solid #d7e1e3;
    border-radius: 6px;
    background: #f1f5f5;
    color: #66777f;
    font-size: 20px;
    line-height: 1;
}

.portal-redesign .portal-modal-close:hover { background: #e5efed; color: var(--login-teal); }

.portal-redesign .portal-modal-form .input-group {
    margin-bottom: 16px;
}

.portal-redesign .portal-modal-form .input-group label {
    position: static;
    display: block;
    margin: 0 0 7px;
    transform: none;
    color: #405057;
    font-size: 13px;
    font-weight: 700;
    pointer-events: auto;
}

.portal-redesign .portal-modal-form .input-group input {
    box-sizing: border-box;
    width: 100%;
    height: 46px;
    padding: 0 13px;
    color: var(--login-ink);
    border: 1px solid #cfd9dd;
    border-radius: 5px;
    background: #fff;
    font-size: 15px;
}

.portal-redesign .portal-modal-form .input-group input:focus {
    border-color: var(--login-teal);
    outline: 0;
    box-shadow: 0 0 0 3px rgba(0, 127, 106, 0.13);
}

.portal-redesign .portal-modal-form .feedback-msg {
    margin-top: 2px;
    color: #b34230;
    font-size: 13px;
}

.portal-redesign .portal-modal-actions {
    display: grid;
    width: 100%;
    grid-template-columns: minmax(112px, 0.72fr) minmax(188px, 1.28fr);
    justify-content: stretch;
    gap: 12px;
    margin-top: 24px;
    flex-direction: row !important;
}

.portal-redesign .portal-modal-actions .btn-primary,
.portal-redesign .portal-modal-actions .btn-secondary {
    width: 100%;
    min-height: 46px;
    flex: 0 0 auto;
    padding: 0 22px;
    border-radius: 5px;
    font-size: 14px;
    font-weight: 700;
}

.portal-redesign .portal-modal-actions .btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    border: 1px solid var(--login-teal);
    background: var(--login-teal);
    color: #fff;
    box-shadow: none;
}

.portal-redesign .portal-modal-actions .btn-primary:hover { background: var(--login-teal-dark); }

.portal-redesign .portal-modal-actions .btn-secondary {
    border: 1px solid #cfd9dd;
    background: #fff;
    color: #405057;
}

.portal-redesign .portal-modal-actions .btn-secondary:hover {
    background: #f1f5f5;
    color: var(--login-ink);
    transform: none;
}

@media (max-width: 560px) {
    .portal-redesign .portal-modal { padding: 16px; }
    .portal-redesign .portal-modal-card { max-height: calc(100svh - 32px); padding: 26px 20px 20px; }
    .portal-redesign .portal-modal-title { font-size: 24px; }
    .portal-redesign .portal-modal-actions { grid-template-columns: 1fr 1.25fr; gap: 10px; }
    .portal-redesign .portal-modal-actions .btn-primary,
    .portal-redesign .portal-modal-actions .btn-secondary { width: 100%; padding: 0 12px; }
}

@media (max-width: 360px) {
    .portal-redesign .portal-modal-actions { grid-template-columns: 1fr; }
    .portal-redesign .portal-modal-actions .btn-secondary { grid-row: 2; }
}

/* Responsive layout consolidation for the login and subject-selection flows. */
@media (min-width: 861px) and (max-width: 1100px) {
    .portal-redesign .portal-wrapper {
        width: min(920px, calc(100% - 48px));
    }

    .portal-redesign .view-grid {
        grid-template-columns: minmax(300px, 1fr) minmax(360px, 400px);
        gap: clamp(36px, 6vw, 64px);
    }

    .portal-redesign .branding-panel { min-height: 400px; }
    .portal-redesign .main-title { font-size: 52px !important; }
}

@media (max-width: 860px) {
    .portal-redesign .portal-content {
        display: grid;
        place-items: center;
        padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
    }

    .portal-redesign .portal-card {
        width: min(100%, 480px) !important;
        margin: 0 auto;
    }

    .portal-redesign .portal-card.portal-stage-subjects {
        width: min(100%, 680px) !important;
        max-width: 680px !important;
    }
}

@media (max-width: 600px) {
    .portal-redesign .portal-content {
        display: block;
        padding: 18px 16px max(18px, env(safe-area-inset-bottom));
    }

    .portal-redesign .portal-card {
        padding: 26px 20px 22px;
    }

    .portal-redesign .portal-card.portal-stage-subjects {
        width: 100% !important;
        max-width: none !important;
        padding: 26px 20px 18px !important;
    }

    .portal-redesign .portal-card.portal-stage-subjects #subjectStage .stage-header {
        margin-bottom: 22px !important;
    }

    .portal-redesign .portal-card.portal-stage-subjects .subject-grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    .portal-redesign .portal-card.portal-stage-subjects .subject-card-stage {
        min-height: 0 !important;
        padding: 18px !important;
        gap: 16px;
    }

    .portal-redesign .portal-card.portal-stage-subjects .stage-actions {
        justify-content: center;
        margin-top: 18px;
        padding-top: 16px;
    }
}

@media (max-width: 380px) {
    .portal-redesign .portal-content { padding-inline: 12px; }
    .portal-redesign .portal-card { padding: 22px 16px 20px; }
    .portal-redesign .card-progress { margin-bottom: 22px; }
    .portal-redesign .stage-header { margin-bottom: 20px; }
    .portal-redesign .stage-header h2 { font-size: 24px; }
    .portal-redesign .auth-tabs { margin-bottom: 22px; }
    .portal-redesign .input-group { margin-bottom: 16px; }
    .portal-redesign .input-group.input-plain input { height: 46px; }
    .portal-redesign .portal-card.portal-stage-subjects { padding: 22px 16px 16px !important; }
    .portal-redesign .portal-card.portal-stage-subjects .stage-header h2 { font-size: 25px; }
    .portal-redesign .portal-card.portal-stage-subjects .subject-card-stage { padding: 16px !important; }
    .portal-redesign .portal-card.portal-stage-subjects .stage-choice { min-height: 58px; }
}

@media (min-width: 601px) and (max-width: 900px) {
    .portal-redesign .portal-wrapper:has(.portal-card.portal-stage-subjects) {
        height: auto !important;
        min-height: 100svh !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
    }

    .portal-redesign .portal-wrapper:has(.portal-card.portal-stage-subjects) .portal-content {
        display: grid !important;
        min-height: 100svh !important;
        padding: 28px 20px !important;
        place-items: center;
    }

    .portal-redesign .portal-wrapper:has(.portal-card.portal-stage-subjects) .view-grid,
    .portal-redesign .portal-wrapper:has(.portal-card.portal-stage-subjects) .action-panel,
    .portal-redesign .portal-wrapper:has(.portal-card.portal-stage-subjects) #subjectStage {
        display: block !important;
        height: auto !important;
        min-height: 0 !important;
    }

    .portal-redesign .portal-wrapper:has(.portal-card.portal-stage-subjects) #availableSubjectGrid,
    .portal-redesign .portal-wrapper:has(.portal-card.portal-stage-subjects) #availableSubjectGrid .subject-grid {
        height: auto !important;
        min-height: 0 !important;
        grid-auto-rows: auto !important;
        grid-template-rows: auto !important;
        overflow: visible !important;
    }

    .portal-redesign .portal-wrapper:has(.portal-card.portal-stage-subjects) .portal-card.portal-stage-subjects {
        display: block !important;
        height: auto !important;
        min-height: 0 !important;
        overflow: visible !important;
    }

    .portal-redesign .portal-wrapper:has(.portal-card.portal-stage-subjects) .subject-card-stage {
        height: auto !important;
        min-height: 214px !important;
        overflow: visible !important;
    }
}

/* Center the primary mobile surfaces without sacrificing short-screen scrolling. */
@media (max-width: 600px) and (min-height: 650px) {
    .portal-redesign .portal-wrapper {
        height: 100svh !important;
        min-height: 100svh !important;
        overflow: hidden !important;
    }

    .portal-redesign .portal-content {
        display: grid !important;
        flex: 1 1 auto;
        min-height: 0 !important;
        padding: 18px 16px !important;
        place-items: center;
    }

    .portal-redesign .view-grid,
    .portal-redesign .action-panel {
        width: 100% !important;
    }

    .portal-redesign .view-grid {
        height: auto !important;
        min-height: 0 !important;
    }

    .portal-redesign .portal-modal {
        align-items: center !important;
        justify-content: center !important;
    }
}

@media (max-width: 600px) and (max-height: 649px) {
    .portal-redesign .portal-wrapper {
        height: auto !important;
        min-height: 100svh !important;
        overflow-y: auto !important;
    }

    .portal-redesign .portal-modal {
        align-items: flex-start !important;
        justify-content: center !important;
    }
}

/* Medium-width browser panes and compact tablets: center against the viewport itself. */
@media (min-width: 601px) and (max-width: 860px) and (min-height: 650px) {
    .portal-redesign .portal-wrapper {
        box-sizing: border-box;
        height: 100svh !important;
        min-height: 100svh !important;
        padding: 0 !important;
        overflow: hidden !important;
    }

    .portal-redesign .portal-content {
        box-sizing: border-box;
        min-height: 0 !important;
        padding: 24px 20px !important;
    }
}

@media (max-width: 860px) and (min-height: 650px) {
    .portal-redesign .portal-wrapper {
        width: 100% !important;
        padding: 0 !important;
    }

    .portal-redesign .view-grid {
        display: block !important;
        width: 100% !important;
        max-width: none !important;
    }

    .portal-redesign .action-panel {
        display: flex !important;
        width: 100% !important;
        max-width: none !important;
        justify-content: center !important;
    }

    .portal-redesign .portal-card.portal-stage-subjects .subject-card-heading {
        display: flex !important;
        width: 100%;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 8px;
        text-align: center;
    }

    .portal-redesign .portal-card.portal-stage-subjects .subject-card-heading .card-info {
        display: flex !important;
        width: auto !important;
        flex-direction: column !important;
        align-items: center !important;
        text-align: center !important;
    }

    .portal-redesign .portal-card.portal-stage-subjects .subject-card-stage {
        min-height: 168px !important;
        padding: 16px 18px !important;
        gap: 12px !important;
    }

    .portal-redesign .portal-card.portal-stage-subjects .subject-card-stage .card-icon {
        display: none !important;
    }

    .portal-redesign .portal-card.portal-stage-subjects .subject-card-heading {
        gap: 3px;
    }

    .portal-redesign .portal-card.portal-stage-subjects .stage-choice {
        min-height: 56px;
    }
}

@media (max-width: 860px) and (min-height: 800px) {
    .portal-redesign .portal-wrapper:has(#userRegisterForm:not([hidden])) .portal-content {
        box-sizing: border-box;
        height: 100svh !important;
        min-height: 100svh !important;
        flex: 0 0 100svh !important;
        align-items: center !important;
        align-content: center !important;
        justify-items: center !important;
    }

    .portal-redesign .portal-wrapper:has(#userRegisterForm:not([hidden])) .view-grid,
    .portal-redesign .portal-wrapper:has(#userRegisterForm:not([hidden])) .action-panel {
        height: auto !important;
        min-height: 0 !important;
        align-self: center !important;
    }
}

/* Keep registration in a single viewport; compact heights scale the complete form. */
@media (max-width: 860px) {
    html:has(#userRegisterForm:not([hidden])),
    body.portal-redesign:has(#userRegisterForm:not([hidden])) {
        height: 100svh;
        overflow: hidden;
    }

    .portal-redesign .portal-wrapper:has(#userRegisterForm:not([hidden])) {
        box-sizing: border-box;
        height: 100svh !important;
        min-height: 100svh !important;
        padding: 0 !important;
        overflow: hidden !important;
    }

    .portal-redesign .portal-wrapper:has(#userRegisterForm:not([hidden])) .portal-content {
        box-sizing: border-box;
        display: grid !important;
        height: 100svh !important;
        min-height: 100svh !important;
        flex: 0 0 100svh !important;
        padding: 18px 16px !important;
        place-items: center;
        overflow: hidden !important;
    }

    .portal-redesign .portal-wrapper:has(#userRegisterForm:not([hidden])) .view-grid,
    .portal-redesign .portal-wrapper:has(#userRegisterForm:not([hidden])) .action-panel {
        width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        max-width: none !important;
        align-self: center !important;
        justify-content: center !important;
    }

    .portal-redesign .portal-wrapper:has(#userRegisterForm:not([hidden])) .portal-card {
        --register-scale: 1;
        max-height: none !important;
        transform: scale(var(--register-scale)) !important;
        transform-origin: center center !important;
    }
}

@media (max-width: 860px) and (max-height: 740px) {
    .portal-redesign .portal-wrapper:has(#userRegisterForm:not([hidden])) .portal-card { --register-scale: 0.86; }
}

@media (max-width: 860px) and (max-height: 640px) {
    .portal-redesign .portal-wrapper:has(#userRegisterForm:not([hidden])) .portal-card { --register-scale: 0.76; }
}

@media (max-width: 860px) and (max-height: 540px) {
    .portal-redesign .portal-wrapper:has(#userRegisterForm:not([hidden])) .portal-card { --register-scale: 0.66; }
}
