.row {
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
}

#grid-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: max-content;
    max-width: 100%;
    margin: 0 auto;
    contain: layout style;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

#grid-container.is-gesturing {
    cursor: grabbing;
}

.board-zoom-toolbar {
    display: flex;
    position: sticky;
    top: 0;
    left: 0;
    z-index: 20;
    align-self: flex-end;
    width: max-content;
    margin: 8px 8px 0;
    border: 1px solid var(--divider-color);
    background: var(--menu-bg);
}

.board-zoom-toolbar[hidden] {
    display: none;
}

.board-zoom-toolbar button {
    min-width: 76px;
    min-height: 44px;
    padding: 8px 12px;
    color: var(--menu-text);
    border: 0;
    background: var(--menu-bg);
    font: inherit;
    font-size: 0.75rem;
    font-weight: 800;
}

.board-zoom-toolbar button + button {
    border-left: 1px solid var(--divider-color);
}

.board-zoom-toolbar button[aria-pressed="true"] {
    color: var(--button-text);
    background: var(--button-bg);
}

.mark-tool-bar,
.mobile-mark-tools {
    display: none;
}

.mark-tool-bar [data-mark-tool],
.mobile-mark-tools [data-mark-tool] {
    min-width: 44px;
    min-height: 44px;
    box-sizing: border-box;
    border: 2px solid var(--divider-color);
    border-radius: 0;
    padding: 8px 12px;
    background: var(--hud-bg);
    color: var(--hud-text);
    font: inherit;
    font-weight: 800;
    line-height: 1;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.mark-tool-bar [data-mark-tool][aria-pressed="true"],
.mark-tool-bar [data-mark-tool].active,
.mobile-mark-tools [data-mark-tool][aria-pressed="true"],
.mobile-mark-tools [data-mark-tool].active {
    border-color: var(--button-bg);
    background: var(--button-bg);
    color: var(--button-text);
    box-shadow: inset 0 -3px 0 rgb(0 0 0 / 20%);
}

.mark-tool-bar [data-mark-tool]:active,
.mobile-mark-tools [data-mark-tool]:active {
    background: var(--surface-3);
    box-shadow: inset 0 2px 0 rgb(0 0 0 / 24%);
}

.mark-tool-bar [data-mark-tool][aria-pressed="true"]:active,
.mobile-mark-tools [data-mark-tool][aria-pressed="true"]:active {
    background: var(--button-active-bg);
}

.mark-tool-bar [data-mark-tool]:focus-visible,
.mobile-mark-tools [data-mark-tool]:focus-visible {
    outline: 3px solid var(--button-focus-ring);
    outline-offset: 2px;
}

.cell {
    --cell-size: var(--grid-cell-size, 30px);
    position: relative;
    display: flex;
    flex: 0 0 var(--cell-size);
    align-items: center;
    justify-content: center;
    width: var(--cell-size);
    height: var(--cell-size);
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    border-right: 1px solid var(--cell-border-thin);
    border-bottom: 1px solid var(--cell-border-thin);
    contain: layout style paint;
}

#grid-container .grid-empty-hint-column {
    display: none;
}

.row.grid-empty-hint-row {
    display: none;
}

.cell[data-game-cell="true"] {
    cursor: pointer;
    transition: background-color 100ms ease, box-shadow 100ms ease;
}

.cell[data-game-cell="true"]:hover {
    z-index: 2;
    box-shadow: inset 0 0 0 2px var(--cell-hover);
}

.cell[data-game-cell="true"]:focus-visible {
    z-index: 3;
    outline: 3px solid var(--navigator-focus);
    outline-offset: -3px;
}

.cell.border-right {
    border-right: 2px solid var(--cell-border-thick);
}

.cell.border-bottom {
    border-bottom: 2px solid var(--cell-border-thick);
}

/*
 * A fitted 30×30 board can put cell edges between CSS pixels. Strengthen its
 * one-cell grid without changing the established weight on smaller boards.
 * Five-cell separators keep the theme accent and remain a full two pixels.
 */
#grid-container[data-puzzle-size="30"] .cell[data-game-cell="true"] {
    --large-grid-major-line: clamp(2px, calc(var(--grid-cell-size) * 0.15), 3px);
    border-right-color: color-mix(
        in srgb,
        var(--cell-border-thin) 78%,
        var(--cell-border-outer)
    );
    border-bottom-color: color-mix(
        in srgb,
        var(--cell-border-thin) 78%,
        var(--cell-border-outer)
    );
}

