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

html {
    overflow-y: auto;
    overflow-x: hidden;
}

:root {
    /* American Flag Colors */
    --flag-red: #B22234;
    --flag-blue: #002868;
    --flag-white: #FFFFFF;
    --primary-color: #B22234;
    --primary-dark: #8B1A2A;
    --primary-light: #D32F2F;
    --secondary-color: #002868;
    --secondary-dark: #001A4A;
    --secondary-light: #003A8F;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --border-color: #e5e7eb;
    --error-color: #B22234;
    --success-color: #10b981;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, var(--flag-blue) 0%, var(--flag-red) 50%, var(--flag-blue) 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
}

.background-animation {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

.shape {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    animation: float 20s infinite ease-in-out;
}

.shape-1 {
    width: 300px;
    height: 300px;
    top: -100px;
    left: -100px;
    animation-delay: 0s;
}

.shape-2 {
    width: 200px;
    height: 200px;
    bottom: -50px;
    right: -50px;
    animation-delay: 5s;
}

.shape-3 {
    width: 150px;
    height: 150px;
    top: 50%;
    right: 10%;
    animation-delay: 10s;
}

@keyframes float {
    0%, 100% {
        transform: translate(0, 0) rotate(0deg);
    }
    33% {
        transform: translate(30px, -30px) rotate(120deg);
    }
    66% {
        transform: translate(-20px, 20px) rotate(240deg);
    }
}

.login-container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 440px;
}

.login-box {
    background: var(--bg-primary);
    border-radius: 24px;
    padding: 48px 40px;
    box-shadow: 0 20px 40px rgba(0, 40, 104, 0.2), 0 10px 20px rgba(178, 34, 52, 0.15);
    backdrop-filter: blur(10px);
    animation: slideUp 0.5s ease-out;
    border: 2px solid rgba(255, 255, 255, 0.2);
    position: relative;
    z-index: 2;
    overflow: hidden;
}

.login-box::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--flag-red) 0%, var(--flag-white) 50%, var(--flag-blue) 100%);
    z-index: 1;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
}

.logo img {
    max-width: 140px;
    height: auto;
    object-fit: contain;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.1));
}

.login-header h1 {
    font-size: 28px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--flag-red) 0%, var(--flag-blue) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.login-header p {
    font-size: 16px;
    color: var(--text-secondary);
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

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

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

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    left: 16px;
    color: var(--text-secondary);
    pointer-events: none;
    z-index: 1;
}

.form-group input {
    width: 100%;
    padding: 14px 16px 14px 48px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-size: 16px;
    transition: all 0.2s ease;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.form-group input:focus {
    outline: none;
    border-color: var(--flag-blue);
    background: var(--bg-primary);
    box-shadow: 0 0 0 3px rgba(0, 40, 104, 0.1);
}

.form-group input::placeholder {
    color: var(--text-secondary);
}

.toggle-password {
    position: absolute;
    right: 16px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease;
}

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

.form-options {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    color: var(--text-secondary);
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--flag-blue);
}

.forgot-password {
    color: var(--flag-blue);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

.forgot-password:hover {
    color: var(--flag-red);
    text-decoration: underline;
}

.btn-primary {
    width: 100%;
    padding: 14px 24px;
    background: linear-gradient(135deg, var(--flag-red) 0%, var(--flag-blue) 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-md);
    position: relative;
    overflow: hidden;
}

.btn-primary::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.btn-primary:hover::before {
    left: 100%;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(178, 34, 52, 0.3), 0 4px 8px rgba(0, 40, 104, 0.2);
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--secondary-light) 100%);
}

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

.btn-primary:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.btn-loader {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.spinner {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.signup-link {
    text-align: center;
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 8px;
}

.signup-link a {
    color: var(--flag-blue);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s ease;
}

.signup-link a:hover {
    color: var(--flag-red);
    text-decoration: underline;
}

.error-message {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--error-color);
    color: var(--error-color);
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    margin-top: 16px;
    text-align: center;
}

.success-message {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid var(--success-color);
    color: var(--success-color);
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    margin-top: 16px;
    text-align: center;
}

/* Forgot password modal (login page) */
.forgot-password-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
}

.forgot-password-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(4px);
}

