:root {
    --ink: #f4f1e8;
    --muted: #a29c90;
    --page: #1f1c18;
    --panel: #262220;
    --line: #3a352f;
    --board-light: #f0eed6;
    --board-dark: #7d945d;
    --accent: #e8c25a;
    --accent-deep: #c39a35;
    /* One colour the palette did not have: a mark for a move that gave the game away.
       Gold already means "the engine likes this" on both arrows and every on-state. */
    --bad: #d96a52;
}

/* One scale for the whole page. Every size in this stylesheet is in rem, so the root
   font-size is the size of the app: the board, the header, the buttons, the type, and the
   shelves grow and shrink together instead of the board shrinking alone inside a fixed
   frame. Width decides it, and only width: a short window scrolls rather than handing the
   board a smaller square, because the board is the game and shrinking it is the worst
   thing the layout can do to it.
   shortcut: the floor keeps type readable on a very narrow window, where the board is then
   the width of the screen and the frame is proportionally larger; revisit if a phone
   narrower than about 24rem ever needs the frame to shrink with it. */
html {
    font-size: clamp(0.8rem, calc(96vw / 34), 1rem);
}

html,
body {
    margin: 0;
    min-height: 100%;
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    background: var(--page);
    color: var(--ink);
    -webkit-text-size-adjust: 100%;
}

#app {
    min-height: 100vh;
    display: flex;
    justify-content: center;
}

:root {
    /* One line for a tray of taken pieces. Reserved on every screen and in the loading
       view, so a capture cannot change the shell's height and push the board. */
    --tray: 1.75rem;
    /* Five gaps and the padding above and below a 544-pixel board are the whole frame
       around it. At 0.9rem the shell needed 822 pixels and a laptop window has 809, so the
       page scrolled by the height of the legend's reserved line, which is empty while the
       marks are off: a scrollbar over nothing. The gap and the padding here are the 48
       pixels that bought it back. Below a window 776 pixels tall the page still scrolls, on
       purpose: the board keeps its size and the scrollbar moves in rather than the board
       shrinking. */
    --shell-gap: 0.7rem;
}

.shell {
    width: min(92vw, 34rem);
    display: flex;
    flex-direction: column;
    gap: var(--shell-gap);
    padding: 0.8rem 0 1.2rem;
    margin: auto;
}

/* A row of pieces that are out of the game: on the line it never leaves, in value
   order, drawn smaller than a square's piece so the board stays the thing you see.
   The shelf is light on purpose. On the page's own background a taken black piece is
   a black shape on near black, which is the defect this shelf fixes: black reads at
   17:1 on the light square colour, and a white piece keeps the dark outline its
   artwork already carries. verify.sh holds the ratio. */
.tray {
    display: flex;
    align-items: center;
    gap: 0.1rem;
    height: var(--tray);
    padding: 0 0.3rem;
    overflow: hidden;
    border-radius: 0.35rem;
    background: var(--board-light);
}

/* The material count, at the far end of the shelf a player already looks at. Pushed by
   the row it is in rather than positioned, so it cannot disagree with the shelf's
   height. Nothing is drawn for an empty tray, so an opening board stays quiet. */
.tray-score {
    margin-left: auto;
    padding-left: 0.4rem;
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
    color: var(--page);
}

.tray img {
    width: calc(var(--tray) - 0.25rem);
    height: calc(var(--tray) - 0.25rem);
    /* Lifts the white pieces off the cream, and keeps their dark outlines reading.
       No opacity: a dimmed piece is a piece you cannot see, which was the complaint. */
    filter: drop-shadow(0 1px 1px rgb(0 0 0 / 45%));
}

h1 {
    font-size: 2rem;
    margin: 0;
    letter-spacing: -0.02em;
}

h1:focus {
    outline: none;
}

.lede {
    margin: 0;
    color: var(--muted);
}

a {
    color: var(--accent);
}

/* Game bar */

/* The header holds the level and the actions, nothing else. The status lives under
   the board, in a slot with its own reserved height, so the shell's vertical
   centring cannot turn a changing line into a moving board. */
.bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.75rem;
    min-height: 2.5rem;
}