#grid-container[data-puzzle-size="30"] .cell.border-right {
    border-right: var(--large-grid-major-line) solid var(--cell-border-thick);
}

#grid-container[data-puzzle-size="30"] .cell.border-bottom {
    border-bottom: var(--large-grid-major-line) solid var(--cell-border-thick);
}

.border-top {
    border-top: 2px solid var(--cell-border-outer);
}

.border-left {
    border-left: 2px solid var(--cell-border-outer);
}

.border-right-outer {
    border-right: 2px solid var(--cell-border-outer);
}

.border-bottom-outer {
    border-bottom: 2px solid var(--cell-border-outer);
}

.cell.blocked {
    background-color: var(--cell-fill);
    box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.55);
    animation: fillCell 100ms ease-out forwards;
}

.cell.blocked:hover {
    background-color: var(--cell-fill);
    box-shadow: inset 0 0 0 2px var(--cell-hover), inset 0 0 8px rgba(0, 0, 0, 0.55);
}

@keyframes fillCell {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.2);
        background-color: var(--cell-place-trail);
        opacity: 1;
    }
    100% {
        transform: scale(1);
        background-color: var(--cell-fill);
        opacity: 1;
    }
}

.cell.cross::before,
.cell.cross::after,
.cell.solver-x::before,
.cell.solver-x::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 70%;
    height: 4px;
    background-color: var(--cell-cross);
    pointer-events: none;
}

.cell.cross::before,
.cell.solver-x::before {
    transform: translate(-50%, -50%) rotate(45deg);
    animation: cross-in-forward 100ms ease-out forwards;
}

.cell.cross::after,
.cell.solver-x::after {
    transform: translate(-50%, -50%) rotate(-45deg);
    animation: cross-in-back 100ms ease-out forwards;
}

.cell.cross.mistake::before,
.cell.cross.mistake::after,
.cell.mistake::before,
.cell.mistake::after {
    background-color: var(--state-error);
}

.cell.mistake-locked {
    cursor: not-allowed;
}

.cell.mistake-locked.mistake {
    background-color: color-mix(in srgb, var(--state-error) 18%, var(--cell-empty));
    outline: 2px solid var(--state-error);
    outline-offset: -2px;
}

@keyframes cross-in-forward {
    0% { transform: translate(-50%, -50%) rotate(45deg) scale(0); }
    50% { transform: translate(-50%, -50%) rotate(45deg) scale(1.2); }
    100% { transform: translate(-50%, -50%) rotate(45deg) scale(1); }
}

@keyframes cross-in-back {
    0% { transform: translate(-50%, -50%) rotate(-45deg) scale(0); }
    50% { transform: translate(-50%, -50%) rotate(-45deg) scale(1.2); }
    100% { transform: translate(-50%, -50%) rotate(-45deg) scale(1); }
}

.cell.dot::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 5px;
    height: 5px;
    background-color: var(--cell-cross);
    transform: translate(-50%, -50%);
}

.penalty-popup {
    position: absolute;
    z-index: 10;
    color: #ffff00;
    font-size: 0.8rem;
    text-shadow: -1px -1px 0 #000, 1px -1px 0 #000,
                 -1px 1px 0 #000, 1px 1px 0 #000;
    pointer-events: none;
    animation: penalty-float 500ms ease-out forwards;
}

@keyframes penalty-float {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(-20px); }
}

.hit-count,
.hit-count-rows > div,
.hit-count-column > div {
    color: #000 !important;
    font-weight: bold !important;
    line-height: 30px;
    text-align: center;
    border: 0 !important;
    outline: 0 !important;
    box-shadow: none !important;
}

.hit-count:hover,
.hit-count-rows > div:hover,
.hit-count-column > div:hover {
    cursor: default !important;
    border: 0 !important;
    outline: 0 !important;
    box-shadow: none !important;
}

.hit-count {
    background-color: var(--hint-bg-normal);
    transition: color 100ms ease, background-color 100ms ease;
}

.cell.hit-count.hit-count-rows.row-even,
.cell.hit-count.hit-count-column.col-even {
    background-color: var(--hint-bg-checker-even);
}

.cell.hit-count.hit-count-rows.row-odd,
.cell.hit-count.hit-count-column.col-odd {
    background-color: var(--hint-bg-checker-odd);
}

.hint-highlight {
    position: relative;
    z-index: 1;
    color: var(--hint-text-highlight) !important;
    background-color: var(--hint-bg-highlight) !important;
}

