/* --- Reset & Global --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    font-family: Tahoma, 'Segoe UI', Arial, sans-serif;
}

body,
html {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background-color: #000;
}

/* --- Desktop Background --- */
#desktop {
    position: relative;
    width: 100%;
    height: calc(100vh - 30px);
    /* taskbar is 30px */
    background: url('../images/xp_background_image.jpg') no-repeat center center;
    background-size: cover;
    display: flex;
    flex-direction: column;
}

/* --- Desktop Grid & Icons --- */
#desktop-grid {
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
    align-content: flex-start;
    padding: 10px;
    height: 100%;
    gap: 15px;
}

.desktop-icon {
    width: 70px;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: default;
}

.desktop-icon-img {
    width: 32px;
    height: 32px;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23f9d976"><path d="M10 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"/></svg>');
    background-size: cover;
    margin-bottom: 4px;
    filter: drop-shadow(1px 1px 2px rgba(0, 0, 0, 0.5));
}

.desktop-icon-text {
    color: white;
    font-size: 11px;
    text-align: center;
    text-shadow: 1px 1px 1px black;
    padding: 2px 4px;
    border: 1px dotted transparent;
}

.desktop-icon.selected .desktop-icon-img {
    filter: brightness(0.8) sepia(1) hue-rotate(180deg) saturate(3) drop-shadow(1px 1px 2px rgba(0, 0, 0, 0.5));
}

.desktop-icon.selected .desktop-icon-text {
    background-color: #0b61ff;
    border: 1px dotted #ccc;
}

/* --- Taskbar --- */
#taskbar {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100vw;
    height: 30px;
    background: linear-gradient(to bottom, #245edb 0%, #3f8cf3 9%, #245edb 18%, #245edb 92%, #1941a5 100%);
    display: flex;
    z-index: 10000;
    box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.3);
}

#start-button {
    height: 100%;
    background: linear-gradient(to bottom, #3b8220 0%, #46a125 10%, #3ca01f 30%, #308f14 50%, #287a11 75%, #1f640a 100%);
    border: none;
    border-right: 1px solid #104201;
    border-radius: 0 10px 10px 0;
    box-shadow: inset 1px 1px 2px rgba(255, 255, 255, 0.5), inset -1px -1px 2px rgba(0, 0, 0, 0.3);
    color: white;
    font-size: 14px;
    font-style: italic;
    font-weight: bold;
    display: flex;
    align-items: center;
    padding: 0 15px 0 10px;
    cursor: default;
}

#start-button:hover {
    background: linear-gradient(to bottom, #449527 0%, #52b730 10%, #46bd24 30%, #38a816 50%, #2f9413 75%, #25790c 100%);
}

#start-button:active,
#start-button.active {
    background: linear-gradient(to bottom, #1f640a 0%, #287a11 25%, #308f14 50%, #3ca01f 70%, #46a125 90%, #3b8220 100%);
    box-shadow: inset 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.start-logo {
    display: inline-block;
    width: 16px;
    height: 16px;
    background: white;
    mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M0 3.44l10.33-1.42v9.31H0V3.44zm11.45-1.57L24 0v11.16H11.45V1.87zM0 12.44h10.33v9.31L0 20.33v-7.89zm11.45 0H24v11.16l-12.55-1.74v-9.42z"/></svg>') no-repeat center / contain;
    -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M0 3.44l10.33-1.42v9.31H0V3.44zm11.45-1.57L24 0v11.16H11.45V1.87zM0 12.44h10.33v9.31L0 20.33v-7.89zm11.45 0H24v11.16l-12.55-1.74v-9.42z"/></svg>') no-repeat center / contain;
    margin-right: 5px;
    box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

#taskbar-apps {
    flex-grow: 1;
    display: flex;
    align-items: center;
    padding: 0 5px;
    gap: 3px;
}

#system-tray {
    background: linear-gradient(to bottom, #0e9ce9 0%, #17a9f6 9%, #159aeb 18%, #1085d7 50%, #0c75c5 92%, #085da5 100%);
    border-left: 1px solid #104aba;
    box-shadow: inset 1px 0px 1px rgba(255, 255, 255, 0.4);
    display: flex;
    align-items: center;
    padding: 0 15px;
    color: white;
    font-size: 11px;
}

#clock {
    margin-left: 10px;
}

