:root {
    --os-bg: #0f172a;
    --win-bg: #1e293b;
    --win-border-light: #475569;
    --win-border-dark: #020617;
    --win-title-bg: #0e7490;
    --win-title-active: #06b6d4;
    --highlight: #22d3ee;
    --menu-bg: #334155;
    --menu-hover: #0ea5e9;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--os-bg);
    color: white;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
    margin: 0;
    padding: 0;
    user-select: none;
    cursor: default;
    position: fixed;
    top: 0;
    left: 0;
    transition: background-color 0.5s ease;
}

/* Standard Cursors */
a,
button,
.clickable,
.desktop-icon,
.task-item,
.window-btn,
.menu-item,
.app-menu-trigger {
    cursor: pointer;
}

input,
textarea,
.text-content {
    cursor: text;
}

.title-bar {
    cursor: default;
}

@media (min-width: 1024px) {
    .title-bar {
        cursor: move;
    }
}

.resize-handle {
    cursor: se-resize;
}

.retro-font {
    font-family: 'Press Start 2P', cursive;
}

.boot-font {
    font-family: 'Courier Prime', monospace;
}

.scanlines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0) 50%, rgba(0, 0, 0, 0.1) 50%, rgba(0, 0, 0, 0.1));
    background-size: 100% 4px;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.2;
}

#desktop {
    position: relative;
    width: 100%;
    height: 100%;
}

/* Background Canvas for 3D Grid */
#bg-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    /* Behind icons */
    pointer-events: none;
}

/* Boot Screen */
#boot-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: black;
    z-index: 20000;
    display: none;
    padding: 40px;
    color: #33ff33;
    font-size: 14px;
    overflow: hidden;
}

.boot-line {
    margin-bottom: 4px;
    white-space: pre-wrap;
    text-shadow: 0 0 5px #33ff33;
}

/* BSOD */
#bsod-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #0000AA;
    color: white;
    z-index: 20001;
    display: none;
    padding: 40px;
    font-family: 'Courier Prime', monospace;
    font-size: 16px;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

/* Context Menu */
#context-menu {
    position: absolute;
    background: var(--win-bg);
    border: 2px outset var(--win-border-light);
    min-width: 150px;
    z-index: 10000;
    display: none;
    box-shadow: 4px 4px 5px rgba(0, 0, 0, 0.5);
}

/* System Tray Popups */
.tray-popup {
    position: absolute;
    bottom: 50px;
    right: 10px;
    background: var(--win-bg);
    border: 2px outset var(--win-border-light);
    z-index: 9002;
    display: none;
    padding: 10px;
    box-shadow: 4px 4px 5px rgba(0, 0, 0, 0.5);
}

/* --- Window System --- */
.os-window {
    position: absolute;
    background-color: var(--win-bg);
    border-top: 2px solid var(--win-border-light);
    border-left: 2px solid var(--win-border-light);
    border-right: 2px solid var(--win-border-dark);
    border-bottom: 2px solid var(--win-border-dark);
    box-shadow: 6px 6px 0px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    min-width: 200px;
    min-height: 150px;
    opacity: 0;
}

.os-window.active {
    z-index: 50;
    border-color: var(--highlight);
}

.title-bar {
    background: var(--win-title-bg);
    padding: 4px 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    touch-action: none;
}

.os-window.active .title-bar {
    background: var(--win-title-active);
}

.window-btn {
    width: 16px;
    height: 16px;
    background: #cbd5e1;
    border: 1px outset #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: black;
    font-weight: bold;
    line-height: 1;
}

.window-btn:active {
    border-style: inset;
    transform: translateY(1px);
}

.resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 16px;
    height: 16px;
    background: linear-gradient(135deg, transparent 50%, var(--win-border-light) 50%);
    z-index: 20;
}

/* --- Desktop Icons --- */
.desktop-icon {
    position: absolute;
    width: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px;
    border: 1px solid transparent;
    text-align: center;
    color: #cbd5e1;
    z-index: 1;
    /* Above canvas */
}

.desktop-icon:hover {
    background: rgba(255, 255, 255, 0.05);
}

.desktop-icon.selected {
    background: rgba(34, 211, 238, 0.2);
    border: 1px dotted var(--highlight);
    color: white;
}

/* --- Taskbar & Start Menu --- */
#taskbar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    min-height: 40px;
    padding-bottom: env(safe-area-inset-bottom, 20px);
    height: auto;
    box-sizing: border-box;
    background: var(--win-bg);
    border-top: 2px solid var(--win-border-light);
    display: flex;
    align-items: center;
    padding: 2px 4px;
    padding-bottom: calc(2px + env(safe-area-inset-bottom, 20px));
    z-index: 9000;
    overflow: hidden;
}

.start-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    margin-right: 8px;
    background: #cbd5e1;
    border: 2px outset #fff;
    font-family: 'Press Start 2P', cursive;
    font-size: 10px;
    color: black;
    box-shadow: 1px 1px 0 #000;
    flex-shrink: 0;
}