.opponent {
    font-weight: 600;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* The level is a choice while the game runs, and a label once it is done. Same
   slot and same height either way, so the board does not move on the change. */
.level-select {
    justify-self: start;
    max-width: 100%;
    height: 2rem;
    padding: 0 1.6rem 0 0.6rem;
    border: 1px solid var(--line);
    border-radius: 0.4rem;
    background-color: var(--panel);
    color: var(--ink);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    /* Centred rather than placed from the top: a touch screen makes this list 44 pixels
       tall, and an arrow 13 pixels from the top of a taller box points at nothing. */
    background-position: calc(100% - 0.9rem) center, calc(100% - 0.55rem) center;
    background-size: 0.35rem 0.35rem, 0.35rem 0.35rem;
    background-repeat: no-repeat;
}

.level-select:hover,
.level-select:focus-visible {
    border-color: var(--accent);
    outline: none;
}

.level-select:disabled {
    color: var(--muted);
    cursor: default;
    background-color: transparent;
    border-color: transparent;
    background-image: none;
    padding-left: 0;
}

.ghost {
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--line);
    border-radius: 0.5rem;
    background: none;
    color: var(--muted);
    font: inherit;
    cursor: pointer;
}

.actions {
    display: flex;
    gap: 0.4rem;
    justify-self: end;
}

.ghost:disabled {
    color: var(--muted);
    opacity: 0.5;
    cursor: default;
}

.ghost:disabled:hover,
.ghost:disabled:focus-visible {
    border-color: var(--line);
    color: var(--muted);
}

.ghost:hover,
.ghost:focus-visible {
    border-color: var(--accent);
    color: var(--ink);
    outline: none;
}

/* Board */

.board {
    position: relative;
    display: grid;
    /* Both axes are explicit and free of content influence: with rows left auto,
       a row of pieces grew taller than an empty row and the cells stopped being
       square. minmax(0, 1fr) refuses to let an image widen or heighten its track. */
    grid-template-columns: repeat(8, minmax(0, 1fr));
    grid-template-rows: repeat(8, minmax(0, 1fr));
    aspect-ratio: 1;
    /* Capped by the viewport height, not the width alone, so a landscape phone
       still holds the whole board without scrolling. */
    width: min(96vw, 34rem);
    border-radius: 0.5rem;
    overflow: hidden;
    box-shadow: 0 18px 40px rgb(0 0 0 / 45%);
    /* A finger on the board is a piece being dragged, never a page being panned.
       Without this the browser claims the gesture and cancels the drag with
       pointercancel on the one device where dragging matters most.
       shortcut: the board refuses touch-action so a drag can own a finger, revisit if
       pinch-zoom over the board is ever wanted, which needs per-gesture touch-action
       support the browsers do not have. */
    touch-action: none;
    /* A drag must not paint a text selection across the squares. */
    user-select: none;
    -webkit-user-select: none;
}

.square {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 0;
    padding: 0;
    border: 0;
    margin: 0;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.square.light {
    background: var(--board-light);
}

.square.dark {
    background: var(--board-dark);
}

.square img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 4%;
    box-sizing: border-box;
    pointer-events: none;
    user-select: none;
}

.square.selected {
    box-shadow: inset 0 0 0 3px var(--accent);
}

.square.target::after {
    content: "";
    position: absolute;
    width: 26%;
    height: 26%;
    border-radius: 50%;
    background: rgb(0 0 0 / 28%);
}

.square.target:has(img)::after {
    width: 86%;
    height: 86%;
    border-radius: 10%;
    background: none;
    box-shadow: inset 0 0 0 4px rgb(0 0 0 / 28%);
}

.square.locked {
    cursor: not-allowed;
}

/* The verdict on the move just played, over the square the piece landed on. Out of flow,
   so a mark cannot resize a cell or move the board; the disc supplies its own background,
   so the glyph's contrast is the same on a light square and a dark one. */
.mark {
    display: grid;
    place-items: center;
    aspect-ratio: 1;
    border-radius: 50%;
    /* The ring separates the disc from a square, or from an arrow, of its own colour. */
    box-shadow: 0 0 0 1px rgb(0 0 0 / 30%);
    pointer-events: none;
}

/* On the board: in the corner of the square the move landed on, over the pieces and over
   the computer's arrow, because the arrow is a line and the mark is the thing being read. */
