:root {
    --bg-dark: #0a0a1a;
    --bg-grad: linear-gradient(135deg, #0a0a1a 0%, #111133 100%);
    --surface: rgba(15, 20, 50, 0.7);
    --surface-hover: rgba(25, 35, 75, 0.8);
    --card-bg: rgba(20, 30, 70, 0.4);
    --border: rgba(255, 255, 255, 0.08);
    --border-highlight: rgba(255, 255, 255, 0.15);
    
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-glow: rgba(99, 102, 241, 0.5);
    --secondary: #ec4899;
    
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    
    --font-main: 'Inter', system-ui, -apple-system, sans-serif;
}

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

body, html {
    width: 100%;
    height: 100dvh;
    font-family: var(--font-main);
    background: var(--bg-grad);
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow: hidden;
    position: relative;
}

/* Background Animations */
.bg-animation {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.glow-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.4;
    animation: float 20s infinite ease-in-out alternate;
}

.orb-1 {
    width: 400px; height: 400px;
    background: var(--primary);
    top: -100px; left: -100px;
}

.orb-2 {
    width: 300px; height: 300px;
    background: var(--secondary);
    bottom: -50px; right: -50px;
    animation-delay: -5s;
}

.orb-3 {
    width: 250px; height: 250px;
    background: #3b82f6;
    top: 40%; left: 40%;
    animation-delay: -10s;
}

@keyframes float {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(50px, 50px) scale(1.1); }
}

/* Screens */
.screen {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    display: none;
    opacity: 0;
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.screen.active {
    display: flex;
    flex-direction: column;
    opacity: 1;
    animation: fadeIn 0.4s ease forwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.98); }
    to { opacity: 1; transform: scale(1); }
}

/* Components */
.card {
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transition: border-color 0.3s ease;
}

.card:hover {
    border-color: var(--border-highlight);
}

.btn {
    font-family: var(--font-main);
    font-weight: 500;
    font-size: 15px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 12px 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #818cf8);
    color: white;
    box-shadow: 0 4px 15px var(--primary-glow);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 8px 25px var(--primary-glow);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: var(--surface);
    box-shadow: none;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-main);
}

.btn-outline:hover {
    background: var(--surface);
    border-color: var(--text-main);
}

.btn-text {
    background: transparent;
    color: var(--text-muted);
}
.btn-text:hover {
    color: var(--error);
}

.btn-block { width: 100%; }
.btn-sm { padding: 8px 16px; font-size: 13px; }
.btn-lg { padding: 16px 24px; font-size: 16px; font-weight: 600; }
.mt-3 { margin-top: 16px; }

/* Login Screen */
#screen-login {
    justify-content: center;
    align-items: center;
}

.login-card {
    width: 100%;
    max-width: 400px;
}

.logo-container {
    text-align: center;
    margin-bottom: 30px;
}

.logo-icon {
    width: 60px; height: 60px;
    margin: 0 auto 15px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 16px;
    box-shadow: 0 0 20px var(--primary-glow);
    position: relative;
    overflow: hidden;
}
.logo-icon::after {
    content: '';
    position: absolute;
    top: 25%; left: 25%; width: 50%; height: 50%;
    border: 3px solid white;
    border-radius: 50%;
    box-sizing: border-box;
}
.logo-icon::before {
    content: '';
    position: absolute;
    top: 40%; left: 40%; width: 20%; height: 20%;
    background: white;
    border-radius: 50%;
}

.logo-text {
    font-size: 24px;
    font-weight: 700;
    background: linear-gradient(to right, #fff, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 20px rgba(255,255,255,0.1);
}

.input-group {
    margin-bottom: 20px;
}
.input-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    color: var(--text-muted);
}
.input-group input {
    width: 100%;
    padding: 14px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: white;
    font-family: inherit;
    font-size: 16px;
    outline: none;
    transition: all 0.2s;
}
.input-group input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.error-msg {
    color: var(--error);
    font-size: 13px;
    margin-bottom: 15px;
    text-align: center;
    min-height: 20px;
}

/* Dashboard Screen */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 40px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(10px);
}
.logo-container-small {
    display: flex;
    align-items: center;
    gap: 12px;
}
.logo-icon-small {
    width: 32px; height: 32px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 8px;
    position: relative;
}
.logo-icon-small::after {
    content: ''; position: absolute; top: 25%; left: 25%; width: 50%; height: 50%;
    border: 2px solid white; border-radius: 50%;
}
.logo-icon-small::before {
    content: ''; position: absolute; top: 40%; left: 40%; width: 20%; height: 20%;
    background: white; border-radius: 50%;
}
.logo-container-small h2 { font-size: 18px; font-weight: 600; }

