:root {
    /* Modern Palette (Dark Mode) */
    --bg-color: #000000;
    --accent-color: #3b82f6;
    /* Modern Blue */
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);

    /* Glassmorphism Tokens */
    --glass-bg: rgba(20, 20, 20, 0.6);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-blur: blur(20px);
    --window-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.1);

    /* Layout */
    --dock-radius: 16px;
    --window-radius: 12px;
    --taskbar-height: 60px;

    /* Animations */
    --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
}

* {
    box-sizing: border-box;
    user-select: none;
    -webkit-font-smoothing: antialiased;
}

/* removed volume popover styles */

/* Theme Classes */
body.light-theme {
    --bg-color: #f0f0f0;
    --text-primary: #000000;
    --text-secondary: rgba(0, 0, 0, 0.7);
    --glass-bg: rgba(255, 255, 255, 0.6);
    --glass-border: rgba(0, 0, 0, 0.1);
    --window-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}

body.light-theme .window {
    background-color: rgba(240, 240, 245, 0.85);
}

body.light-theme .title-bar span {
    color: black;
}

body.light-theme #start-menu {
    background: rgba(240, 240, 245, 0.95);
    color: black;
}

body.light-theme .user-name {
    color: black;
}

body.light-theme .user-status {
    color: rgba(0, 0, 0, 0.6);
}

body.light-theme .start-item:hover {
    background: rgba(0, 0, 0, 0.05);
}

/* Speedtest UI */
.speedtest-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: center;
    padding: 10px;
}

.speed-gauges {
    display: flex;
    gap: 30px;
    justify-content: center;
    width: 100%;
}

.speed-metric {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.metric-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent-color);
    font-variant-numeric: tabular-nums;
}

.metric-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.metric-unit {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.ping-display {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: -10px;
}

.test-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    width: 100%;
}

.test-progress-bar {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent-color);
    width: 0%;
    transition: width 0.2s linear;
}

.start-test-btn {
    padding: 12px 32px;
    border-radius: 24px;
    background: var(--accent-color);
    color: white;
    font-weight: 600;
    font-size: 1rem;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4);
    transition: transform 0.1s, box-shadow 0.2s;
}

.start-test-btn:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5);
}

.start-test-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.start-test-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

body.light-theme .metric-value {
    color: #2563eb;
    /* Darker blue for light mode */
}

body.light-theme .test-progress-bar {
    background: rgba(0, 0, 0, 0.1);
}

/* Volume Window Styles */
.volume-window-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 20px;
    padding: 20px;
}

.volume-number {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.volume-slider-large {
    width: 100%;
    -webkit-appearance: none;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    outline: none;
}

body.light-theme .volume-slider-large {
    background: rgba(0, 0, 0, 0.1);
}

.volume-slider-large::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: var(--accent-color);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
    transition: transform 0.1s;
}

.volume-slider-large::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    /* 1) Global Modern Typography */
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--text-primary);
    background-color: var(--bg-color);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Typography Overrides */
button,
input,
textarea,
.window,
.taskbar-item,
.start-menu {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* 3) Interaction Cleanups (Tray Icons) */
.tray-icon {
    font-size: 1rem;
    opacity: 0.8;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    transition: opacity 0.2s, transform 0.1s;
}

.tray-icon:hover {
    opacity: 1;
    transform: scale(1.1);
}

.tray-icon:active {
    transform: scale(0.95);
}

/* 2) Volume Popover (Minimalist) */
#volume-popover {
    position: fixed;
    bottom: calc(var(--taskbar-height) + 20px);
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    width: 160px;
    height: 50px;
    background: rgba(30, 30, 35, 0.9);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 25px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    z-index: 10000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

#volume-popover.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}

/* Mobile responsive tweak if needed, though desktop focused */
@media (max-width: 768px) {
    #volume-popover {
        right: 20px;
        transform: none;
        bottom: 90px;
    }

    #volume-popover.visible {
        transform: translateY(0);
    }
}

.popover-slider {
    width: 100%;
    height: 4px;
    -webkit-appearance: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    outline: none;
}

.popover-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
    transition: transform 0.1s;
}

.popover-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

body.light-theme #volume-popover {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(0, 0, 0, 0.1);
}

body.light-theme .popover-slider {
    background: rgba(0, 0, 0, 0.1);
}

