:root {
    --table: #23313a;
    --panel: #1a252c;
    --ink: #f3efe7;
    --muted: #b8c2c8;
    --accent: #e0793f;
    --accent-ink: #1a1410;
    --radius: 0.5rem;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: var(--ink);
    background: var(--table);
}

* {
    box-sizing: border-box;
}

html,
body {
    /* No pull-to-refresh or bounce: a swipe that starts on the toolbar must not reload a half-done puzzle. */
    overscroll-behavior: none;
}

body {
    margin: 0;
}

[hidden] {
    display: none !important;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.75rem;
    min-height: 2.75rem;
    padding: 0 0.9rem;
    border: 1px solid #3c4d57;
    border-radius: var(--radius);
    color: var(--ink);
    background: #2c3d47;
    font: inherit;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}

.button:hover {
    background: #364955;
    border-color: var(--accent);
}

.button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.button.primary {
    border-color: var(--accent);
    color: var(--accent-ink);
    background: var(--accent);
    font-weight: 600;
}

.button.primary:hover {
    background: #ea8a52;
}

.button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* --- Picker --- */

.picker {
    max-width: 72rem;
    margin: 0 auto;
    padding: 1.5rem 1rem 0;
}

.picker-header {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.picker-header h1 {
    margin: 0;
    font-size: 2rem;
}

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

/* The saved game, at the top of the picker. */
.continue {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    max-width: 36rem;
    padding: 0.5rem 0.75rem 0.5rem 0.5rem;
    border: 2px solid var(--accent);
    border-radius: var(--radius);
    color: var(--ink);
    background: var(--panel);
    text-decoration: none;
}

.continue:hover,
.continue:focus-visible {
    background: #24333c;
}

.continue:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.continue-thumbnail {
    width: 6rem;
    height: 4.5rem;
    flex: none;
    border-radius: calc(var(--radius) / 2);
    background: #101a20;
    object-fit: contain;
}

.continue-text {
    flex: 1;
    font-weight: 600;
}

/* Today's puzzle, above the saved game: the same kind of card, with the day, the painting and how far you are. */
.daily {
    margin-bottom: 0.75rem;
}

.daily-text {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.daily-label {
    color: var(--accent);
    font-size: 0.85rem;
    font-weight: 600;
}

.daily-title {
    font-weight: 600;
}

.daily-status {
    color: var(--muted);
    font-size: 0.85rem;
}

.continue-go {
    color: var(--accent);
    font-size: 1.5rem;
}

.choose fieldset {
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
    gap: 1rem;
    margin: 1.25rem 0;
    padding: 0;
    list-style: none;
}

/* Each card is a label around a hidden radio button, so the gallery works like any radio group. */
.card {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    height: 100%;
    padding: 0.6rem;
    border: 2px solid transparent;
    border-radius: var(--radius);
    background: var(--panel);
    cursor: pointer;
}

.card:hover {
    border-color: #3c4d57;
}

.own {
    border-style: dashed;
    border-color: #3c4d57;
}

.card:has(input:checked) {
    border-color: var(--accent);
}

.card:has(input:focus-visible) {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.thumbnail {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 4 / 3;
    border-radius: calc(var(--radius) / 2);
    background: #101a20;
    object-fit: contain;
}

.own-placeholder {
    display: grid;
    place-items: center;
    color: var(--muted);
    font-size: 3rem;
}

.card-title {
    font-weight: 600;
}

/* The artist gets a line of their own, in the same ink as the title, above the smaller credit. */
.card-artist {
    margin-top: -0.2rem;
}

.credit {
    color: var(--muted);
    font-size: 0.85rem;
}

.credit a {
    color: inherit;
}

.own .button {
    align-self: flex-start;
    margin-top: auto;
}

/* The piece counts and Start button stay in view at the bottom while the gallery scrolls. */
.start-bar {
    position: sticky;
    bottom: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1rem;
    align-items: center;
    margin: 0 -1rem;
    padding: 0.75rem 1rem;
    background: var(--panel);
    box-shadow: 0 -0.5rem 1.5rem rgb(0 0 0 / 0.3);
}

.counts legend {
    float: left;
    margin: 0.75rem 0.75rem 0 0;
    padding: 0;
}

.count-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.count span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 3rem;
    min-height: 2.75rem;
    padding: 0 0.6rem;
    border: 1px solid #3c4d57;
    border-radius: 999px;
    background: #2c3d47;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
}

.count input:checked + span {
    border-color: var(--accent);
    color: var(--accent-ink);
    background: var(--accent);
    font-weight: 600;
}

.count input:focus-visible + span {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.count input:disabled + span {
    opacity: 0.35;
    text-decoration: line-through;
    cursor: not-allowed;
}

#start {
    margin-left: auto;
}

.note {
    flex-basis: 100%;
    margin: 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.note:empty {
    display: none;
}

.drop-zone {
    position: fixed;
    inset: 0.75rem;
    z-index: 10;
    display: grid;
    place-items: center;
    border: 3px dashed var(--accent);
    border-radius: var(--radius);
    background: rgb(26 37 44 / 0.85);
    font-size: 1.4rem;
    pointer-events: none;
}

/* --- Game --- */

.game {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    user-select: none;
    -webkit-user-select: none;
    /* The game handles every touch itself; a pinch that starts on the toolbar must not zoom the page. */
    touch-action: none;
}

.toolbar {
    display: flex;
    flex: none;
    gap: 0.5rem;
    align-items: center;
    padding: 0.4rem 0.5rem;
    overflow-x: auto;
    background: var(--panel);
    touch-action: pan-x; /* it may scroll sideways when the buttons don't fit */
}

.toolbar > * {
    flex-shrink: 0;
}

.timer,
.progress {
    padding: 0 0.5rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.progress {
    min-width: 6.5rem; /* room for "100% done" from the start, so the label beside it stays put as it grows */
    color: var(--muted);
}

/* The buttons on the right of the toolbar. */
.toolbar-end {
    display: flex;
    gap: inherit;
    align-items: center;
    margin-left: auto;
}

/* The picture's title and artist between the toolbar's two ends, like the label next to a painting. The title
   links to the picture's page at its museum. Both lines shrink with an ellipsis when the toolbar is short. */
.toolbar > .artwork {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    align-items: center;
    min-width: 0;
    margin: 0;
    line-height: 1.3;
}

.artwork-title {
    display: flex;
    max-width: 100%;
    min-width: 0;
    color: var(--ink);
    font-weight: 600;
    text-decoration: none;
}

.artwork-title:hover {
    text-decoration: underline;
}

.artwork-title:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.artwork-name,
.artwork-by {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.artwork-by {
    max-width: 100%;
    min-width: 0;
    color: var(--muted);
    font-size: 0.85rem;
}

/* Too narrow for the label beside the buttons: it gets a row of its own under them, on one line. A grid rather
   than wrapping, so the buttons never drop to a row of their own (where the fixed ⋯ menu would cover them):
   their row scrolls sideways when it doesn't fit, as before. */
@media (max-width: 56rem) {
    .toolbar {
        display: grid;
        grid-template-columns: auto auto auto 1fr;
        row-gap: 0.3rem;
    }

    .toolbar-end {
        grid-column: -2;
    }

    .progress {
        min-width: auto; /* the label isn't beside it here, so it needn't keep room */
    }

    .toolbar > .artwork {
        grid-row: 2;
        grid-column: 1 / -1;
        flex-direction: row;
        gap: 0.6rem;
        align-items: baseline;
        justify-content: center;
    }

    /* Short of room, the title gives way before the artist's name does. */
    .artwork-by {
        flex-shrink: 0;
        max-width: 60%;
    }
}

/* The area under the toolbar: the board, with the preview picture and the celebration on top of it. */
.table {
    position: relative;
    flex: 1;
    min-height: 0;
}

.board {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    background: var(--table);
    touch-action: none;
}

.preview {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    max-width: min(40%, 24rem);
    max-height: 40%;
    border: 3px solid var(--panel);
    border-radius: var(--radius);
    box-shadow: 0 0.5rem 1.5rem rgb(0 0 0 / 0.45);
    cursor: pointer;
}

.celebration {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* A toggle button that is on. */
.button[aria-pressed="true"] {
    border-color: var(--accent);
    background: #4a3426;
}

/* The ⋯ menu. Its items are fixed rather than absolute, so the toolbar's sideways scrolling can't clip them. */
.menu summary {
    list-style: none;
    font-size: 1.25rem;
}

.menu summary::-webkit-details-marker {
    display: none;
}

.menu[open] summary {
    border-color: var(--accent);
}

.menu-items {
    position: fixed;
    top: 3.75rem;
    right: 0.5rem;
    z-index: 5;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    min-width: 11rem;
    padding: 0.5rem;
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: 0 0.5rem 1.5rem rgb(0 0 0 / 0.45);
}

.menu-items .button {
    justify-content: flex-start;
}

.notice {
    position: absolute;
    left: 50%;
    bottom: 1.5rem;
    width: min(26rem, calc(100% - 2rem));
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: 0 0.5rem 2rem rgb(0 0 0 / 0.4);
    text-align: center;
    transform: translateX(-50%);
}

.notice p {
    margin: 0;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.actions:not(:empty) {
    margin-top: 0.75rem !important;
}

@media (max-width: 30rem) {
    .toolbar {
        grid-template-columns: auto auto 1fr; /* no column for the progress, which is hidden here */
        gap: 0.35rem;
    }

    .toolbar .button {
        padding: 0 0.45rem;
    }

    .timer {
        padding: 0 0.2rem;
    }

    .progress,
    .wide-only {
        display: none;
    }

    /* On a phone the counts fit on one row and the Start button (which names the count) gets its own. */
    .counts legend {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
    }

    .count span {
        min-width: 2.6rem;
        padding: 0 0.3rem;
    }

    #start {
        width: 100%;
        margin-left: 0;
    }
}
