:root {
    --board-bg: #d8ad75;
    --board-line: #76502d;
    --board-edge: #b7834f;
    --bg-color: #f4f1e9;
    --bg-pattern: linear-gradient(115deg, rgba(255, 255, 255, 0.48), transparent 38%), repeating-linear-gradient(45deg, rgba(126, 91, 57, 0.062) 0 1px, transparent 1px 72px), repeating-linear-gradient(-45deg, rgba(126, 91, 57, 0.062) 0 1px, transparent 1px 72px);
    --text-color: #1c1c1e;
    --button-bg: #e7e2d9;
    --button-active: #d8d1c5;
    --button-border: rgba(112, 82, 55, 0.12);
    --win-glow: rgba(210, 151, 55, 0.68);
    --turn-accent: #9a6848;
    --turn-accent-text: #805238;
    --turn-accent-soft: rgba(154, 104, 72, 0.14);
    --turn-accent-faint: rgba(154, 104, 72, 0.04);
    --font-ui: "Avenir Next", "Helvetica Neue", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-drag: none;
    -webkit-user-select: none;
    user-select: none;
}

html {
    min-height: 100%;
    background-color: var(--bg-color);
    background-image: linear-gradient(to bottom, var(--bg-color) 0, transparent 150px, transparent calc(100% - 150px), var(--bg-color) 100%), var(--bg-pattern);
    background-size: auto;
    touch-action: manipulation;
}

body {
    font-family: var(--font-ui);
    background: transparent;
    color: var(--text-color);
    overscroll-behavior: none;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    touch-action: manipulation;
    transition: background-color 0.5s ease;
}

html.theme-sage,
body.theme-sage {
    --bg-color: #edf2eb;
    --bg-pattern: linear-gradient(155deg, rgba(255, 255, 255, 0.5), transparent 45%), repeating-linear-gradient(45deg, rgba(78, 101, 82, 0.058) 0 1px, transparent 1px 86px), repeating-linear-gradient(-45deg, rgba(78, 101, 82, 0.042) 0 1px, transparent 1px 86px);
}

html.theme-ink,
body.theme-ink {
    --bg-color: #edf1f3;
    --bg-pattern: linear-gradient(25deg, rgba(255, 255, 255, 0.53), transparent 42%), repeating-linear-gradient(45deg, rgba(77, 91, 96, 0.066) 0 1px, transparent 1px 68px), repeating-linear-gradient(-45deg, rgba(77, 91, 96, 0.048) 0 1px, transparent 1px 68px);
}

html.theme-clay,
body.theme-clay {
    --bg-color: #f3eae2;
    --bg-pattern: linear-gradient(135deg, rgba(255, 255, 255, 0.48), transparent 44%), repeating-linear-gradient(135deg, rgba(126, 77, 55, 0.058) 0 1px, transparent 1px 78px), repeating-linear-gradient(45deg, rgba(126, 77, 55, 0.042) 0 1px, transparent 1px 78px);
}

.app-container {
    position: relative;
    width: 100%;
    max-width: 500px;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: max(14px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom));
}

header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 18px;
    flex-shrink: 0;
}

