@font-face {
    font-family: 'Source Sans Pro';
    font-display: swap;
    src: url('fonts/SourceSansPro-Regular.woff2') format('woff2');
}

@font-face {
    font-family: 'Source Sans Pro';
    font-weight: 600;
    font-display: swap;
    src: url('fonts/SourceSansPro-Semibold.woff2') format('woff2');
}

@font-face {
    font-family: 'Source Code Pro';
    font-display: swap;
    src: url('fonts/SourceCodePro-Regular.woff2') format('woff2');
}

@font-face {
    font-family: 'Source Code Pro';
    font-weight: 600;
    font-display: swap;
    src: url('fonts/SourceCodePro-Semibold.woff2') format('woff2');
}

html {
    --body-bg: #fff8f1;
    --header-bg: #fff8f1;
    --nav-bg: #f5e7da;
    --separator-color: #d9c0ad;
    --control-border: #98725e;
    --box-bg: #f6eadf;
    --button-bg: #f3dfce;
    --button-hover-bg: #ecd3bc;
    --code-bg: #edddcd;

    --heading-color: #37251d;
    --text-color: #3f2d25;
    --text-muted-color: #765849;
    --accent-color: #a3431c;
    --link-hover-color: #8e310f;

    --green: #1e6b39;
    --green-muted: #4d6a21;
    --yellow: #85610d;
    --orange: #a64517;
    --red: #b8342b;

    --max-page-width: 768px;

    color-scheme: light;
}

html[data-theme = 'dark'] {
    --body-bg: #211a17;
    --header-bg: #211a17;
    --nav-bg: #30241f;
    --separator-color: #604b40;
    --control-border: #ac8870;
    --box-bg: #2c221d;
    --button-bg: #3a2c24;
    --button-hover-bg: #4b382d;
    --code-bg: #3a2c24;

    --heading-color: #fff2e7;
    --text-color: #f3e5d7;
    --text-muted-color: #c4a997;
    --accent-color: #ffad75;
    --link-hover-color: #ffc99f;

    --green: #94cf9b;
    --green-muted: #c7d692;
    --yellow: #e7c775;
    --orange: #ffb17d;
    --red: #f6968a;

    color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
    /* Unfortunately needs to be duplicated to work both without JS and with manual switching in JS */
    html:not([data-theme = 'light']) {
        --body-bg: #211a17;
        --header-bg: #211a17;
        --nav-bg: #30241f;
        --separator-color: #604b40;
        --control-border: #ac8870;
        --box-bg: #2c221d;
        --button-bg: #3a2c24;
        --button-hover-bg: #4b382d;
        --code-bg: #3a2c24;

        --heading-color: #fff2e7;
        --text-color: #f3e5d7;
        --text-muted-color: #c4a997;
        --accent-color: #ffad75;
        --link-hover-color: #ffc99f;

        --green: #94cf9b;
        --green-muted: #c7d692;
        --yellow: #e7c775;
        --orange: #ffb17d;
        --red: #f6968a;

        color-scheme: dark;
    }
}

html {
    box-sizing: border-box;
}

*, *:before, *:after {
    box-sizing: inherit;
}

body {
    min-height: 100vh;
    font-family: 'Source Sans Pro', sans-serif;
    color: var(--text-color);
    background: var(--body-bg);
    line-height: 1.3;
    caret-color: var(--accent-color);
    scrollbar-color: var(--control-border) var(--body-bg);
}

::selection {
    color: var(--body-bg);
    background: var(--accent-color);
}

pre, code {
    font-family: 'Source Code Pro', monospace;
    font-size: 90%;

    color: var(--text-color);
    background: var(--code-bg);
    padding: .1em .3em;
}

pre {
    /* inline-block has almost the same effect, but at the same time makes the
       <li> marker move its position for some reason, which inline-flex doesn't
       do */
    display: inline-flex;
}

h3 {
    margin: 0 0 .75em;
    font-size: 120%;
    font-weight: 600;
}

button, a.button {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    outline: none;
    border: none;

    width: 1.8rem;
    height: 1.8rem;
    padding: 0;

    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;

    border-radius: 3px;
    background-color: var(--button-bg);
    box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.1);
    transition: background-color,box-shadow .2s;
}

button:hover,
button.active,
a.button:hover,
a.button.active {
    background-color: var(--button-hover-bg);
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.1);
}

button svg,
a.button svg {
    width: 1.15rem;
    height: 1.15rem;
}

button svg path,
a.button svg path {
    fill: var(--text-color);
}

header, nav.explore {
    position: fixed;
    width: 100%;
    border-bottom: solid 1px var(--separator-color);
}

header {
    top: 0;
    height: 3.5rem;
    background: var(--header-bg);
    z-index: 10;
}

header .inner,
nav.explore .inner {
    max-width: var(--max-page-width);
    height: 100%;
    margin: 0 auto;
    display: flex;
    align-items: center;
    padding: 0 1rem;
}

