.gomoku-entry-icon {
    color: var(--text2) !important;
}
.gomoku-entry-icon svg {
    width: 25px;
    height: 25px;
    overflow: visible;
}
.gomoku-entry-icon path {
    stroke: currentColor;
    stroke-width: 1.05;
    opacity: .66;
}
.gomoku-entry-black {
    fill: var(--text);
    stroke: var(--text);
    stroke-width: .7;
}
.gomoku-entry-white {
    fill: var(--surface);
    stroke: var(--text3);
    stroke-width: .85;
}
[data-theme="dark"] .gomoku-entry-icon {
    color: var(--text2) !important;
}

.gomoku-window {
    --gomoku-ink: #4d4943;
    --gomoku-paper: #f8f3e8;
    --gomoku-board: #dec79e;
    position: fixed;
    z-index: 900;
    top: max(74px, env(safe-area-inset-top));
    right: max(18px, calc((100vw - 720px) / 2 + 18px));
    width: min(420px, calc(100vw - 24px));
    max-height: calc(var(--app-height, 100dvh) - 96px);
    color: var(--gomoku-ink);
    background: rgba(248, 243, 232, .96);
    background: color-mix(in srgb, var(--gomoku-paper) 94%, transparent);
    border: 1px solid rgba(105, 91, 70, .18);
    border-radius: 22px;
    box-shadow: 0 18px 52px rgba(71, 61, 48, .2), 0 2px 10px rgba(71, 61, 48, .08);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    overflow: hidden;
    touch-action: none;
}

.gomoku-head {
    height: 58px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 13px 0 17px;
    border-bottom: 1px dashed rgba(92, 78, 58, .17);
    cursor: grab;
    user-select: none;
    touch-action: none;
}

