:root {
    --bg-gradient: linear-gradient(135deg, #e8f0f8 0%, #d4e4f7 25%, #e0e7f1 50%, #f0e8f5 75%, #e8f0f8 100%);
    --bg-overlay-light: rgba(173, 216, 230, 0.18);
    --bg-overlay-light-2: rgba(224, 231, 255, 0.12);
    --bg-overlay-dark: rgba(200, 220, 240, 0.12);
    --card-bg: #ffffff;
    --card-shadow: 0 2px 6px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
    --text-primary: #000000;
    --text-secondary: #5E5E5E;
    --text-tertiary: #8a8886;
    --input-border: #d2d0ce;
    --input-bg: #ffffff;
    --input-focus-border: #0067b8;
    --error-color: #e81123;
    --success-color: #7fba00;
    --success-veil: rgba(127, 186, 0, 0.1);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-gradient: linear-gradient(135deg, #1a1a1a 0%, #252525 25%, #1f1f1f 50%, #2a2520 75%, #1a1a1a 100%);
        --bg-overlay-light: rgba(100, 140, 180, 0.2);
        --bg-overlay-light-2: rgba(80, 100, 140, 0.15);
        --bg-overlay-dark: rgba(60, 80, 120, 0.1);
        --card-bg: #2d2d2d;
        --card-shadow: 0 2px 6px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.1);
        --text-primary: #e0e0e0;
        --text-secondary: #b0b0b0;
        --text-tertiary: #909090;
        --input-border: #404040;
        --input-bg: #1f1f1f;
        --input-focus-border: #4a9eff;
        --error-color: #ff6b6b;
        --success-color: #8fd450;
        --success-veil: rgba(143, 212, 80, 0.15);
    }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px 20px 80px;
    position: relative;
    overflow: hidden;
    color: var(--text-primary);
    background-color: var(--card-bg);
}

.background-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-gradient);
    z-index: -1;
}

.background-container::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -20%;
    width: 80%;
    height: 150%;
    background: linear-gradient(165deg, var(--bg-overlay-light) 0%, var(--bg-overlay-light-2) 50%, transparent 100%);
    transform: rotate(-15deg);
    pointer-events: none;
}

.background-container::after {
    content: '';
    position: absolute;
    bottom: -30%;
    left: -10%;
    width: 60%;
    height: 100%;
    background: linear-gradient(45deg, var(--bg-overlay-dark) 0%, transparent 70%);
    transform: rotate(10deg);
    pointer-events: none;
}