.caniuse {
    width: calc(100% - 6.2rem);
    display: flex;
    font-size: 110%;
    padding: .5rem;
    color: var(--heading-color);
    align-items: flex-end;
}

.caniuse input {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    outline: none;
    border: none;
    border-radius: 0;
    background: none;

    flex: 1;
    margin: 0 .6em;
    position: relative;
    min-width: 6em;
    height: 1.5rem;
    bottom: -1px;
    color: var(--text-color);
    border-bottom: 1px solid var(--text-muted-color);
}

header nav {
    width: 6.2rem;
    height: 100%;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    position: relative;
}

header nav button {
    margin-left: .5rem;
}

.menu {
    position: absolute;
    margin: 0;
    padding: 0;
    top: 3.15rem; /* 2.65rem from top to lower button edge + .5rem margin */
    right: 0;
    width: 10rem;

    list-style: none;
    background-color: var(--button-hover-bg);
    box-shadow: 0 2px 3px 0 rgba(0, 0, 0, 0.1);

    -moz-user-select: none;
    -webkit-user-select: none;
    -ms-user-select: none;
    -o-user-select: none;
    user-select: none;
}

.menu, .menu a, .menu a:hover {
    color: var(--heading-color);
}

.menu:not(.active) {
    display: none;
}

.menu::before {
    content: '';
    position: absolute;
    right: .4rem;
    top: calc(-1rem + 1px);
    border: solid .5rem transparent;
    border-bottom-color: transparent;
    border-bottom-color: var(--button-hover-bg);
}

.menu a {
    padding: .45em .6em;
}

.menu li:not(:last-child) {
    border-bottom: solid 1px var(--text-muted-color);
}

.menu a {
    display: flex;
    align-items: center;
    text-decoration: underline;
    cursor: pointer;
}

.menu a svg {
    height: 17px;
    margin-right: .4em;
}

.menu path {
    fill: var(--text-color);
}

nav.explore {
    top: 3.5rem;
    left: 0;
    height: 2.5rem;
    font-size: 80%;
    background: var(--nav-bg);
    z-index: 5;
}

nav.explore a {
    height: 100%;
    line-height: 1.5rem;
    padding: .5rem 1rem;
    border: 0 solid var(--separator-color);
    text-decoration: none;
}

nav.explore a:hover,
nav.explore a.active {
    background-color: var(--button-bg);
}

nav.explore a:first-child {
    border-left-width: 1px;
}

nav.explore a {
    border-right-width: 1px;
}

a {
    color: var(--text-color);
    transition: color .2s;
}

a:hover {
    color: var(--link-hover-color);
}

a, button {
    cursor: pointer;
}

.muted {
    color: var(--text-muted-color);
}

.search-results > .box.muted {
    width: 100%;
    max-width: 32rem;
    margin: 3rem auto;
    padding: 2rem;
    text-align: center;
}

.search-results > .box.muted::before {
    content: '';
    display: block;
    width: 96px;
    aspect-ratio: 3 / 2;
    margin: 0 auto 1rem;
    background: url('/ferris.svg') center / contain no-repeat;
}

.page {
    max-width: var(--max-page-width);
    margin: 0 auto;
    padding: 3.5rem 1rem 1rem;
}

.page > :first-child:not(nav) {
    margin-top: 1rem;
}

.page nav.explore + * {
    margin-top: 3.5rem;
}

.feature-list:first-child {
    margin-top: -1rem;
}

.feature-list {
    margin-bottom: -1rem;
}

.search-results {
    margin-top: 2rem;
}

.reference-heading {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--separator-color);
}

.reference-heading h1 {
    margin: 0;
    color: var(--heading-color);
    font-size: clamp(1.6rem, 3vw, 2.25rem);
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -.025em;
}

.reference-heading p {
    margin: .5rem 0 0;
    color: var(--text-muted-color);
    font-size: .85rem;
    line-height: 1.6;
}

.search-results .feature-list {
    margin: 0;
}

.search-results .feature-entry {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 6rem;
    align-items: start;
    gap: 1rem;
    margin: 0;
    padding: 1rem 0;
    border-bottom: 1px solid var(--separator-color);
}

.search-results .feature-entry .box {
    width: auto;
    padding: 0;
    background: none;
}

.search-results .title {
    overflow: visible;
}

.search-results .title h3 {
    margin: 0;
    font-size: .95rem;
    font-weight: 400;
    line-height: 1.45;
}

.search-results .title code {
    padding: 0;
    background: none;
}

.search-results .flag {
    color: var(--text-muted-color);
    font-size: .8rem;
    line-height: 1.6;
}

.search-results .version {
    width: auto;
    padding: 0;
    font-size: .85rem;
    line-height: 1.6;
    text-align: right;
}

.search-results .version a {
    text-underline-offset: .2em;
}