.dashboard-content {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.view-panel {
    display: none;
    width: 100%;
    max-width: 500px;
}
.view-panel.active { display: block; animation: fadeIn 0.4s ease; }

.view-panel h3 { font-size: 22px; margin-bottom: 10px; text-align: center; }
.subtitle { color: var(--text-muted); text-align: center; margin-bottom: 30px; }

.server-info {
    background: rgba(0,0,0,0.2);
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 25px;
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    border: 1px solid var(--border);
}
.server-info .label { color: var(--text-muted); }
.server-info .value { color: var(--primary); font-family: monospace; font-size: 14px;}

.pairing-code-container {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 30px;
}
.digit-input {
    width: calc(100% / 6 - 8px);
    aspect-ratio: 1;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    border-radius: 12px;
    text-align: center;
    font-size: 28px;
    font-family: monospace;
    font-weight: 700;
    color: white;
    outline: none;
    transition: all 0.2s;
}
.digit-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 15px var(--primary-glow);
    transform: scale(1.05);
}

.device-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 30px;
}
.device-icon {
    font-size: 48px;
    background: var(--surface);
    width: 80px; height: 80px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 20px;
    border: 1px solid var(--border);
}
.device-info h3 { text-align: left; margin-bottom: 5px; }
.status-text { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-muted); }

/* Controller Screen */
.controller-header {
    height: 40px;
    background: #000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 15px;
    border-bottom: 1px solid #222;
}
.ctrl-left, .ctrl-center, .ctrl-right {
    display: flex;
    align-items: center;
    gap: 15px;
}
.ctrl-center { flex: 1; justify-content: center; }

.status-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    display: inline-block;
}
.status-dot.online { background: var(--success); box-shadow: 0 0 10px var(--success); animation: pulse 2s infinite; }
.status-dot.offline { background: var(--error); box-shadow: 0 0 10px var(--error); }
.status-dot.connecting { background: var(--warning); box-shadow: 0 0 10px var(--warning); animation: pulse 1s infinite; }

@keyframes pulse {
    0% { transform: scale(0.95); opacity: 0.8; }
    50% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(0.95); opacity: 0.8; }
}

#ctrl-device-name { font-size: 13px; font-weight: 500; }

.icon-btn {
    background: transparent; border: none; color: var(--text-main);
    font-size: 16px; cursor: pointer; padding: 4px; border-radius: 4px;
    transition: 0.2s;
}
.icon-btn:hover { background: rgba(255,255,255,0.1); }

.pill-badge {
    background: #222; border-radius: 12px; padding: 2px 8px;
    font-size: 11px; font-weight: 600; color: #aaa;
    border: 1px solid #333;
}

.controller-toolbar {
    height: 44px;
    background: #0f0f0f;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    border-bottom: 1px solid #222;
    padding: 0 10px;
}
.tool-btn {
    width: 36px; height: 36px;
    background: transparent; border: none; color: #ddd;
    border-radius: 6px; font-size: 18px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}
.tool-btn:hover {
    background: rgba(255,255,255,0.1);
    color: white;
    transform: translateY(-1px);
    border-bottom: 2px solid var(--primary);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}
.separator { width: 1px; height: 20px; background: #333; margin: 0 5px; }

.viewer-container {
    flex: 1;
    position: relative;
    background: #000;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

#screen-canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    /* Aspect ratio will be maintained by the rendering context/canvas size */
    box-shadow: 0 0 20px rgba(0,0,0,0.8);
}

.viewer-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    z-index: 10;
}
.viewer-overlay.hidden { display: none; }

.spinner {
    width: 40px; height: 40px;
    border: 4px solid rgba(255,255,255,0.1);
    border-left-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}
@keyframes spin { 100% { transform: rotate(360deg); } }

.controller-footer {
    height: 24px;
    background: #0a0a0a;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 15px;
    font-size: 11px;
    color: #666;
    border-top: 1px solid #222;
}
.footer-stats, .footer-hints { display: flex; align-items: center; gap: 10px; }
.divider { color: #333; }

/* Toasts */
#toast-container {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}
.toast {
    background: var(--surface);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    padding: 12px 24px;
    border-radius: 30px;
    color: white;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    animation: slideUp 0.3s ease forwards;
    display: flex;
    align-items: center;
    gap: 10px;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--error); }
.toast.fade-out { opacity: 0; transform: translateY(20px); transition: all 0.3s ease; }

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

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #000; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #555; }

/* Responsive */
@media (max-width: 768px) {
    .app-header { padding: 15px 20px; }
    .card { padding: 25px; }
    .digit-input { font-size: 22px; }
    .controller-toolbar { gap: 2px; }
    .tool-btn { width: 32px; height: 32px; font-size: 16px; }
    .footer-hints { display: none; }
}
/* Notification Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    width: 90%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.modal-content h3 {
    margin: 0;
    color: var(--text-primary);
}

.modal-content textarea {
    width: 100%;
    background-color: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 0.75rem;
    color: var(--text-primary);
    font-family: inherit;
    resize: vertical;
}

.modal-content textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}
