/* Gomoku styles - align with /display liquid background */
/* Minimal page frame mimicking display.html */
body { background: #e9e1cf; color: #2b2b2b; overflow: hidden; }
.pebble-bg { position: fixed; inset: 0; z-index: 0; background:
    radial-gradient(800px 500px at 50% 10%, rgba(255,255,255,0.6), transparent 60%),
    radial-gradient(1000px 700px at 50% 120%, rgba(0,0,0,0.06), transparent 60%),
    repeating-linear-gradient(24deg, rgba(0,0,0,0.05) 0 2px, transparent 2px 16px),
    linear-gradient(180deg, #f3ead2, #e6dcc4);
    transform: rotate(180deg);
    transform-origin: center center;
}
.liquid-bg { position: fixed; inset: 0; background: linear-gradient(45deg, #000000, #1a1a1a); z-index: 0; overflow: hidden; }
.liquid-bg .orb { position: absolute; border-radius: 50%; filter: blur(15px); opacity: 0.4; width: 600px; height: 600px; left: calc(50% - 300px); top: calc(50% - 300px); transform-origin: center center; mix-blend-mode: screen; }
.liquid-bg .orb:nth-child(1){ background: radial-gradient(circle, rgba(0, 123, 255, 0.6), transparent 70%); animation: moveBlue 32s cubic-bezier(0.45, 0.05, 0.55, 0.95) infinite, pulseBlue 32s ease-in-out infinite; }
.liquid-bg .orb:nth-child(2){ background: radial-gradient(circle, rgba(255, 61, 61, 0.6), transparent 70%); animation: moveRed 32s cubic-bezier(0.45, 0.05, 0.55, 0.95) infinite, pulseRed 32s ease-in-out infinite; }
@keyframes moveBlue { 0% { transform: translate(-300px, -300px) rotate(0deg); } 20% { transform: translate(300px, -300px) rotate(72deg); } 35% { transform: translate(300px, 300px) rotate(126deg); } 48% { transform: translate(-300px, 300px) rotate(172.8deg); } 49% { transform: translate(0, 0) rotate(176.4deg) scale(1.5); } 51% { transform: translate(300px, 300px) rotate(180deg); } 65% { transform: translate(300px, -300px) rotate(234deg); } 80% { transform: translate(-300px, -300px) rotate(288deg); } 95% { transform: translate(-300px, 300px) rotate(342deg); } 97% { transform: translate(0, 0) rotate(349.2deg) scale(1.5); } 98% { transform: translate(-300px, -300px) rotate(356.4deg); } 100% { transform: translate(-300px, -300px) rotate(360deg); } }
@keyframes moveRed { 0% { transform: translate(300px, 300px) rotate(0deg); } 20% { transform: translate(-300px, 300px) rotate(-72deg); } 35% { transform: translate(-300px, -300px) rotate(-126deg); } 48% { transform: translate(300px, -300px) rotate(-172.8deg); } 49% { transform: translate(0, 0) rotate(-176.4deg) scale(1.5); } 51% { transform: translate(-300px, -300px) rotate(-180deg); } 65% { transform: translate(-300px, 300px) rotate(-234deg); } 80% { transform: translate(300px, 300px) rotate(-288deg); } 95% { transform: translate(300px, -300px) rotate(-342deg); } 97% { transform: translate(0, 0) rotate(-349.2deg) scale(1.5); } 98% { transform: translate(300px, 300px) rotate(-356.4deg); } 100% { transform: translate(300px, 300px) rotate(-360deg); } }
@keyframes pulseBlue { 0%, 100% { filter: blur(15px); opacity: 0.4; } 48%, 96% { filter: blur(25px); opacity: 0.7; } 49%, 97% { filter: blur(40px); opacity: 0.9; } }
@keyframes pulseRed { 0%, 100% { filter: blur(15px); opacity: 0.4; } 48%, 96% { filter: blur(25px); opacity: 0.7; } 49%, 97% { filter: blur(40px); opacity: 0.9; } }

.gomoku-stage { position: relative; z-index: 1; width: 100%; min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
@supports (height: 100svh) { .gomoku-stage { min-height: 100svh; } }
.brand-pill { position: fixed; left: 20px; top: 24px; z-index: 6; background: rgba(255,255,255,0.92); border: 1px solid #cbb98d; color: #5a4520; font-weight: 700; padding: 0 14px; height: 48px; border-radius: 999px; box-shadow: 0 8px 20px rgba(0,0,0,0.18); cursor: pointer; perspective: 600px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-family: 'Marcellus', serif; }
.brand-pill:focus { outline: 2px solid #2f6f3f; outline-offset: 2px; }
.brand-face { display: inline-block; backface-visibility: hidden; transform-origin: center; transition: transform 420ms cubic-bezier(0.2,0.6,0.2,1); }
.brand-front { transform: rotateY(0deg); }
.brand-back { position: absolute; transform: rotateY(180deg); }
.brand-pill.flipped .brand-front { transform: rotateY(180deg); }
.brand-pill.flipped .brand-back { transform: rotateY(360deg); }
@media (prefers-reduced-motion: reduce) {
    .brand-face { transition: none; }
}
.gomoku-status { color: #7b5d1e; font-weight: 600; text-align: center; margin-top: 12px; }

.gomoku-board-container { display: flex; justify-content: center; align-items: center; overflow: visible; padding: 8px; width: 100%; box-sizing: border-box; --board-offset-x: -22px; --board-offset-y: -28px; transform: translate(var(--board-offset-x), var(--board-offset-y)); }
.gomoku-board {
    --board-size: 15; /* cells per side */
    --board-padding: 160px; /* space for breathing room and FABs */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --line: 1px; /* grid line thickness used for precise centering */
    --hoshi-size: 8px; /* size for all star points, including center */
    --cell: min(
        calc((100vh - var(--board-padding) - var(--safe-top) - var(--safe-bottom)) / var(--board-size)),
        calc((100vw - var(--board-padding) - var(--safe-left) - var(--safe-right)) / var(--board-size))
    );
    position: relative;
    display: grid;
    grid-template-columns: repeat(var(--board-size), var(--cell));
    grid-template-rows: repeat(var(--board-size), var(--cell));
    /* Grid lines over richer wood grain background; first two layers are lines */
    background-image:
        linear-gradient(to right, rgba(60, 42, 20, 0.65) 1px, transparent 1px), /* vertical lines */
        linear-gradient(to bottom, rgba(60, 42, 20, 0.65) 1px, transparent 1px), /* horizontal lines */
        repeating-linear-gradient(8deg, rgba(120, 90, 40, 0.10) 0 2px, transparent 2px 18px), /* long grain */
        repeating-linear-gradient(90deg, rgba(90, 60, 30, 0.06) 0 1px, transparent 1px 4px), /* fine pores */
        radial-gradient(120% 75% at 50% 40%, rgba(0,0,0,0.07), transparent 60%), /* subtle vignette */
        linear-gradient(180deg, #e2c185, #d1a862); /* base wood */
    background-size:
        var(--cell) var(--cell),
        var(--cell) var(--cell),
        auto,
        auto,
        auto;
    background-position:
        calc(var(--cell) / 2 - var(--line) / 2) calc(var(--cell) / 2 - var(--line) / 2),
        calc(var(--cell) / 2 - var(--line) / 2) calc(var(--cell) / 2 - var(--line) / 2),
        0 0,
        0 0,
        0 0;
    border: 2px solid #8c6a2f;
    border-radius: 10px;
    box-shadow: inset 0 10px 24px rgba(0,0,0,0.12), inset 0 -6px 16px rgba(0,0,0,0.08), 0 18px 48px rgba(0,0,0,0.35);
    user-select: none;
    touch-action: manipulation;
    margin-left: auto;
    margin-right: auto;
}
@supports (height: 100svh) {
    .gomoku-board {
        --cell: min(
            calc((100svh - var(--board-padding) - var(--safe-top) - var(--safe-bottom)) / var(--board-size)),
            calc((100vw - var(--board-padding) - var(--safe-left) - var(--safe-right)) / var(--board-size))
        );
    }
}

.gomoku-cell {
    width: var(--cell);
    height: var(--cell);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
}

.gomoku-cell:hover { background: rgba(255,255,255,0.05); }



/* Ghost stone hover preview based on turn */
.gomoku-board.turn-black .gomoku-cell:hover:empty::after {
    content: '';
    position: absolute;
    width: 72%;
    height: 72%;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, rgba(255,255,255,0.12), rgba(0,0,0,0.6));
    border: 2px solid rgba(0,0,0,0.4);
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}
.gomoku-board.turn-white .gomoku-cell:hover:empty::after {
    content: '';
    position: absolute;
    width: 72%;
    height: 72%;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, rgba(255,255,255,0.7), rgba(255,255,255,0.2));
    border: 2px solid rgba(255,255,255,0.6);
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

.stone { width: 72%; height: 72%; border-radius: 50%; box-shadow: 0 2px 6px rgba(0,0,0,0.6); position: relative; z-index: 1; }
.stone.black { background: #0a0a0a; border: 2px solid #3e3e3e; }
.stone.white { background: #e8e8e8; }
.stone.black::after { content: ''; position: absolute; inset: 18%; border-radius: 50%; background: radial-gradient(circle at 35% 35%, rgba(255,255,255,0.18), rgba(255,255,255,0) 60%); }
.stone.white::after { content: ''; position: absolute; inset: 18%; border-radius: 50%; background: radial-gradient(circle at 35% 35%, rgba(255,255,255,0.6), rgba(255,255,255,0) 60%); }

.last-move {
    outline: 2px solid #ffb347;
    outline-offset: -2px;
}

.win-highlight { box-shadow: 0 0 10px #ffb347, 0 0 20px rgba(255,179,71,0.6) inset; }

/* Sparkly win animation */
@keyframes glowPulse {
    0% { transform: scale(1); box-shadow: 0 0 10px rgba(255,179,71,0.6), 0 0 20px rgba(255,179,71,0.4) inset; }
    50% { transform: scale(1.06); box-shadow: 0 0 16px rgba(255,196,120,0.85), 0 0 26px rgba(255,179,71,0.6) inset; }
    100% { transform: scale(1); box-shadow: 0 0 10px rgba(255,179,71,0.6), 0 0 20px rgba(255,179,71,0.4) inset; }
}

.stone.win-highlight { animation: glowPulse 900ms ease-in-out 3; }

/* Subtle spin/scale victory animation inspired by Pebbles */
@keyframes stoneSpinScale {
    0% { transform: scale(1) rotate(0deg); }
    55% { transform: scale(1.15) rotate(280deg); }
    100% { transform: scale(1) rotate(360deg); }
}
.stone.stone-win-animate {
    will-change: transform;
    animation: stoneSpinScale 700ms ease-out;
}

@keyframes twinkle {
    0% { transform: translate(0,0) scale(0.4); opacity: 0; }
    20% { opacity: 1; }
    60% { opacity: 0.9; }
    100% { transform: translate(var(--dx, 0), var(--dy, 0)) scale(1.1); opacity: 0; }
}

.sparkle {
    position: absolute;
    width: 6px; height: 6px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255,255,255,0.95) 0 45%, rgba(255,255,255,0.6) 46% 60%, transparent 61%);
    box-shadow: 0 0 10px rgba(255,255,255,0.75);
    pointer-events: none;
    z-index: 2;
    animation: twinkle 900ms ease-out forwards;
}

/* Star points (hoshi): four inner corners + larger center */
.gomoku-board .gomoku-cell:nth-child(49)::before,
.gomoku-board .gomoku-cell:nth-child(57)::before,
.gomoku-board .gomoku-cell:nth-child(169)::before,
.gomoku-board .gomoku-cell:nth-child(177)::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: var(--hoshi-size);
    height: var(--hoshi-size);
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: rgba(0,0,0,0.75);
    z-index: 0;
}
.gomoku-board .gomoku-cell:nth-child(113)::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: var(--hoshi-size);
    height: var(--hoshi-size);
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: rgba(0,0,0,0.85);
    z-index: 0;
}

/* Floating action buttons */
.floating-actions { position: relative; z-index: 5; }
.fab {
    width: 48px; height: 48px; border-radius: 50%;
    border: none; cursor: pointer;
    background: rgba(255,255,255,0.9);
    color: #2b2b2b; box-shadow: 0 8px 20px rgba(0,0,0,0.25);
    display: inline-flex; align-items: center; justify-content: center;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.fab#undoBtn { width: auto; padding: 0 14px; border-radius: 999px; font-weight: 600; font-family: 'Marcellus', serif; font-size: 14px; color: #5a4520; }
.fab#undoBtn { position: fixed; left: 24px; bottom: 24px; }
.fab#soundBtn { position: fixed; right: 24px; top: 24px; }
.fab#newGameBtn { position: fixed; right: 24px; bottom: 24px; }
.fab:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(0,0,0,0.3); background: #ffffff; }
.fab:active { transform: translateY(0); box-shadow: 0 6px 14px rgba(0,0,0,0.22); }
.fab-primary { background: #2f6f3f; color: #ffffff; }
.fab-primary:hover { background: #358049; }

/* Confirmation modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.35); backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; z-index: 1000; opacity: 0; visibility: hidden; transition: opacity 0.2s ease, visibility 0.2s ease; }
.modal-overlay.open { opacity: 1; visibility: visible; }
.modal { width: min(90vw, 420px); background: linear-gradient(180deg, #fff9e8, #f1e6c9); border: 1px solid #ccb98b; border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,0.35); padding: 20px; }
.modal-title { font-weight: 700; color: #5a4520; font-size: 20px; margin-bottom: 8px; }
.modal-title.hidden { display: none; }
.modal-body { color: #6b5730; margin-bottom: 16px; }
.modal-body #modalPrompt.emphasis { font-weight: 800; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.btn { background: #ffffff; color: #2b2b2b; border: 1px solid #cbb98d; border-radius: 9px; padding: 8px 14px; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,0.08); transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease; }
.btn:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(0,0,0,0.15); }
.btn:active { transform: translateY(0); box-shadow: 0 2px 8px rgba(0,0,0,0.12); }
.btn-primary { background: #2f6f3f; color: #ffffff; border-color: #2f6f3f; }
.btn-primary:hover { background: #358049; }

/* Confetti canvas overlay */
.confetti-overlay { position: fixed; inset: 0; pointer-events: none; z-index: 999; display: none; }
.confetti-overlay.active { display: block; }

/* Zen ripple overlay (copied from Pebbles, slightly toned) */
.zen-ripple {
    position: fixed;
    top: 50%; left: 50%;
    width: 50px; height: 50px;
    border: 3px solid rgba(161,177,170,0.8);
    border-radius: 50%;
    opacity: 0.55;
    transform: scale(0.2) translate(-50%, -50%);
    animation: ripple 1600ms ease-out forwards;
    z-index: 1000;
    pointer-events: none;
}
@keyframes ripple {
    0% { opacity: 0.55; transform: scale(0.2) translate(-50%, -50%); }
    100% { opacity: 0; transform: scale(2.6) translate(-50%, -50%); }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .stone.win-highlight { animation: none; }
    .sparkle { display: none; }
}

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 46px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; inset: 0; background: #c9b988; transition: .2s; border-radius: 999px; box-shadow: inset 0 1px 2px rgba(0,0,0,0.15); }
.slider:before { position: absolute; content: ""; height: 20px; width: 20px; left: 3px; bottom: 3px; background-color: white; transition: .2s; border-radius: 50%; box-shadow: 0 2px 6px rgba(0,0,0,0.25); }
.switch input:checked + .slider { background: #2f6f3f; }
.switch input:checked + .slider:before { transform: translateX(20px); }
.option-text { color: #5a4520; }

@media (max-width: 768px) {
    .gomoku-stage { padding: 12px; }
    .gomoku-board { --board-padding: 90px; }
    .gomoku-board-container { --board-offset-x: -14px; --board-offset-y: -22px; }
}

@media (max-width: 480px) {
    .gomoku-stage { padding: 8px; }
    .gomoku-board { --board-padding: 56px; }
    .fab { width: 42px; height: 42px; }
    .fab#undoBtn { width: auto; height: 42px; padding: 0 12px; font-size: 13px; color: #5a4520; }
    .brand-pill { height: 42px; }
    .gomoku-board-container { --board-offset-x: -8px; --board-offset-y: -18px; }
}


/* ==========================
   Clean, natural theme
   ========================== */
body.theme-clean { background: #f6f2e9; color: #2b2b2b; }
body.theme-clean .pebble-bg {
    background:
        radial-gradient(120% 80% at 50% 20%, rgba(255,255,255,0.7), transparent 60%),
        radial-gradient(100% 80% at 50% 120%, rgba(0,0,0,0.04), transparent 60%),
        linear-gradient(180deg, #f6f2e9, #eee6d6);
    transform: none;
}

/* Board: soft maple, hairline grid, subtle vignette */
body.theme-clean .gomoku-board {
    --hoshi-size: 6px;
    background-image:
        linear-gradient(to right, rgba(45, 30, 15, 0.45) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(45, 30, 15, 0.45) 1px, transparent 1px),
        radial-gradient(120% 75% at 50% 40%, rgba(0,0,0,0.05), transparent 60%),
        linear-gradient(180deg, #e9d7b4, #d7ba87);
    border: 1px solid #b18a4a;
    border-radius: 12px;
    box-shadow: inset 0 6px 14px rgba(0,0,0,0.08), inset 0 -4px 10px rgba(0,0,0,0.06), 0 14px 36px rgba(0,0,0,0.28);
}

/* Stones: matte, natural highlights */
body.theme-clean .stone { width: 82%; height: 82%; box-shadow: 0 3px 6px rgba(0,0,0,0.25); }
body.theme-clean .stone.black { background: #1a1a1a; border: 1px solid #2b2b2b; }
body.theme-clean .stone.black::after { inset: 22%; background: radial-gradient(circle at 35% 35%, rgba(255,255,255,0.14), rgba(255,255,255,0) 60%); }
body.theme-clean .stone.white { background: #f5f5f5; border: 1px solid rgba(0,0,0,0.12); }
body.theme-clean .stone.white::after { inset: 22%; background: radial-gradient(circle at 35% 35%, rgba(255,255,255,0.5), rgba(255,255,255,0) 60%); }

/* Ghost stones: lighter and smaller preview */
body.theme-clean .gomoku-board.turn-black .gomoku-cell:hover:empty::after {
    width: 82%;
    height: 82%;
    background: radial-gradient(circle at 35% 35%, rgba(255,255,255,0.10), rgba(0,0,0,0.4));
    border: 1px solid rgba(0,0,0,0.45);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.10);
}
body.theme-clean .gomoku-board.turn-white .gomoku-cell:hover:empty::after {
    width: 82%;
    height: 82%;
    background: radial-gradient(circle at 35% 35%, rgba(255,255,255,0.75), rgba(255,255,255,0.25));
    border: 1px solid rgba(0,0,0,0.18);
}

/* UI chrome: calmer surface so board stands out */
body.theme-clean .brand-pill { background: rgba(255,255,255,0.94); border-color: #d5c6a0; color: #5a4520; }
body.theme-clean .fab { background: rgba(255,255,255,0.88); color: #2b2b2b; }
body.theme-clean .fab:hover { background: #ffffff; }
body.theme-clean .fab.fab-primary { background: #2f6f3f; color: #ffffff; }
body.theme-clean .fab.fab-primary:hover { background: #358049; }

/* Intro overlay and turn toast */
.intro-overlay { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; background: radial-gradient(110vmax 110vmax at 50% 45%, rgba(0,0,0,0.28), rgba(0,0,0,0.75) 70%); backdrop-filter: blur(1.5px); opacity: 1; visibility: visible; transition: opacity 280ms ease, visibility 280ms ease; }
.intro-overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.intro-card { background: transparent; border: none; border-radius: 0; padding: 0; box-shadow: none; text-align: center; }
.intro-title { font-weight: 600; color: #f0f0f0; font-size: clamp(20px, 3.2vw, 36px); letter-spacing: 0.01em; text-shadow: 0 0 12px rgba(255,255,255,0.25), 0 0 32px rgba(0,120,255,0.25), 0 0 48px rgba(255,120,0,0.2); font-family: 'Marcellus', serif; }
.intro-sub { margin-top: 12px; color: rgba(255,255,255,0.92); font-size: clamp(12px, 1.7vw, 17px); text-shadow: 0 1px 12px rgba(0,0,0,0.3); font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, 'Helvetica Neue', Arial, 'Noto Sans', 'Liberation Sans', sans-serif; }

.turn-toast { position: fixed; left: 50%; top: 18px; transform: translateX(-50%); background: rgba(255,255,255,0.96); color: #2b2b2b; border: 1px solid #d5c6a0; border-radius: 999px; padding: 8px 14px; z-index: 1001; box-shadow: 0 10px 28px rgba(0,0,0,0.18); opacity: 0; transition: opacity 240ms ease, transform 240ms ease; }
.turn-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