body.light-theme .popover-slider::-webkit-slider-thumb {
    background: var(--accent-color);
}

/* Desktop Container */
#desktop {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    /* Deep dark gradient fallback */
    background: radial-gradient(circle at center, #1a1a2e 0%, #000000 100%);
}

/* Background & Branding */
#background {
    position: fixed;
    /* Fixed to viewport prevents mobile scroll issues */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;

    /* Reliable Background Image */
    background-image: url('assets/wallpaper.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    /* iOS/Safari fix for viewport height vs bar */
    height: 100svh;
}

/* Remove old img tag styling */
#bg-image {
    display: none;
}

#brand-logo {
    position: relative;
    font-size: 8rem;
    font-weight: 800;
    color: rgba(255, 255, 255, 0.03);
    text-shadow: 0 0 100px rgba(255, 255, 255, 0.05);
    font-family: 'Inter', sans-serif;
    letter-spacing: -0.05em;
    z-index: 1;
}

/* Icons Container */
#icons-container {
    position: absolute;
    top: 30px;
    left: 30px;
    width: auto;
    height: calc(100% - var(--taskbar-height) - 40px);
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.desktop-icon {
    width: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s var(--ease-out-expo);
}

.desktop-icon:hover {
    transform: scale(1.05);
}

.desktop-icon:active {
    transform: scale(0.95);
}

.icon-img {
    width: 64px;
    height: 64px;
    margin-bottom: 8px;
    border-radius: 16px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    object-fit: contain;
    transition: box-shadow 0.2s;
}

.desktop-icon:hover .icon-img {
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
}

.icon-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: white;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
    background: transparent;
    padding: 2px 6px;
    border-radius: 6px;
    transition: background 0.2s;
}

.desktop-icon:hover .icon-label {
    background-color: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(4px);
}

/* Windows Area */
#windows-area {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 20;
    pointer-events: none;
}

.window {
    position: absolute;
    background-color: rgba(30, 30, 35, 0.85);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: var(--window-radius);
    box-shadow: var(--window-shadow);
    display: flex;
    flex-direction: column;
    pointer-events: auto;
    min-width: 360px;
    min-height: 240px;
    overflow: hidden;

    /* Animation */
    opacity: 0;
    transform: scale(0.95);
    transition:
        opacity 0.2s ease-out,
        transform 0.2s var(--ease-out-expo),
        box-shadow 0.2s ease;
}

.window.visible {
    opacity: 1;
    transform: scale(1);
}

.window.active {
    box-shadow: 0 40px 80px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.2);
}

.title-bar {
    height: 48px;
    background: transparent;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
    cursor: grab;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.title-bar span {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    opacity: 0.9;
}

.title-bar:active {
    cursor: grabbing;
}

.window-controls {
    display: flex;
    gap: 8px;
}

.control-btn {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    position: relative;
    padding: 0;
    color: transparent;
    transition: transform 0.1s, opacity 0.2s;
}

.control-btn:hover {
    transform: scale(1.1);
    opacity: 0.9;
}

.control-btn.close {
    background-color: #ff5f56;
}

.control-btn.minimize {
    background-color: #ffbd2e;
}

.control-btn.maximize {
    background-color: #27c93f;
}

.window-content {
    flex-grow: 1;
    padding: 20px;
    overflow: auto;
    color: var(--text-secondary);
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    line-height: 1.6;
}

.window-content h3 {
    margin-top: 0;
    font-weight: 600;
    color: var(--text-primary);
}

/* Taskbar / Dock */
#taskbar {
    position: fixed;
    /* Stable positioning */
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    height: var(--taskbar-height);

    /* Modern Glassmorphism (Safari + Chrome) */
    background: rgba(30, 30, 35, 0.6);
    /* Slightly more transparent */
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);

    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.1);

    border-radius: var(--dock-radius);
    z-index: 1000;
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 12px;

    /* Mobile/SafeArea Support */
    margin-bottom: env(safe-area-inset-bottom, 0px);
}

#start-btn {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
}

#start-btn:hover,
#start-btn.active {
    background: rgba(255, 255, 255, 0.2);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.1);
}

#start-btn:active {
    transform: scale(0.95);
}

/* Separator */
.taskbar-separator {
    width: 1px;
    height: 24px;
    background: rgba(255, 255, 255, 0.15);
    margin: 0 4px;
}

#taskbar-apps {
    display: flex;
    gap: 8px;
}