.status {
    display: flex;
    align-items: center;
    gap: 9px;
    width: fit-content;
    max-width: 100%;
    padding: 9px 0;
    font-size: clamp(20px, 6vw, 28px);
    font-weight: 700;
    line-height: 1.1;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.status-my-turn {
    color: var(--text-color);
    border: none;
    background: transparent;
    box-shadow: none;
    animation: statusArrive 0.4s ease-out both;
}

.status-opponent-turn {
    color: #706a62;
    animation: statusArrive 0.4s ease-out both;
}

.header-actions {
    position: relative;
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.action-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 42px;
    border: 1px solid var(--button-border);
    padding: 9px 11px;
    border-radius: 25px;
    background: linear-gradient(145deg, rgba(250, 247, 241, 0.92), rgba(226, 220, 209, 0.9));
    color: var(--text-color);
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 650;
    letter-spacing: 0.015em;
    line-height: 1;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    max-width: 180px;
    box-shadow: 0 3px 8px rgba(83, 59, 38, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.72);
    transition: max-width 0.35s ease, padding 0.35s ease, border-width 0.35s ease, opacity 0.35s ease, transform 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}

.action-button:hover {
    background: linear-gradient(145deg, #fffdf8, #e9e2d8);
    box-shadow: 0 5px 12px rgba(83, 59, 38, 0.14), inset 0 1px 0 rgba(255, 255, 255, 0.82);
    transform: translateY(-1px);
}

.action-button:disabled {
    cursor: wait;
    opacity: 0.58;
    transform: none;
}

.action-button:disabled:hover {
    background: linear-gradient(145deg, rgba(250, 247, 241, 0.92), rgba(226, 220, 209, 0.9));
    box-shadow: 0 3px 8px rgba(83, 59, 38, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.72);
    transform: none;
}

.action-icon {
    display: inline-grid;
    width: 17px;
    height: 17px;
    place-items: center;
    color: #76502d;
    font-size: 17px;
    font-weight: 700;
    line-height: 1;
    vertical-align: -2px;
}

.action-label {
    display: inline-block;
}

.is-connected:not(.game-started) #copy-link {
    position: relative;
    isolation: isolate;
    animation: inviteButtonHalo 5.2s cubic-bezier(0.33, 1, 0.68, 1) infinite;
}

.is-connected:not(.game-started) #copy-link::after {
    position: absolute;
    top: -55%;
    bottom: -55%;
    left: -42%;
    z-index: 0;
    width: 48%;
    content: '';
    background: linear-gradient(105deg, transparent 0%, rgba(255, 255, 255, 0.14) 27%, rgba(255, 255, 255, 0.96) 50%, rgba(255, 255, 255, 0.14) 73%, transparent 100%);
    filter: blur(3px);
    pointer-events: none;
    opacity: 0;
    transform: translateX(-150%) skewX(-16deg);
    animation: inviteButtonShimmer 5.2s ease-in-out infinite;
}

.is-connected:not(.game-started) #copy-link>* {
    position: relative;
    z-index: 1;
}

.game-started .game-id {
    animation: gameIdFade 30s ease-out forwards;
}

.game-started #copy-link {
    max-width: 0;
    padding-left: 0;
    padding-right: 0;
    border-width: 0;
    opacity: 0;
    transform: translateX(8px) scale(0.94);
    pointer-events: none;
    transition: none;
}

.app-container:not(.game-state-ready) #copy-link {
    visibility: hidden;
}

.waiting-hint {
    flex: 0 0 100%;
    max-width: 360px;
    margin: 6px 0 0;
    color: rgba(74, 56, 40, 0.64);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.01em;
    line-height: 1.35;
    text-align: left;
}

.app-container:not(.game-state-ready) .waiting-hint,
.game-started .waiting-hint {
    display: none;
}

.game-state-ready #copy-link {
    transition: none;
}

.board-wrapper {
    flex-direction: column;
}

.board-actions {
    position: absolute;
    right: max(16px, env(safe-area-inset-right));
    bottom: max(16px, env(safe-area-inset-bottom));
    z-index: 6;
}

.undo-button {
    display: none;
    border: 0;
    padding: 6px 2px;
    background: transparent;
    color: rgba(74, 56, 40, 0.38);
    font: 600 12px/1 var(--font-ui);
    letter-spacing: 0.02em;
    text-decoration: underline;
    text-decoration-color: rgba(118, 80, 45, 0.22);
    text-underline-offset: 4px;
    opacity: 0.55;
    pointer-events: none;
    cursor: default;
    transition: color 0.25s ease, opacity 0.25s ease, text-decoration-color 0.25s ease;
}

.game-started .undo-button:not([hidden]) {
    display: inline-block;
}

