:root {
    font-family:
        Inter,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        "PingFang SC",
        sans-serif;
    font-size: 16px;
    font-synthesis: none;
    color: var(--ink);
    background: var(--page);
    --ink: #202b3c;
    --muted: #657084;
    --line: #e4e8ef;
    --page: #fcfcfd;
    --surface: #fff;
    --accent: #146557;
    --accent-ink: #0f4d43;
    --accent-soft: #e4f1ec;
    --board: #263b48;
    --focus: #2f9e8b;
}
* {
    box-sizing: border-box;
}
body {
    margin: 0;
    padding-bottom: var(--round-height, 0px);
}
[hidden] {
    display: none !important;
}
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* Controls */
button,
select,
input,
.button {
    font: inherit;
    font-size: 0.875rem;
    color: inherit;
}
button,
.button {
    border: 1px solid var(--line);
    background: var(--surface);
    border-radius: 9px;
    padding: 10px 12px;
    cursor: pointer;
    transition:
        background 0.15s,
        border-color 0.15s;
}
button:disabled {
    opacity: 0.45;
    cursor: default;
}
button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 600;
}
/* Touch screens keep :hover after a tap, so hover styles only apply with a real pointer. */
@media (hover: hover) {
    button:hover:not(:disabled),
    .button:hover {
        background: #eef5f2;
        border-color: #a9c4bc;
    }
    button.primary:hover:not(:disabled) {
        background: var(--accent-ink);
        border-color: var(--accent-ink);
    }
    #board .ghost:hover rect {
        fill-opacity: 0.32;
    }
}
select {
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    cursor: pointer;
}
button:focus-visible,
select:focus-visible,
input:focus-visible,
summary:focus-visible,
.button:focus-within {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

/* Page frame */
header,
main {
    max-width: 1280px;
    margin: 0 auto;
}
/* Header matches the game list page: same size, weight and rule below. */
header {
    display: flex;
    align-items: center;
    gap: 14px;
    max-width: none;
    padding: 30px max(24px, (100% - 1280px) / 2 + 24px);
    border-bottom: 1px solid var(--line);
}
.site-title {
    margin: 0;
    font-size: 19px;
    letter-spacing: 0.02em;
    font-weight: 650;
    line-height: 1.4;
}
main {
    display: grid;
    gap: 16px;
    padding: 24px 24px;
}
/* Quiet text button beside the title, styled like the link back to the game list. */
.text-button {
    border: 0;
    background: none;
    padding: 4px 2px;
    color: var(--muted);
    font-size: 0.875rem;
}
@media (hover: hover) {
    .text-button:hover:not(:disabled) {
        background: none;
        color: var(--ink);
        text-decoration: underline;
        text-underline-offset: 4px;
    }
}
aside {
    min-width: 0;
}
footer {
    max-width: 1280px;
    margin: 0 auto;
    padding: 16px 24px 24px;
    display: flex;
    justify-content: flex-end;
    font-size: 0.75rem;
    color: var(--muted);
    border-top: 1px solid var(--line);
}
footer a {
    color: inherit;
}

/* Board */
.workspace {
    min-width: 0;
}
.board-shell {
    background: var(--board);
    padding: 12px;
    border-radius: 14px;
}
#board {
    width: 100%;
    margin: 0 auto;
    border-radius: 4px;
}
#board:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 6px;
}
#board svg {
    display: block;
    width: 100%;
    height: auto;
    overflow: visible;
    -webkit-user-select: none;
    user-select: none;
}
#board .robot[role="button"] {
    cursor: grab;
    touch-action: none;
}
#board .ghost {
    cursor: pointer;
}
#board .ghost rect {
    transition: fill-opacity 0.15s;
}
#board .ghost.hinted rect {
    animation: hint-pulse 0.7s ease-in-out 2;
    transform-box: fill-box;
    transform-origin: center;
}
#board .target.reached .target-glow {
    animation: reached 0.9s ease-out 1;
    transform-box: fill-box;
    transform-origin: center;
}
#board.editing [data-cell] {
    cursor: crosshair;
}
#board svg [role="gridcell"]:focus {
    outline: none;
}
#board .cell-focus {
    fill: var(--focus);
    fill-opacity: 0.14;
    stroke: var(--focus);
    stroke-width: 2.5;
}
#board .wall-hit {
    cursor: crosshair;
}
@keyframes hint-pulse {
    50% {
        transform: scale(1.15);
    }
}
@keyframes reached {
    from {
        opacity: 0.45;
        transform: scale(0.6);
    }
    to {
        opacity: 0;
        transform: scale(1.9);
    }
}

