:root {
  color-scheme: dark light;
}
@media (prefers-color-scheme: dark) {
    * {
        --text-color: #faf2f5;
        --bg-color: #1a1a1d;
        --header-color: #37373d;
        --interactive-color: #266170;
        --button-color: color-mix(in oklab, var(--text-color) 30%, var(--interactive-color) 70%);
        --incorrect-color: rgb(240, 72, 108);
    }
}

@media (prefers-color-scheme: light) {
    * {
        --text-color: #180e12;
        --bg-color: #faf8f9;
        --header-color: #e0dbdd;
        --interactive-color: #76dfce;
        --button-color: color-mix(in oklab, var(--text-color) 30%, var(--interactive-color) 70%);
        --incorrect-color: rgb(211, 84, 101);
    }
}
html {
    /* Target font size: 16px at 800px */
    --ratio: calc(16 / 800);
    /* Fluid type, linearly interpolate and clamp between 480px and 800px */
    font-size: clamp(calc(var(--ratio) * 480px), calc(var(--ratio) * 100vw), calc(var(--ratio) * 800px));
}
body {
    font-family: "Segoe UI", Roboto, Arial, Helvetica, sans-serif;
    font-weight: normal;
    background-color: var(--bg-color);
    color: var(--text-color);
}
h1 {
    text-align: center;
    font-size: 3em;
    font-weight: bold;
}
h2 {
    font-size: 1.1em;
    font-weight: bold;
}
ul {
    padding-left: 1em;
}
button {
    cursor: pointer;
    padding: 0.05em 0.25em;
    background: none;
    border: none;
    color: var(--button-color);
}
button:hover,
button:focus-visible {
    color: var(--interactive-color);
}
main {
    width: min(800px, 100dvw);
    margin: 0 auto;
    padding-inline: 2em;
}
header {
    margin: 0 auto;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3rem;
    flex-wrap: wrap;
}

header .title {
    display: flex;
    flex-direction: column;
}
header .title h2 {
    font-weight: normal;
    font-size: 80%; 
    border-top:1px solid var(--text-color);
    padding:0.2em;
    &:not(.visible) {
        display: none;
    }
}
#grid {
    display: grid;
    margin: 0.5rem auto;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: clamp(2px, 2dvw, 1rem);
}
#grid > div {
    position: relative;
    width: 100%;
    height: 100%;
    aspect-ratio: 1/1;
    border-radius: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    text-wrap: balance;
}
#grid > div:has(*)
{
    box-shadow: 0px 0px 1rem color(from var(--text-color) srgb r g b / 0.05);
    cursor: pointer;
}
#grid > .header {
    padding: 1rem;
    background-color: var(--header-color);
    border:1px solid var(--bg-color);
    overflow: hidden;

    &:after{
        content:'?';
        position: absolute;
        top: 0.5rem;
        right: 0.5rem;
        width: 1rem;
        height: 1rem;
        line-height: 1rem;
        font-size: 70%;
        border-radius: 100%;
        background:var(--bg-color);
    }

    & .cell-content {
        font-weight: bold;
    }
}
#grid > .header:hover {
    border-color: var(--interactive-color);
    box-shadow: inset 0 0 0 0.3em var(--interactive-color);
    &:after{
        background: var(--interactive-color);
    }
}

#grid > .cell{
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    overflow: hidden;
    border:1px solid color(from var(--text-color) srgb r g b / 0.3);
    text-shadow: 0px 0px 2px var(--bg-color), 0px 0px 2px var(--bg-color);

    &:hover {
        border-color: var(--interactive-color);
        box-shadow: inset 0 0 0 0.3em var(--interactive-color);
    }
}
#grid > .cell .icon-container {
    position: absolute;
    z-index: -2;
    inset:0;
    overflow: hidden;
    & img {
        max-width: 100%;
        max-height: 100%;
    }
}
#grid > .cell.incorrect {
    color: var(--incorrect-color);
    & .icon-container img {
        filter: brightness(1.9) grayscale(100%);
        opacity: 0.2;
    }
}
#grid > .cell .name {
    z-index:-1;
    width: 100%;
    padding: 0.5rem;
    line-height: 1.1;
    background: linear-gradient(to bottom, transparent, var(--bg-color));
}

dialog {
    width: min(600px, 95dvw);
    background: var(--bg-color);
    color: var(--text-color);
    margin-top: 20dvh;
    max-height: 75dvh;
    border: 1px solid var(--text-color);
}
dialog::backdrop {
    background-color: color(from var(--bg-color) srgb r g b / 0.8);
}

dialog .close-dialog-button {
    font-size: 75%;
    position:absolute;
    top: 0.5em;
    right: 0.5em;
    background: none;
    border: none;
    cursor: pointer;
}

#help-dialog {
    padding: 1rem;
    padding-top: 0.5rem;
}
#howto-dialog ul {
    padding: 1rem;
    padding-top: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

#answer-dialog:open {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
#answer-input {
    font-size: 120%;
    padding: 0.5rem;
    margin-block: 0.5rem;
}
#answer-autocomplete-matches {
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}
#answer-autocomplete-matches .autocomplete-help {
    font-size: 80%;
    font-style: italic;
}
#answer-autocomplete-matches button {
    font-size: 120%;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 0.5rem;
    padding: 0.5rem;
    margin-block: 0.25rem;
    color: var(--text-color);
}
#answer-autocomplete-matches button .already-used {
    display: inline-block;
    margin-left: 0.5em;
    font-size: 75%;
    font-style: italic;
}
#answer-autocomplete-matches button {
    &:not(disabled) {
        &:hover, &:focus {
            background: var(--interactive-color);
        }
    }
    &:disabled {
        &:hover, &:focus {
            background: var(--header-color);
        }
    }
}
@media (pointer: fine) {
    /* On desktop,
    * if the list of matches isn't being hovered
    * and none of the matches are focused,
    * style the first match like it's focused 
    * (it will be picked by default upon pressing enter)
    */
    #answer-autocomplete-matches:not(:has(*:focus,*:hover)):not(:hover) button:first-child{
        &:not(disabled) {
            background: var(--interactive-color);
        }
        &:disabled {
            background: var(--header-color);
        }
    }
}
#answer-autocomplete-matches button img {
    width: 2.5em;
    height: 2.5em;
}
#answer-autocomplete-matches span.autocomplete-match {
    font-weight: bold;
}

#solutions-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1rem;
}
details {
    & summary {
        cursor: pointer;
        color: var(--button-color);
        &:hover {
            color: var(--interactive-color);
        }

        &::marker {
            color: var(--text-color);
        }
    }
}
#solutions-dialog .picked {
    font-weight: bold;
}
#solutions-share {
    width: 100%;
    display: flex;
    flex-direction: row;
    gap: 0.5em;
    align-items: center;
    & input {
        flex-grow: 1;
    }
}

#top-menu, #bottom-menu {
    display: flex;
    flex-direction: row;
    justify-content: flex-end;
    & .dot-separator {
        margin-inline: 0.1rem;
    }
    & > div {
        padding-inline: 0.25em;
    }
}
footer {
    margin-top: 2rem;
    margin-bottom: 1rem;
    text-align: center;
    font-size:80%;
}