.gomoku-head:active { cursor: grabbing; }
.gomoku-title-wrap { display: flex; align-items: center; gap: 10px; }
.gomoku-title-wrap > div { display: grid; gap: 1px; }
.gomoku-title-wrap strong { font-size: 15px; letter-spacing: .08em; }
.gomoku-title-wrap small { color: #918779; font-size: 10px; }
.gomoku-title-mark {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    color: #373634;
    background: #f4efe5;
    box-shadow: inset -4px -5px 9px rgba(76, 68, 57, .12), 0 2px 5px rgba(68, 59, 48, .12);
}

.gomoku-window-actions { display: flex; gap: 4px; }
.gomoku-window-actions button {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: #81786c;
    font-size: 20px;
    line-height: 1;
}
.gomoku-window-actions button:hover { background: rgba(119, 105, 85, .09); }
.gomoku-body { padding: 12px 14px 14px; touch-action: auto; }
.gomoku-statusbar { display: flex; justify-content: space-between; align-items: center; margin: 0 2px 10px; }
.gomoku-turn { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 650; }
.gomoku-turn i {
    display: block;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .22);
}
.gomoku-turn i.black { background: #3c3b39; }
.gomoku-turn i.white { background: #faf7ef; border: 1px solid #c8bda9; }
.gomoku-meta { display: flex; gap: 10px; color: #928879; font-size: 10px; }
.gomoku-board-wrap { position: relative; }
.gomoku-board {
    position: relative;
    display: grid;
    grid-template-columns: repeat(15, 1fr);
    width: 100%;
    aspect-ratio: 1;
    padding: 13px;
    box-sizing: border-box;
    background-color: var(--gomoku-board);
    background-image: linear-gradient(115deg, rgba(255,255,255,.14), transparent 35%, rgba(113,83,47,.06));
    border: 1px solid rgba(105, 75, 40, .18);
    border-radius: 12px;
    box-shadow: inset 0 0 24px rgba(115, 82, 44, .08);
    overflow: hidden;
}
.gomoku-cell {
    position: relative;
    min-width: 0;
    padding: 0;
    border-radius: 0;
    cursor: pointer;
}
.gomoku-cell::before,
.gomoku-cell::after {
    content: '';
    position: absolute;
    z-index: 0;
    background: rgba(78, 61, 42, .48);
}
.gomoku-cell::before { left: 0; right: 0; top: 50%; height: 1px; }
.gomoku-cell::after { top: 0; bottom: 0; left: 50%; width: 1px; }
.gomoku-cell.edge-left::before { left: 50%; }
.gomoku-cell.edge-right::before { right: 50%; }
.gomoku-cell.edge-top::after { top: 50%; }
.gomoku-cell.edge-bottom::after { bottom: 50%; }
.gomoku-cell.star::marker { display: none; }
.gomoku-cell.star .gomoku-star {
    position: absolute;
    z-index: 1;
    left: 50%;
    top: 50%;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: rgba(69, 53, 36, .72);
    transform: translate(-50%, -50%);
}
.gomoku-stone {
    position: absolute;
    z-index: 2;
    inset: 8%;
    border-radius: 50%;
    pointer-events: none;
    animation: gomoku-place .2s cubic-bezier(.2, .9, .35, 1.3);
}
.gomoku-stone.black { background: radial-gradient(circle at 34% 28%, #686663, #272725 72%); box-shadow: 0 2px 4px rgba(43, 35, 27, .34); }
.gomoku-stone.white { background: radial-gradient(circle at 35% 27%, #fff, #e9e3d8 72%); box-shadow: 0 2px 4px rgba(63, 48, 31, .25), inset 0 0 0 1px rgba(95, 80, 61, .12); }
.gomoku-stone.last::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #bb705f;
    box-shadow: 0 0 0 2px rgba(255,255,255,.5);
    transform: translate(-50%, -50%);
}
.gomoku-board.user-turn .gomoku-cell:not(.occupied):hover::after {
    z-index: 2;
    inset: 12%;
    width: auto;
    height: auto;
    border-radius: 50%;
    background: rgba(48, 47, 44, .25);
}
.gomoku-board:not(.user-turn) .gomoku-cell { cursor: default; }
.gomoku-waiting {
    position: absolute;
    left: 50%;
    bottom: 12px;
    z-index: 4;
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 7px 12px;
    border-radius: 999px;
    background: rgba(250, 246, 237, .91);
    box-shadow: 0 3px 14px rgba(62, 51, 37, .16);
    color: #746b60;
    font-size: 11px;
    transform: translateX(-50%);
    white-space: nowrap;
}
.gomoku-waiting[hidden] { display: none; }
.gomoku-waiting span { width: 6px; height: 6px; border-radius: 50%; background: #a98a72; animation: gomoku-pulse 1.1s infinite; }
.gomoku-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 11px; }
.gomoku-actions button {
    min-height: 36px;
    border: 1px solid rgba(112, 94, 71, .14);
    border-radius: 11px;
    background: rgba(255, 252, 246, .58);
    color: #6e655a;
    font-size: 12px;
}
.gomoku-actions button:disabled { opacity: .38; }
.gomoku-actions button:not(:disabled):active { transform: scale(.97); }
.gomoku-feedback { min-height: 16px; margin: 7px 3px 0; color: #9a7168; font-size: 10px; text-align: center; }
.gomoku-mini { display: none; align-items: center; gap: 9px; width: 100%; padding: 10px 14px; text-align: left; }
.gomoku-mini > span:nth-child(2) { display: grid; }
.gomoku-mini strong { font-size: 12px; }
.gomoku-mini small { color: #948a7c; font-size: 9px; }
.gomoku-mini-stones { position: relative; width: 35px; height: 27px; }
.gomoku-mini-stones i { position: absolute; width: 22px; height: 22px; border-radius: 50%; box-shadow: 0 2px 5px rgba(60,45,30,.2); }
.gomoku-mini-stones i:first-child { left: 0; top: 1px; background: #353432; }
.gomoku-mini-stones i:last-child { right: 0; bottom: 0; background: #f9f5ec; border: 1px solid #d1c6b4; }
.gomoku-window.minimized { width: 158px; border-radius: 16px; }
.gomoku-window.minimized .gomoku-head,
.gomoku-window.minimized .gomoku-body { display: none; }
.gomoku-window.minimized .gomoku-mini { display: flex; }
.gomoku-window.minimized .gomoku-setup,
.gomoku-window.minimized .gomoku-result { display: none; }
.gomoku-setup { position: absolute; inset: 0; z-index: 9; display: grid; place-items: center; padding: 18px; background: rgba(244, 238, 226, .82); backdrop-filter: blur(8px); }
.gomoku-setup[hidden] { display: none; }
.gomoku-setup-card { width: min(270px, 90%); padding: 23px 20px 18px; border: 1px solid rgba(109,90,67,.14); border-radius: 19px; background: #fbf7ef; box-shadow: 0 14px 38px rgba(67,55,40,.17); text-align: center; }
.gomoku-setup-card > strong { display: block; margin-bottom: 15px; color: #514b43; font-size: 15px; }
.gomoku-first-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 14px; padding: 4px; border-radius: 12px; background: #eee7db; }
.gomoku-first-options button { min-height: 33px; border-radius: 9px; color: #786f63; font-size: 11px; }
.gomoku-first-options button[aria-checked="true"] { color: #514b43; background: #fffaf2; box-shadow: 0 2px 7px rgba(62,53,44,.1); font-weight: 650; }
.gomoku-setup-start { width: 100%; min-height: 36px; border-radius: 10px; color: #fffaf2; background: #71685e; font-size: 11px; }
.gomoku-setup-cancel { width: 100%; min-height: 32px; margin-top: 6px; color: #817668; font-size: 10px; }
.gomoku-result { position: absolute; inset: 0; z-index: 8; display: grid; place-items: center; padding: 18px; background: rgba(244, 238, 226, .82); backdrop-filter: blur(8px); }
.gomoku-result[hidden] { display: none; }
.gomoku-result-card { width: min(270px, 90%); padding: 25px 21px 19px; border: 1px solid rgba(109,90,67,.14); border-radius: 19px; background: #fbf7ef; box-shadow: 0 14px 38px rgba(67,55,40,.17); text-align: center; }
.gomoku-result-stone { display: block; width: 45px; height: 45px; margin: 0 auto 12px; border-radius: 50%; }
.gomoku-result-stone.black { background: radial-gradient(circle at 34% 28%, #686663, #272725 72%); }
.gomoku-result-stone.white { background: radial-gradient(circle at 35% 27%, #fff, #e9e3d8 72%); border: 1px solid #d5c9b8; }
.gomoku-result-stone.draw { background: linear-gradient(135deg, #393836 0 49%, #f6f1e7 51%); }
.gomoku-result-card h2 { margin: 0; color: #514b43; font-size: 20px; }
.gomoku-result-card p { margin: 7px 0 15px; color: #8c8173; font-size: 11px; }
.gomoku-record { padding: 9px; border-radius: 10px; background: #f3ede2; color: #827668; font-size: 11px; }
.gomoku-result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.gomoku-result-actions button { padding: 9px 7px; border-radius: 10px; background: #eee6d9; color: #766b5e; font-size: 11px; }
.gomoku-result-actions button:last-child { background: #71685e; color: #fffaf2; }

[data-theme="dark"] .gomoku-window,
body.dark .gomoku-window {
    --gomoku-ink: #e5ded2;
    --gomoku-paper: #302e2b;
    --gomoku-board: #9d815e;
    background: rgba(48, 46, 43, .96);
    background: color-mix(in srgb, var(--gomoku-paper) 94%, transparent);
    border-color: rgba(255,255,255,.1);
    box-shadow: 0 20px 55px rgba(0,0,0,.4);
}
[data-theme="dark"] .gomoku-actions button,
body.dark .gomoku-actions button { background: rgba(255,255,255,.05); color: #d4cabd; }
[data-theme="dark"] .gomoku-result,
body.dark .gomoku-result,
[data-theme="dark"] .gomoku-setup,
body.dark .gomoku-setup { background: rgba(38,36,33,.84); }
[data-theme="dark"] .gomoku-result-card,
body.dark .gomoku-result-card,
[data-theme="dark"] .gomoku-setup-card,
body.dark .gomoku-setup-card { background: #35322e; }
[data-theme="dark"] .gomoku-setup-card > strong,
body.dark .gomoku-setup-card > strong { color: #e5ded2; }
[data-theme="dark"] .gomoku-first-options,
body.dark .gomoku-first-options { background: #292724; }
[data-theme="dark"] .gomoku-first-options button[aria-checked="true"],
body.dark .gomoku-first-options button[aria-checked="true"] { color: #eee7dc; background: #4a4640; }

@keyframes gomoku-place { from { opacity: .2; transform: scale(.25); } to { opacity: 1; transform: scale(1); } }
@keyframes gomoku-pulse { 50% { opacity: .35; transform: scale(.7); } }

@media (max-width: 540px) {
    .gomoku-window { top: max(62px, env(safe-area-inset-top)); right: 12px; width: calc(100vw - 24px); }
    .gomoku-body { padding: 10px 11px 12px; }
    .gomoku-board { padding: 10px; }
}

@media (prefers-reduced-motion: reduce) {
    .gomoku-stone, .gomoku-waiting span { animation: none; }
}