/* Round panel: the one place for what to do next. Pinned to the bottom on phones. */
.round-panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 16px 18px;
}
.round-panel[data-phase="won"] {
    border-color: var(--accent);
    box-shadow: inset 0 0 0 1px var(--accent);
}
.round-head {
    display: flex;
    align-items: center;
    gap: 12px;
}
.goal {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-weight: 600;
    font-size: 0.95rem;
    line-height: 1.4;
}
.goal-glyph svg {
    display: block;
    width: 22px;
    height: 22px;
}
.count {
    margin: 0 0 0 auto;
    display: flex;
    align-items: baseline;
    gap: 3px;
    color: var(--muted);
    font-size: 0.8rem;
    white-space: nowrap;
}
.count strong {
    color: var(--ink);
    font-size: 1.9rem;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}
.count.urgent strong {
    color: #b4462f;
}
/* Remaining thinking time, shrinking towards zero. */
.think-bar {
    height: 4px;
    margin-top: 10px;
    border-radius: 2px;
    background: var(--line);
    overflow: hidden;
}
.think-bar span {
    display: block;
    height: 100%;
    background: var(--accent);
    transition: width 0.25s linear;
}
.think-bar.urgent span {
    background: #b4462f;
}
.status {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 0.875rem;
    line-height: 1.5;
}
.status:empty {
    margin: 0;
}
.actions {
    margin-top: 14px;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    gap: 8px;
}
.actions button {
    padding: 11px 6px;
    white-space: nowrap;
}

/* Panels */
.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 16px 18px;
    margin-top: 14px;
}
.panel h2 {
    font-size: 0.95rem;
    font-weight: 650;
    margin: 0;
}
.panel-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.compact {
    padding: 6px 10px;
    font-size: 0.8rem;
}
#moves {
    list-style: none;
    padding: 0;
    margin: 10px 0 0;
    max-height: 240px;
    overflow: auto;
    font-size: 0.875rem;
}
#moves li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 5px 8px;
}
#moves li:has(button) {
    padding: 0;
}
#moves button {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 0;
    padding: 5px 8px;
    text-align: left;
}
#moves button.selected {
    background: var(--accent-soft);
}
.move-no {
    width: 1.6em;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}
#moves small {
    margin-left: auto;
    color: var(--muted);
}
.swatch {
    width: 14px;
    height: 14px;
    border-radius: 4px;
    background: var(--color);
    border: 1px solid #0002;
    flex-shrink: 0;
}

/* Setup */
.setup-panel > .full-control {
    margin-top: 14px;
}
.setup-group {
    border-top: 1px solid var(--line);
    margin-top: 12px;
}
summary {
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    padding: 12px 0 2px;
}
.setup-group[open] > summary {
    margin-bottom: 10px;
}
.fine {
    font-size: 0.8rem;
    line-height: 1.6;
    color: var(--muted);
    margin: 8px 0;
}
.control-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
}
.control-grid button,
.control-grid .button {
    padding: 9px 6px;
    text-align: center;
}
.control-grid button.active,
.tool.active {
    border-color: var(--accent);
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 1px var(--accent);
}
.full-control {
    width: 100%;
    margin-top: 9px;
    padding: 9px;
}
.full-control.active {
    border-color: var(--accent);
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 1px var(--accent);
}
.field-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 12px;
    font-size: 0.875rem;
}
.tools {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px;
}
.tool {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 2px;
    font-size: 0.8rem;
}
.rule-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    line-height: 1.6;
}
.rule-toggle input {
    accent-color: var(--accent);
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}
.goal-picker {
    margin-top: 8px;
}
.goal-color-row {
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr);
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    font-size: 0.75rem;
}
.goal-buttons {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
}
.goal-buttons button {
    min-width: 0;
    padding: 4px 2px;
    color: var(--goal-color);
}
.goal-buttons b,
.goal-buttons small {
    display: block;
}
.goal-buttons b svg {
    display: block;
    width: 18px;
    height: 18px;
    margin: 2px auto;
}
.goal-buttons small {
    font-size: 0.65rem;
    color: var(--muted);
}
.goal-buttons button.active {
    border-color: var(--goal-color);
    box-shadow: inset 0 0 0 1px var(--goal-color);
    background: #edf5f3;
}

