header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 20px;

    position: relative;
    box-shadow: 0 2px 4px var(--overlay-shadow);
    background-color: var(--overlay-bg);
    padding: 10px;
    z-index: 1000;
    font-size: 25px;
    color: var(--overlay-text);
}

/* Logo & title */
header .brand {
    outline: unset;

    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding-right: 10px;
    width: max-content;
    line-height: 0;

    &:is(:hover, :focus-visible) > h1 {
        color: var(--overlay-subtext);
    }

    img {
        height: 40px;
        aspect-ratio: 1;
    }

    h1 {
        font-weight: unset;
        font-size: inherit;
        padding-left: 5px;
    }
}

/* Navigation */
header .navigation {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    gap: min(3vw, 35px);
    align-items: center;

    > a:hover, > a:focus-visible {
        color: var(--overlay-subtext);
    }
}

header .navigation > * {
    width: 6vw;
    min-width: max-content;
    max-width: 75px;

    height: max-content;
    text-align: center;
    outline: unset;

    /* Make space for underline below and keep text centered with same above */
    border-top: 3px solid transparent;
    border-bottom: 3px solid transparent;

    &.selected {
        border-bottom: 3px solid var(--accent-color);
    }
}

header .navigation .info {
    button {
        outline: unset;
        padding: unset;

        font-size: inherit;
        color: var(--overlay-text);

        cursor: default;
        anchor-name: --info-btn;
    }

    .menu {
        border: unset;
        padding: unset;

        inset: auto;
        position-anchor: --info-btn;
        top: anchor(bottom);
        left: anchor(center);
        translate: -50% 0;

        flex-direction: column;
        background-color: var(--dropdown-bg);
        border-radius: 10px;
        width: max-content;

        a {
            outline: unset;

            font-size: 20px;
            padding: 5px;

            &:hover, &:focus-visible {
                background-color: var(--overlay-subtext);
            }
        }
    }

    &:hover .menu, .menu:popover-open {
        display: flex;
    }

    &:hover button,
    &:focus-within button,
    &:has(.menu:popover-open) button {
        color: var(--overlay-subtext);
    }
}

/* Settings */
.settings {
    padding: unset;

    height: 35px;
    aspect-ratio: 1;
    
    border-radius: 50%;
    justify-self: right;
    align-self: center;
    anchor-name: --settings;

    &:hover, &:focus-visible, &.open {
        outline: 2px solid var(--accent-color);
        outline-offset: 1px;
    }

    &:hover:focus-visible, &.open:hover {
        outline-offset: 2px;
    }

    svg {
        width: 100%;
        height: 100%;
    }
}

.settings-menu {
    border: unset;
    color: unset;

    inset: auto;
    position-anchor: --settings;
    top: anchor(bottom);
    right: anchor(right);

    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);

    /* Transition opacity and only delay display and overlay */
    will-change: display, opacity, overlay;
    opacity: 0;

    transition:
        opacity 0.15s ease-in-out,
        display 0.15s linear allow-discrete,
        overlay 0.15s linear allow-discrete;

    flex-direction: column;
    align-items: center;

    margin-top: 20px;
    background-color: var(--overlay-bg);
    padding: 10px;
    justify-self: end;
    border-radius: 15px;
    width: max-content;
    overflow: visible;
    box-shadow: 0 1px 2px var(--overlay-shadow);

    &:popover-open {
        display: flex;
        opacity: 1;

        @starting-style {
            opacity: 0;
        }
    }

    hr {
        margin: 10px;
        width: 100%;
        border: none;
        border-top: 1px solid var(--overlay-subtext);
        box-sizing: border-box;
    }
}

.settings-menu .top-bar {
    width: 100%;
    display: flex;
    margin-bottom: 8px;

    .close {
        margin-left: auto;
    }
}

.settings-wrapper {
    display: grid;
    grid-template-columns: repeat(2, max-content);
    grid-auto-rows: 1em;
    gap: 5px 15px;

    width: max(100%, max-content);
    box-sizing: border-box;
    font-size: 18px;
    padding: 0 10px;
    margin-bottom: 5px;
    justify-self: start;
}

.settings-wrapper > :nth-child(even) {
    justify-self: end;
}

.settings-wrapper > label {
    pointer-events: none;
    line-height: 100%; /* Center text vertically */
}

.settings-wrapper .switch {
    height: calc(100% - 2px);
    aspect-ratio: 2/1;

    background-color: var(--accent-color);
    border-radius: 50vw;
    position: relative;
    display: flex;
    filter: grayscale();

    &:has(input:checked) {
        filter: unset;
    }
}

.settings-wrapper .switch input {
    margin: unset;

    width: 100%;
    height: 100%;

    position: absolute;
    opacity: 0;
    cursor: pointer;
    z-index: 5;

    &:is(:hover, :focus-visible) + .slider {
        opacity: 0.65;
    }
}

.settings-wrapper .switch .slider {
    height: calc(100% - 4px); /* Account for the margin */
    width: auto;
    aspect-ratio: 1;

    background-color: var(--overlay-text);
    border-radius: 50%;
    margin: 2px;
    transition: transform 150ms ease;
}

.settings-wrapper .switch input:checked + .slider {
    transform: translateX(calc(100% + 4px));
}

