:root {
    --window-border-radius: 12px;

    /* Light theme colors - pure black text for maximum contrast */
    --headerbar-bg-light: #ffffff;
    --headerbar-fg-light: #000000;

    /* Dark theme colors - pure white text for maximum contrast */
    --headerbar-bg-dark: #303030;
    --headerbar-fg-dark: #ffffff;

    /* Current theme colors (default to light) */
    --headerbar-bg: var(--headerbar-bg-light);
    --headerbar-fg: var(--headerbar-fg-light);
}

@media (prefers-color-scheme: dark) {
    :root {
        --headerbar-bg: var(--headerbar-bg-dark);
        --headerbar-fg: var(--headerbar-fg-dark);
    }
}

body {
    margin: 0;
    padding: 0;
    font-family: "Adwaita Sans", sans-serif;
    background: var(--headerbar-bg);
    color: var(--headerbar-fg);
    user-select: none;
    -webkit-user-select: none;
    /* Smooth transition for theme color changes */
    transition: background-color 0.3s ease, color 0.3s ease;
}

#titlebar {
    --titlebar-control-inset: 120px;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 6px;
    position: relative;
    box-sizing: border-box;
}

.window-title {
    font-size: 11px;
    font-weight: bold;
    margin: 0;
    text-align: center;
    position: absolute;
    left: 50%;
    top: calc(50% - 1px);
    transform: translate(-50%, -50%);
    width: max-content;
    max-width: max(0px, calc(100% - (2 * var(--titlebar-control-inset))));
    box-sizing: border-box;
    min-width: 0; /* Allow flex item to shrink below content size */
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    /* Add some padding to prevent touching buttons */
    padding: 0 12px;
    /* Center the text's own line box instead of relying on titlebar height. */
    line-height: 1.2;
    /* Smooth transition for theme color changes */
    transition: color 0.3s ease;
}

.window-controls {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: center;
    /* Ensure controls don't shrink */
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}
.window-controls.left {
    margin-right: auto;
    margin-left: 5px;
}
.window-controls.right {
    margin-left: auto;
    margin-right: 5px;
}

/* Shoutout to Mie UI, I stole their CSS here*/
.window-button {
    width: 10px;
    height: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    display: inline-flex;
    border: transparent;
    border-radius: 500rem;
    position: relative;
    transition: background-color 0.15s ease, color 0.15s ease, filter 0.15s ease;
    color: var(--headerbar-fg);
    font-weight: 700;
    padding: 0.7rem 0.7rem;
    background-color: var(--headerbar-bg);
    margin: 0;
}
.window-button img {
    transition: filter 0.3s ease;
}
@media (prefers-color-scheme: light) {
    .window-button {
        background-color: color-mix(in srgb,var(--headerbar-bg),#000000 6.5%);
    }
    .window-button:hover {
        background-color: color-mix(in srgb,var(--headerbar-bg),#000000 11.75%);
    }
    .window-button:active {
        background-color: color-mix(in srgb,var(--headerbar-bg),#000000 24%);
    }
    /* Force pure black icons for light theme */
    .window-button img {
        filter: brightness(0);
    }
}
@media (prefers-color-scheme: dark) {
    .window-button {
        background-color: color-mix(in srgb,var(--headerbar-bg),#ffffff 10%);
    }
    .window-button:hover {
        background-color: color-mix(in srgb,var(--headerbar-bg),#ffffff 15%);
    }
    .window-button:active {
        background-color: color-mix(in srgb,var(--headerbar-bg),#ffffff 30.5%);
    }
    /* Force pure white icons for dark theme */
    .window-button img {
        filter: brightness(0) invert(1);
    }
}

/* Custom theme color overrides - Light theme (dark text on light background) */
body.custom-theme-color.theme-light .window-button {
    background-color: color-mix(in srgb,var(--headerbar-bg),#000000 6.5%);
}
body.custom-theme-color.theme-light .window-button:hover {
    background-color: color-mix(in srgb,var(--headerbar-bg),#000000 11.75%);
}
body.custom-theme-color.theme-light .window-button:active {
    background-color: color-mix(in srgb,var(--headerbar-bg),#000000 24%);
}
/* Force pure black icons for light theme */
body.custom-theme-color.theme-light .window-button img {
    filter: brightness(0);
}

/* Custom theme color overrides - Dark theme (light text on dark background) */
body.custom-theme-color.theme-dark .window-button {
    background-color: color-mix(in srgb,var(--headerbar-bg),#ffffff 10%);
}
body.custom-theme-color.theme-dark .window-button:hover {
    background-color: color-mix(in srgb,var(--headerbar-bg),#ffffff 15%);
}
body.custom-theme-color.theme-dark .window-button:active {
    background-color: color-mix(in srgb,var(--headerbar-bg),#ffffff 30.5%);
}
/* Force pure white icons for dark theme */
body.custom-theme-color.theme-dark .window-button img {
    filter: brightness(0) invert(1);
}
.window-button.flat {
    /* Transparent by default - only show background on hover */
    background-color: transparent !important;
    border-radius: 8px;
    transition: background-color 0.15s ease, color 0.15s ease;
    /* Square button matching GNOME native style */
    width: 28px;
    height: 28px;
    padding: 0;
    margin: 0;
}
.window-button.flat:disabled {
    opacity: 0.35;
    pointer-events: none;
}
@media (prefers-color-scheme: light) {
    .window-button.flat:hover:not(:disabled) {
        background-color: color-mix(in srgb,var(--headerbar-bg),#000000 8%) !important;
    }
    .window-button.flat:active:not(:disabled) {
        background-color: color-mix(in srgb,var(--headerbar-bg),#000000 16%) !important;
    }
}
@media (prefers-color-scheme: dark) {
    .window-button.flat:hover:not(:disabled) {
        background-color: color-mix(in srgb,var(--headerbar-bg),#ffffff 12%) !important;
    }
    .window-button.flat:active:not(:disabled) {
        background-color: color-mix(in srgb,var(--headerbar-bg),#ffffff 20%) !important;
    }
}

/* Flat button overrides for custom theme colors */
body.custom-theme-color.theme-light .window-button.flat:hover:not(:disabled) {
    background-color: color-mix(in srgb,var(--headerbar-bg),#000000 8%) !important;
}
body.custom-theme-color.theme-light .window-button.flat:active:not(:disabled) {
    background-color: color-mix(in srgb,var(--headerbar-bg),#000000 16%) !important;
}
body.custom-theme-color.theme-dark .window-button.flat:hover:not(:disabled) {
    background-color: color-mix(in srgb,var(--headerbar-bg),#ffffff 12%) !important;
}
body.custom-theme-color.theme-dark .window-button.flat:active:not(:disabled) {
    background-color: color-mix(in srgb,var(--headerbar-bg),#ffffff 20%) !important;
}
.window-button svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

/* Position back button closer to window edge */
.window-button.back {
    margin-left: -2px;
}

/*.window-button.close svg {*/
/*    width: 14px;*/
/*    height: 14px;*/
/*}*/

.draggable {
    -webkit-app-region: drag;
}

.no-drag {
    -webkit-app-region: no-drag;
}

::-webkit-scrollbar {
    display: none;
}