/* --- Start Menu --- */
#start-menu {
    position: absolute;
    bottom: 30px;
    left: 0;
    width: 380px;
    background: #fff;
    border: 1px solid #0831d9;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
    box-shadow: 2px -2px 5px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    z-index: 10001;
}

#start-menu.hidden {
    display: none;
}

.start-menu-header {
    background: linear-gradient(to bottom, #1868CE 0%, #0E60CB 12%, #0E60CB 20%, #1164CF 32%, #1667D0 33%, #1B6CD3 47%, #1E70D9 54%, #2071DB 60%, #2475E0 65%, #297AE4 77%, #3482E8 79%, #3482E8 90%, #2071DB 100%);
    color: white;
    padding: 8px;
    display: flex;
    align-items: center;
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
    box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.4);
}

.user-avatar {
    width: 42px;
    height: 42px;
    background: #fff;
    border: 2px solid rgba(255, 255, 255, 0.8);
    border-radius: 3px;
    margin-right: 10px;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23666"><path d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"/></svg>');
    background-size: cover;
}

.username {
    font-size: 15px;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.start-menu-body {
    display: flex;
    min-height: 350px;
}

.start-menu-left {
    width: 50%;
    background: white;
    padding: 5px;
    display: flex;
    flex-direction: column;
}

.start-menu-right {
    width: 50%;
    background: #d3e5fa;
    border-left: 1px solid #9dbaf0;
    padding: 5px;
    display: flex;
    flex-direction: column;
}

.start-item {
    display: flex;
    align-items: center;
    padding: 8px 5px;
    cursor: default;
}

.start-item:hover {
    background: #2f71cd;
    color: white;
}

.start-item-icon {
    width: 32px;
    height: 32px;
    margin-right: 8px;
}

.calc-icon {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23333"><path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-8 14H7v-2h4v2zm0-4H7v-2h4v2zm0-4H7V7h4v2zm6 8h-4v-2h4v2zm0-4h-4v-2h4v2zm0-4h-4V7h4v2z"/></svg>');
    background-size: cover;
}

.folder-icon {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23f9d976"><path d="M10 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"/></svg>');
    background-size: cover;
}

.start-item-title {
    font-size: 11px;
    font-weight: bold;
}

.start-divider {
    border-bottom: 1px solid #dcdcdc;
    margin: 3px 5px;
}

.right-divider {
    border-bottom: 1px solid #aebce8;
}

.start-right-item {
    padding: 6px 10px;
    font-size: 11px;
    font-weight: bold;
    color: #00136b;
    cursor: default;
}

.start-right-item:hover {
    background: #2f71cd;
    color: white;
}

.start-menu-footer {
    background: linear-gradient(to bottom, #4489dd 0%, #3e81d7 100%);
    padding: 5px 10px;
    display: flex;
    justify-content: flex-end;
    gap: 15px;
}

.footer-btn {
    display: flex;
    align-items: center;
    color: white;
    font-size: 11px;
    cursor: default;
}

.footer-btn:hover {
    text-decoration: underline;
}

.footer-icon {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    margin-right: 5px;
}

.logoff-icon {
    background: #f0c330;
    border: 1px solid white;
}

.turnoff-icon {
    background: #e0322d;
    border: 1px solid white;
}

/* --- Window Manager --- */
.window {
    position: absolute;
    width: 400px;
    height: 300px;
    background: #ece9d8;
    border: 3px solid #0055ea;
    border-radius: 8px 8px 0 0;
    box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: visible;
}

.window.focused {
    border-color: #0055ea;
    box-shadow: 3px 3px 15px rgba(0, 0, 0, 0.6);
    z-index: 100;
    /* Handled via JS typically */
}

.window:not(.focused) {
    border-color: #7792ce;
}

.title-bar {
    background: linear-gradient(to right, #0058e6 0%, #3a93ff 8%, #288eff 40%, #127dff 88%, #036bba 100%);
    color: white;
    padding: 3px 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: default;
    user-select: none;
    height: 30px;
}

.window:not(.focused) .title-bar {
    background: linear-gradient(to right, #7697e7 0%, #7e9ea9 8%, #8ea5d9 40%, #7a96df 88%, #6a8ec2 100%);
}

.title-bar-text {
    font-weight: bold;
    font-size: 13px;
    display: flex;
    align-items: center;
    text-shadow: 1px 1px 2px #0f1089;
    flex-grow: 1;
}

.title-bar-icon {
    width: 16px;
    height: 16px;
    margin-right: 5px;
    background-size: cover;
}

.title-bar-controls {
    display: flex;
    gap: 2px;
}

.title-btn {
    width: 21px;
    height: 21px;
    border: 1px solid white;
    border-radius: 3px;
    background: linear-gradient(to bottom, #fff 0%, #e4e2d5 100%);
    box-shadow: inset 1px 1px 1px rgba(255, 255, 255, 0.7), 1px 1px 2px rgba(0, 0, 0, 0.3);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 10px;
    font-weight: bold;
    color: black;
    cursor: default;
}

.title-btn:active {
    background: #d4d0c8;
    box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.title-btn.close {
    background: linear-gradient(to bottom, #f08c73 0%, #e64b28 100%);
    color: white;
}

.title-btn.close:hover {
    background: linear-gradient(to bottom, #f3a08b 0%, #ec6042 100%);
}

.title-btn.close:active {
    background: #d03d1e;
}

.window-body {
    flex-grow: 1;
    background: #ece9d8;
    margin: 0;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.window-content-wrapper {
    background: #fff;
    border: 1px solid #7f9db9;
    margin: 0 3px 3px 3px;
    flex-grow: 1;
    overflow: auto;
}

/* Resize handles */
.resize-handle {
    position: absolute;
    z-index: 10;
}

.resize-handle.n {
    top: -3px;
    left: 0;
    right: 0;
    height: 5px;
    cursor: n-resize;
}

.resize-handle.s {
    bottom: -3px;
    left: 0;
    right: 0;
    height: 5px;
    cursor: s-resize;
}

.resize-handle.e {
    top: 0;
    bottom: 0;
    right: -3px;
    width: 5px;
    cursor: e-resize;
}

.resize-handle.w {
    top: 0;
    bottom: 0;
    left: -3px;
    width: 5px;
    cursor: w-resize;
}

.resize-handle.se {
    bottom: -3px;
    right: -3px;
    width: 10px;
    height: 10px;
    cursor: se-resize;
}

/* Taskbar Windows */
.taskbar-item {
    background: linear-gradient(to bottom, #3c81f3 0%, #2f73e6 100%);
    border: 1px solid #003dbb;
    border-radius: 3px;
    color: white;
    padding: 2px 8px;
    max-width: 150px;
    min-width: 80px;
    height: 24px;
    display: flex;
    align-items: center;
    font-size: 11px;
    cursor: default;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    box-shadow: inset 1px 1px 1px rgba(255, 255, 255, 0.4);
}

.taskbar-item.focused {
    background: linear-gradient(to bottom, #1941a5 0%, #102a73 100%);
    box-shadow: inset 1px 1px 3px rgba(0, 0, 0, 0.6);
}

.taskbar-item:hover {
    background: linear-gradient(to bottom, #4f8cf6 0%, #3e81e9 100%);
}

.taskbar-item .taskbar-icon {
    width: 16px;
    height: 16px;
    margin-right: 5px;
    background-size: cover;
}

/* --- File Explorer --- */
.explorer {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.explorer-toolbar {
    background: #ece9d8;
    border-bottom: 1px solid #7f9db9;
    padding: 5px;
    display: flex;
    align-items: center;
}

.toolbar-btn {
    padding: 2px 8px;
    margin-right: 10px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 3px;
}

.toolbar-btn:hover {
    border: 1px solid #9dbaf0;
    background: rgba(255, 255, 255, 0.5);
}

.address-bar {
    display: flex;
    flex-grow: 1;
    align-items: center;
}

.address-bar span {
    margin-right: 5px;
    color: #555;
}

.address-bar input {
    flex-grow: 1;
    border: 1px solid #7f9db9;
    padding: 2px 4px;
}

.explorer-body {
    display: flex;
    flex-grow: 1;
    overflow: hidden;
    /* Content handles scroll */
}

.explorer-sidebar {
    width: 180px;
    background: linear-gradient(to bottom, #748de7 0%, #748de7 100%);
    /* XP blue sidebar */
    padding: 10px;
    border-right: 1px solid #7f9db9;
    flex-shrink: 0;
}

.sidebar-box {
    background: white;
    border-radius: 3px;
    border: 1px solid white;
    box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
    margin-bottom: 10px;
    overflow: hidden;
}

.box-title {
    background: linear-gradient(to right, #ffffff 0%, #d6e2fb 100%);
    color: #0c327d;
    font-weight: bold;
    padding: 3px 8px;
    border-bottom: 1px solid #d6e2fb;
}

.box-content {
    padding: 8px;
    color: #0c327d;
    font-size: 11px;
}

.box-content ul {
    list-style: none;
}

.box-content li {
    margin-bottom: 4px;
    text-decoration: underline;
    cursor: default;
}

.explorer-content {
    flex-grow: 1;
    background: white;
    overflow: auto;
    padding: 10px;
}

.file-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
}

.file-item {
    width: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 5px;
    cursor: default;
}

.file-item.selected {
    background: #316ac5;
    color: white;
}

.file-item:not(.selected) {
    color: black;
}

.file-icon {
    width: 48px;
    height: 48px;
    margin-bottom: 5px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

/* --- Notepad --- */
.notepad {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.notepad-menu,
.calc-menu {
    background: #ece9d8;
    border-bottom: 1px solid #7f9db9;
    padding: 2px 5px;
    font-size: 11px;
    display: flex;
}

.notepad-menu span,
.calc-menu span {
    padding: 2px 6px;
    cursor: default;
}

.notepad-menu span:hover,
.calc-menu span:hover {
    background: #316ac5;
    color: white;
}

.notepad-iframe {
    flex-grow: 1;
    width: 100%;
    background: white;
}

/* --- Calculator --- */
.calculator {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: #ece9d8;
}

.calc-body {
    padding: 10px;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.calc-display {
    background: white;
    border: 2px inset #fff;
    border-bottom-color: #d4d0c8;
    border-right-color: #d4d0c8;
    text-align: right;
    padding: 5px;
    font-family: 'Courier New', monospace;
    font-size: 24px;
    margin-bottom: 10px;
    flex-shrink: 0;
    overflow: hidden;
    height: 40px;
}

.calc-clear-row {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 5px;
}

.calc-btn {
    background: linear-gradient(to bottom, #f3f2ee 0%, #ece9d8 100%);
    border: 1px solid #fff;
    border-bottom-color: #aca899;
    border-right-color: #aca899;
    box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.1);
    font-size: 14px;
    font-weight: bold;
    border-radius: 2px;
}

.calc-btn:active {
    background: #d4d0c8;
    border: 1px inset #aca899;
    box-shadow: none;
    padding-top: 1px;
}

.calc-clear {
    color: #cc0000;
    width: 50%;
    padding: 4px;
}

.calc-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
    flex-grow: 1;
}

.calc-op {
    color: #cc0000;
}

.calc-eq {
    color: #cc0000;
}

/* --- Media Viewer --- */
.media-viewer {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: #ece9d8;
}

.media-viewer-toolbar {
    background: #ece9d8;
    border-top: 1px solid #7f9db9;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    height: 40px;
    flex-shrink: 0;
}

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

.media-viewer-element {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.audio-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
}

.audio-icon {
    width: 64px;
    height: 64px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    filter: drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.3));
}