:root {
    --primary: #8b5cf6; /* Modern Violet */
    --primary-hover: #7c3aed;
    --primary-rgb: 139, 92, 246;
    
    --bg-page: #030304; /* Pitch black background */
    --bg-card: linear-gradient(135deg, rgba(255, 255, 255, 0.14) 0%, rgba(255, 255, 255, 0.03) 100%); /* Liquid Glass Light */
    --border-glass: rgba(255, 255, 255, 0.22);
    --border-active: rgba(139, 92, 246, 0.7);
    
    --text-primary: #e4e4e7;
    --text-muted: #a1a1aa;
    --text-active: #ffffff;
    
    --input-bg: rgba(255, 255, 255, 0.08);
    --input-border: rgba(255, 255, 255, 0.15);
    
    --transition-smooth: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    --shadow-card: 0 50px 120px rgba(0, 0, 0, 0.7), inset 0 1.5px 2px rgba(255, 255, 255, 0.35), inset 0 -1px 1px rgba(255, 255, 255, 0.1);
}

:root.dark-theme {
    --bg-page: #020203;
    --bg-card: linear-gradient(135deg, rgba(255, 255, 255, 0.09) 0%, rgba(255, 255, 255, 0.02) 100%); /* Liquid Glass Dark */
    --border-glass: rgba(255, 255, 255, 0.14);
    --border-active: rgba(139, 92, 246, 0.5);
    
    --text-primary: #d4d4d8;
    --text-muted: #71717a;
    --text-active: #ffffff;
    
    --input-bg: rgba(255, 255, 255, 0.05);
    --input-border: rgba(255, 255, 255, 0.1);
    
    --shadow-card: 0 60px 140px rgba(0, 0, 0, 0.9), inset 0 1.5px 2px rgba(255, 255, 255, 0.22), inset 0 -1px 1px rgba(255, 255, 255, 0.05);
}

/* ==========================================
   Reset & Base Styles
   ========================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-page);
    color: var(--text-primary);
    margin: 0;
    padding: 0;
}

/* ==========================================
   Centered login container wrapper
   ========================================== */
.login-container {
    position: relative;
    z-index: 10;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ==========================================
   Layout Wrapper & Card
   ========================================== */
.login-wrapper {
    width: 100%;
    max-width: 520px; /* Widened to 520px */
    padding: 20px;
    z-index: 10;
    animation: fadeInScale 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.login-card {
    width: 100%;
    aspect-ratio: 1 / 1; /* Make the form card perfectly square */
    position: relative;
    overflow: hidden;
    background-color: var(--bg-card);
    border: 1px solid var(--border-glass);
    border-radius: 24px;
    box-shadow: var(--shadow-card);
    transition: var(--transition-smooth);
    backdrop-filter: blur(48px) saturate(2.2); /* Liquid Glass effect */
    -webkit-backdrop-filter: blur(48px) saturate(2.2);
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.login-card:hover {
    border-color: rgba(255, 255, 255, 0.35);
    box-shadow: 0 60px 140px rgba(0, 0, 0, 0.9), inset 0 1.5px 2px rgba(255, 255, 255, 0.4);
    transform: translateY(-2px);
}

body.dark-theme .login-card:hover {
    border-color: rgba(255, 255, 255, 0.15);
}

/* ==========================================
   Video Background (Contained Inside Card)
   ========================================== */
.card-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 1;
    pointer-events: none;
    opacity: 0.15; /* Subtly overlays video inside card to match iOS style */
    filter: brightness(0.95) contrast(1.05);
}

.card-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Dark/Light gradient over video depending on the theme */
    background: radial-gradient(
        circle at center,
        rgba(255, 255, 255, 0.05) 0%,
        rgba(255, 255, 255, 0.15) 80%,
        rgba(255, 255, 255, 0.25) 100%
    );
    z-index: 2;
}

body.dark-theme .card-overlay {
    background: linear-gradient(
        135deg,
        rgba(15, 23, 42, 0.2) 0%,
        rgba(9, 9, 11, 0.4) 100%
    );
}

/* ==========================================
   Music Toggle Button (Upper Right corner of the Card)
   ========================================== */
.music-toggle {
    position: absolute;
    top: 18px;
    right: 20px;
    z-index: 10;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-glass);
    border-radius: 20px;
    padding: 6px 12px;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-smooth);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    user-select: none;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.music-toggle:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.25);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.music-toggle.active {
    background: rgba(139, 92, 246, 0.25);
    border-color: var(--primary);
    color: var(--text-active);
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.25);
}

/* ==========================================
   Theme Toggle Button (Upper Left corner of the Card)
   ========================================== */
.theme-toggle {
    position: absolute;
    top: 18px;
    left: 20px;
    z-index: 10;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-glass);
    border-radius: 20px;
    padding: 6px 12px;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-smooth);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    user-select: none;
    letter-spacing: 0.5px;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.25);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.theme-toggle.active {
    background: rgba(139, 92, 246, 0.25);
    border-color: var(--primary);
    color: var(--text-active);
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.25);
}

/* ==========================================
   Card Content (Positioned Above Video)
   ========================================== */
.card-content {
    position: relative;
    z-index: 3;
    padding: 40px 45px; /* Increased internal padding for larger square layout */
}

/* ==========================================
   Card Header
   ========================================== */