.forgot-password-modal__panel {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 400px;
    background: var(--bg-primary);
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border-color);
}

.forgot-password-modal__title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 8px 0;
}

.forgot-password-modal__hint {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 0;
}

.forgot-password-modal__actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
    flex-wrap: wrap;
}

.forgot-password-modal__cancel {
    padding: 10px 16px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.forgot-password-modal__cancel:hover {
    background: var(--border-color);
}

.forgot-password-modal__submit {
    min-height: 42px;
    padding: 10px 18px;
    font-size: 14px;
}

.forgot-password-modal__submit .btn-loader {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* —— Auth pages (login / signup / reset): compact, viewport-safe layout —— */
html.auth-page {
    overflow-x: hidden;
    height: 100%;
}

html.auth-page body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #eceff3;
    background-image: linear-gradient(165deg, #e4e9f0 0%, #f2f4f7 42%, #eef1f5 100%);
    box-sizing: border-box;
    min-height: 100dvh;
    min-height: 100svh;
    padding:
        max(8px, env(safe-area-inset-top, 0px))
        max(10px, env(safe-area-inset-right, 0px))
        max(8px, env(safe-area-inset-bottom, 0px))
        max(10px, env(safe-area-inset-left, 0px));
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
}

html.auth-page .login-container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: min(400px, 100%);
    margin-inline: auto;
    flex: 0 1 auto;
    max-height: none;
}

/* When the viewport is tall enough, center the card vertically */
@media (min-height: 640px) {
    html.auth-page body {
        justify-content: center;
    }
}

html.auth-page .background-animation {
    z-index: 0;
}

html.auth-page .shape {
    background: rgba(0, 40, 104, 0.055);
    animation-duration: 32s;
    filter: blur(0.5px);
}

@media (prefers-reduced-motion: reduce) {
    html.auth-page .shape {
        animation: none;
    }
}

html.auth-page .login-box {
    border-radius: 16px;
    padding: clamp(1.75rem, 5vw, 2.5rem) clamp(1.25rem, 4vw, 1.75rem);
    border: 1px solid rgba(0, 0, 0, 0.06);
    background: #ffffff;
    box-shadow:
        0 1px 2px rgba(0, 0, 0, 0.04),
        0 16px 48px rgba(0, 40, 104, 0.1);
    backdrop-filter: none;
    overflow: visible;
    max-width: 100%;
}

html.auth-page .login-box::before {
    height: 3px;
    border-radius: 16px 16px 0 0;
    background: var(--flag-blue);
    opacity: 1;
}

html.auth-page .login-header {
    margin-bottom: clamp(1rem, 3vw, 1.35rem);
    text-align: center;
}

html.auth-page .logo {
    margin-bottom: clamp(1rem, 3vw, 1.25rem);
}

html.auth-page .logo img {
    max-width: min(120px, 44vw);
    filter: none;
}

html.auth-page .login-header h1 {
    font-size: clamp(1.35rem, 4.5vw, 1.625rem);
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.2;
    color: var(--text-primary);
    background: none;
    -webkit-text-fill-color: currentColor;
    background-clip: unset;
    -webkit-background-clip: unset;
    margin-bottom: 0.35rem;
}

html.auth-page .login-header p {
    font-size: 0.9375rem;
    line-height: 1.45;
    color: var(--text-secondary);
    font-weight: 500;
    max-width: 26rem;
    margin-left: auto;
    margin-right: auto;
}

html.auth-page .login-form {
    gap: clamp(0.65rem, 2.2vw, 0.95rem);
}

html.auth-page .login-form .form-group {
    gap: 5px;
}

html.auth-page .form-group label {
    font-size: 0.8125rem;
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0.01em;
}

html.auth-page .form-group input {
    min-height: 44px;
    padding: 9px 14px 9px 42px;
    border-width: 1px;
    border-color: #e2e8f0;
    border-radius: 10px;
    font-size: 16px;
    background: #fafbfc;
    transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

html.auth-page .form-group input:hover {
    border-color: #cbd5e1;
    background: #fff;
}

html.auth-page .form-group input:focus {
    border-color: var(--flag-blue);
    background: #fff;
    box-shadow: 0 0 0 4px rgba(0, 40, 104, 0.1);
}

/* Reset password & fields without leading icons — avoid extra left padding */
html.auth-page .form-group .input-wrapper:not(:has(.input-icon)) input {
    padding-left: 16px;
}

html.auth-page .input-wrapper:has(.toggle-password) input {
    padding-right: 44px;
}

html.auth-page .input-icon {
    left: 14px;
    width: 20px;
    height: 20px;
}

html.auth-page .form-options {
    flex-wrap: wrap;
    gap: 6px 12px;
    align-items: center;
    font-size: 0.8125rem;
    margin-top: -0.1rem;
}

html.auth-page .checkbox-label {
    min-width: 0;
}

html.auth-page .forgot-password {
    font-weight: 600;
    margin-left: auto;
}

html.auth-page .btn-primary {
    min-height: 48px;
    padding: 12px 20px;
    border-radius: 10px;
    background: var(--flag-blue);
    border: none;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
    font-weight: 600;
    letter-spacing: 0.01em;
}

html.auth-page .btn-primary::before {
    display: none;
}

html.auth-page .btn-primary:hover {
    background: var(--secondary-light);
    transform: none;
    box-shadow: 0 4px 16px rgba(0, 40, 104, 0.24);
}

html.auth-page .btn-primary:active {
    transform: scale(0.99);
}

html.auth-page .signup-link {
    text-align: center;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
    line-height: 1.45;
}

html.auth-page .signup-link a {
    color: var(--flag-blue);
    font-weight: 600;
    text-decoration: none;
}

html.auth-page .signup-link a:hover {
    color: var(--flag-red);
    text-decoration: underline;
}

html.auth-page .error-message,
html.auth-page .success-message {
    border-radius: 10px;
    text-align: left;
    font-size: 0.8125rem;
    line-height: 1.4;
    padding: 10px 12px;
    margin-top: 0.25rem;
}

html.auth-page .forgot-password-modal {
    padding: clamp(12px, 3vw, 20px);
}

html.auth-page .forgot-password-modal__panel {
    border-radius: 18px;
    padding: clamp(1.35rem, 4vw, 1.65rem);
    max-width: min(380px, 100%);
    border: 1px solid rgba(255, 255, 255, 0.9);
    box-shadow:
        0 24px 48px -12px rgba(15, 23, 42, 0.2),
        0 0 0 1px rgba(0, 40, 104, 0.06);
    background: linear-gradient(180deg, #fff 0%, #fafbfc 100%);
}

html.auth-page .forgot-password-modal__title {
    letter-spacing: -0.02em;
}

html.auth-page .forgot-password-modal__actions {
    justify-content: stretch;
    gap: 10px;
}

html.auth-page .forgot-password-modal__cancel,
html.auth-page .forgot-password-modal__submit {
    flex: 1 1 auto;
    min-width: 0;
}

/* Short viewports (landscape phones, small windows): stay within the screen */
@media (max-height: 640px) {
    html.auth-page body {
        justify-content: flex-start;
    }

    html.auth-page .logo img {
        max-height: 44px;
        max-width: min(96px, 36vw);
    }

    html.auth-page .login-header h1 {
        font-size: clamp(1.1rem, 4vw, 1.35rem);
    }

    html.auth-page .login-form {
        gap: 0.55rem;
    }
}

@media (max-height: 520px) {
    html.auth-page .logo {
        margin-bottom: 0.5rem;
    }

    html.auth-page .logo img {
        max-height: 36px;
    }

    html.auth-page .login-header p {
        font-size: 0.6875rem;
        line-height: 1.25;
    }

    html.auth-page .signup-link {
        padding-top: 0.25rem;
    }
}

@media (max-width: 380px) {
    html.auth-page .form-options {
        flex-direction: column;
        align-items: stretch;
    }

    html.auth-page .forgot-password {
        margin-left: 0;
        text-align: right;
    }
}

/* Error page styles */
.error-container {
    text-align: center;
    color: white;
    max-width: 600px;
    margin: 0 auto;
}

.error-code {
    font-size: 120px;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 24px;
    text-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.error-title {
    font-size: 32px;
    font-weight: 600;
    margin-bottom: 16px;
}

.error-message {
    font-size: 18px;
    margin-bottom: 32px;
    opacity: 0.9;
}

.error-btn {
    display: inline-block;
    padding: 14px 32px;
    background: white;
    color: var(--primary-color);
    text-decoration: none;
    border-radius: 12px;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-lg);
}

.error-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-xl);
}

/* Maintenance page styles */
.maintenance-container {
    text-align: center;
    color: white;
    max-width: 600px;
    margin: 0 auto;
}

.maintenance-icon {
    font-size: 80px;
    margin-bottom: 32px;
}

.maintenance-title {
    font-size: 36px;
    font-weight: 700;
    margin-bottom: 16px;
}

.maintenance-message {
    font-size: 18px;
    margin-bottom: 24px;
    opacity: 0.9;
    line-height: 1.6;
}

.maintenance-details {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 24px;
    margin-top: 32px;
    text-align: left;
}

.maintenance-details h3 {
    font-size: 20px;
    margin-bottom: 12px;
}

.maintenance-details p {
    font-size: 14px;
    opacity: 0.8;
    line-height: 1.6;
}

/* Responsive design */
@media (max-width: 640px) {
    .login-box {
        padding: 32px 24px;
    }

    html.auth-page .login-box {
        padding: clamp(1.5rem, 5vw, 2rem) clamp(1rem, 4vw, 1.35rem);
    }
    
    .login-header h1 {
        font-size: 24px;
    }
    
    .error-code {
        font-size: 80px;
    }
    
    .error-title {
        font-size: 24px;
    }

    .subscription-success-modal {
        padding: 28px 22px 24px;
    }

    .subscription-success-modal__title {
        font-size: 1.35rem;
    }
}

/* Subscription checkout success (Premium / Platinum) — used by js/subscription.js */
.subscription-success-overlay {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(6px);
    animation: subscriptionOverlayIn 0.2s ease-out;
}

@keyframes subscriptionOverlayIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.subscription-success-modal {
    width: 100%;
    max-width: 420px;
    background: var(--bg-primary);
    border-radius: 16px;
    padding: 32px 28px 28px;
    text-align: center;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(0, 0, 0, 0.06);
    animation: subscriptionModalIn 0.28s ease-out;
}

@keyframes subscriptionModalIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.subscription-success-modal__icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 20px;
    border-radius: 50%;
    background: linear-gradient(145deg, #10b981 0%, #059669 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(16, 185, 129, 0.35);
}

.subscription-success-modal__title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 8px;
    letter-spacing: -0.02em;
    line-height: 1.25;
}