.container {
    width: 100%;
    max-width: 460px;
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.login-card {
    background: var(--card-bg);
    box-shadow: var(--card-shadow);
    padding: 40px 36px 28px;
    min-height: 520px;
    display: flex;
    flex-direction: column;
    position: relative;
    border-radius: 8px;
}

.logo-container {
    margin-bottom: 28px;
    text-align: center;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo {
    display: inline-block;
}

.back-button {
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    border-radius: 4px;
    transition: background-color 0.2s ease;
    position: absolute;
    left: 0;
}

.content-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.view {
    position: absolute;
    width: 100%;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
}

.view.active {
    position: relative;
    opacity: 1;
    transform: translateX(0);
    pointer-events: all;
}

.view.slide-out-left {
    animation: slideOutLeft 0.3s ease forwards;
}

.view.slide-in-right {
    animation: slideInRight 0.3s ease forwards;
}

.view.slide-out-right {
    animation: slideOutRight 0.3s ease forwards;
}

.view.slide-in-left {
    animation: slideInLeft 0.3s ease forwards;
}

@keyframes slideOutLeft {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(-30px);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideOutRight {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(30px);
    }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.title {
    font-size: 22px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
    text-align: center;
}

.subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    text-align: center;
    font-weight: 400;
}

.user-identity {
    margin-bottom: 16px;
    text-align: center;
}

.user-tile {
    background-color: transparent;
    border: 1px solid var(--text-tertiary);
    border-radius: 18px;
    padding: 6px 14px;
    display: inline-block;
    text-align: center;
}

.user-email {
    font-size: 15px;
    color: var(--text-primary);
    font-weight: 400;
    text-align: center;
}

.input-group {
    margin-bottom: 16px;
    position: relative;
}

.password-group {
    margin-bottom: 8px;
}

.input-label {
    position: absolute;
    left: 2px;
    top: -8px;
    background: var(--card-bg);
    padding: 0 4px;
    font-size: 13px;
    color: var(--text-tertiary);
    font-weight: 400;
    z-index: 1;
    pointer-events: none;
}

.password-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.toggle-password {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease;
    border-radius: 4px;
}

.toggle-password:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.alternative-signin {
    text-align: center;
    margin-top: 0;
    font-size: 15px;
}

.input-field {
    width: 100%;
    padding: 10px 12px;
    font-size: 15px;
    border: 1px solid var(--input-border);
    border-radius: 4px;
    outline: none;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    transition: border-color 0.2s ease;
    background-color: var(--input-bg);
    color: var(--text-primary);
}

.password-group .input-field {
    padding: 10px 40px 10px 12px;
}

.input-field:hover {
    border-color: var(--input-focus-border);
}

.input-field:focus {
    border-color: var(--input-focus-border);
    border-width: 2px;
    padding: 9px 11px;
}

.password-group .input-field:focus {
    padding: 9px 39px 9px 11px;
}

.input-field::placeholder {
    color: var(--text-tertiary);
}

.error-message {
    color: var(--error-color);
    font-size: 12px;
    margin-top: 8px;
    min-height: 16px;
    animation: shake 0.3s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.links-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.link {
    color: var(--input-focus-border);
    text-decoration: none;
    font-size: 13px;
    transition: color 0.2s ease;
}

.link:hover {
    color: var(--input-focus-border);
    text-decoration: underline;
    opacity: 0.8;
}

.button-container {
    margin-top: auto;
    margin-bottom: 16px;
}

.btn-primary {
    background-color: var(--input-focus-border);
    color: #ffffff;
    border: none;
    border-radius: 4px;
    padding: 11px 32px;
    font-size: 15px;
    font-weight: 400;
    cursor: pointer;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    transition: background-color 0.2s ease;
    min-width: 108px;
    width: 100%;
}

.btn-primary:hover {
    opacity: 0.9;
}

.btn-primary:active {
    opacity: 0.8;
}

.btn-primary:focus {
    outline: 1px solid var(--text-primary);
    outline-offset: 2px;
}

.create-account {
    text-align: center;
    font-size: 15px;
    color: var(--text-secondary);
}

.create-text {
    margin-right: 4px;
}

.page-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 16px 20px;
    text-align: center;
    background: transparent;
    z-index: 10;
}

.footer-links {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 8px;
}

.footer-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 11px;
    transition: color 0.2s ease;
}

.footer-link:hover {
    color: var(--text-primary);
    text-decoration: underline;
}

.footer-note {
    font-size: 11px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.link-inline {
    color: var(--input-focus-border);
    text-decoration: none;
    font-size: 11px;
}

.link-inline:hover {
    text-decoration: underline;
}

.success-animation {
    display: flex;
    justify-content: center;
    margin-bottom: 24px;
}

.checkmark {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    stroke-width: 2;
    stroke: var(--success-color);
    stroke-miterlimit: 10;
    margin: 20px auto;
    animation: fill 0.4s ease-in-out 0.4s forwards, scale 0.3s ease-in-out 0.9s both;
    background-color: var(--success-veil);
}

.checkmark-circle {
    stroke-dasharray: 166;
    stroke-dashoffset: 166;
    stroke-width: 2;
    stroke-miterlimit: 10;
    stroke: var(--success-color);
    animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

.checkmark-check {
    transform-origin: 50% 50%;
    stroke-dasharray: 48;
    stroke-dashoffset: 48;
    stroke: var(--success-color);
    stroke-width: 3;
    animation: stroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.8s forwards;
}

@keyframes stroke {
    100% {
        stroke-dashoffset: 0;
    }
}

@keyframes scale {
    0%, 100% {
        transform: none;
    }
    50% {
        transform: scale3d(1.1, 1.1, 1);
    }
}

@keyframes fill {
    100% {
        box-shadow: inset 0 0 0 30px var(--success-color);
    }
}

.success-message {
    text-align: center;
    color: var(--text-secondary);
    font-size: 15px;
    margin-top: 16px;
}

/* Face verification layout */
.camera-container {
    position: relative;
    width: 100%;
    max-width: 340px;
    margin: 6px auto 16px;
    background: radial-gradient(ellipse at center, rgba(255,255,255,0.06) 0%, rgba(0,0,0,0.9) 55%, #000 100%);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 16px;
    overflow: hidden;
    /* Maintain a pleasant portrait ratio inside the card */
    aspect-ratio: 4 / 5;
    box-shadow: 0 6px 20px rgba(0,0,0,0.22);
}

.camera-video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* Mirror front camera for a natural UX */
    transform: scaleX(-1);
    background: #000;
    display: block;
}

/* Soft face oval guide */
.camera-container::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 68%;
    height: 76%;
    border-radius: 50% / 56%;
    box-shadow: 0 0 0 1.5px rgba(255,255,255,0.28), inset 0 0 70px rgba(0,0,0,0.4);
    pointer-events: none;
}

.face-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    margin-top: 14px;
}

.btn-danger {
    background-color: var(--error-color);
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 11px 32px;
    font-size: 15px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    transition: background-color 0.2s ease, opacity 0.2s ease;
    min-width: 108px;
}

.btn-danger:hover {
    opacity: 0.9;
}

.btn-danger:active {
    opacity: 0.8;
}

.btn-danger:focus {
    outline: 1px solid var(--text-primary);
    outline-offset: 2px;
}

@media (max-width: 480px) {
    body {
        background: var(--card-bg);
    }

    .background-container {
        display: none;
    }

    .login-card {
        padding: 20px 18px;
        box-shadow: none;
    }

    .title {
        font-size: 20px;
    }

    .input-field {
        font-size: 16px;
    }

    .footer-links {
        justify-content: center;
    }

    .camera-container {
        max-width: 100%;
        aspect-ratio: 4 / 5;
        border-radius: 12px;
    }

    .face-buttons .btn-primary,
    .face-buttons .btn-danger {
        flex: 1 1 calc(50% - 10px);
        min-width: 120px;
    }
}

/* Fine-tune spacing specifically for facial view */
#faceView .title {
    margin-bottom: 4px;
}

