#game-root {
    --gm-accent: #10B981;
    --gm-accent-dark: #0c8d64;
    --gm-accent-light: #e3f9ef;
    --gm-accent-border: #a7f3d0;
    --gm-wood: #e7b567;
    --gm-wood-dark: #c98f3c;
    --gm-line: rgba(84, 52, 18, .72);
    --gm-glass-bg: rgba(255, 255, 255, .62);
    --gm-glass-border: rgba(255, 255, 255, .45);
}

#game-root button {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* Tier/status colors passed to KidWorldIcons.svg() (not defined site-wide). */
#game-root .kwi-trophy { color: #F59E0B; }
#game-root .kwi-stars { color: #8B5CF6; }
#game-root .kwi-thumbsup { color: #10B981; }
#game-root .kwi-lightning { color: #3B82F6; }
#game-root .kwi-smile { color: #F472B6; }
#game-root .kwi-muted { color: #cbd5e1; }

.kwg-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 14px;
}

.gm-wrap {
    max-width: 540px;
    margin: 0 auto;
}

.gm-wrap-setup {
    max-width: 500px;
}

.gm-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 10px;
}

.gm-header-icon {
    display: flex;
    font-size: 18px;
    line-height: 1;
}

.gm-header-title {
    font-size: 22px;
    font-weight: 800;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, .2);
}

/* ---- Setup screen ---- */

.gm-setup-card {
    background: var(--gm-glass-bg);
    backdrop-filter: blur(14px) saturate(160%);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    border: 1px solid var(--gm-glass-border);
    border-radius: var(--kw-radius, 12px);
    padding: 20px;
    box-shadow: 0 3px 12px rgba(0, 0, 0, .12);
}

.gm-setup-section {
    margin-bottom: 20px;
}

.gm-setup-section-last {
    margin-bottom: 0;
}

.gm-setup-label {
    font-size: 13px;
    font-weight: 800;
    color: #888;
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: 10px;
}

.gm-opponent-grid,
.gm-size-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.gm-difficulty-grid,
.gm-two-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.gm-theme-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.gm-option-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 4px;
    border: 2px solid var(--gm-accent-border);
    border-radius: var(--kw-radius, 14px);
    background: rgba(255, 255, 255, .5);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 12px 8px;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .06);
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}

.gm-option-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 14px rgba(0, 0, 0, .1);
}

.gm-option-card.gm-option-selected {
    border-color: var(--gm-accent);
    background: var(--gm-accent-light);
    box-shadow: 0 0 0 2px var(--gm-accent) inset;
}