.start-btn:active,
.start-btn.active {
    border-style: inset;
    transform: translateY(1px);
    box-shadow: none;
}

#task-list-container {
    flex-grow: 1;
    display: flex;
    align-items: center;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    -ms-overflow-style: none;
    scrollbar-width: none;
    margin-right: 4px;
}

#task-list-container::-webkit-scrollbar {
    display: none;
}

#task-list {
    display: flex;
    align-items: center;
}

.task-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    margin-right: 4px;
    background: var(--win-bg);
    border: 2px outset var(--win-border-light);
    color: #cbd5e1;
    font-size: 11px;
    max-width: 160px;
    flex-shrink: 0;
}

.task-item.active {
    background: #334155;
    border-style: inset;
    color: white;
    font-weight: bold;
}

#tray-area {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    flex-shrink: 0;
}

.tray-icon {
    font-size: 14px;
    cursor: pointer;
    padding: 2px 4px;
}

.tray-icon:hover {
    background: rgba(255, 255, 255, 0.1);
}

#clock {
    padding: 2px 6px;
    background: #0f172a;
    border: 1px solid #475569;
    color: var(--highlight);
    cursor: pointer;
}

#start-menu {
    position: absolute;
    bottom: calc(44px + env(safe-area-inset-bottom, 20px));
    left: 4px;
    width: 250px;
    background: var(--win-bg);
    border: 2px outset var(--win-border-light);
    box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.5);
    z-index: 9001;
    display: none;
    flex-direction: column;
    max-height: 60vh;
}

#start-menu.open {
    display: flex;
}

.start-side {
    background: linear-gradient(180deg, #0e7490, #1e3a8a);
    width: 30px;
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 8px;
}

.start-side span {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    color: white;
    font-weight: bold;
    font-family: 'Press Start 2P', cursive;
    font-size: 12px;
}

.start-content {
    padding: 4px 4px 4px 34px;
    overflow-y: auto;
    flex: 1;
}

.start-content::-webkit-scrollbar {
    width: 6px;
}

.start-content::-webkit-scrollbar-thumb {
    background: #475569;
}

.menu-item {
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: white;
    font-size: 12px;
}

.menu-item:hover {
    background: var(--menu-hover);
    color: white;
}

.menu-divider {
    height: 1px;
    background: var(--win-border-light);
    margin: 4px 0;
}

.app-menu-bar {
    background: #334155;
    padding: 2px 4px;
    display: flex;
    gap: 2px;
    font-size: 11px;
    color: #cbd5e1;
}

.app-menu-trigger {
    padding: 2px 6px;
    position: relative;
}

.app-menu-trigger:hover {
    background: #475569;
    color: white;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--win-bg);
    border: 1px outset var(--win-border-light);
    min-width: 120px;
    z-index: 100;
    display: none;
    box-shadow: 4px 4px 5px rgba(0, 0, 0, 0.5);
}

.dropdown-menu.show {
    display: block;
}

.dropdown-item {
    padding: 6px 12px;
    display: block;
    color: white;
    cursor: pointer;
}

.dropdown-item:hover {
    background: var(--menu-hover);
}

canvas {
    image-rendering: pixelated;
}

.hidden {
    display: none !important;
}

iframe {
    display: block;
    border: none;
}

/* --- Ghost Window Style --- */
.ghost-window {
    z-index: 99990;
}

.ghost-trail {
    position: absolute;
    background-color: var(--win-bg);
    border-top: 2px solid var(--win-border-light);
    border-left: 2px solid var(--win-border-light);
    border-right: 2px solid var(--win-border-dark);
    border-bottom: 2px solid var(--win-border-dark);
    width: 320px;
    height: 150px;
    z-index: 99980;
    opacity: 0.3;
    pointer-events: none;
}

/* --- File Explorer Style --- */
.explorer-item {
    display: flex;
    align-items: center;
    padding: 8px;
    border-bottom: 1px solid #e2e8f0;
    cursor: pointer;
}

.explorer-item:hover {
    background: #e0f2fe;
}

/* --- Settings Range Slider Style --- */
input[type=range] {
    -webkit-appearance: none;
    width: 100%;
    background: transparent;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 16px;
    width: 16px;
    background: #cbd5e1;
    border: 2px outset #fff;
    cursor: pointer;
    margin-top: -6px;
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: #475569;
    border: 1px inset #000;
}

input[type=checkbox].retro-check {
    appearance: none;
    width: 16px;
    height: 16px;
    background: white;
    border: 2px inset #475569;
    cursor: pointer;
    position: relative;
}

input[type=checkbox].retro-check:checked::after {
    content: '✓';
    position: absolute;
    top: -2px;
    left: 2px;
    color: black;
    font-weight: bold;
    font-size: 12px;
}