#grid-container .navigator-hint {
    color: #1e90ff !important;
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
    background-color: inherit !important;
    box-shadow: none !important;
}

.cell[data-game-cell="true"].row-even.col-even,
.cell[data-game-cell="true"].row-odd.col-odd {
    background-color: var(--cell-bg-checker-even);
}

.cell[data-game-cell="true"].row-even.col-odd,
.cell[data-game-cell="true"].row-odd.col-even {
    background-color: var(--cell-bg-checker-odd);
}

.cell[data-game-cell="true"].blocked {
    background-color: var(--cell-fill);
}

.cell:not([data-game-cell="true"]):not(.hit-count):not(.hit-count-rows):not(.hit-count-column) {
    cursor: default !important;
    background: none !important;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
}

#grid-container .coord-x,
#grid-container .coord-y {
    position: absolute;
    z-index: 2;
    color: var(--navigator-focus);
    font-size: 10px;
    line-height: 1;
    pointer-events: none;
}

#grid-container .coord-x {
    top: 2px;
    right: 3px;
}

#grid-container .coord-y {
    bottom: 2px;
    left: 3px;
}

#hover-col-highlight,
#hover-row-highlight {
    z-index: 0;
    border-radius: 0 !important;
    opacity: 1;
}

#grid-container .cell.solver-block::after {
    content: "";
    position: absolute;
    inset: 4px;
    z-index: 2;
    border: 2px solid var(--navigator-focus);
    background: transparent;
    pointer-events: none;
}

#grid-container .cell.solver-x::before,
#grid-container .cell.solver-x::after {
    z-index: 2;
    background-color: var(--navigator-focus);
}

.solution-mark {
    position: relative;
    z-index: 2;
    color: var(--navigator-focus);
    font-size: 0.68rem;
    font-weight: bold;
    line-height: 1;
    pointer-events: none;
}

.solved {
    background-color: green !important;
}

@media (max-width: 760px), (max-width: 900px) and (max-height: 500px), (pointer: coarse) {
    .board-frame.board-fitted-mobile {
        overflow: hidden;
    }

    .board-frame.board-fitted-mobile #grid-wrapper {
        width: 100%;
        min-width: 0;
        padding: 8px;
        overflow: hidden;
    }

    .board-frame.board-fitted-mobile #grid-container {
        max-width: 100%;
    }

    .board-frame.board-detail-mobile {
        align-items: flex-start;
        justify-content: flex-start;
        max-height: min(72dvh, 680px);
        overflow: auto;
        overscroll-behavior: contain;
        scrollbar-gutter: stable;
    }

    .board-frame.board-detail-mobile #grid-wrapper {
        width: max-content;
        min-width: max-content;
        max-width: none;
        padding: 16px 48px 48px 16px;
        overflow: visible;
    }

    .board-frame.board-detail-mobile #grid-container {
        max-width: none;
        margin: 0;
    }

    .board-frame.board-move-mode,
    .board-frame.board-move-mode #grid-container {
        cursor: grab;
    }

    .board-frame.board-move-mode .cell[data-game-cell="true"] {
        pointer-events: none;
    }

    .board-frame.board-fitted-mobile .cell {
        font-size: clamp(0.38rem, calc(var(--grid-cell-size) * 0.48), 0.88rem);
        line-height: var(--grid-cell-size);
    }

    .board-frame.board-fitted-mobile .cell.cross::before,
    .board-frame.board-fitted-mobile .cell.cross::after,
    .board-frame.board-fitted-mobile .cell.solver-x::before,
    .board-frame.board-fitted-mobile .cell.solver-x::after {
        height: clamp(1px, calc(var(--grid-cell-size) * 0.12), 4px);
    }

    .board-frame.board-fitted-mobile .cell.dot::before {
        width: clamp(2px, calc(var(--grid-cell-size) * 0.18), 5px);
        height: clamp(2px, calc(var(--grid-cell-size) * 0.18), 5px);
    }

    .mark-tool-bar,
    .mobile-mark-tools {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
        width: min(100%, 360px);
        margin: 0 auto 10px;
    }

    .mark-tool-bar [data-mark-tool],
    .mobile-mark-tools [data-mark-tool] {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 7px;
    }

    .cell[data-game-cell="true"]:hover {
        box-shadow: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .cell,
    .cell::before,
    .cell::after,
    .penalty-popup {
        animation-duration: 1ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 1ms !important;
    }
}
