/* ==========================================================================
   Puzzle page (/Puzzler and every page that renders _Puzzler.cshtml)
   Layout, components and motion for the UX refresh. Spec: design SPEC.md c + d.
   Everything is scoped under html.ux-puzzle (added by _Puzzler.cshtml) and only
   uses theme vars (--t-*) and tokens (--ux-*) from ux-tokens.css.
   ========================================================================== */

/* ---------- Sizing ---------- */
html.ux-puzzle {
    --board-size: clamp(320px, min(calc(100svh - 250px), calc(100vw - 32px)), 760px);
    --ux-dock-h: 72px;
    /* Board top corners: as the pre-redesign board (chess_board.css .chess-board 5px; square in portrait <= 1200px,
       site.css). Only the dock's bottom corners keep the card radius. */
    --ux-r-board-top: 5px;
}

@media screen and (max-width: 1200px) and (max-aspect-ratio: 1/1) {
    html.ux-puzzle {
        --ux-r-board-top: 0px;
    }
}

@media (min-width: 1200px) {
    html.ux-puzzle {
        --board-size: clamp(420px, min(calc(100svh - 250px), calc(100vw - 2 * 16px - 300px - 44px)), 860px);
    }
}

/* Phones: full-bleed board and dock, edge to edge with square corners (as before the redesign). */
@media (max-width: 767.98px) {
    html.ux-puzzle {
        --board-size: 100vw;
        --ux-r-board: 0px;
        --ux-r-board-top: 0px;
        --ux-dock-h: 64px;
    }
}

/* ---------- Stage ---------- */
html.ux-puzzle #ux-stage {
    max-width: 100%;
}

html.ux-puzzle #ux-stage > .center-container {
    margin-top: 0 !important;
    align-items: flex-start;
}

html.ux-puzzle #chess-board-container.chess-board-container {
    width: var(--board-size) !important;
    max-width: none;
    flex: 0 0 auto;
}

@media (min-width: 1200px) {
    html.ux-puzzle #ux-stage .ad-sidebar-responsive,
    html.ux-puzzle #ux-stage .second-ad-container {
        /* lines up with the stats panel: clear of the 32px stats tab plus a 12px gap */
        margin-left: 44px;
    }
}

/* ---------- Focus mode (desktop) ----------
   The board is centred on the screen and grows to fill the height. The navbar goes (it was only faded
   before, so it still took space), and the right rail (ad + stats panel) leaves the flow and hangs off the
   board's right edge, so it no longer pushes the board off centre. The width term keeps room for that rail
   (16px gutter + 44px gap + 300px) on both sides. Height term: everything stays on screen, i.e. top row 64px +
   dock + XP progress bar 87px + leader ad 102px + 13px breathing room = 266px + dock. The max() with the normal
   desktop size (first --board-size) means focus mode never shrinks the board on shorter screens. */
@media (min-width: 1200px) {
    html.ux-puzzle.ux-focus {
        --board-size: clamp(420px, min(max(min(calc(100svh - 250px), 860px), calc(100svh - 266px - var(--ux-dock-h))), calc(100vw - 2 * 360px)), 1400px);
    }

    html.ux-puzzle.ux-focus #navbar {
        display: none !important;
    }

    html.ux-puzzle.ux-focus #ux-stage > .center-container {
        position: relative;
    }

    html.ux-puzzle.ux-focus #ux-stage .ux-rail {
        position: absolute;
        left: 100%;
        top: 0;
    }

    html.ux-puzzle.ux-focus .ux-toprow {
        margin-top: 12px;
    }
}

/* ---------- Top row (Focus / Theme) ---------- */
html.ux-puzzle .ux-toprow {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    width: var(--board-size);
    max-width: 100%;
    margin: 16px 0 12px;
}

html.ux-puzzle .ux-pill {
    height: 40px;
    padding: 0 16px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 0;
    border-radius: var(--ux-r-pill);
    font: 15px/1 var(--ux-font);
    letter-spacing: 0.01em;
    white-space: nowrap;
    color: var(--t-on-surface);
    background: color-mix(in srgb, var(--t-accent-1) 62%, transparent);
    box-shadow: var(--ux-inset-top), var(--ux-shadow-1);
    opacity: 1;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: transform var(--ux-d-fast) var(--ux-ease-out),
                background-color var(--ux-d-fast),
                color var(--ux-d-fast),
                box-shadow var(--ux-d-base) var(--ux-ease-out);
}

html.ux-puzzle .ux-pill:hover {
    background: var(--t-accent-1);
    transform: translateY(-1px);
    box-shadow: var(--ux-inset-top), var(--ux-shadow-2);
    opacity: 1;
}

html.ux-puzzle .ux-pill:active {
    transform: translateY(0) scale(0.97);
    transition-duration: var(--ux-d-instant);
}

html.ux-puzzle .ux-pill:focus-visible {
    outline: 2px solid var(--t-accent-2);
    outline-offset: 2px;
}

html.ux-puzzle .ux-pill[aria-pressed="true"],
html.ux-puzzle .ux-pill[aria-expanded="true"],
html.ux-puzzle .ux-pill.theme-button-selected {
    background: var(--t-accent-2);
    color: var(--t-on-accent-2);
}

