:root {
    --bg-deep: #04060f;
    --bg-dark: #070812;
    --bg-gradient-start: #0a1428;
    --bg-gradient-mid: #0d1030;
    --bg-gradient-end: #030408;
    --surface: rgba(10, 18, 38, 0.82);
    --surface-elevated: rgba(16, 28, 55, 0.88);
    --surface-light: rgba(22, 36, 68, 0.55);
    --border: rgba(120, 160, 220, 0.12);
    --border-hover: rgba(140, 190, 255, 0.32);
    --text-primary: #eef2ff;
    --text-secondary: #94a3c4;
    --text-muted: #5c6b88;
    --accent: #5eb8ff;
    --accent-hover: #7ec8ff;
    --accent-glow: rgba(94, 184, 255, 0.28);
    --accent-purple: #8b7cf7;
    --accent-gold: #d4af6a;
    --accent-gold-glow: rgba(212, 175, 106, 0.25);
    --success: #4ade80;
    --warning: #fbbf24;
    --danger: #f87171;
    --info: #60a5fa;
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 18px;
    --radius-xl: 24px;
    --shadow-sm: 0 4px 16px rgba(0, 0, 0, 0.25);
    --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
    --shadow-glow: 0 0 40px rgba(94, 184, 255, 0.12);
    --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-ar: 'Segoe UI', Tahoma, 'Noto Sans Arabic', system-ui, sans-serif;
    --transition-fast: 0.15s ease;
    --transition: 0.25s ease;
    --transition-slow: 0.45s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
    font-family: var(--font);
    background: var(--bg-deep);
    background-image: linear-gradient(160deg, var(--bg-gradient-start) 0%, var(--bg-gradient-mid) 42%, var(--bg-gradient-end) 100%);
    background-attachment: fixed;
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    overflow-x: hidden;
}

html[dir="rtl"] body { font-family: var(--font-ar); }

.page-container {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.glass-card {
    background: var(--surface);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.75rem;
    box-shadow: var(--shadow);
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    filter: drop-shadow(0 0 12px var(--accent-glow));
}

.user-icon {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-purple));
    flex-shrink: 0;
    opacity: 0.85;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.brand-icon { font-size: 2rem; }

h1, h2, h3 { font-weight: 700; line-height: 1.3; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.125rem; color: var(--text-secondary); margin-bottom: 1rem; }

.subtitle { color: var(--text-secondary); margin-bottom: 1.5rem; }

/* Forms */
.form-group { margin-bottom: 1.25rem; }
.form-group label { display: block; margin-bottom: 0.4rem; font-size: 0.875rem; color: var(--text-secondary); font-weight: 500; }
.form-group.inline { display: flex; align-items: center; gap: 0.75rem; }
.form-group.inline label { margin-bottom: 0; white-space: nowrap; }
.form-group.checkbox label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

input[type="text"], input[type="password"], input[type="number"], input[type="search"], input[type="email"], select, textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 1rem;
    transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