.undo-button.is-available {
    opacity: 1;
    pointer-events: auto;
    color: #76502d;
    cursor: pointer;
    text-decoration-color: rgba(118, 80, 45, 0.58);
}

.undo-button:not(:disabled):hover,
.undo-button:not(:disabled):focus-visible {
    color: #4f321d;
    text-decoration-color: #4f321d;
    outline: none;
}

.undo-button:active {
    opacity: 0.65;
}

.undo-button[hidden] {
    display: none;
}

.reaction-toggle {
    display: inline-block;
    width: auto;
    min-width: 0;
    height: auto;
    min-height: 0;
    border: 0;
    padding: 5px 10px;
    border-radius: 25px;
    background: transparent;
    color: rgba(74, 56, 40, 0.42);
    font: 600 12px/1 var(--font-ui);
    letter-spacing: 0.02em;
    text-decoration-color: rgba(118, 80, 45, 0.22);
    text-underline-offset: 4px;
    opacity: 0;
    box-shadow: none;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(4px);
    transition: opacity 0.35s ease, transform 0.35s ease, visibility 0.35s ease, color 0.18s ease;
}

.reaction-actions {
    position: absolute;
    bottom: max(34px, calc(env(safe-area-inset-bottom) + 26px));
    left: 50%;
    z-index: 7;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translateX(-50%);
}

.game-started .reaction-toggle {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
    color: #76502d;
    text-decoration-color: rgba(118, 80, 45, 0.55);
}

.reaction-toggle:hover,
.reaction-toggle:focus-visible {
    color: #4f321d;
    background: transparent;
    box-shadow: none;
    transform: none;
    text-decoration-color: #4f321d;
    outline: none;
}

.reaction-toggle:active {
    background: transparent;
    box-shadow: none;
    transform: none;
}

.reaction-menu {
    position: absolute;
    bottom: calc(100% + 7px);
    left: 50%;
    z-index: 8;
    display: flex;
    gap: 3px;
    padding: 6px;
    border: 1px solid var(--button-border);
    border-radius: 14px;
    background: rgba(250, 247, 241, 0.96);
    box-shadow: 0 8px 20px rgba(83, 59, 38, 0.16), inset 0 1px 0 rgba(255, 255, 255, 0.8);
    transform: translateX(-50%);
    transform-origin: bottom center;
    animation: reactionMenuIn 0.16s ease-out both;
}

.reaction-menu[hidden] {
    display: none;
}

.reaction-choice {
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    font-size: 21px;
    line-height: 1;
    cursor: pointer;
    transition: background-color 0.14s ease, transform 0.14s ease;
}

.reaction-choice:hover,
.reaction-choice:focus-visible {
    background: rgba(216, 173, 117, 0.2);
    outline: none;
    transform: translateY(-2px);
}

.reaction-display {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    z-index: 1;
    font-size: 38px;
    line-height: 1;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 8px) scale(0.72);
}

.reaction-display.is-visible {
    animation: reactionFloat 1.65s cubic-bezier(0.22, 0.7, 0.32, 1) both;
}

.action-button:active {
    transform: translateY(1px) scale(0.98);
    background: var(--button-active);
    box-shadow: 0 1px 3px rgba(83, 59, 38, 0.12), inset 0 1px 2px rgba(83, 59, 38, 0.08);
}

.action-button:focus-visible {
    outline: 2px solid rgba(118, 80, 45, 0.78);
    outline-offset: 3px;
    box-shadow: 0 0 0 5px rgba(216, 173, 117, 0.28), 0 5px 12px rgba(83, 59, 38, 0.14);
}

.board-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 0;
    min-width: 0;
    padding: 2px 0;
}

.game-id {
    position: absolute;
    right: 0;
    bottom: max(3px, env(safe-area-inset-bottom));
    left: 0;
    padding: 5px 0 max(3px, env(safe-area-inset-bottom));
    color: rgba(74, 56, 40, 0.42);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 10px;
    letter-spacing: 0.08em;
    text-align: center;
    pointer-events: none;
}