html.ux-puzzle .ux-pill-icon {
    width: 16px;
    height: 16px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

html.ux-puzzle .ux-pill-icon .ux-fill {
    fill: currentColor;
    stroke: none;
}

html.ux-puzzle .ux-pill-chev {
    width: 14px;
    height: 14px;
    margin-right: -4px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform var(--ux-d-base) var(--ux-ease-out);
}

html.ux-puzzle .ux-pill[aria-expanded="true"] .ux-pill-chev,
html.ux-puzzle .ux-pill.theme-button-selected .ux-pill-chev {
    transform: rotate(180deg);
}

/* Old .theme-button look (opacity .5, unicode arrow, margins) */
html.ux-puzzle #theme-info-container.theme-button {
    margin: 0 0 0 auto;
    display: inline-flex;
}

html.ux-puzzle #theme-info-container.theme-button::after {
    content: none !important;
}

/* ---------- Board card ---------- */
html.ux-puzzle .ux-board-card {
    position: relative;
    width: var(--board-size);
    border-radius: var(--ux-r-board-top) var(--ux-r-board-top) var(--ux-r-board) var(--ux-r-board);
    box-shadow: var(--ux-shadow-board);
    background: var(--t-surface);
    isolation: isolate;
}

/* inner rim */
html.ux-puzzle .ux-board-card::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.06);
    pointer-events: none;
    z-index: 2;
}

html.ux-puzzle #chess-board.chess-board {
    width: 100% !important;
    height: auto !important;
    min-width: 0 !important;
    min-height: 0 !important;
    max-width: none;
    aspect-ratio: 1 / 1;
    margin: 0;
    border-radius: var(--ux-r-board-top) var(--ux-r-board-top) 0 0 !important;
    box-shadow: none;
    background-color: var(--t-dark);
    -webkit-tap-highlight-color: transparent;
}

html.ux-puzzle #chess-board .chess-square {
    border: 0 !important;
}

/* ---------- Coordinates ---------- */
html.ux-puzzle #chess-board .chess-layout-text {
    font: 12px/1 var(--ux-font-bold) !important;
    letter-spacing: 0.02em;
    opacity: 0.9;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
}

html.ux-puzzle #chess-board .chess-layout-text-left,
html.ux-puzzle #chess-board .chess-layout-number-opposite {
    top: 4px;
    left: 5px;
    right: auto;
    bottom: auto;
}

html.ux-puzzle #chess-board .chess-layout-text-bottom,
html.ux-puzzle #chess-board .chess-layout-letter-opposite {
    bottom: 3px;
    right: 5px;
    top: auto;
    left: auto;
}

/* dark squares: coordinates in the light-square colour (was plain white) */
html.ux-puzzle #chess-board .colour- {
    color: var(--t-light);
}

@media (max-width: 767.98px) {
    html.ux-puzzle #chess-board .chess-layout-text {
        font-size: 10px !important;
    }

    html.ux-puzzle #chess-board .chess-layout-text-left,
    html.ux-puzzle #chess-board .chess-layout-number-opposite {
        top: 3px;
        left: 3px;
    }

    html.ux-puzzle #chess-board .chess-layout-text-bottom,
    html.ux-puzzle #chess-board .chess-layout-letter-opposite {
        bottom: 2px;
        right: 3px;
    }
}

/* ---------- Pieces ---------- */
html.ux-puzzle #chess-board .chess-image {
    width: 88%;
    -webkit-user-drag: none;
    filter: drop-shadow(0 1.5px 1px rgb(0 0 0 / 0.28));
    transition: scale var(--ux-d-fast) var(--ux-ease-spring),
                translate var(--ux-d-fast) var(--ux-ease-out);
}

/* Pick-up: the one dragged piece lifts and casts a shadow */
html.ux-puzzle #chess-board .chess-image.ui-draggable-dragging {
    scale: 1.08;
    filter: drop-shadow(0 8px 8px rgb(0 0 0 / 0.35));
    cursor: grabbing;
    z-index: 1000 !important;
    transition: scale var(--ux-d-fast) var(--ux-ease-spring);
}

/* Hover on a piece of the side to move */
@media (hover: hover) and (pointer: fine) {
    html.ux-puzzle:not(.ux-btp) #chess-board .chess-square > .chess-image[id*="_light_"]:hover,
    html.ux-puzzle.ux-btp #chess-board .chess-square > .chess-image[id*="_dark_"]:hover {
        translate: 0 -2px;
        scale: 1.03;
    }
}

@media (prefers-reduced-motion: reduce) {
    html.ux-puzzle #chess-board .chess-image,
    html.ux-puzzle #chess-board .chess-image:hover,
    html.ux-puzzle #chess-board .chess-image.ui-draggable-dragging {
        scale: none !important;
        translate: none !important;
        transition: none;
    }
}

/* ---------- Square overlays: selected / last move / hover target / clue / flash ---------- */
html.ux-puzzle #chess-board .chess-square::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: transparent;
    transition: background-color var(--ux-d-instant) linear;
}

html.ux-puzzle #chess-board .chess-square.ux-last-from::before,
html.ux-puzzle #chess-board .chess-square.ux-last-to::before {
    background-color: var(--t-hl-last);
}