.taskbar-item {
    padding: 8px 16px;
    height: 44px;
    border-radius: 10px;
    background: transparent;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.taskbar-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.taskbar-item.active {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
}

/* Active indicator dot */
.taskbar-item.active::after {
    content: '';
    position: absolute;
    bottom: -6px;
    /* below the item */
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    background: var(--accent-color);
    border-radius: 50%;
    box-shadow: 0 0 5px var(--accent-color);
}

#system-tray {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: 8px;
    padding-left: 12px;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
}

.tray-icon {
    font-size: 1rem;
    opacity: 0.8;
}

#clock {
    font-weight: 500;
    font-size: 0.9rem;
    color: white;
    opacity: 0.9;
    letter-spacing: 0.5px;
}

/* Start Menu */
#start-menu {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    width: 340px;
    background: rgba(30, 30, 35, 0.95);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: 18px;
    padding: 0;
    z-index: 999;
    box-shadow: 0 40px 80px rgba(0, 0, 0, 0.6);
    opacity: 0;
    pointer-events: none;
    transition: all 0.25s var(--ease-out-expo);
    display: flex !important;
    flex-direction: column;
    overflow: hidden;
}

#start-menu.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

#start-menu.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateX(-50%) translateY(20px);
}

.start-header {
    background: rgba(255, 255, 255, 0.05);
    /* Slight separation */
    padding: 24px;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 16px;
}

.user-avatar {
    width: 56px;
    height: 56px;
    /* Profile Placeholder Asset */
    background-image: url('assets/profile-placeholder.png');
    background-size: cover;
    background-position: center;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-size: 1.2rem;
    font-weight: 700;
    color: white;
}

.user-status {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.6);
}

.start-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    width: 100%;
}

.start-content {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.start-item {
    padding: 12px 16px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--text-primary);
    transition: background 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    gap: 12px;
}

.start-item:active {
    transform: scale(0.98);
}

.start-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Restart Overlay */
#restart-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #000;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

#restart-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.restart-text {
    font-size: 1.2rem;
    color: white;
    font-weight: 500;
}

/* removed volume popover styles */

/* Theme Classes */
body.light-theme {
    --bg-color: #f0f0f0;
    --text-primary: #000000;
    --text-secondary: rgba(0, 0, 0, 0.7);
    --glass-bg: rgba(255, 255, 255, 0.6);
    --glass-border: rgba(0, 0, 0, 0.1);
    --window-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}

body.light-theme .window {
    background-color: rgba(240, 240, 245, 0.85);
}

body.light-theme .title-bar span {
    color: black;
}

body.light-theme #start-menu {
    background: rgba(240, 240, 245, 0.95);
    color: black;
}

body.light-theme .user-name {
    color: black;
}

body.light-theme .user-status {
    color: rgba(0, 0, 0, 0.6);
}

body.light-theme .start-item:hover {
    background: rgba(0, 0, 0, 0.05);
}

/* Speedtest UI */
.speedtest-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: center;
    padding: 10px;
}

.speed-gauges {
    display: flex;
    gap: 30px;
    justify-content: center;
    width: 100%;
}

.speed-metric {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.metric-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent-color);
    font-variant-numeric: tabular-nums;
}

.metric-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.metric-unit {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.ping-display {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: -10px;
}

.test-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    width: 100%;
}

.test-progress-bar {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent-color);
    width: 0%;
    transition: width 0.2s linear;
}

.start-test-btn {
    padding: 12px 32px;
    border-radius: 24px;
    background: var(--accent-color);
    color: white;
    font-weight: 600;
    font-size: 1rem;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4);
    transition: transform 0.1s, box-shadow 0.2s;
}

.start-test-btn:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5);
}

.start-test-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.start-test-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

body.light-theme .metric-value {
    color: #2563eb;
    /* Darker blue for light mode */
}

body.light-theme .test-progress-bar {
    background: rgba(0, 0, 0, 0.1);
}

/* Volume Window Styles */
.volume-window-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 20px;
    padding: 20px;
}

.volume-number {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.volume-slider-large {
    width: 100%;
    -webkit-appearance: none;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    outline: none;
}

body.light-theme .volume-slider-large {
    background: rgba(0, 0, 0, 0.1);
}

.volume-slider-large::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: var(--accent-color);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
    transition: transform 0.1s;
}

.volume-slider-large::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}