.settings-wrapper .accent-selector {
    height: 100%;
    aspect-ratio: 1;

    & > button {
        width: 100%;
        height: 100%;
        
        border-radius: 50%;
        background-color: var(--accent-color);

        &:hover, &:focus-visible {
            outline: 1px solid white;
        }
    }
}

.color-selector {
    border: unset;

    width: 400px;
    max-width: 75vh;
    box-sizing: border-box;

    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);

    /* Transition opacity and only delay display and overlay */
    will-change: display, opacity, overlay;
    opacity: 0;

    transition:
        opacity 0.15s ease-in-out,
        display 0.15s linear allow-discrete,
        overlay 0.15s linear allow-discrete;

    background-color: var(--overlay-bg);
    padding: min(2.5vw, 25px);
    border-radius: min(2.5vw, 25px);
    box-shadow: 0 1px 2px var(--overlay-shadow);
    position: fixed;
    overflow: hidden;
    flex-direction: column;

    &:popover-open {
        opacity: 1;
        display: flex;

        @starting-style {
            opacity: 0;
        }
    }
}

.color-selector .close {
    max-height: 6vw;
    position: absolute;
    top: min(4vw, 25px);
    right: min(4vw, 25px);
    transform: translate(50%, -50%);
}

.color-selector .wheel-wrapper {
    width: 100%;
    aspect-ratio: 1;

    position: relative;
    pointer-events: none;
}

.color-selector #color-wheel {
    width: 100%;
    height: 100%;

    /* Prevent interactions */
    pointer-events: initial;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    
    user-select: none;
    -webkit-user-select: none;

    background: conic-gradient(
        from 0deg,
        hsl(0, 100%, 60%),
        hsl(60, 100%, 60%),
        hsl(120, 100%, 60%),
        hsl(180, 100%, 60%),
        hsl(240, 100%, 60%),
        hsl(300, 100%, 60%),
        hsl(360, 100%, 60%)
    );

    border-radius: 50%;
    cursor: pointer;

    /* Make a hole through the middle (Percentages are radius based in a radial gradient) */
    /* 80% = 100% - (2 * 10%) */
    -webkit-mask: radial-gradient(
        farthest-side,
        transparent 80%,
        black 80%
    );

    mask: radial-gradient(
        farthest-side,
        transparent 80%,
        black 80%
    );
}

.color-selector #color-preview {
    /* 60% = 100% - 10% * 2 * 2 (Total width - wheel width * wheel and spacing * both sides) */
    width: 60%;

    min-width: max-content;
    aspect-ratio: 1;
    
    padding: 10px;
    box-sizing: border-box;

    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);

    display: flex;
    justify-content: center;
    align-items: center;

    border-radius: 50%;
    font-size: min(6.5vw, 50px);
}

.color-selector #color-handle  {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    
    width: 10%;
    aspect-ratio: 1;

    border-radius: 50%;
    border: min(0.35vw, 3px) solid var(--overlay-text);
    pointer-events: none;
}

.color-selector .reset {
    font-size: min(3.5vw, 20px);
    color: var(--overlay-text);

    align-self: center;
    margin-top: min(1.75vw, 15px);

    &:hover, &:focus-visible {
        color: var(--danger-color);
    }
}

#currency-selector {
    z-index: 100;
    position: relative;
}

#currency-selector .trigger {
    padding: unset;
    outline: unset;

    font-size: 18px;
    color: var(--overlay-text);

    &:hover, &:focus-visible {
        color: var(--overlay-subtext);
    }
}

#currency-selector .options {
    position: absolute;
    top: 1.5em;
    right: 0;

    background-color: var(--dropdown-bg);
    border-radius: 10px;
    overflow: hidden;
    overscroll-behavior: contain;

    /* Transition */
    will-change: max-height, visibility;

    max-height: 0;
    visibility: hidden;

    /* Only transition when opening or closing and not on resize */
    &.transition {
        /* Transition opacity, but only delay visibility when hidding tooltip */
        transition:
            max-height 0.2s ease,
            visibility 0.2s linear;
    }

    &.scrollable {
        overflow-y: scroll;
    }

    .option {
        outline: unset;

        text-align: left;
        text-wrap: nowrap;
        font-size: 18px;
        color: var(--overlay-text);

        width: 100%;
        cursor: pointer;
        padding: 5px;

        &:hover, &:focus-visible {
            background-color: var(--overlay-subtext);
        }

        &.selected {
            background-color: color-mix(in srgb, var(--accent-color) 75%, transparent);
        }
    }
}

#currency-selector.open .options {
    visibility: visible;
}

.sign-in {
    outline: unset;
    padding: unset;
    font-size: 18px;
    color: var(--overlay-subtext);

    &:hover, &:focus-visible {
        color: var(--text);
    }
}

@media(max-width: 1000px) {
    .settings-menu {
        border-radius: unset;
        margin: unset;

        /* Size */
        box-sizing: border-box;
        width: 100vw;
        height: 100vh;

        /* Position */
        position: fixed;
        top: 0;
        left: 0;

        .settings-wrapper  {
            flex: 1;
        }

        .currency-selector .options {
            right: unset;
            left: 50%;
            transform: translateX(-50%);
        }
    }
}

@media(max-width: 850px) {
    header > .title {
        display: unset;
        padding: unset;

        h1 {
            display: none;
        }
    }
}

@media(max-width: 500px) {
    header {
        font-size: 4vw;
        gap: 3vw;
    }

    header > .title > img,
    header > .settings {
        height: 9vw;
        width: 9vw;
    }
}