html.ux-puzzle #chess-board .chess-square.ux-selected::before {
    background-color: var(--t-hl-select);
}

@media (hover: hover) {
    html.ux-puzzle #chess-board .chess-square.possible-move:hover::before,
    html.ux-puzzle #chess-board .chess-square:has(> .dot[style*="block"]):hover::before {
        background-color: rgb(255 255 255 / 0.14);
    }
}

/* Legal move dot */
html.ux-puzzle #chess-board .dot,
html.ux-puzzle #chess-board .dot-light-blue {
    position: relative;
    z-index: 2;
    width: 28%;
    height: 28%;
    border-radius: 50%;
    opacity: 1;
    background-color: var(--t-move-dot) !important;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--t-move) 25%, transparent);
    /* No entry animation: dots appear instantly and stay steady (owner found the pop-in read as a flash). */
}

/* Legal capture */
html.ux-puzzle #chess-board .chess-square.possible-move {
    border: 0 !important;
    border-radius: 0;
    outline: 0;
    box-shadow: inset 0 0 0 4px var(--t-move), inset 0 0 22px color-mix(in srgb, var(--t-move) 40%, transparent);
}

/* Clue: keep the square colour, overlay + ring that pulses twice */
html.ux-puzzle #chess-board .chess-square.clue.js-dark {
    background-color: var(--t-dark) !important;
}

html.ux-puzzle #chess-board .chess-square.clue.js-light {
    background-color: var(--t-light) !important;
}

html.ux-puzzle #chess-board .chess-square.clue::before {
    background-color: var(--t-hl-select);
    box-shadow: inset 0 0 0 3px var(--t-accent-2);
}

@media (prefers-reduced-motion: no-preference) {
    html.ux-puzzle #chess-board .chess-square.clue::before {
        animation: ux-clue 700ms ease-in-out 4 alternate;
    }
}

@keyframes ux-clue {
    from { opacity: 1; }
    to { opacity: 0.55; }
}

/* Wrong move: origin square flashes red */
html.ux-puzzle #chess-board .chess-square.ux-flash-bad::before {
    background-color: color-mix(in srgb, var(--t-bad) 35%, transparent);
    animation: ux-fade-out 300ms ease-out 40ms both;
    transition: none;
}

@keyframes ux-fade-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* Correct move: ring "ping" on the destination square */
html.ux-puzzle #chess-board .chess-square.ux-ping::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 101;
    pointer-events: none;
    box-shadow: inset 0 0 0 3px var(--t-accent-2);
    opacity: 0;
    animation: ux-ping 420ms var(--ux-ease-out);
}

html.ux-puzzle #chess-board .chess-square.ux-ping.ux-ping-big::after {
    box-shadow: inset 0 0 0 4px var(--t-accent-2);
    animation: ux-ping-big 620ms var(--ux-ease-out);
}

@keyframes ux-ping {
    from { transform: scale(0.6); opacity: 0.9; }
    to { transform: scale(1.12); opacity: 0; }
}

@keyframes ux-ping-big {
    from { transform: scale(0.6); opacity: 1; }
    to { transform: scale(1.5); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    html.ux-puzzle #chess-board .chess-square.ux-ping::after {
        animation: none;
    }
}

/* ---------- Board glow (correct / wrong / solved) ---------- */
html.ux-puzzle #chess-board.pulse,
html.ux-puzzle #chess-board.pulse-fail {
    animation: none !important;
    box-shadow: none !important;
}

html.ux-puzzle #chess-board::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 150;
    pointer-events: none;
    border-radius: inherit;
    opacity: 0;
    box-shadow: inset 0 0 0 2px var(--t-glow), inset 0 0 48px var(--t-glow-soft);
}

html.ux-puzzle #chess-board.pulse::after {
    animation: ux-glow 700ms ease-out;
}

html.ux-puzzle #chess-board.pulse-fail::after {
    box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--t-bad) 75%, transparent),
                inset 0 0 48px color-mix(in srgb, var(--t-bad) 32%, transparent);
    animation: ux-glow 600ms ease-out;
}

html.ux-puzzle #chess-board.pulse.ux-solved-glow::after {
    box-shadow: inset 0 0 0 3px var(--t-accent-2), inset 0 0 90px var(--t-glow);
    animation: ux-glow-solved 900ms ease-out;
}

@keyframes ux-glow {
    0% { opacity: 0; }
    12% { opacity: 1; }
    100% { opacity: 0; }
}

@keyframes ux-glow-solved {
    0% { opacity: 0; }
    10% { opacity: 1; }
    55% { opacity: 0.8; }
    100% { opacity: 0; }
}

/* Solved sheen sweep (element created by puzzler-ux.js inside #chess-board) */
html.ux-puzzle .ux-sheen {
    position: absolute;
    inset: 0;
    z-index: var(--ux-z-board-fx);
    pointer-events: none;
    background: linear-gradient(115deg, transparent 38%, rgb(255 255 255 / 0.2) 50%, transparent 62%);
    transform: translateX(-100%);
}

/* Particle burst (layer appended to body by puzzler-ux.js) */
.ux-burst {
    position: absolute;
    width: 0;
    height: 0;
    z-index: 9000;
    pointer-events: none;
}