.board-square {
    position: relative;
    width: min(100%, 500px);
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 1 / 1;
    align-self: center;
    background:
        repeating-linear-gradient(108deg, rgba(112, 72, 35, 0.035) 0 1px, transparent 1px 42px),
        radial-gradient(ellipse at 24% 16%, rgba(255, 245, 214, 0.2), transparent 48%),
        linear-gradient(135deg, rgba(255, 238, 195, 0.2), transparent 42%, rgba(101, 59, 25, 0.1)),
        var(--board-bg);
    border: 1px solid var(--board-edge);
    border-radius: 16px;
    padding: 10px;
    box-shadow: 0 18px 38px rgba(70, 43, 22, 0.18), 0 3px 8px rgba(70, 43, 22, 0.12), inset 0 1px 0 rgba(255, 239, 204, 0.42), inset 0 0 14px rgba(103, 62, 26, 0.18);
    display: flex;
    flex: 0 1 auto;
    transition: box-shadow 0.45s ease;
}

.board-square.board-expanding {
    animation: boardExpansion 0.85s cubic-bezier(0.22, 0.72, 0.28, 1) both;
}

.game-opening .board-square {
    animation: boardOpening 0.9s cubic-bezier(0.22, 0.72, 0.28, 1) both;
    transform-style: preserve-3d;
    transform-origin: center center;
    will-change: transform;
    transition: none;
}

.board-square::after {
    content: '';
    position: absolute;
    inset: -7px;
    border: 2px solid var(--win-glow);
    border-radius: 18px;
    opacity: 0;
    pointer-events: none;
}

.board-square::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 3;
    border: 2px solid transparent;
    border-radius: 15px;
    pointer-events: none;
    transition: border-color 0.45s ease, box-shadow 0.45s ease;
}

.game-won .board-square {
    box-shadow: 0 16px 42px rgba(116, 75, 25, 0.22), 0 0 26px var(--win-glow), inset 0 0 10px rgba(139, 90, 43, 0.2);
}

.game-won.winner-reveal .board-square {
    animation: winnerLift 0.8s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.game-won.winner-reveal .board-square::after {
    animation: winnerRing 1.8s ease-out 0.15s both;
}

.game-won .board-square::before {
    border-color: rgba(210, 151, 55, 0.52);
    box-shadow: inset 0 0 0 1px rgba(255, 246, 218, 0.28), 0 0 18px rgba(210, 151, 55, 0.24);
}

.game-won .status {
    color: #9a641d;
    text-shadow: 0 0 18px rgba(210, 151, 55, 0.38);
}

.game-won.winner-reveal .status {
    animation: winnerStatus 0.65s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.game-won::before,
.game-won::after {
    content: '';
    position: absolute;
    top: -18px;
    left: 10%;
    z-index: 4;
    width: 6px;
    height: 13px;
    border-radius: 3px;
    opacity: 0;
    pointer-events: none;
    will-change: transform, opacity;
}

.game-won.winner-reveal::before {
    background: #d29737;
    box-shadow: 46px 72px #c47e42, 112px 24px #e3b764, 178px 105px #b86f37, 246px 48px #d9a34d, 318px 138px #c47e42, 382px 62px #e3b764;
    animation: confettiFall 2.8s cubic-bezier(0.22, 0.61, 0.36, 1) 0.25s both;
}

.game-won.winner-reveal::after {
    left: 25%;
    width: 5px;
    height: 10px;
    background: #b86f37;
    box-shadow: 58px 126px #e3b764, 132px 42px #d29737, 214px 94px #c47e42, 286px 16px #e3b764, 354px 118px #d29737;
    animation: confettiFall 3.2s cubic-bezier(0.22, 0.61, 0.36, 1) 0.5s both;
}

.turn-my-turn .board-square {
    box-shadow: 0 18px 38px rgba(70, 43, 22, 0.18), 0 0 10px rgba(154, 104, 72, 0.12), inset 0 0 14px rgba(103, 62, 26, 0.18);
}

.turn-my-turn .board-square::before {
    border-color: rgba(154, 104, 72, 0.34);
    box-shadow: inset 0 0 0 1px rgba(255, 245, 225, 0.18);
}

.turn-my-turn .board-square::after {
    opacity: 0;
}

.turn-opponent .board-square {
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12), 0 0 12px rgba(154, 128, 98, 0.1), inset 0 0 10px rgba(139, 90, 43, 0.2);
}

.turn-opponent .board-square::before {
    border-color: rgba(154, 104, 72, 0.36);
}

.turn-waiting .board-square {
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.1), inset 0 0 10px rgba(139, 90, 43, 0.2);
}

