.reference-game-board {
    /*
     * Game components consume the application's semantic theme tokens.
     * Any future theme only needs to define the standard --bg/--text/
     * --border/--accent/--status variables; no game-specific selector is needed.
     */
    --rg-panel: var(--game-panel-bg, var(--theme-panel-bg, var(--bg-secondary, #1c1c1c)));
    --rg-border: var(--game-border, var(--border-secondary, #303030));
    --rg-cell: var(--game-cell-bg, var(--bg-primary, #171717));
    --rg-cell-alt: var(--game-cell-alt-bg, var(--bg-tertiary, #202020));
    --rg-text: var(--game-text, var(--text-primary, #f0f0f0));
    --rg-muted: var(--game-muted, var(--text-secondary, #989898));
    --rg-mine: var(--game-player-color, var(--status-success, var(--accent-primary, #4ade80)));
    --rg-theirs: var(--game-opponent-color, var(--link-color, #5b9bd5));
    --rg-danger: var(--game-danger, var(--status-error, #f87171));
    width: 100%;
    padding: 0;
    box-sizing: border-box;
    position: relative;
}

.reference-game-shell {
    width: min(100%, 440px);
    margin: auto;
    padding: 0;
    color: var(--rg-text);
    position: relative;
}

.reference-panel-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 11px 2px 0;
    color: var(--rg-muted);
    font: 600 11px/1 Inter, sans-serif;
}

.game-picker-card:focus-visible {
    outline: 2px solid var(--gp-strong);
    outline-offset: 2px;
}

.game-mark-checkers-a { position: relative; width: 26px; height: 22px; color: var(--gp-strong); }
.game-mark-checkers-a i,
.game-mark-checkers-a b { position: absolute; left: 1px; width: 24px; height: 12px; border-radius: 50%; background: currentColor; }
.game-mark-checkers-a i { bottom: 0; }
.game-mark-checkers-a b { bottom: 6px; border: 1.5px solid var(--gp-card); }

.game-mark-mine-a { position: relative; width: 26px; height: 26px; display: grid; place-items: center; color: var(--gp-strong); }
.game-mark-mine-a i { position: absolute; width: 25px; height: 3px; border-radius: 2px; background: currentColor; }
.game-mark-mine-a i:nth-child(2) { transform: rotate(90deg); }
.game-mark-mine-a i:nth-child(3) { transform: rotate(45deg); }
.game-mark-mine-a i:nth-child(4) { transform: rotate(135deg); }
.game-mark-mine-a b { position: relative; width: 18px; height: 18px; border-radius: 50%; background: currentColor; }
.game-mark-mine-a em { position: absolute; top: 8px; left: 8px; width: 4px; height: 4px; border-radius: 50%; background: var(--gp-card); }

.game-mark-sudoku-b {
    width: 24px;
    height: 24px;
    display: grid;
    place-items: center;
    border: 2px solid currentColor;
    border-radius: 6px;
    color: var(--gp-strong);
    font: 800 13px/1 Inter, sans-serif;
}

.reference-setup {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 20px 8px 14px;
    color: var(--rg-text);
    text-align: center;
}
.reference-setup > strong { font: 700 18px/1.2 "Comic Neue", cursive; }
.reference-setup > span,
.reference-setup > small { color: var(--rg-muted); font: 500 11px/1.4 Inter, sans-serif; }
.reference-setup-options { width: 100%; display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; margin-top: 4px; }
.reference-setup-options.three { grid-template-columns: repeat(3, 1fr); }
.reference-setup-options button {
    min-height: 50px;
    padding: 9px 5px;
    border: 1px solid var(--rg-border);
    border-radius: 10px;
    background: var(--rg-panel);
    color: var(--rg-text);
    font: 700 13px/1.2 Inter, sans-serif;
}
.reference-setup-options button small { display: block; margin-top: 3px; color: var(--rg-muted); font-size: 9px; }
.reference-setup-options button.selected { border-color: var(--accent-primary); background: color-mix(in srgb, var(--accent-primary) 12%, var(--rg-panel)); }
.reference-setup-options button:disabled:not(.selected) { opacity: .45; }

.sudoku-grid {
    display: grid;
    grid-template-columns: repeat(var(--sudoku-size), minmax(0, 1fr));
    grid-template-rows: repeat(var(--sudoku-size), minmax(0, 1fr));
    overflow: hidden;
    border: 2px solid var(--rg-border);
    border-radius: 10px;
    aspect-ratio: 1;
    background: var(--rg-border);
}

.sudoku-board .reference-game-shell {
    width: min(100%, 310px);
}

.game-area:has(.sudoku-board) .game-title {
    color: var(--text-primary);
}

.sudoku-title-name,
.sudoku-title-turn.mine {
    color: var(--text-primary);
}

.sudoku-title-turn {
    font-style: normal;
}

.sudoku-title-turn.theirs {
    color: var(--text-secondary);
}

.sudoku-cell {
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    padding: 0;
    border: 0;
    border-right: 1px solid var(--rg-border);
    border-bottom: 1px solid var(--rg-border);
    background: var(--rg-cell);
    color: var(--rg-text);
    font: 700 18px/1 Inter, sans-serif;
}

.sudoku-cell.box-right { border-right-width: 3px; }
.sudoku-cell.box-bottom { border-bottom-width: 3px; }
.sudoku-cell.box-alt { background: var(--rg-cell-alt); }
.sudoku-grid.size-9 .sudoku-cell { font-size: 15px; }
.sudoku-cell.given { color: var(--rg-muted); font-weight: 800; }
.sudoku-cell.mine { color: var(--rg-mine); }
.sudoku-cell.theirs { color: var(--rg-theirs); }
.sudoku-cell.selected { background: color-mix(in srgb, var(--rg-mine) 23%, var(--rg-cell)); }
.sudoku-cell.wrong { background: color-mix(in srgb, var(--rg-danger) 45%, var(--rg-cell)); animation: rg-shake .4s ease; }

.sudoku-pad {
    display: grid;
    grid-template-columns: repeat(var(--sudoku-size, 9), minmax(0, 1fr));
    gap: 5px;
    margin-top: 11px;
}

.sudoku-pad button {
    min-width: 0;
    height: 34px;
    padding: 0 2px;
    border: 1px solid var(--rg-border);
    border-radius: 9px;
    background: var(--rg-panel);
    color: var(--rg-text);
    font: 800 15px/1 Inter, sans-serif;
}

.sudoku-pad button:disabled { opacity: .38; }

.mines-reference-actions {
    position: absolute;
    right: 94px;
    top: -39px;
    z-index: 2;
}

.game-area:has(.minesweeper-board) .game-board-container {
    overflow: visible;
}

.game-area:has(.minesweeper-board) .game-title {
    color: var(--text-primary);
    text-transform: none;
}

.mines-title-name,
.mines-title-turn.mine {
    color: var(--text-primary);
}

.mines-title-turn {
    font-style: normal;
}

.mines-title-turn.theirs {
    color: var(--text-secondary);
}

.minesweeper-board .reference-game-shell {
    width: min(100%, 310px);
}

.mines-reference-actions button {
    width: 28px;
    height: 28px;
    padding: 0;
    display: grid;
    place-items: center;
    border: 1px solid var(--rg-border);
    border-radius: 8px;
    background: var(--rg-panel);
    color: var(--rg-muted);
}

.mines-reference-actions button.active {
    border-color: var(--accent-primary);
    background: var(--accent-primary);
    color: var(--bg-primary);
}

.mines-grid {
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    grid-template-rows: repeat(8, minmax(0, 1fr));
    gap: 3px;
    aspect-ratio: 1;
}

.mine-tile {
    --mines-hidden-bg: var(--game-mines-hidden-bg, var(--rg-cell-alt));
    --mines-hidden-border: var(--game-mines-hidden-border, var(--rg-border));
    --mines-open-bg: var(--game-mines-open-bg, var(--rg-cell));
    --mines-open-border: var(--game-mines-open-border, var(--rg-border));
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    padding: 0;
    border: 1px solid var(--mines-hidden-border);
    border-radius: 7px;
    background: var(--mines-hidden-bg);
    color: var(--rg-text);
    font: 800 15px/1 Inter, sans-serif;
    box-shadow: inset 0 1px 1px rgba(255, 255, 255, .06);
}

.mine-tile.revealed {
    border-color: var(--mines-open-border);
    background: var(--mines-open-bg);
    box-shadow: none;
    animation: ms-reveal .22s ease;
}
.mine-tile.flagged { color: #e0a54a; }
.mine-tile.exploded { background: color-mix(in srgb, var(--rg-danger) 55%, var(--rg-cell)); color: var(--rg-text); animation: ms-boom .4s ease; }
.mine-tile[data-count="1"] { color: #5b9bd5; }
.mine-tile[data-count="2"] { color: #57b96a; }
.mine-tile[data-count="3"] { color: #e0837c; }
.mine-tile[data-count="4"] { color: #a879d6; }
.mine-tile[data-count="5"] { color: #e0a54a; }

.checkers-grid {
    --checkers-square-light: var(--game-checkers-square-light, var(--rg-cell));
    --checkers-square-dark: var(--game-checkers-square-dark, var(--rg-cell-alt));
    --checkers-board-border: var(--game-checkers-board-border, var(--rg-border));
    --checkers-you-piece: var(--game-checkers-player-piece, var(--rg-text));
    --checkers-you-border: var(--game-checkers-player-border, var(--rg-muted));
    --checkers-foe-piece: var(--game-checkers-opponent-piece, var(--rg-muted));
    --checkers-foe-border: var(--game-checkers-opponent-border, var(--rg-border));
    --checkers-focus: var(--game-checkers-focus, var(--accent-primary));
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    grid-template-rows: repeat(8, minmax(0, 1fr));
    overflow: hidden;
    border: 1.5px solid var(--checkers-board-border);
    border-radius: 12px;
    aspect-ratio: 1;
}

.checkers-grid.rotated { transform: rotate(180deg); }
.checkers-grid.rotated .checker-piece { transform: rotate(180deg); }
.checkers-square {
    position: relative;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    padding: 0;
    display: grid;
    place-items: center;
    border: 0;
    background: var(--checkers-square-light);
}
.checkers-square.dark { background: var(--checkers-square-dark); }
.checkers-square.selected { background: color-mix(in srgb, var(--checkers-focus) 34%, var(--checkers-square-dark)); }
.checkers-square.target { background: color-mix(in srgb, var(--checkers-focus) 18%, var(--checkers-square-dark)); }
.checkers-square.target::after { content: ""; position: absolute; width: 26%; height: 26%; border-radius: 50%; background: var(--checkers-focus); opacity: .55; }

.sudoku-cell:focus-visible,
.mine-tile:focus-visible,
.checkers-square:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: -3px;
}

.checker-piece {
    position: relative;
    width: 74%;
    height: 74%;
    display: grid;
    place-items: center;
    border-radius: 50%;
    border: 2px solid color-mix(in srgb, currentColor 72%, var(--rg-text));
    background: currentColor;
    box-shadow: 0 3px 6px rgba(0,0,0,.4), inset 0 1px 1px rgba(255,255,255,.35);
}

.checkers-square.selected .checker-piece { box-shadow: 0 0 0 2px var(--accent-primary), 0 3px 6px rgba(0,0,0,.4); }
.checker-piece.mine { color: var(--checkers-you-piece); border-color: var(--checkers-you-border); }
.checker-piece.theirs { color: var(--checkers-foe-piece); border-color: var(--checkers-foe-border); }
.checker-piece.king i { color: #d9c88a; font-size: 15px; }
.checker-piece.just-moved { animation: ck-drop .28s ease; }
.checkers-grid.rotated .checker-piece.just-moved { animation-name: ck-drop-rotated; }

.game-area:has(.checkers-board) .game-title {
    color: var(--text-primary);
    font-family: "Comic Neue", cursive;
    font-weight: 700;
}

.checkers-title-name,
.checkers-title-turn.mine { color: var(--text-primary); }
.checkers-title-turn { font-style: normal; }
.checkers-title-turn.theirs { color: var(--text-secondary); }

.reference-result-overlay {
    position: absolute;
    inset: 0;
    z-index: 9;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 30px;
    background: transparent;
}
.reference-result-overlay[hidden] { display: none; }

.reference-result-card {
    position: relative;
    width: 100%;
    padding: 26px 22px 22px;
    border-radius: 20px;
    background: var(--rg-panel, var(--theme-panel-bg, var(--bg-secondary)));
    color: var(--rg-text, var(--text-primary));
    text-align: center;
    box-shadow: 0 16px 36px -16px rgba(0, 0, 0, .65);
    animation: rg-result-pop .2s ease;
}

.reference-result-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 30px;
    height: 30px;
    padding: 0;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--rg-muted, var(--text-secondary));
    font-size: 17px;
    box-shadow: none;
    cursor: pointer;
}
.reference-result-close:hover {
    background: var(--rg-cell-alt, var(--bg-tertiary));
    color: var(--rg-text, var(--text-primary));
}

.reference-result-spark {
    display: none;
    justify-content: center;
    gap: 9px;
    margin-bottom: 14px;
}

.reference-result-overlay[data-rematch-state="requested"] .reference-result-spark {
    display: flex;
}

.reference-result-spark i {
    width: 16px;
    height: 16px;
    border: 2.5px solid var(--accent-primary);
    border-radius: 5px;
    transform: rotate(45deg);
    animation: rg-diamond 1.1s ease-in-out infinite;
}

.reference-result-spark i + i { animation-delay: .18s; }
.reference-result-card h2 { margin: 0 0 6px; color: var(--rg-text, var(--text-primary)); font: 700 22px/1.2 "Comic Neue", cursive; }
.reference-result-card p { margin: 0 0 18px; color: var(--rg-muted, var(--text-secondary)); font: 500 13px/1.5 Inter, sans-serif; }
.reference-result-play-again {
    width: 100%;
    padding: 13px 0;
    border: 0;
    border-radius: 14px;
    background: var(--accent-primary);
    color: var(--bg-primary);
    font: 700 15px/1 "Comic Neue", cursive;
    box-shadow: 0 10px 26px rgba(0, 0, 0, .35);
}
.reference-result-play-again:disabled { opacity: .48; cursor: not-allowed; box-shadow: none; }
.reference-result-overlay[data-rematch-state="requested"] .reference-result-play-again:disabled {
    opacity: .65;
    cursor: not-allowed;
}

@keyframes rg-shake { 25%, 75% { transform: translateX(-3px); } 50% { transform: translateX(3px); } }
@keyframes rg-pop { 50% { transform: scale(1.12); } }
@keyframes ms-reveal {
    from { transform: scale(.7); opacity: .2; }
    to { transform: scale(1); opacity: 1; }
}
@keyframes ms-boom {
    0% { transform: scale(1); }
    40% { transform: scale(1.25); }
    100% { transform: scale(1); }
}
@keyframes rg-result-pop { from { transform: scale(.94); opacity: 0; } }
@keyframes rg-diamond { 50% { transform: rotate(45deg) scale(.72); opacity: .45; } }
@keyframes ck-drop {
    from { transform: scale(.6); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}
@keyframes ck-drop-rotated {
    from { transform: rotate(180deg) scale(.6); opacity: 0; }
    to { transform: rotate(180deg) scale(1); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .checker-piece.just-moved,
    .mine-tile.revealed,
    .mine-tile.exploded { animation: none; }
}

@media (max-width: 430px) {
    .sudoku-cell { font-size: 15px; }
}