.ux-burst > i {
    position: absolute;
    left: -5px;
    top: -7px;
    width: 10px;
    height: 14px;
    border-radius: 2px;
    box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.35);
    background: var(--c, var(--t-accent-2));
    opacity: 0;
    animation: ux-burst 900ms var(--ux-ease-out) var(--delay, 0ms) both;
}

@keyframes ux-burst {
    0% { opacity: 1; transform: rotate(var(--a)) translateY(0) rotate(0deg) scale(1); }
    70% { opacity: 1; }
    100% { opacity: 0; transform: rotate(var(--a)) translateY(calc(-1 * var(--d))) rotate(var(--spin, 180deg)) scale(0.6); }
}

/* Re-deal ghost layer (old pieces fading out) */
html.ux-puzzle .ux-deal-layer {
    position: absolute;
    inset: 0;
    z-index: 120;
    pointer-events: none;
}

html.ux-puzzle .ux-deal-layer > img {
    position: absolute;
    margin: 0;
}

/* ---------- Dock ---------- */
html.ux-puzzle .ux-dock.daily-header {
    height: auto !important;
    min-height: var(--ux-dock-h);
    padding: 0 14px !important;
    margin: 0;
    gap: 0;
    display: flex;
    justify-content: center;
    background: var(--t-surface) !important;
    color: var(--t-on-surface);
    box-shadow: var(--ux-inset-top);
    border-radius: 0 0 var(--ux-r-board) var(--ux-r-board) !important;
    position: relative;
    z-index: 1;
}

html.ux-puzzle .ux-dock-row {
    display: grid !important;
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    align-items: center;
    gap: 12px;
    min-height: var(--ux-dock-h);
}

html.ux-puzzle .ux-dock-row.d-none {
    display: none !important;
}

html.ux-puzzle .ux-dock-side.share-row-container {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
}

/* ---------- Dock icons (share, clue, skip, analyse, refresh, next/ready, volume) ----------
   At rest every icon is drawn at the size of the "White to play!" text beside it: the icon's ink (not its
   viewBox) is as tall as the status line's ascender-to-descender extent (HamlinBold 24px: 18 + 5 = 23px;
   20px on phones: 19px). No resting box, background or padding. A transparent ::before keeps a 44px
   hit area centred on the icon without taking any layout space.
   Hover (fine pointers only): the icon grows slightly, like the original .puzzler-svg-button:hover. */
html.ux-puzzle .ux-dock {
    --ux-dock-text: 24px;
    --ux-dock-ink: calc(var(--ux-dock-text) * 0.96);
}

html.ux-puzzle .ux-dock .share-button,
html.ux-puzzle .ux-dock .volume-button,
html.ux-puzzle .ux-icon-btn.puzzler-svg-button {
    position: relative;
    width: auto;
    height: auto;
    flex: none;
    margin: 0 !important;
    padding: 0;
    display: grid;
    place-items: center;
    border-radius: 6px;
    background: transparent;
    box-shadow: none;
    cursor: pointer;
    transform: none;
    -webkit-tap-highlight-color: transparent;
    transition: scale var(--ux-d-fast) var(--ux-ease-out), opacity var(--ux-d-fast) linear;
}

html.ux-puzzle .ux-dock .share-button::before,
html.ux-puzzle .ux-dock .volume-button::before,
html.ux-puzzle .ux-icon-btn.puzzler-svg-button::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: max(44px, 100%);
    height: max(44px, 100%);
    translate: -50% -50%;
    border-radius: 50%;
}

/* SVG box = ink height / the icon's ink-to-viewBox ratio; width follows the viewBox aspect. */
html.ux-puzzle .ux-dock .share-button svg {
    width: var(--ux-dock-ink);
    height: var(--ux-dock-ink);
    display: block;
}

html.ux-puzzle .ux-dock .volume-button svg {
    width: calc(var(--ux-dock-ink) / 0.875 * 1.125);
    height: calc(var(--ux-dock-ink) / 0.875);
    display: block;
}

html.ux-puzzle .ux-dock .share-button svg,
html.ux-puzzle .ux-dock .share-button svg path,
html.ux-puzzle .ux-dock .volume-button svg,
html.ux-puzzle .ux-dock .volume-button svg path {
    fill: var(--t-accent-2);
}

@media (hover: hover) and (pointer: fine) {
    html.ux-puzzle .ux-dock .share-button:hover,
    html.ux-puzzle .ux-dock .volume-button:hover,
    html.ux-puzzle .ux-icon-btn.puzzler-svg-button:hover {
        scale: 1.08;
        transform: none;
        background: transparent;
    }
}

html.ux-puzzle .ux-dock .share-button:active,
html.ux-puzzle .ux-dock .volume-button:active,
html.ux-puzzle .ux-icon-btn.puzzler-svg-button:active {
    scale: 0.94;
    transform: none;
    transition-duration: var(--ux-d-instant);
}

html.ux-puzzle .ux-dock .volume-button.muted {
    filter: none;
    opacity: 0.45;
}

html.ux-puzzle .ux-dock-center.center-row {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: center;
    gap: 18px;
    min-width: 0;
    margin: 0 !important;
    padding: 8px 0;
}