.undoing .board-square {
    animation: undoBoard 0.5s ease-out both;
}

.board {
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(var(--board-size, 13), 1fr);
    grid-template-rows: repeat(var(--board-size, 13), 1fr);
    position: relative;
    border-radius: 8px;
    overflow: visible;
}

.cell {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.cell:focus-visible {
    z-index: 5;
    outline: 2px solid rgba(118, 80, 45, 0.9);
    outline-offset: -3px;
    background: rgba(255, 239, 198, 0.32);
}

.cell.last-move {
    background: radial-gradient(circle, rgba(121, 151, 143, 0.12) 0 38%, rgba(121, 151, 143, 0.05) 56%, transparent 78%);
}

.cell::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background-color: rgba(100, 62, 30, 0.7);
    z-index: 1;
}

.cell::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 1px;
    background-color: rgba(100, 62, 30, 0.7);
    z-index: 1;
}

.cell.left-col::before {
    left: 50%;
}

.cell.right-col::before {
    right: 50%;
}

.cell.top-row::after {
    top: 50%;
}

.cell.bottom-row::after {
    bottom: 50%;
}

.stone {
    position: relative;
    z-index: 2;
    width: 91%;
    aspect-ratio: 1 / 1;
    height: auto;
    flex: 0 0 auto;
    border-radius: 50%;
    box-shadow: 2px 4px 6px rgba(0, 0, 0, 0.3);
    animation: popIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    transform: scale(0);
}