.card-header {
    text-align: center;
    margin-bottom: 22px; /* Balanced spacing */
}

.card-header h1 {
    font-size: 26px;
    font-weight: 600;
    color: var(--text-active);
    margin-bottom: 6px;
    letter-spacing: -0.5px;
}

.card-header p {
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 400;
}

/* ==========================================
   Form Styling (Inputs & Labels)
   ========================================== */
.login-form {
    display: flex;
    flex-direction: column;
    gap: 18px; /* Balanced gap for square form elements */
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-group label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

.label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.forgot-link {
    font-size: 12px;
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition-smooth);
}

.forgot-link:hover {
    color: #a78bfa;
    text-decoration: underline;
}

.input-group input {
    width: 100%;
    padding: 14px 16px; /* Restored comfortable padding */
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 10px;
    color: var(--text-active);
    font-size: 14px;
    outline: none;
    transition: var(--transition-smooth);
}

.input-group input::placeholder {
    color: rgba(161, 161, 170, 0.4);
}

.input-group input:focus {
    border-color: var(--border-active);
    background: rgba(255, 255, 255, 0.15); /* Keep it translucent for liquid glass look */
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.2);
}

body.dark-theme .input-group input:focus {
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.3);
}

/* Prevent browser autocomplete overrides from turning inputs solid white/yellow */
.input-group input:-webkit-autofill,
.input-group input:-webkit-autofill:hover, 
.input-group input:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--text-active) !important;
    -webkit-box-shadow: 0 0 0px 1000px rgba(15, 23, 42, 0.95) inset !important;
    box-shadow: 0 0 0px 1000px rgba(15, 23, 42, 0.95) inset !important;
    transition: background-color 5000s ease-in-out 0s;
}

/* Password input specific wrapper for toggle button */
.password-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.password-wrapper input {
    width: 100%;
    padding-left: 65px; /* Give space for Show/Hide text on the left */
    padding-right: 16px;
}

.toggle-password {
    position: absolute;
    left: 16px; /* Position on the left for RTL */
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: var(--transition-smooth);
    user-select: none;
}

.toggle-password:hover {
    color: var(--text-active);
}

/* ==========================================
   Custom Checkbox (Remember Me)
   ========================================== */
.checkbox-group {
    margin-top: 2px;
}

.custom-checkbox {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    font-size: 13px;
    user-select: none;
    color: var(--text-muted);
    transition: var(--transition-smooth);
}

.custom-checkbox:hover {
    color: var(--text-primary);
}

.custom-checkbox input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.checkmark {
    height: 18px;
    width: 18px;
    background-color: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 4px;
    margin-left: 10px; /* Space between checkmark and text in RTL */
    margin-right: 0;
    position: relative;
    transition: var(--transition-smooth);
}

.custom-checkbox:hover input ~ .checkmark {
    border-color: var(--border-active);
}

.custom-checkbox input:checked ~ .checkmark {
    background-color: var(--primary);
    border-color: transparent;
}

.checkmark::after {
    content: "";
    position: absolute;
    display: none;
}

.custom-checkbox input:checked ~ .checkmark::after {
    display: block;
}

.custom-checkbox .checkmark::after {
    left: 6px;
    top: 2px;
    width: 4px;
    height: 8px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* ==========================================
   Submit Button
   ========================================== */
.submit-btn {
    width: 100%;
    padding: 14px;
    background-color: var(--primary);
    border: none;
    border-radius: 10px;
    color: #ffffff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-smooth);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.submit-btn:hover {
    background-color: var(--primary-hover);
    box-shadow: 0 6px 16px rgba(139, 92, 246, 0.3);
}

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

/* Loader Styles */
.btn-loader {
    display: flex;
    justify-content: center;
    align-items: center;
}

.spinner {
    animation: rotate 2s linear infinite;
    width: 20px;
    height: 20px;
}

.spinner .path {
    stroke: #ffffff;
    stroke-linecap: round;
    animation: dash 1.5s ease-in-out infinite;
}

/* ==========================================
   Card Footer
   ========================================== */
.card-footer {
    text-align: center;
    font-size: 13.5px;
    color: var(--text-muted);
    margin-top: 25px;
}

.signup-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    transition: var(--transition-smooth);
    margin-left: 2px;
}

.signup-link:hover {
    color: #a78bfa;
    text-decoration: underline;
}

/* ==========================================
   Toast Notification
   ========================================== */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: rgba(24, 24, 27, 0.95);
    border: 1px solid var(--border-glass);
    border-radius: 8px;
    padding: 14px 20px;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    opacity: 0;
    z-index: 100;
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.4s ease;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast-success {
    border-left: 4px solid #10b981;
}

.toast-error {
    border-left: 4px solid #ef4444;
}

/* Auth Screens */
.auth-screen.hidden {
    display: none !important;
}

/* ==========================================
   Animations
   ========================================== */
@keyframes fadeInScale {
    0% {
        opacity: 0;
        transform: scale(0.97);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes rotate {
    100% {
        transform: rotate(360deg);
    }
}

@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;
    }
}

/* ==========================================
   Responsive Styles
   ========================================== */
@media (max-width: 480px) {
    .card-content {
        padding: 35px 25px;
    }
    .card-header h1 {
        font-size: 22px;
    }
}