.gm-option-selected::after {
    content: '✓';
    position: absolute;
    top: 6px;
    right: 6px;
    width: 16px;
    height: 16px;
    background: var(--gm-accent);
    color: #fff;
    border-radius: 50%;
    font-size: 10px;
    font-weight: 800;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gm-option-emoji {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 26px;
    font-size: 26px;
    line-height: 1;
}

.gm-option-label {
    font-size: 13px;
    font-weight: 800;
    color: var(--kw-text, #2D2A32);
}

.gm-option-sub {
    font-size: 11px;
    color: #888;
    font-weight: 600;
}

.gm-difficulty-bullets {
    list-style: none;
    margin: 4px 0 0;
    padding: 0;
    font-size: 11px;
    color: #777;
    font-weight: 600;
    line-height: 1.5;
}

.gm-difficulty-bullets li::before {
    content: '• ';
    color: var(--gm-accent);
}

/* A tiny wooden board whose line spacing hints at the grid size. */
.gm-size-preview {
    display: block;
    width: 34px;
    height: 34px;
    border-radius: 4px;
    background-color: var(--gm-wood);
    box-shadow: inset 0 -2px 0 var(--gm-wood-dark);
    background-image:
        linear-gradient(var(--gm-line) 1px, transparent 1px),
        linear-gradient(90deg, var(--gm-line) 1px, transparent 1px);
    background-position: 1px 1px;
}

.gm-size-preview-9 { background-size: 8px 8px; }
.gm-size-preview-13 { background-size: 5.5px 5.5px; }
.gm-size-preview-15 { background-size: 4.6px 4.6px; }

.gm-mini-stone {
    display: inline-block;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    vertical-align: middle;
}

.gm-mini-b {
    background: radial-gradient(circle at 34% 30%, #6b6b6b, #111 62%);
    box-shadow: 0 1px 2px rgba(0, 0, 0, .35);
}

.gm-mini-w {
    background: radial-gradient(circle at 34% 30%, #fff, #d6d3cd 72%);
    box-shadow: 0 1px 2px rgba(0, 0, 0, .3), inset 0 0 0 1px rgba(0, 0, 0, .08);
}

.gm-mini-emoji {
    font-size: 22px;
    line-height: 1;
}

.gm-timed-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.gm-timed-checkbox {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.gm-timed-toggle-track {
    position: relative;
    width: 44px;
    height: 24px;
    background: var(--gm-accent-border);
    border-radius: 999px;
    transition: background .15s ease;
    flex-shrink: 0;
}

.gm-timed-toggle-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
    transition: transform .15s ease;
}

.gm-timed-checkbox:checked + .gm-timed-toggle-track {
    background: var(--gm-accent);
}

.gm-timed-checkbox:checked + .gm-timed-toggle-track .gm-timed-toggle-thumb {
    transform: translateX(20px);
}

.gm-timed-toggle-label {
    font-size: 14px;
    font-weight: 700;
    color: var(--kw-text, #2D2A32);
}

.gm-timed-toggle-label small {
    color: #888;
    font-weight: 600;
}

.gm-start-btn {
    display: block;
    width: 100%;
    text-align: center;
    font-size: 16px;
    padding: 14px;
    margin-top: 20px;
}

/* ---- Game screen ---- */

.gm-mode-row {
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

.gm-mode-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--gm-accent-light);
    color: var(--gm-accent-dark);
    border-radius: 999px;
    padding: 6px 12px;
    font-weight: 700;
    font-size: 12px;
}

.gm-mode-pill-icon {
    display: inline-flex;
    line-height: 1;
}

.gm-change-setup-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 1px solid var(--gm-glass-border);
    background: var(--gm-glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: var(--gm-accent-dark);
    border-radius: 999px;
    font-weight: 700;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    padding: 6px 12px 6px 10px;
    transition: transform .1s ease, background .15s ease;
}

.gm-change-setup-btn svg {
    width: 12px;
    height: 12px;
}

.gm-change-setup-btn:hover {
    background: rgba(255, 255, 255, .8);
    transform: translateY(-1px);
}

.gm-players-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-bottom: 12px;
}

.gm-player-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    min-width: 88px;
    padding: 8px 14px;
    border-radius: 8px;
    background: rgba(255, 255, 255, .82);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 2px solid var(--gm-accent-border);
    transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}

.gm-player-mark {
    display: flex;
    min-height: 24px;
    align-items: center;
}

.gm-player-mark .gm-mini-stone {
    width: 24px;
    height: 24px;
}

.gm-player-name {
    font-size: 11px;
    font-weight: 800;
    color: #999;
}

.gm-player-chip.gm-player-active {
    border-color: var(--gm-accent);
    box-shadow: 0 0 0 2px var(--gm-accent-light) inset, 0 4px 10px rgba(16, 185, 129, .25);
    transform: translateY(-2px);
}

.gm-player-chip.gm-player-active .gm-player-name {
    color: var(--gm-accent-dark);
}

.gm-players-vs {
    font-size: 12px;
    font-weight: 800;
    color: #bbb;
}

.gm-status-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 4px;
    min-height: 22px;
}

.gm-status {
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    text-align: center;
}

.gm-rule {
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: rgba(255, 255, 255, .85);
    margin-bottom: 12px;
}

.gm-timer {
    font-size: 13px;
    font-weight: 800;
    color: #b91c1c;
    background: #fee2e2;
    border-radius: 999px;
    padding: 2px 10px;
}

.gm-board-card {
    container-type: inline-size;
    background-color: var(--gm-wood);
    background-image:
        repeating-linear-gradient(100deg, rgba(255, 255, 255, .07) 0 3px, transparent 3px 11px),
        linear-gradient(160deg, rgba(255, 255, 255, .18), rgba(0, 0, 0, .06));
    border-radius: var(--kw-radius, 12px);
    padding: clamp(6px, 2.4vw, 14px);
    box-shadow: inset 0 -4px 0 var(--gm-wood-dark), 0 4px 12px rgba(0, 0, 0, .16);
}

.gm-board {
    --gm-n: 13;
    display: grid;
    grid-template-columns: repeat(var(--gm-n), 1fr);
    font-size: 16px;
    font-size: calc(100cqw / var(--gm-n) * .6);
    user-select: none;
    -webkit-user-select: none;
}

.gm-pt {
    position: relative;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* The two grid lines through each point's center. */
.gm-pt::before,
.gm-pt::after {
    content: '';
    position: absolute;
    background: var(--gm-line);
    pointer-events: none;
}

.gm-pt::before {
    left: 0;
    right: 0;
    top: 50%;
    height: 1px;
    transform: translateY(-50%);
}

.gm-pt::after {
    top: 0;
    bottom: 0;
    left: 50%;
    width: 1px;
    transform: translateX(-50%);
}

.gm-edge-l::before { left: 50%; }
.gm-edge-r::before { right: 50%; }
.gm-edge-t::after { top: 50%; }
.gm-edge-b::after { bottom: 50%; }
.gm-edge-t::before, .gm-edge-b::before { height: 2px; }
.gm-edge-l::after, .gm-edge-r::after { width: 2px; }

.gm-dot {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 22%;
    height: 22%;
    border-radius: 50%;
    background: var(--gm-line);
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.gm-stone {
    position: absolute;
    inset: 6%;
    z-index: 1;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    pointer-events: none;
    opacity: 0;
}

.gm-live .gm-pt:not(.gm-filled) {
    cursor: pointer;
}

.gm-filled .gm-stone {
    opacity: 1;
    animation: gm-place .22s ease;
}

.gm-theme-classic .gm-b .gm-stone {
    background: radial-gradient(circle at 34% 30%, #6b6b6b, #111 62%);
    box-shadow: 1px 2px 3px rgba(0, 0, 0, .4);
}

.gm-theme-classic .gm-w .gm-stone {
    background: radial-gradient(circle at 34% 30%, #fff, #d6d3cd 72%);
    box-shadow: 1px 2px 3px rgba(0, 0, 0, .35);
}

.gm-theme-emoji .gm-b .gm-stone {
    background: #fee2e2;
    box-shadow: inset 0 0 0 2px #f87171, 0 1px 2px rgba(0, 0, 0, .25);
}

.gm-theme-emoji .gm-w .gm-stone {
    background: #dbeafe;
    box-shadow: inset 0 0 0 2px #60a5fa, 0 1px 2px rgba(0, 0, 0, .25);
}

/* Faint preview of the stone about to be placed (mouse only). */
@media (hover: hover) {
    .gm-live .gm-pt:not(.gm-filled):hover .gm-stone {
        opacity: .45;
    }

    .gm-live.gm-turn-b.gm-theme-classic .gm-pt:not(.gm-filled):hover .gm-stone {
        background: #111;
    }

    .gm-live.gm-turn-w.gm-theme-classic .gm-pt:not(.gm-filled):hover .gm-stone {
        background: #fff;
    }

    .gm-live.gm-turn-b.gm-theme-emoji .gm-pt:not(.gm-filled):hover .gm-stone {
        background: #f87171;
    }

    .gm-live.gm-turn-w.gm-theme-emoji .gm-pt:not(.gm-filled):hover .gm-stone {
        background: #60a5fa;
    }
}

/* The most recent stone gets a small marker. */
.gm-last .gm-stone::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 26%;
    height: 26%;
    border-radius: 50%;
    background: #ef4444;
    transform: translate(-50%, -50%);
}

.gm-theme-emoji .gm-last .gm-stone::after {
    width: 22%;
    height: 22%;
    left: auto;
    top: auto;
    right: -4%;
    bottom: -4%;
    transform: none;
    box-shadow: 0 0 0 1px #fff;
}

.gm-win .gm-stone {
    z-index: 2;
    animation: gm-win-pulse .6s ease infinite alternate;
}

.gm-hint .gm-stone {
    opacity: 1;
    background: rgba(16, 185, 129, .35);
    box-shadow: 0 0 0 3px var(--gm-accent);
    animation: gm-hint-pulse .45s ease infinite alternate;
}

.gm-actions-row {
    justify-content: center;
    margin-top: 18px;
    margin-bottom: 0;
}

.gm-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: none;
    background: var(--gm-accent-light);
    color: var(--gm-accent-dark);
    border-radius: 999px;
    padding: 8px 16px;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    transition: transform .1s ease, background .15s ease;
}

.gm-action-btn:hover:not(:disabled) {
    background: var(--gm-accent-border);
    transform: translateY(-1px);
}

.gm-action-btn:disabled {
    opacity: .45;
    cursor: default;
}

.gm-hint-count {
    font-weight: 600;
    opacity: .8;
}

/* ---- Done screen ---- */

.gm-done-card {
    text-align: center;
    background: var(--gm-glass-bg);
    backdrop-filter: blur(14px) saturate(160%);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    border-radius: var(--kw-radius, 12px);
    padding: 32px 20px;
    box-shadow: 0 3px 12px rgba(0, 0, 0, .12);
    animation: gm-pop .3s ease;
    border: 2px solid transparent;
}

.gm-done-card.gm-done-win {
    border-color: var(--gm-accent-border);
    box-shadow: 0 3px 16px rgba(16, 185, 129, .22);
}

.gm-done-card.gm-done-draw {
    border-color: #fde68a;
}

.gm-done-card.gm-done-loss {
    border-color: #fecaca;
}

.gm-done-emoji {
    font-size: 56px;
    margin-bottom: 8px;
}

.gm-done-title {
    font-size: 20px;
    font-weight: 800;
    color: var(--gm-accent-dark);
    margin-bottom: 8px;
}

.gm-done-score {
    font-size: 16px;
    font-weight: 600;
    color: #555;
    margin-bottom: 4px;
}

.gm-done-details {
    font-size: 12px;
    font-weight: 600;
    color: #888;
    margin-bottom: 10px;
}

.gm-done-stars {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    font-size: 24px;
}

.gm-done-share {
    justify-content: center;
    margin-top: 16px;
}

.gm-done-actions {
    justify-content: center;
    margin-top: 20px;
}

.gm-btn-primary,
.gm-btn-secondary {
    border: none;
    padding: 12px 22px;
    border-radius: 999px;
    font-weight: 800;
    font-size: 14px;
    cursor: pointer;
    transition: transform .1s ease;
}

.gm-btn-primary {
    background: var(--gm-accent);
    color: #fff;
    box-shadow: 0 3px 0 var(--gm-accent-dark);
}

.gm-btn-primary:hover {
    transform: translateY(-1px);
}

.gm-btn-secondary {
    background: var(--gm-accent-light);
    color: var(--gm-accent-dark);
}

.gm-btn-secondary:hover {
    background: var(--gm-accent-border);
}

@keyframes gm-pop {
    0% { transform: scale(.7); }
    100% { transform: scale(1); }
}

@keyframes gm-place {
    0% { transform: scale(.4); opacity: 0; }
    70% { transform: scale(1.08); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes gm-win-pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--gm-accent); }
    100% { transform: scale(1.1); box-shadow: 0 0 0 2px #fff, 0 0 0 6px var(--gm-accent); }
}

@keyframes gm-hint-pulse {
    0% { transform: scale(.85); }
    100% { transform: scale(1.05); }
}

/* Edge points already leave a half-cell margin inside the board, so the
   card's own padding can shrink to a thin rim on phones. */
@media (max-width: 480px) {
    .gm-board-card {
        padding: 2px 2px 5px;
        border-radius: 8px;
    }
}

@media (max-width: 420px) {
    .gm-opponent-grid {
        grid-template-columns: 1fr;
    }

    .gm-theme-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .gm-option-sub {
        font-size: 10px;
    }
}