/* Toast */
#toast {
    position: fixed;
    bottom: calc(var(--round-height, 0px) + 16px);
    left: 50%;
    transform: translateX(-50%);
    max-width: 90vw;
    padding: 12px 18px;
    border-radius: 9px;
    background: #243746;
    color: #fff;
    box-shadow: 0 5px 30px #0003;
    font-size: 0.875rem;
    z-index: 6;
}

/* Board assembly dialog */
dialog {
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 24px;
    width: min(860px, 94vw);
    max-height: 90vh;
    color: var(--ink);
    background: #f5f8fa;
    box-shadow: 0 25px 80px #0004;
}
.help-dialog {
    width: min(440px, 92vw);
    padding: 20px 22px 22px;
    background: var(--surface);
}
.help-dialog h2 {
    font-size: 1.05rem;
}
.help-dialog p {
    margin: 12px 0 0;
    color: var(--muted);
    font-size: 0.875rem;
    line-height: 1.7;
}
.dialog-heading button {
    border: 0;
    background: none;
    padding: 4px 8px;
    color: var(--muted);
}
dialog::backdrop {
    background: #12263599;
}
.dialog-heading,
.assembly-toolbar,
.dialog-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.dialog-heading h2 {
    font-size: 1.2rem;
    margin: 0;
}
.assembly-help {
    font-size: 0.875rem;
    color: var(--muted);
    line-height: 1.7;
}
.assembly-slots {
    width: 310px;
    max-width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    margin: 18px auto;
}
.assembly-slot,
.tile-option {
    min-width: 0;
    padding: 7px;
    border: 2px solid var(--line);
    border-radius: 8px;
}
.assembly-slot span,
.tile-option span {
    display: block;
    font-size: 0.75rem;
}
.assembly-slot span {
    margin-bottom: 7px;
}
.tile-option span {
    margin-top: 7px;
}
.assembly-slot svg,
.tile-option svg {
    width: 100%;
    display: block;
}
.assembly-slot.selected,
.tile-option.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
    background: #e8f3ef;
}
.assembly-toolbar {
    font-size: 0.875rem;
    padding: 14px 0;
    border-top: 1px solid var(--line);
}
.assembly-toolbar span {
    margin-right: auto;
}
#tile-catalog {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}
.tile-group h3 {
    font-size: 0.875rem;
    margin: 8px 0;
}
.tile-options {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}
.dialog-footer {
    position: sticky;
    bottom: -24px;
    background: #f5f8fa;
    padding: 15px 0;
}

/* Two columns once the board and the side panel both fit. */
@media (min-width: 860px), (min-width: 740px) and (min-aspect-ratio: 6/5) {
    main {
        grid-template-columns: minmax(0, 1fr) clamp(300px, 32vw, 390px);
        align-items: start;
        gap: 22px;
    }
    .workspace {
        position: sticky;
        top: 12px;
    }
    /* Fit the whole board in the window: header, top padding and a bottom margin; the frame shrinks with it. */
    .board-shell {
        padding: 16px;
        width: min(100%, max(332px, calc(100dvh - 144px)));
    }
    #moves {
        max-height: min(46dvh, 420px);
    }
}

/* Phones and narrow portrait windows: round panel docks at the bottom of the screen. */
@media (max-width: 859px) and (max-aspect-ratio: 6/5), (max-width: 739px) {
    header {
        padding: 22px 14px;
    }
    main {
        padding: 12px 10px 16px;
        gap: 4px;
    }
    .board-shell {
        padding: 6px;
        border-radius: 10px;
    }
    .round-panel {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 4;
        border-radius: 14px 14px 0 0;
        border-bottom: 0;
        padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
        box-shadow: 0 -6px 24px #142c3d1f;
    }
    .round-panel[data-phase="won"] {
        box-shadow:
            inset 0 1px 0 var(--accent),
            0 -6px 24px #142c3d1f;
    }
    .goal {
        font-size: 0.875rem;
    }
    .count strong {
        font-size: 1.5rem;
    }
    .status {
        margin-top: 4px;
        font-size: 0.8rem;
    }
    .actions {
        margin-top: 10px;
    }
    .panel {
        margin-top: 10px;
        padding: 14px;
    }
    footer {
        padding: 14px;
    }
    dialog {
        padding: 18px;
    }
    .assembly-toolbar {
        flex-wrap: wrap;
    }
    .assembly-toolbar span {
        width: 100%;
    }
    .dialog-footer {
        bottom: -18px;
    }
    #tile-catalog {
        gap: 10px;
    }
    .tile-options {
        gap: 4px;
    }
    .tile-option {
        padding: 3px;
    }
}
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}