.subscription-success-modal__plan {
    font-size: 0.8125rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--flag-blue);
    margin: 0 0 16px;
}

.subscription-success-modal__text {
    font-size: 0.9375rem;
    line-height: 1.55;
    color: var(--text-secondary);
    margin: 0 0 24px;
    text-align: center;
}

.subscription-success-modal__btn {
    width: 100%;
    min-height: 48px;
    padding: 12px 20px;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    background: var(--flag-blue);
    color: #fff;
    transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
    box-shadow: 0 2px 8px rgba(0, 40, 104, 0.25);
}

.subscription-success-modal__btn:hover {
    background: var(--secondary-light);
    box-shadow: 0 4px 16px rgba(0, 40, 104, 0.3);
}

.subscription-success-modal__btn:active {
    transform: scale(0.99);
}

.subscription-success-modal__btn--secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    box-shadow: none;
    margin-top: 10px;
}

.subscription-success-modal__btn--secondary:hover {
    background: var(--border-color);
    box-shadow: none;
}

/* Referral link on signup (?ref=) */
.affiliate-ref-notice {
    font-size: 0.875rem;
    color: var(--secondary-color);
    background: rgba(0, 40, 104, 0.06);
    border: 1px solid rgba(0, 40, 104, 0.15);
    border-radius: 8px;
    padding: 0.5rem 0.65rem;
    margin-top: 0.35rem;
    line-height: 1.4;
}

/* Referral signup notice */
.affiliate-ref-notice{font-size:0.875rem;color:var(--secondary-color);background:rgba(0,40,104,.06);border:1px solid rgba(0,40,104,.15);border-radius:8px;padding:.5rem .65rem;margin-top:.35rem;line-height:1.4;}