.square .mark {
    position: absolute;
    top: 2%;
    right: 2%;
    width: 30%;
    z-index: 1;
}

.mark svg {
    width: 72%;
    height: 72%;
}

.mark svg polygon,
.mark svg circle {
    fill: var(--page);
}

.mark svg path,
.mark svg polyline,
.mark svg line {
    fill: none;
    stroke: var(--page);
    stroke-width: 4;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.mark.best {
    background: var(--accent);
}

.mark.good {
    background: var(--muted);
}

.mark.dubious {
    background: var(--accent-deep);
}

.mark.bad {
    background: var(--bad);
}

/* The computer's last move, drawn over the board: a shaft between the square
   centres with a head on the destination. Accent colour, mostly opaque, so it reads
   on both square colours, and it never takes a click. */
/* What the four marks mean. One reserved line under the status, empty while the marks are
   off, so the switch cannot move the board. The discs are smaller than the ones on the
   board and behave like punctuation in front of the word they explain. */
.legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.25rem 0.9rem;
    min-height: 1.3rem;
    margin: 0;
    font-size: 0.8rem;
    color: var(--muted);
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.legend .mark {
    width: 1.05rem;
}

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

.engine-arrow line {
    stroke: var(--accent);
    stroke-width: 14;
    stroke-opacity: 0.85;
    stroke-linecap: round;
}

.engine-arrow polygon {
    fill: var(--accent);
    fill-opacity: 0.85;
}

/* The suggested move: the same geometry, drawn as a dashed, thinner, dimmer arrow so
   that "it played there" and "you could play there" cannot be confused, including for
   someone who cannot tell the two colours apart. */
.hint-arrow line {
    stroke-width: 9;
    stroke-opacity: 0.75;
    stroke-dasharray: 26 20;
}

.hint-arrow polygon {
    fill-opacity: 0.75;
}

/* Read by a screen reader and invisible on the page: the suggested move is drawn as an
   arrow, which says nothing aloud. */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* A switch that is on says so with the accent colour and a filled border, not only with
   `aria-pressed`. */
.ghost.on {
    border-color: var(--accent);
    color: var(--accent);
}

/* The two toggles in the header are symbols. A switch you hold on is a state, and a word
   for it costs width the header does not have on a phone: the level list takes what the
   actions leave. The glyph is decorative and the name lives on the button. */
.ghost.icon {
    display: grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
}

.ghost.icon svg {
    width: 1.15rem;
    height: 1.15rem;
}

.ghost.icon svg path,
.ghost.icon svg rect {
    fill: currentColor;
}

.ghost.icon svg .cut {
    fill: none;
    stroke: var(--page);
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* The piece in the air, under the pointer and out of the way of the events that
   track it. Sized and placed from the board's own measurement, so it is the same
   piece at any board size. */
.drag-piece {
    position: absolute;
    z-index: 2;
    pointer-events: none;
    will-change: left, top;
}

/* The square the piece was taken from: still there, visibly emptied. */
.square.lifted img {
    opacity: 0.25;
}

.status {
    margin: 0;
    min-height: 1.6rem;
    text-align: center;
    color: var(--muted);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.status.over {
    color: var(--accent);
    font-weight: 600;
}

.error {
    margin: 0;
    color: #e8897c;
}

/* Blazor's own chrome: the loading screen and the error bar */

#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgb(0 0 0 / 20%);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.blazor-error-boundary {
    padding: 1rem;
    color: white;
    background: #b32121;
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}

/* The loading screen is the board itself, filling one square at a time as the
   runtime arrives. The squares are the board's own two colours and the filled ones
   take the accent, so the wait looks like the product instead of a spinner. */
/* The same board the game shows, in the same geometry: the shell's width, square,
   one radius, one shadow, no gap. The wait must not change the size of the thing it
   is standing in for. */
.loading-board {
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    grid-template-rows: repeat(8, minmax(0, 1fr));
    aspect-ratio: 1;
    width: min(92vw, 34rem);
    border-radius: 0.5rem;
    overflow: hidden;
    box-shadow: 0 18px 40px rgb(0 0 0 / 45%);
}

.loading-board span {
    display: grid;
    place-items: center;
    min-width: 0;
    min-height: 0;
}

.loading-board span img {
    width: 92%;
    height: 92%;
    opacity: 0;
    transform: scale(0.6);
    transition: opacity 0.2s ease-out, transform 0.2s ease-out;
}

.loading-board span.spawned img {
    opacity: 1;
    transform: scale(1);
}

.loading-board .light {
    background: var(--board-light);
}

.loading-board .dark {
    background: var(--board-dark);
}

/* The loading view is the game view with the pieces still arriving: the same shell,
   the same header row with placeholders, the same board. Nothing moves or resizes
   when the app takes over, which is the whole point of the screen. */
.loading-placeholder {
    visibility: hidden;
}

/* The dynamic viewport follows the mobile browser chrome, which is what a phone
   actually gives the page. The plain vh fallback above keeps older browsers working. */
@supports (height: 100dvh) {
    html {
        font-size: clamp(0.8rem, calc(96vw / 34), 1rem);
    }

    .board,
    .loading-board {
        width: min(96vw, 34rem);
    }
}

@media (max-width: 30rem) {
    /* A phone gets a taller shelf, because at arm's length 24-pixel pieces are a guess
       rather than a picture. --chrome reads this, so the board gives up exactly this
       much height and no more. */
    :root {
        --tray: 2.25rem;
    }

    h1 {
        font-size: 1.6rem;
    }

    .shell {
        width: min(96vw, 34rem);
    }

    /* Two rows: the level list across the first, the actions under it. One row cannot
       hold a 44-pixel list beside four 44-pixel actions at this width, and the control
       that gets squeezed is the one a thumb has to hit. The loading screen's placeholder
       controls carry the same classes, so they take the same rows and the board does not
       move when the app takes over. */
    .bar {
        grid-template-columns: minmax(0, 1fr);
        gap: 0.45rem;
    }

    .level-select {
        justify-self: stretch;
        width: 100%;
    }

    .actions {
        justify-self: stretch;
        justify-content: flex-end;
        flex-wrap: wrap;
    }
}

/* The build the page came from, in the corner, for whoever has to answer "which version
   are you running?". Fixed and out of the flow, so it cannot move the board the way a row
   would, and unable to take a click, so it cannot swallow a drag or a tap. Muted like the
   status line rather than bright: it is the answer to a question, not something to read
   while playing. */
.version {
    position: fixed;
    right: 0.5rem;
    bottom: 0.4rem;
    font-size: 0.8rem;
    line-height: 1;
    color: var(--muted);
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
}

/* A phone is not a small window, and treating it as one is what made the page look
   miniature on the Pixel it was tested on: the type scale is derived from the board's
   width, so on a phone it sits on its 0.8rem floor and the header's words came out at 12.8
   pixels inside finger-sized boxes. A coarse pointer is the one signal that says "phone",
   so a phone gets the full type size, and the controls grow with the words to 48 pixels,
   which is one square of the board there and what Android's own controls use. 48 is in
   pixels for the same reason 44 was: a finger is not a type size.
   The gap between the rows and the bottom padding give back the height the bigger type
   takes, so a phone that fitted its window before still fits. The block sits at the end of
   the stylesheet on purpose: the viewport block above also sets the root size, and a later
   rule with the same specificity would undo this one. */
@media (pointer: coarse) {
    html {
        font-size: 1rem;
    }

    .shell {
        --shell-gap: 0.55rem;
        padding-bottom: 1rem;
    }

    /* Google asks for about 8 pixels between two touch targets, and at a 16-pixel root the
       0.4rem the buttons had came to 6.4. A distance a finger needs is not a type size, so
       these two are in pixels as well. */
    .bar {
        gap: 8px;
    }

    .actions {
        gap: 8px;
    }

    .level-select {
        height: 48px;
    }

    .ghost {
        min-height: 48px;
        padding: 0 0.95rem;
    }

    /* The one control on the not-found page is a link: its text box is 18 pixels tall, and
       Google asks for 48. The box grows, the text stays where it was and says what it said. */
    .shell a {
        display: flex;
        align-items: center;
        min-height: 48px;
    }

    .ghost.icon {
        width: 48px;
        height: 48px;
        padding: 0;
    }

    .ghost.icon svg {
        width: 1.5rem;
        height: 1.5rem;
    }
}