/* Status: "White to play!" (plain text, no side-to-move pip) */
html.ux-puzzle .ux-dock .ux-status.chess-font {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    margin: 0 6px 0 0 !important;
    font: 24px/1.1 var(--ux-font-bold) !important;
    color: var(--t-on-surface);
    text-wrap: balance;
    text-align: left;
}

html.ux-puzzle .ux-solved-status {
    display: none;
    align-items: center;
    gap: 8px;
    margin: 0 6px 0 0 !important;
    font: 24px/1.1 var(--ux-font-bold);
    color: var(--t-on-surface);
    white-space: nowrap;
}

html.ux-puzzle .ux-solved-status svg {
    width: 22px;
    height: 22px;
    flex: none;
    fill: none;
    stroke: var(--t-accent-2);
    stroke-width: 2.25;
    stroke-linecap: round;
    stroke-linejoin: round;
}

html.ux-puzzle.ux-solved .ux-dock .ux-status {
    display: none !important;
}

html.ux-puzzle.ux-solved .ux-solved-status {
    display: inline-flex;
    animation: ux-status-in 220ms var(--ux-ease-out) both;
}

@keyframes ux-status-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: none; }
}

/* Rating change after a rated solve. Sits right after "Solved!" and only as wide as its text
   (width:auto beats site.css's mobile `.upper-row > .text-row { width: 100% }`). */
html.ux-puzzle .ux-dock .rating-row {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    width: auto;
    flex: none;
    margin: 0;
    white-space: nowrap;
}

html.ux-puzzle .ux-dock .rating-row.d-none {
    display: none !important;
}

html.ux-puzzle .ux-dock .rating-row .chess-font {
    width: auto !important;
    margin: 0 !important;
    font: 18px/1 var(--ux-font) !important;
    font-variant-numeric: tabular-nums;
    color: var(--t-on-surface-muted);
}

html.ux-puzzle .ux-dock .rating-row .difficulty.chess-font {
    font-family: var(--ux-font-bold) !important;
    display: inline-block;
}

html.ux-puzzle .ux-dock .difficulty.rating-positive {
    color: var(--t-accent-2);
}

html.ux-puzzle .ux-dock .difficulty.rating-negative {
    color: var(--t-bad);
}

html.ux-puzzle .ux-dock .difficulty.ux-rise {
    animation: ux-rise 600ms var(--ux-ease-spring) both;
}

@keyframes ux-rise {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}

/* Icon buttons: sizes */
html.ux-puzzle .ux-icon-btn:focus-visible,
html.ux-puzzle .ux-dock .share-button:focus-visible,
html.ux-puzzle .ux-dock .volume-button:focus-visible {
    outline: 2px solid var(--t-accent-2);
    outline-offset: 3px;
}

html.ux-puzzle .ux-icon-btn > svg,
html.ux-puzzle .ux-icon-btn > div > svg {
    display: block;
}

/* clue (448x512, ink 87.5%), skip (512x512, 75%), analyse (512x512, 100%), refresh (512x512, 87.5%), next (448x512, 75%) */
html.ux-puzzle #clue.ux-icon-btn > svg {
    width: calc(var(--ux-dock-ink) / 0.875 * 0.875);
    height: calc(var(--ux-dock-ink) / 0.875);
}

html.ux-puzzle #skip.ux-icon-btn > svg {
    width: calc(var(--ux-dock-ink) / 0.75);
    height: calc(var(--ux-dock-ink) / 0.75);
}

html.ux-puzzle #analyse.ux-icon-btn > svg {
    width: var(--ux-dock-ink);
    height: var(--ux-dock-ink);
}

html.ux-puzzle .ux-icon-btn .refresh-box > svg {
    width: calc(var(--ux-dock-ink) / 0.875);
    height: calc(var(--ux-dock-ink) / 0.875);
}

html.ux-puzzle .ux-icon-btn .next-svg-container > svg {
    width: calc(var(--ux-dock-ink) / 0.75 * 0.875);
    height: calc(var(--ux-dock-ink) / 0.75);
}

html.ux-puzzle .ux-icon-btn svg path {
    fill: var(--t-accent-2);
}

html.ux-puzzle .ux-icon-btn .next-svg-container,
html.ux-puzzle .ux-icon-btn .refresh-box {
    padding: 0;
    border-radius: 0;
    background: transparent !important;
    display: grid;
    place-items: center;
}

/* Next / Ready: a plain icon like the others, with a very soft glow so it still reads as the next step. */
html.ux-puzzle .ux-icon-btn.ux-next .next-svg-container > svg {
    filter: drop-shadow(0 0 5px var(--t-glow-soft));
}

@media (prefers-reduced-motion: no-preference) {
    html.ux-puzzle .ux-icon-btn.ux-next {
        animation: ux-pop-in 360ms var(--ux-ease-spring) both;
    }
}

@keyframes ux-pop-in {
    from { opacity: 0; transform: scale(0.6); }
    to { opacity: 1; transform: none; }
}

/* ---------- Solved progress panel ---------- */
html.ux-puzzle .solved-progress-host {
    margin-top: 12px;
}

html.ux-puzzle .solved-progress-panel {
    background: var(--t-surface) !important;
    color: var(--t-on-surface);
    border-radius: 16px;
    box-shadow: var(--ux-inset-top), var(--ux-shadow-2);
}