#faceView .subtitle {
    margin-bottom: 14px;
}

#faceView .input-group .error-message {
    text-align: center;
    min-height: 18px;
}

#faceView .button-container {
    margin-bottom: 10px;
}

@media (max-width: 360px) {
    .login-card {
        padding: 16px;
    }

    .btn-primary {
        width: 100%;
    }
}

.btn-primary.loading {
    position: relative;
    color: transparent;
    pointer-events: none;
}

.btn-primary.loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid #ffffff;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spinner 0.6s linear infinite;
}

@keyframes spinner {
    to {
        transform: rotate(360deg);
    }
}

.biometric-spinner {
    animation: spinner 2s linear infinite;
    width: 50px;
    height: 50px;
    margin: 0 auto;
    display: block;
}

.biometric-spinner-circle {
    stroke: var(--input-focus-border);
    stroke-width: 4;
    stroke-linecap: round;
    animation: dash 1.5s ease-in-out infinite;
}

@keyframes dash {
    0% { stroke-dasharray: 1, 150; stroke-dashoffset: 0; }
    50% { stroke-dasharray: 90, 150; stroke-dashoffset: -35; }
    100% { stroke-dasharray: 90, 150; stroke-dashoffset: -124; }
}

@media (prefers-color-scheme: dark) {
    .toggle-password:hover {
        background-color: rgba(255, 255, 255, 0.1);
    }

    .create-account {
        color: var(--text-secondary);
    }

    .create-text {
        color: var(--text-secondary);
    }

    .create-link {
        color: var(--input-focus-border);
    }
}