.stone.black {
    background: radial-gradient(circle at 28% 24%, #777 0%, #27231f 34%, #050505 78%);
    box-shadow: 2px 4px 7px rgba(48, 29, 14, 0.3), 0 5px 8px rgba(48, 29, 14, 0.16), inset -2px -3px 5px rgba(0, 0, 0, 0.38), inset 2px 2px 4px rgba(255, 255, 255, 0.12);
}

.stone.white {
    background: radial-gradient(circle at 28% 24%, #fffef8 0%, #eee7d7 48%, #c8beaa 100%);
    box-shadow: 1px 3px 6px rgba(48, 29, 14, 0.2), 0 5px 8px rgba(48, 29, 14, 0.12), inset -2px -3px 5px rgba(119, 96, 68, 0.18), inset 2px 2px 4px rgba(255, 255, 255, 0.72);
}

.stone.black.last-move {
    filter: drop-shadow(0 0 4px rgba(86, 111, 108, 0.32));
}

.stone.white.last-move {
    filter: drop-shadow(0 0 4px rgba(86, 111, 108, 0.28));
}

.stone.last-move {
    outline: 1px solid rgba(86, 111, 108, 0.52);
    outline-offset: 3px;
}

.cell.winning-cell {
    background: radial-gradient(circle, rgba(126, 91, 57, 0.14) 0 40%, rgba(126, 91, 57, 0.05) 62%, transparent 80%);
}

.stone.winning-stone {
    z-index: 2;
    outline: none;
}

.stone.black.winning-stone {
    box-shadow: 0 0 0 2px rgba(255, 246, 220, 0.82), 0 0 9px 3px rgba(255, 244, 210, 0.48), 2px 4px 7px rgba(48, 29, 14, 0.38), inset -2px -3px 5px rgba(0, 0, 0, 0.38), inset 2px 2px 4px rgba(255, 255, 255, 0.12);
}

.stone.white.winning-stone {
    box-shadow: 0 0 0 2px rgba(69, 48, 34, 0.78), 0 0 9px 3px rgba(69, 48, 34, 0.3), 1px 3px 6px rgba(48, 29, 14, 0.24), inset -2px -3px 5px rgba(119, 96, 68, 0.18), inset 2px 2px 4px rgba(255, 255, 255, 0.72);
}

@keyframes popIn {
    0% {
        transform: scale(0);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes boardOpening {
    0% {
        transform: perspective(1200px) rotateY(0) rotateX(0) scale(0.985);
    }

    22% {
        transform: perspective(1200px) rotateY(68deg) rotateX(3deg) scale(0.965);
    }

    50% {
        transform: perspective(1200px) rotateY(180deg) rotateX(0) scale(0.94);
    }

    78% {
        transform: perspective(1200px) rotateY(292deg) rotateX(-3deg) scale(0.97);
    }

    100% {
        transform: perspective(1200px) rotateY(360deg) rotateX(0) scale(1);
    }
}

@keyframes boardExpansion {
    0% {
        transform: scale(0.975);
        filter: brightness(1);
    }

    36% {
        transform: scale(1.012);
        filter: brightness(1.045);
    }

    100% {
        transform: scale(1);
        filter: brightness(1);
    }
}

@keyframes winnerLift {
    0% {
        transform: translateY(0) scale(1);
    }

    45% {
        transform: translateY(-7px) scale(1.012);
    }

    100% {
        transform: translateY(0) scale(1);
    }
}

@keyframes gameIdFade {
    0% {
        opacity: 0.72;
    }

    100% {
        opacity: 0;
    }
}

@keyframes inviteButtonShimmer {

    0%,
    18% {
        opacity: 0;
        transform: translateX(-150%) skewX(-16deg);
    }

    28% {
        opacity: 1;
    }

    48% {
        opacity: 1;
        transform: translateX(290%) skewX(-16deg);
    }

    58%,
    100% {
        opacity: 0;
        transform: translateX(290%) skewX(-16deg);
    }
}

@keyframes inviteButtonHalo {

    0%,
    20%,
    68%,
    100% {
        box-shadow: 0 0 0 0 rgba(216, 173, 117, 0), 0 3px 8px rgba(83, 59, 38, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.72);
    }

    44% {
        box-shadow: 0 0 0 3px rgba(216, 173, 117, 0.14), 0 4px 11px rgba(83, 59, 38, 0.11), inset 0 1px 0 rgba(255, 255, 255, 0.76);
    }

    54% {
        box-shadow: 0 0 0 6px rgba(216, 173, 117, 0.28), 0 7px 16px rgba(83, 59, 38, 0.14), inset 0 1px 0 rgba(255, 255, 255, 0.82);
    }
}

@keyframes undoBoard {
    0% {
        transform: scale(1);
        filter: brightness(1);
    }

    45% {
        transform: scale(0.992);
        filter: brightness(1.06);
    }

    100% {
        transform: scale(1);
        filter: brightness(1);
    }
}

@keyframes reactionMenuIn {
    from {
        opacity: 0;
        transform: translateX(-50%) scale(0.94) translateY(3px);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) scale(1) translateY(0);
    }
}

@keyframes reactionFloat {
    0% {
        opacity: 0;
        transform: translate(-50%, 8px) scale(0.68);
    }

    16% {
        opacity: 0.96;
        transform: translate(calc(-50% - 2px), -9px) scale(1.08);
    }

    54% {
        opacity: 0.78;
        transform: translate(calc(-50% + 5px), -54px) scale(1);
    }

    100% {
        opacity: 0;
        transform: translate(calc(-50% + 10px), -94px) scale(0.72);
    }
}


@keyframes winnerRing {
    0% {
        transform: scale(0.96);
        opacity: 0;
    }

    30% {
        opacity: 0.9;
    }

    100% {
        transform: scale(1.045);
        opacity: 0;
    }
}

@keyframes winnerStatus {
    0% {
        opacity: 0.35;
        transform: translateY(5px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes confettiFall {
    0% {
        opacity: 0;
        transform: translate3d(0, -8px, 0) rotate(0deg);
    }

    12% {
        opacity: 0.78;
    }

    68% {
        opacity: 0.48;
    }

    100% {
        opacity: 0;
        transform: translate3d(18px, 78vh, 0) rotate(250deg);
    }
}

@keyframes statusArrive {
    0% {
        opacity: 0.45;
        transform: translateY(3px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (prefers-reduced-motion: reduce) {

    .game-won .board-square,
    .game-won .board-square::after,
    .game-won .board-square::before,
    .game-won .status,
    .game-won::before,
    .game-won::after,
    .game-opening .board-square,
    .board-square.board-expanding,
    .is-connected:not(.game-started) #copy-link,
    .is-connected:not(.game-started) #copy-link::after,
    .turn-my-turn .board-square::after,
    .status-my-turn,
    .status-opponent-turn,
    .reaction-menu,
    .reaction-display.is-visible {
        animation: none;
    }
}

@media (min-aspect-ratio: 1/1) {
    .app-container {
        flex-direction: row;
        max-width: 900px;
        align-items: center;
        gap: 60px;
    }

    .board-wrapper {
        flex: 2;
    }

    header {
        flex: 1;
        flex-direction: column;
        justify-content: center;
        align-items: flex-start;
    }

    .header-actions {
        margin-top: 20px;
    }
}

@media (max-aspect-ratio: 1/1) and (min-width: 520px) {
    header {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        column-gap: 14px;
        row-gap: 8px;
    }

    .status {
        grid-column: 1;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: clamp(17px, 3.5vw, 21px);
    }

    .header-actions {
        grid-column: 2;
        margin: 0;
    }

    .waiting-hint {
        grid-column: 1 / -1;
        margin-top: 0;
    }
}

@media (max-aspect-ratio: 1/1) and (max-width: 519px) {
    header {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: flex-start;
        column-gap: 8px;
        row-gap: 8px;
    }

    .status {
        grid-column: 1;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: clamp(14px, 4vw, 15px);
    }

    .header-actions {
        grid-column: 2;
        gap: 3px;
        margin: 0;
    }

    .header-actions .action-button {
        min-height: 36px;
        gap: 4px;
        padding: 6px 6px;
        font-size: 9.5px;
    }

    .header-actions .action-icon {
        width: 14px;
        height: 14px;
        font-size: 14px;
    }

    .waiting-hint {
        grid-column: 1 / -1;
        margin-top: 8px;
    }
}

@media (max-width: 380px) {
    .app-container {
        padding-left: 12px;
        padding-right: 12px;
    }

    .header-actions {
        gap: 5px;
    }

    .action-button {
        padding-left: 8px;
        padding-right: 8px;
        font-size: 12px;
    }

    .status {
        font-size: 14px;
    }

    .header-actions .action-button {
        gap: 3px;
        padding: 5px 4px;
        font-size: 8px;
    }

    .header-actions .action-icon {
        width: 12px;
        height: 12px;
        font-size: 12px;
    }
}

@media (max-width: 600px) and (max-aspect-ratio: 1/1) {
    header {
        gap: 6px;
    }

    .status {
        font-size: 15px;
        padding: 6px 0;
    }

    .header-actions {
        gap: 4px;
    }

    .action-button {
        min-height: 36px;
        padding: 7px 8px;
        font-size: 11px;
    }

    .action-icon {
        width: 14px;
        height: 14px;
        font-size: 14px;
    }

}