html.ux-puzzle .solved-progress-panel .solved-progress-level-value,
html.ux-puzzle .solved-progress-panel .solved-streak-value,
html.ux-puzzle .solved-progress-panel .solved-progress-label {
    font-variant-numeric: tabular-nums;
}

/* ---------- Analysis overlay buttons inside the card ---------- */
html.ux-puzzle .ux-board-card .total-analysis-container {
    background: var(--t-surface);
}

/* ---------- Mobile ---------- */
@media (max-width: 767.98px) {
    html.ux-puzzle #ux-stage {
        width: 100% !important;
    }

    html.ux-puzzle #ux-stage > .center-container {
        justify-content: center;
    }

    html.ux-puzzle .ux-toprow {
        width: calc(100vw - 24px);
        margin: 12px auto 8px;
    }

    html.ux-puzzle .ux-dock.daily-header {
        padding: 0 10px !important;
        --ux-dock-text: 20px;
    }

    html.ux-puzzle .ux-dock-row {
        grid-template-columns: 44px minmax(0, 1fr) 44px;
        gap: 6px;
    }

    /* Status text and action buttons sit together as one centred group; the flex gap is the only spacing,
       so every text/button neighbour is the same distance apart. */
    html.ux-puzzle .ux-dock-center.center-row {
        justify-content: center;
        gap: clamp(8px, 3vw, 14px);
    }

    /* width:auto beats site.css's mobile `.upper-row > .colour { width: 100% }`, which would push the buttons to the edge. */
    html.ux-puzzle .ux-dock .ux-status.chess-font,
    html.ux-puzzle .ux-solved-status {
        width: auto;
        flex: none;
        font-size: 20px !important;
        margin: 0 !important;
        white-space: nowrap;
    }

    html.ux-puzzle .ux-dock .rating-row .chess-font {
        font-size: 15px !important;
    }

    html.ux-puzzle .ux-dock .rating-row .rating {
        display: none;
    }
}

/* Share overlay, moved to <body> by puzzler-ux.js: keep the centred text it inherited from the stage. */
.ux-share-host.share-popup-container {
    text-align: center;
}

/* The two #refresh copies are identical; one is enough in the dock. */
html.ux-puzzle .ux-dock .ux-refresh.show-mobile {
    display: none !important;
}

html.ux-puzzle .ux-dock .ux-refresh.show-desktop:not(.d-none) {
    display: grid;
}

/* Solved: the clue no longer applies */
html.ux-puzzle.ux-solved .ux-dock #clue {
    display: none !important;
}

/* ==========================================================================
   Polish pass (art direction): atmosphere, board presence, welcome, solve
   moment, personal touch, contrast for light themes. Theme vars only.
   ========================================================================== */

/* ---------- Pool of light that follows the board (every theme) ----------
   A soft radial pool in the theme's light-square colour with a hint of the
   highlight colour, centred on the board card wherever the layout puts it.
   It breathes very slowly (opacity + scale only, its own compositor layer). */
html.ux-puzzle #chess-board-container {
    position: relative;
}

html.ux-puzzle .ux-board-card,
html.ux-puzzle .solved-progress-host {
    z-index: 1;
}

html.ux-puzzle .solved-progress-host {
    position: relative;
}

html.ux-puzzle #chess-board-container::before,
html.ux-puzzle #chess-board-container::after {
    content: "";
    position: absolute;
    left: 50%;
    top: calc((var(--board-size) + var(--ux-dock-h)) / 2);
    width: calc(var(--board-size) * 2.3);
    height: calc(var(--board-size) * 2.1);
    translate: -50% -50%;
    z-index: 0;
    pointer-events: none;
    border-radius: 50%;
}

html.ux-puzzle #chess-board-container::before {
    background: radial-gradient(closest-side,
        color-mix(in srgb, color-mix(in oklab, var(--t-dark), var(--t-light) 30%) 36%, transparent) 0%,
        color-mix(in srgb, var(--t-dark) 24%, transparent) 40%,
        color-mix(in srgb, var(--t-dark) 10%, transparent) 64%,
        color-mix(in srgb, var(--t-dark) 3%, transparent) 84%,
        transparent 100%);
    opacity: 0.9;
}

/* Solve flare: the room lights up in the highlight colour, then settles. */
html.ux-puzzle #chess-board-container::after {
    background: radial-gradient(closest-side,
        color-mix(in srgb, color-mix(in oklab, var(--t-accent-2), white 20%) 55%, transparent) 0%,
        color-mix(in srgb, var(--t-accent-2) 30%, transparent) 40%,
        color-mix(in srgb, var(--t-accent-2) 9%, transparent) 70%,
        transparent 100%);
    opacity: 0;
}

@media (prefers-reduced-motion: no-preference) {
    html.ux-puzzle #chess-board-container::before {
        will-change: opacity, transform;
        animation: ux-pool-in 1.1s var(--ux-ease-out) both, ux-breathe 9s ease-in-out 1.1s infinite alternate;
    }

    html.ux-puzzle.ux-solved #chess-board-container::after {
        animation: ux-flare 1.8s var(--ux-ease-out) 60ms both;
    }
}

@keyframes ux-pool-in {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 0.9; transform: scale(1); }
}