select { cursor: pointer; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23a0b0d0'%3E%3Cpath d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 1rem center; padding-right: 2.5rem; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary { background: linear-gradient(135deg, var(--accent), #2563eb); color: #fff; box-shadow: 0 4px 15px var(--accent-glow); }
.btn-primary:hover:not(:disabled) { background: linear-gradient(135deg, var(--accent-hover), #3b82f6); transform: translateY(-1px); }
.btn-secondary { background: var(--surface-light); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--border-hover); background: rgba(40, 60, 100, 0.5); }
.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid transparent; }
.btn-ghost:hover { color: var(--text-primary); background: rgba(255,255,255,0.05); }
.btn-warning { background: var(--warning); color: #1a1a1a; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-lg { padding: 1rem 2rem; font-size: 1.0625rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-group { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* Language selector */
.lang-selector select {
    width: auto;
    min-width: 120px;
    padding: 0.5rem 2rem 0.5rem 0.75rem;
    font-size: 0.875rem;
    background-color: rgba(0,0,0,0.3);
}

/* Alerts */
.alert { padding: 0.875rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.9375rem; }
.alert-error { background: rgba(248, 113, 113, 0.15); border: 1px solid rgba(248, 113, 113, 0.3); color: #fca5a5; }
.alert-success { background: rgba(52, 211, 153, 0.15); border: 1px solid rgba(52, 211, 153, 0.3); color: #6ee7b7; }
.alert-info { background: rgba(77, 166, 255, 0.15); border: 1px solid rgba(77, 166, 255, 0.3); color: #93c5fd; }
.hidden { display: none !important; }

/* Connection status */
.connection-status {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1000;
}
.status-dot {
    display: block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 8px rgba(74, 222, 128, 0.55);
    transition: background var(--transition), box-shadow var(--transition);
    animation: statusDotPulse 2.4s ease-in-out infinite;
}
.connection-status.online .status-dot,
.connection-status:not(.offline) .status-dot {
    background: var(--success);
    box-shadow: 0 0 8px rgba(74, 222, 128, 0.55), 0 0 18px rgba(74, 222, 128, 0.28);
    animation: statusDotPulse 2.4s ease-in-out infinite;
}
.connection-status.offline .status-dot {
    background: #9ca3af;
    box-shadow: 0 0 6px rgba(248, 113, 113, 0.45);
    animation: none;
}
@keyframes statusDotPulse {
    0%, 100% { box-shadow: 0 0 6px rgba(74, 222, 128, 0.4), 0 0 14px rgba(74, 222, 128, 0.18); }
    50% { box-shadow: 0 0 10px rgba(74, 222, 128, 0.7), 0 0 22px rgba(74, 222, 128, 0.35); }
}
@media (prefers-reduced-motion: reduce) {
    .status-dot,
    .connection-status.online .status-dot,
    .connection-status:not(.offline) .status-dot {
        animation: none;
    }
}

/* Music notes container */
.music-notes-container {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

@keyframes floatNote {
    0% { opacity: 0; transform: translateY(0) rotate(0deg); }
    8% { opacity: var(--note-opacity, 0.28); }
    92% { opacity: var(--note-opacity, 0.28); }
    100% { opacity: 0; transform: translateY(-105vh) rotate(360deg); }
}

.music-note {
    position: absolute;
    bottom: -5%;
    opacity: 0;
    pointer-events: none;
    user-select: none;
    animation: floatNote linear infinite;
    will-change: transform, opacity;
}
.music-note::before {
    content: '';
    display: block;
    width: var(--note-w, 14px);
    height: var(--note-h, 18px);
    border: 2px solid var(--accent);
    border-radius: 0 0 8px 8px;
    opacity: 0.35;
    transform: rotate(-12deg);
}
.music-note::after {
    content: '';
    position: absolute;
    top: -6px;
    right: -2px;
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    opacity: 0.4;
}

/* Toast */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: min(360px, calc(100vw - 2rem));
    pointer-events: none;
}
html[dir="rtl"] .toast-container { right: auto; left: 1rem; }
.toast {
    padding: 0.75rem 1rem;
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    animation: toastIn 0.35s var(--transition-slow);
    pointer-events: auto;
    font-size: 0.875rem;
}
.toast-success { border-color: rgba(74, 222, 128, 0.35); }
.toast-error { border-color: rgba(248, 113, 113, 0.35); }
.toast-info { border-color: rgba(96, 165, 250, 0.35); }
.toast-warning { border-color: rgba(251, 191, 36, 0.35); }
@keyframes toastIn {
    from { transform: translateY(-8px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Modal */
.modal { position: fixed; inset: 0; z-index: 5000; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); }
.modal-content { position: relative; z-index: 1; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 1.5rem; }

/* Language dropdown */
.lang-dropdown { position: relative; display: inline-block; }
.lang-dropdown-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.45rem 0.65rem;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.8125rem;
    font-family: inherit;
    cursor: pointer;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.lang-dropdown-toggle:hover,
.lang-dropdown-toggle:focus-visible {
    border-color: var(--border-hover);
    box-shadow: 0 0 0 1px rgba(94, 184, 255, 0.15);
    outline: none;
}
.lang-flag { width: 20px; height: 14px; object-fit: cover; border-radius: 2px; flex-shrink: 0; }
.lang-chevron {
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid var(--text-muted);
    margin-inline-start: 0.15rem;
}
.lang-dropdown-menu {
    position: absolute;
    top: calc(100% + 4px);
    inset-inline-end: 0;
    min-width: 168px;
    list-style: none;
    margin: 0;
    padding: 0.35rem;
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    z-index: 5000;
}
html[dir="rtl"] .lang-dropdown-menu { inset-inline-end: 0; inset-inline-start: auto; }
.lang-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 0.65rem;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.8125rem;
    font-family: inherit;
    cursor: pointer;
    text-align: start;
}
.lang-option:hover, .lang-option:focus-visible { background: rgba(94, 184, 255, 0.1); outline: none; }
.lang-option-selected { background: rgba(94, 184, 255, 0.12); }
.lang-check {
    margin-inline-start: auto;
    width: 14px;
    height: 14px;
    background: var(--accent);
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z'/%3E%3C/svg%3E") center/contain no-repeat;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z'/%3E%3C/svg%3E") center/contain no-repeat;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid rgba(94, 184, 255, 0.25);
    flex-shrink: 0;
}

/* Setup */
.setup-card { max-width: 480px; width: 100%; text-align: center; }
.setup-desc { color: var(--text-secondary); margin-bottom: 2rem; }
.setup-links { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; }

@media (max-width: 640px) {
    .form-row { grid-template-columns: 1fr; }
    h1 { font-size: 1.5rem; }
    .glass-card { padding: 1.5rem; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}


/* ===== Mobile resilience ===== */
html,
body {
    width: 100%;
    max-width: 100%;
}

img,
video {
    max-width: 100%;
}

button,
a,
input,
select,
textarea {
    -webkit-tap-highlight-color: transparent;
}

@media (max-width: 640px) {
    html { -webkit-text-size-adjust: 100%; }
    body {
        min-height: 100dvh;
        background-attachment: scroll;
        overflow-x: clip;
    }
    .page-container {
        width: 100%;
        max-width: 100%;
        min-height: 100dvh;
        padding: max(0.75rem, env(safe-area-inset-top, 0px))
                 max(0.75rem, env(safe-area-inset-right, 0px))
                 max(0.75rem, env(safe-area-inset-bottom, 0px))
                 max(0.75rem, env(safe-area-inset-left, 0px));
    }
    .glass-card {
        max-width: 100%;
    }
    .btn,
    button,
    [role="button"] {
        touch-action: manipulation;
    }
    .btn { min-height: 44px; }
    .btn-group {
        width: 100%;
        min-width: 0;
    }
    .btn-group .btn {
        flex: 1 1 140px;
        min-width: 0;
    }
    .form-group.inline {
        flex-wrap: wrap;
        align-items: stretch;
    }
    .form-group.inline > * {
        min-width: 0;
    }
    .lang-dropdown-menu {
        max-width: calc(100vw - 1.5rem);
    }
}