.feature-entry {
    display: flex;
    margin: 1rem 0;
}

.box {
    width: calc(100% - 6.2rem);
    padding: .5rem;
    background: var(--box-bg);
    position: relative;
}

.box > :last-child {
    margin-bottom: 0;
}

.box > :last-child > :last-child {
    margin-bottom: 0;
}

.page > .button {
    margin-bottom: 1em;
}

.title {
    overflow: hidden;
    text-overflow: ellipsis;
}

a.title {
    display: block;
    text-decoration: none;
}

a.title:hover {
    color: var(--text-color);
    text-decoration: underline;
}

.version {
    text-align: right;
    width: 6.2rem;
    flex-shrink: 0;
    padding: .6rem 0;
}

.version a {
    color: inherit;
}

.stable {
    color: var(--green);
}

.beta {
    color: var(--green-muted);
}

.nightly {
    color: var(--yellow);
}

.none {
    color: var(--orange);
}

.info {
    display: grid;
    grid-template-columns: max-content 1fr;
    grid-gap: 0 .5rem;
}

.info > :nth-child(odd) {
    color: var(--text-muted-color);
}

.flag {
    margin: .5rem 0;
}

.links {
    display: flex;
    padding: 0;
    list-style: none;
    margin-top: .6em;
    margin-bottom: .1em;
}

.links:empty {
    margin: 0;
}

.links li {
    padding-right: .5em;
}

.items {
    margin-top: .6rem;
}

.items ul {
    margin: .4rem 0 0;
    padding-left: 2rem;
}

h4 {
    margin: 1em 0;
}

p {
    margin: .65em 0;
}

.about ul {
    margin: .3em 0;
}

input[type = 'search']::-webkit-search-decoration,
input[type = 'search']::-webkit-search-cancel-button,
input[type = 'search']::-webkit-search-results-button,
input[type = 'search']::-webkit-search-results-decoration {
    display: none;
}

/* Shared navigation stays usable on the atlas and the existing reference pages. */
header .inner {
    max-width: 1440px;
    gap: 1.5rem;
    padding: 0 2rem;
}

.site-brand {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    flex-shrink: 0;
    font-weight: 600;
    text-decoration: none;
}

.site-brand::before {
    content: '';
    flex: 0 0 36px;
    width: 36px;
    aspect-ratio: 3 / 2;
    background: url('/ferris.svg') center / contain no-repeat;
}

.caniuse {
    flex: 1;
    align-items: center;
    width: auto;
    min-width: 0;
    max-width: 660px;
    margin-left: auto;
}

.caniuse input {
    min-width: 0;
    min-height: 44px;
}

.caniuse input::placeholder {
    color: var(--text-muted-color);
    opacity: 1;
}

header nav {
    width: auto;
    flex-shrink: 0;
}

header nav > button {
    width: 40px;
    height: 40px;
    margin: 0;
}

.menu {
    width: 13rem;
}

.menu-action {
    width: 100%;
    height: auto;
    min-height: 44px;
    flex-direction: row;
    justify-content: flex-start;
    gap: .4em;
    padding: .45em .6em;
    margin: 0;
    background: none;
    box-shadow: none;
    color: var(--heading-color);
}

.menu a {
    min-height: 44px;
}

.caniuse .search-clear {
    width: auto;
    height: 36px;
    padding: 0 .5rem;
    background: none;
    box-shadow: none;
    color: var(--text-color);
    font-size: .75rem;
}

:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 3px;
}

.caniuse input:focus-visible {
    outline: 2px solid var(--text-color);
    outline-offset: 3px;
}

header button:focus-visible {
    outline: 2px solid var(--text-color);
    outline-offset: 3px;
}

.info > *,
.box {
    min-width: 0;
}

.page > .box {
    width: 100%;
}

.links {
    flex-wrap: wrap;
    gap: .5rem 0;
}

.title,
.flag code,
.items code {
    overflow-wrap: anywhere;
}

@media (max-width: 700px) {
    header {
        height: 4.5rem;
    }

    header .inner {
        padding: 0 1rem;
        gap: .75rem;
    }

    .site-brand {
        gap: .375rem;
        font-size: .85rem;
    }

    .site-brand::before {
        flex-basis: 28px;
        width: 28px;
    }

    .caniuse {
        width: 100%;
        margin-left: 0;
        padding: 0;
        font-size: .85rem;
    }

    .caniuse label {
        position: absolute;
        width: 1px;
        height: 1px;
        clip-path: inset(50%);
        overflow: hidden;
    }

    .caniuse input {
        margin-left: 0;
        width: 100%;
    }

    .page {
        padding-top: 4.5rem;
    }

    nav.explore {
        top: 4.5rem;
    }

    .feature-entry {
        flex-direction: column;
    }

    .feature-entry .box {
        width: 100%;
    }

    .version {
        text-align: left;
        width: auto;
        padding: .4rem .5rem;
    }
}