@keyframes ux-breathe {
    from { opacity: 0.9; transform: scale(1); }
    to { opacity: 0.62; transform: scale(0.94); }
}

@keyframes ux-flare {
    0% { opacity: 0; transform: scale(0.8); }
    18% { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(1.12); }
}

/* The pool is wider than a phone: clip it at the (full-width) stage so it can never
   widen the layout viewport. overflow-x: clip, unlike hidden, leaves y visible and
   creates no scroll container. */
@media (max-width: 1199.98px) {
    html.ux-puzzle #ux-stage {
        overflow-x: clip;
    }

    html.ux-puzzle #chess-board-container::before,
    html.ux-puzzle #chess-board-container::after {
        width: min(calc(var(--board-size) * 2.3), 100vw);
    }
}

@media (max-width: 767.98px) {
    html.ux-puzzle #chess-board-container::before,
    html.ux-puzzle #chess-board-container::after {
        height: calc(var(--board-size) * 1.6);
    }
}

/* ---------- Board card: rim light, bevel, dock seam ---------- */
html.ux-puzzle .ux-board-card::after {
    box-shadow:
        inset 0 1px 0 rgb(255 255 255 / 0.16),
        inset 0 0 0 1px rgb(255 255 255 / 0.06),
        inset 0 -1px 0 rgb(0 0 0 / 0.22);
}

/* Dock: a faint top-lit gradient on the panel colour, a soft lip where the
   board overhangs it, and a highlight-coloured hairline that fades at the ends. */
html.ux-puzzle .ux-dock.daily-header {
    background:
        linear-gradient(180deg, color-mix(in srgb, white 5%, transparent), transparent 70%),
        var(--t-surface) !important;
    box-shadow: inset 0 10px 14px -12px rgb(0 0 0 / 0.45);
}

html.ux-puzzle .ux-dock.daily-header::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    height: 1px;
    pointer-events: none;
    background: linear-gradient(90deg, transparent 4%,
        color-mix(in srgb, var(--t-icon, var(--t-accent-2)) 70%, transparent) 35%,
        color-mix(in srgb, var(--t-icon, var(--t-accent-2)) 70%, transparent) 65%, transparent 96%);
    opacity: 0.75;
}

/* ---------- Dock typography ---------- */
html.ux-puzzle .ux-dock .ux-status.chess-font,
html.ux-puzzle .ux-solved-status {
    letter-spacing: -0.005em;
    text-shadow: 0 1px 1px rgb(0 0 0 / 0.18);
}

/* Icons in the dock / stats tab follow --t-icon (accent-2, auto-darkened by puzzler-ux.js
   when accent-2 would vanish on the panel colour, e.g. Light Mode's white-on-sky). */
html.ux-puzzle .ux-dock .share-button svg,
html.ux-puzzle .ux-dock .share-button svg path,
html.ux-puzzle .ux-dock .volume-button svg,
html.ux-puzzle .ux-dock .volume-button svg path,
html.ux-puzzle .ux-icon-btn svg path {
    fill: var(--t-icon, var(--t-accent-2));
}

html.ux-puzzle .ux-solved-status svg {
    stroke: var(--t-icon, var(--t-accent-2));
}

html.ux-puzzle .ux-stats-tab {
    color: var(--t-icon, var(--t-accent-2));
}

/* Streak flourish next to "Solved!" (puzzler-ux.js adds it for 2+ clean in a row) */
html.ux-puzzle .ux-streak-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: 4px;
    padding: 4px 9px 4px 7px;
    border-radius: var(--ux-r-pill);
    font: 13px/1 var(--ux-font-bold);
    letter-spacing: 0.02em;
    font-variant-numeric: tabular-nums;
    text-shadow: none;
    color: var(--t-on-surface);
    background: color-mix(in srgb, var(--t-icon, var(--t-accent-2)) 22%, transparent);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--t-icon, var(--t-accent-2)) 45%, transparent);
}

html.ux-puzzle .ux-streak-chip svg {
    width: 12px;
    height: 12px;
    fill: var(--t-icon, var(--t-accent-2));
    stroke: none;
}

@media (prefers-reduced-motion: no-preference) {
    html.ux-puzzle .ux-streak-chip {
        animation: ux-pop-in 420ms var(--ux-ease-spring) 380ms both;
    }
}

@media (max-width: 767.98px) {
    html.ux-puzzle .ux-streak-chip .ux-streak-label {
        display: none;
    }
}

/* ---------- Top row pills: glass on the theme's panel colour ---------- */
html.ux-puzzle .ux-pill {
    color: var(--t-on-surface);
    background: color-mix(in srgb, var(--t-surface) 84%, transparent);
    box-shadow: var(--ux-inset-top), inset 0 0 0 1px var(--t-line), var(--ux-shadow-1);
}

html.ux-puzzle .ux-pill:hover {
    background: var(--t-surface-raised);
    box-shadow: var(--ux-inset-top), inset 0 0 0 1px var(--t-line-strong), var(--ux-shadow-2);
}

