:root {
    --desktop-titlebar-bg: rgba(16, 18, 24, 0.92);
    --desktop-titlebar-border: rgba(255, 255, 255, 0.08);
    --desktop-titlebar-foreground: rgba(255, 255, 255, 0.85);
    --desktop-titlebar-control-size: 36px;
    --desktop-titlebar-control-height: 26px;
    --desktop-titlebar-control-gap: 6px;
}

body.desktop-shell-active {
    padding-top: var(--desktop-titlebar-height);
}

body.desktop-shell-fullscreen .desktop-titlebar {
    display: none;
}

.desktop-titlebar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--desktop-titlebar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    background: var(--desktop-titlebar-bg);
    color: var(--desktop-titlebar-foreground);
    -webkit-app-region: drag;
    z-index: 9999;
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--desktop-titlebar-border);
}

.desktop-titlebar__drag-region {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1 1 auto;
    -webkit-app-region: drag;
    pointer-events: none;
}

.desktop-titlebar__title {
    font-size: 13px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    opacity: 0.9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
}

.desktop-titlebar__controls {
    display: flex;
    align-items: center;
    gap: var(--desktop-titlebar-control-gap);
    -webkit-app-region: no-drag;
}

.titlebar-btn {
    position: relative;
    width: var(--desktop-titlebar-control-size);
    height: var(--desktop-titlebar-control-height);
    display: inline-flex;
    justify-content: center;
    align-items: center;
    border: none;
    background: transparent;
    color: var(--desktop-titlebar-foreground);
    border-radius: 6px;
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease;
    -webkit-app-region: no-drag;
}

.titlebar-btn::before,
.titlebar-btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: currentColor;
}

.titlebar-btn[data-window-action="minimize"]::before {
    width: 12px;
    height: 2px;
}

.titlebar-btn[data-window-action="maximize"]::before {
    width: 12px;
    height: 10px;
    border: 2px solid currentColor;
    background: transparent;
    border-radius: 2px;
}

.titlebar-btn[data-window-action="maximize"].is-restored::before {
    width: 10px;
    height: 8px;
    border: 2px solid currentColor;
    background: transparent;
    transform: translate(-40%, -60%);
}

.titlebar-btn[data-window-action="maximize"].is-restored::after {
    width: 10px;
    height: 8px;
    border: 2px solid currentColor;
    background: transparent;
    border-top-color: transparent;
    border-left-color: transparent;
    transform: translate(-10%, -30%);
}

.titlebar-btn.titlebar-btn--close::before {
    width: 12px;
    height: 2px;
    transform: translate(-50%, -50%) rotate(45deg);
}

.titlebar-btn.titlebar-btn--close::after {
    width: 12px;
    height: 2px;
    transform: translate(-50%, -50%) rotate(-45deg);
}

.titlebar-btn:hover {
    background: rgba(255, 255, 255, 0.12);
}

.titlebar-btn:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.6);
    outline-offset: 1px;
}

.titlebar-btn.titlebar-btn--close:hover {
    background: #e81123;
    color: #ffffff;
}

body.desktop-shell-platform-mac .desktop-titlebar {
    justify-content: center;
    padding: 0 70px;
}

body.desktop-shell-platform-mac .desktop-titlebar__controls {
    order: -1;
    margin-right: 14px;
    gap: 8px;
}

body.desktop-shell-platform-mac .desktop-titlebar__drag-region {
    justify-content: center;
}

body.desktop-shell-platform-mac .titlebar-btn {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    padding: 0;
}

body.desktop-shell-platform-mac .titlebar-btn.titlebar-btn--close {
    order: 0;
}

body.desktop-shell-platform-mac .titlebar-btn[data-window-action="minimize"] {
    order: 1;
}

body.desktop-shell-platform-mac .titlebar-btn[data-window-action="maximize"] {
    order: 2;
}

body.desktop-shell-platform-mac .titlebar-btn::before,
body.desktop-shell-platform-mac .titlebar-btn::after {
    width: 8px;
    height: 2px;
    transform: translate(-50%, -50%);
    opacity: 0;
}

body.desktop-shell-platform-mac .titlebar-btn[data-window-action="minimize"] {
    background: #f4bf4f;
}

body.desktop-shell-platform-mac .titlebar-btn[data-window-action="maximize"] {
    background: #62c554;
}

body.desktop-shell-platform-mac .titlebar-btn.titlebar-btn--close {
    background: #ff5f57;
}

body.desktop-shell-platform-mac .titlebar-btn:hover::before,
body.desktop-shell-platform-mac .titlebar-btn:hover::after {
    opacity: 0.65;
}

body.desktop-shell-platform-mac .titlebar-btn[data-window-action="minimize"]::before {
    width: 8px;
    height: 2px;
}

body.desktop-shell-platform-mac .titlebar-btn[data-window-action="maximize"]::before {
    width: 8px;
    height: 8px;
    border-radius: 2px;
    border: 1px solid rgba(0, 0, 0, 0.6);
    background: transparent;
}

body.desktop-shell-platform-mac .titlebar-btn[data-window-action="maximize"].is-restored::before,
body.desktop-shell-platform-mac .titlebar-btn[data-window-action="maximize"].is-restored::after {
    display: none;
}

body.desktop-shell-platform-mac .titlebar-btn.titlebar-btn--close::before,
body.desktop-shell-platform-mac .titlebar-btn.titlebar-btn--close::after {
    width: 8px;
    opacity: 0.7;
}

body.desktop-shell-platform-mac .titlebar-btn:hover {
    filter: brightness(1.1);
}

body.desktop-shell-platform-windows .desktop-titlebar__controls,
body.desktop-shell-platform-linux .desktop-titlebar__controls {
    margin-left: 18px;
}
