:root {
    --desktop-background: #008080;
    --desktop-background-size: cover;
    --desktop-background-repeat: no-repeat;
    --desktop-background-position: center;

    --u32-resize-handle-size: 6px;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Pixelated MS Sans Serif', sans-serif;
    background: var(--desktop-background);
    background-size: var(--desktop-background-size);
    background-repeat: var(--desktop-background-repeat);
    background-position: var(--desktop-background-position);
    overflow: hidden;
    cursor: default;
}

/* Windows */
.window {
    position: absolute;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 100px;
    min-height: 60px;
}

/* Text cursor only on text inputs */
input[type="text"],
textarea,
input[type="password"] {
    cursor: text;
}

* {
    cursor: default;
}

button,
.title-bar-controls button,
select {
    cursor: default;
}

.desktop {
    width: 100vw;
    height: 100vh;
    position: relative;
    background: var(--desktop-background);
    background-size: var(--desktop-background-size);
    background-repeat: var(--desktop-background-repeat);
    background-position: var(--desktop-background-position);
}

/* crisp visuals */
img,
.menu-bar,
.dropdown-menu {
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    -webkit-user-drag: none;
    user-select: none;
    -moz-user-select: none;
    -webkit-user-select: none;
    -ms-user-select: none;
}

/* Minimized behavior: keep title bar, hide content */
.window.minimized .window-body,
.window.minimized .status-bar,
.window.minimized .menu-bar,
.window.minimized .toolbar {
    display: none !important;
}

.window.minimized {
    display: flex !important;
    height: auto !important;
    min-height: 0 !important;
}

/* Menu Bar */
.menu-bar {
    position: relative;
    user-select: none;
    font-size: 11px;
    padding: 2px;
    background: var(--surface);
}

.menu-item-header {
    padding: 2px 6px;
    font-size: 11px;
    display: inline-block;
    position: relative;
}

.menu-item-header:hover {
    background: var(--selected-item);
    color: white;
}

.menu-item-header.active {
    background: var(--selected-item);
    color: white;
}

/* left side: icon + caption, allowed to shrink */
.title-bar-text {
    display: flex;
    align-items: center;
    gap: 3px;
    flex: 1 1 auto;
    /* take remaining space */
    min-width: 0;
    /* allow shrinking so ellipsis can work */
}

.title-bar-icon {
    width: 16px;
    height: 16px;
    flex: 0 0 auto;
    padding: 0;
    vertical-align: middle;
}

/* caption gets the elastic space and truncates */
.title-bar-caption {
    flex: 1 1 auto;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
}

/* right side: fixed-width controls, pinned to the right */
.title-bar-controls {
    display: flex;
    flex: 0 0 auto;
    /* do not grow */
    margin-left: auto;
    /* push to the right edge */
    white-space: nowrap;
}

.title-bar-controls button {
    flex: 0 0 auto;
}

/* Dropdown Menu (single shared element) */
.dropdown-menu {
    position: absolute;
    background: var(--surface);
    border: 1px outset var(--surface);
    min-width: 140px;
    z-index: 50000;
    font-size: 11px;
    display: none;
    padding: 5px 0;
    box-shadow: var(--border-raised-outer), var(--border-raised-inner);
}

.dropdown-item {
    padding: 1px 14px;
    white-space: nowrap;
    position: relative;
    margin: 0 4px;
    font-size: 11px;
}

.dropdown-item:hover {
    background: var(--selected-item);
    color: white;
}

.dropdown-item.disabled {
    color: #808080;
    pointer-events: none;
}

.dropdown-item.disabled:hover {
    background: transparent;
    color: #808080;
}

.dropdown-separator {
    height: 1px;
    background: var(--button-shadow);
    margin: 2px 2px;
    border-bottom: 1px solid var(--button-face);
}

.separator {
    width: 100%;
    border-top: 1px solid var(--button-shadow);
    border-bottom: 1px solid var(--button-face);
}

/* Toolbar */
.toolbar {
    display: flex;
    gap: 1px;
    padding: 3px;
    background: var(--surface);
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.toolbar button {
    width: 23px;
    height: 22px;
    padding: 1px;
    background: var(--surface);
    border: 1px outset var(--surface);
    background-size: 16px 16px;
    background-repeat: no-repeat;
    background-position: center;
}

.toolbar button:active {
    border: 1px inset #c0c0c0;
}

/* default: nothing is selectable */
#desktop,
#desktop *:not(input):not(textarea):not([contenteditable="true"]):not(.selectable) {
    -webkit-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* allow selection where it makes sense */
input,
textarea,
[contenteditable="true"],
.selectable {
    -webkit-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* images never start a drag */
img {
    -webkit-user-drag: none;
    /* Safari */
    user-drag: none;
}

/* optional: kill long-press callout on mobile */
#desktop {
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

.status-bar {
    margin: 1px;
    background: var(--surface);
}

.status-bar-field {
    padding: 3px 4px;
}

.window-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;

    /* classic Win9x dialog spacing */
}

.status-bar {
    flex: 0 0 auto;
}

/* Non interactive windows */
.window[data-interactive="0"] {
    pointer-events: none;
}

/* Resize handles */
.u32-resize-handle {
    position: absolute;
    pointer-events: auto;
    z-index: 9999;
    /* sit above title bar */
    touch-action: none;
}

/* edges */
.u32-resize-handle.u32-n,
.u32-resize-handle.u32-s {
    left: 0;
    right: 0;
    height: var(--u32-resize-handle-size);
}

.u32-resize-handle.u32-n {
    top: 0;
    cursor: n-resize;
}

.u32-resize-handle.u32-s {
    bottom: 0;
    cursor: s-resize;
}

.u32-resize-handle.u32-e,
.u32-resize-handle.u32-w {
    top: 0;
    bottom: 0;
    width: var(--u32-resize-handle-size);
}

.u32-resize-handle.u32-e {
    right: 0;
    cursor: e-resize;
}

.u32-resize-handle.u32-w {
    left: 0;
    cursor: w-resize;
}

/* corners */
.u32-resize-handle.u32-ne,
.u32-resize-handle.u32-nw,
.u32-resize-handle.u32-se,
.u32-resize-handle.u32-sw {
    width: calc(var(--u32-resize-handle-size) + 2px);
    height: calc(var(--u32-resize-handle-size) + 2px);
}

.u32-resize-handle.u32-ne {
    top: 0;
    right: 0;
    cursor: ne-resize;
}

.u32-resize-handle.u32-nw {
    top: 0;
    left: 0;
    cursor: nw-resize;
}

.u32-resize-handle.u32-se {
    bottom: 0;
    right: 0;
    cursor: se-resize;
}

.u32-resize-handle.u32-sw {
    bottom: 0;
    left: 0;
    cursor: sw-resize;
}