html.ux-puzzle .ux-pill[aria-pressed="true"],
html.ux-puzzle .ux-pill[aria-expanded="true"],
html.ux-puzzle .ux-pill.theme-button-selected {
    background: var(--t-accent-2);
    color: var(--t-on-accent-2);
    /* the ring keeps the pill visible when accent-2 matches the page (Light Mode: white on white) */
    box-shadow: var(--ux-inset-top), inset 0 0 0 1px var(--t-line-strong), 0 4px 14px -4px var(--t-glow), var(--ux-shadow-1);
}

html.ux-puzzle .ux-pill-icon {
    opacity: 0.85;
}

/* ---------- Personal greeting (centre of the top row, >= 768px) ---------- */
/* A quiet glass chip rather than bare text, so it reads on any background
   (flat colours, photos like Chess Puzzler's wood, or moving effects). */
html.ux-puzzle .ux-toprow {
    position: relative;
}

html.ux-puzzle .ux-greet {
    position: absolute;
    left: 50%;
    top: 50%;
    translate: -50% -50%;
    max-width: 36%;
    height: 30px;
    padding: 0 13px;
    display: none;
    justify-content: center;
    align-items: center;
    gap: 6px;
    overflow: hidden;
    white-space: nowrap;
    font: 13px/1 var(--ux-font);
    letter-spacing: 0.01em;
    color: var(--t-on-surface);
    background: color-mix(in srgb, var(--t-surface) 82%, transparent);
    border-radius: var(--ux-r-pill);
    box-shadow: inset 0 0 0 1px var(--t-line);
}

html.ux-puzzle .ux-greet b {
    font-family: var(--ux-font-bold);
    font-weight: normal;
    color: var(--t-on-surface);
}

html.ux-puzzle .ux-greet .ux-greet-text {
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

html.ux-puzzle .ux-greet svg {
    width: 13px;
    height: 13px;
    flex: none;
    fill: var(--t-icon, var(--t-accent-2));
}

@media (min-width: 768px) {
    html.ux-puzzle .ux-greet {
        display: inline-flex;
    }
}

@media (prefers-reduced-motion: no-preference) {
    html.ux-puzzle .ux-greet.is-in {
        animation: ux-greet-in 700ms var(--ux-ease-out) both;
    }
}

@keyframes ux-greet-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: none; }
}

/* ---------- Last move: a soft fill plus a thin inner ring in the highlight colour,
   so it stays crisp on dark squares (a fill alone turns khaki on warm browns) ---------- */
html.ux-puzzle #chess-board .chess-square.ux-last-from::before,
html.ux-puzzle #chess-board .chess-square.ux-last-to::before {
    box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--t-accent-2) 50%, transparent);
}

html.ux-puzzle #chess-board .chess-square.js-dark.ux-last-from::before,
html.ux-puzzle #chess-board .chess-square.js-dark.ux-last-to::before {
    background-color: color-mix(in srgb, color-mix(in oklab, var(--t-accent-2), var(--t-light) 40%) 26%, transparent);
    box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--t-accent-2) 70%, transparent);
}

/* ---------- Coordinates: a touch larger on big boards ---------- */
@media (min-width: 768px) {
    html.ux-puzzle #chess-board .chess-layout-text {
        font-size: clamp(12px, calc(var(--board-size) / 50), 15px) !important;
        opacity: 0.95;
    }
}

/* ---------- Welcome: the table sets itself on first load ---------- */
@media (prefers-reduced-motion: no-preference) {
    /* on the wrapper, so the card's own animation slot stays free for the solve "thump" */
    html.ux-puzzle #chess-board-container {
        animation: ux-card-in 700ms var(--ux-ease-emph) 40ms backwards;
    }

    html.ux-puzzle .ux-toprow > * {
        animation: ux-toprow-in 520ms var(--ux-ease-out) backwards;
    }

    html.ux-puzzle .ux-toprow > :nth-child(1) { animation-delay: 160ms; }
    html.ux-puzzle .ux-toprow > :nth-child(2) { animation-delay: 220ms; }
    html.ux-puzzle .ux-toprow > :nth-child(3) { animation-delay: 280ms; }

    html.ux-puzzle .ux-rail {
        animation: ux-fade-in 600ms ease-out 300ms backwards;
    }

    /* Solve: the card gives a small, satisfied "thump" */
    html.ux-puzzle.ux-solved .ux-board-card {
        animation: ux-card-cheer 560ms var(--ux-ease-spring) both;
    }
}

@keyframes ux-card-in {
    from { opacity: 0; transform: translateY(18px) scale(0.985); }
    to { opacity: 1; transform: none; }
}

@keyframes ux-toprow-in {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: none; }
}

@keyframes ux-card-cheer {
    0% { transform: none; }
    35% { transform: scale(1.014); }
    100% { transform: none; }
}

/* ---------- "Remove Ads": same blue bar, same size class, just finished edges ---------- */
html.ux-puzzle .remove-ads-link {
    padding: 7px 12px;
    border-radius: 10px;
    box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.22), var(--ux-shadow-1);
    transition: transform var(--ux-d-fast) var(--ux-ease-out), box-shadow var(--ux-d-base) var(--ux-ease-out);
}

@media (max-width: 767.98px) {
    html.ux-puzzle .remove-ads-link {
        margin-left: 12px;
        margin-right: 12px;
    }
}

html.ux-puzzle .remove-ads-link:hover {
    transform: translateY(-1px);
    box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.22), var(--ux-shadow-2);
}
