/* ===================================================================
   SCHACH ONLINE — chess.com-inspired dark theme
   Pieces: cburnett SVG set (frei lizenziert, siehe pieces/CREDITS.md)
   =================================================================== */

:root {
    /* Surfaces */
    --bg: #302e2b;
    --panel: #262421;
    --panel-2: #21201d;
    --panel-3: #3a3733;
    --border: #46423d;
    --text: #ececea;
    --text-dim: #a8a39d;
    --text-mute: #807a73;

    /* Accent (chess.com green) */
    --accent: #81b64c;
    --accent-hover: #95c75b;
    --accent-press: #6a9c3e;
    --danger: #d36b58;

    /* Board (green default) */
    --board-light: #eeeed2;
    --board-dark: #769656;

    /* Board highlights */
    --hl-move: rgba(255, 255, 51, 0.45);
    --hl-select: rgba(255, 255, 51, 0.5);
    --valid-move: rgba(20, 20, 20, 0.22);
    --check-color: rgba(232, 65, 56, 0.85);

    /* Sizing */
    --board-size: min(calc(100vh - 170px), calc(100vw - 380px), 680px);
    --bar-h: 52px;
    --panel-w: 320px;
}

* { box-sizing: border-box; }

body {
    min-height: 100vh;
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 18px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--text);
}

/* Neutralize the site-wide purple background overlay from main.css
   (body::before paints var(--body-bg-image/-color) over our dark theme) */
body::before { display: none !important; }
html { background: var(--bg); }

/* Background themes (body) */
.theme-default { background: var(--bg); }
.theme-digital { background: radial-gradient(circle at 30% 20%, #1f2a1c, #16140f 70%); }
.theme-ocean { background: linear-gradient(135deg, #14323f, #0c1d24); }
.theme-sunset { background: linear-gradient(135deg, #3a2420, #241715); }
.theme-forest { background: linear-gradient(135deg, #1c2b1a, #11160f); }
.theme-elegant { background: linear-gradient(135deg, #2a2724, #161412); }

/* ===================================================================
   LOBBY
   =================================================================== */

.lobby-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.75rem;
    max-width: 440px;
    width: 100%;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
    animation: cardIn 0.25s ease;
    /* JS toggles display:flex for the AI dialog — keep children stacked vertically */
    flex-direction: column;
}

@keyframes cardIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.lobby-brand {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.lobby-logo {
    width: 56px;
    height: 56px;
    flex-shrink: 0;
    border-radius: 12px;
    background: var(--accent);
    color: #1c2b13;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    box-shadow: 0 6px 16px rgba(129, 182, 76, 0.35);
}

.lobby-title {
    margin: 0;
    font-size: 1.9rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: #fff;
}

.lobby-subtitle {
    margin: 0;
    color: var(--text-dim);
    font-size: 0.9rem;
}

.lobby-header-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.lobby-heading {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 700;
    color: #fff;
}

.icon-back {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border: none;
    border-radius: 10px;
    background: var(--panel-3);
    color: var(--text);
    font-size: 1.1rem;
    cursor: pointer;
    transition: background 0.15s;
}

.icon-back:hover { background: var(--border); }

.section-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-mute);
    margin: 0 0 0.6rem;
}

.time-control-section { margin-bottom: 1.4rem; }
.setting-block { margin-bottom: 1.25rem; }

/* Time control grid */
.time-control-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.time-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: var(--panel-3);
    border: 2px solid transparent;
    color: var(--text);
    padding: 0.6rem 0.3rem;
    border-radius: 9px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.time-btn .t-main { font-weight: 700; font-size: 0.95rem; }
.time-btn .t-sub { font-size: 0.62rem; color: var(--text-mute); text-transform: uppercase; letter-spacing: 0.5px; }
.time-btn:hover { background: var(--border); }
.time-btn.active { background: rgba(129, 182, 76, 0.18); border-color: var(--accent); }
.time-btn.active .t-sub { color: var(--accent-hover); }

/* Fun mode toggle */
.fun-mode-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: -0.35rem 0 1.25rem;
    padding: 0.85rem 0.95rem;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.fun-mode-toggle strong {
    display: block;
    color: #fff;
    font-size: 0.95rem;
}
.fun-mode-toggle span {
    display: block;
    color: var(--text-mute);
    font-size: 0.76rem;
}
.fun-switch {
    position: relative;
    width: 54px;
    height: 30px;
    flex-shrink: 0;
    cursor: pointer;
}
.fun-switch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}
.fun-switch > span {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    background: #151412;
    border: 1px solid var(--border);
    transition: background 0.18s ease, border-color 0.18s ease;
}
.fun-switch > span::after {
    content: '';
    position: absolute;
    top: 4px;
    left: 4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--text-dim);
    transition: transform 0.18s ease, background 0.18s ease;
}
.fun-switch input:checked + span {
    background: rgba(211, 107, 88, 0.28);
    border-color: var(--danger);
    box-shadow: 0 0 18px rgba(211, 107, 88, 0.22);
}
.fun-switch input:checked + span::after {
    transform: translateX(24px);
    background: #f5c45f;
}

/* Mode list */
.mode-list { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 1rem; }

.mode-btn {
    display: flex;
    align-items: center;
    gap: 1rem;
    width: 100%;
    text-align: left;
    background: var(--panel-3);
    border: 1px solid var(--border);
    border-radius: 11px;
    padding: 0.85rem 1rem;
    color: var(--text);
    cursor: pointer;
    transition: all 0.15s ease;
}

.mode-btn:hover { background: var(--border); transform: translateY(-1px); }

.mode-btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #18260f;
}
.mode-btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.mode-btn-primary .mode-icon { background: rgba(0, 0, 0, 0.15); color: #18260f; }
.mode-btn-primary .mode-text small { color: rgba(24, 38, 15, 0.7); }

.mode-icon {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    border-radius: 9px;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    color: var(--accent);
}

.mode-text { display: flex; flex-direction: column; flex: 1; line-height: 1.3; }
.mode-text strong { font-size: 1rem; }
.mode-text small { font-size: 0.78rem; color: var(--text-dim); }
.mode-arrow { color: inherit; opacity: 0.5; }

.lobby-back {
    display: block;
    text-align: center;
    color: var(--text-dim);
    text-decoration: none;
    font-size: 0.88rem;
    padding: 0.5rem;
    transition: color 0.15s;
}
.lobby-back:hover { color: var(--text); }

/* Segmented controls */
.segmented {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 4px;
    background: var(--panel-2);
    border-radius: 10px;
    padding: 4px;
}

.seg-btn {
    border: none;
    background: transparent;
    color: var(--text-dim);
    padding: 0.55rem 0.4rem;
    border-radius: 7px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.15s ease;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--accent); color: #18260f; }

/* Play / secondary buttons */
.btn-play {
    width: 100%;
    border: none;
    border-radius: 11px;
    background: var(--accent);
    color: #18260f;
    font-weight: 800;
    font-size: 1.05rem;
    padding: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    box-shadow: 0 4px 0 var(--accent-press);
    transition: all 0.12s ease;
}
.btn-play:hover { background: var(--accent-hover); }
.btn-play:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-press); }

.btn-secondary {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel-3);
    color: var(--text);
    font-weight: 600;
    padding: 0.7rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: background 0.15s;
}
.btn-secondary:hover { background: var(--border); }

.code-input {
    width: 100%;
    text-align: center;
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 6px;
    text-transform: uppercase;
    background: var(--panel-2);
    border: 2px solid var(--border);
    border-radius: 10px;
    color: #fff;
    padding: 0.7rem;
    margin-bottom: 0.6rem;
    outline: none;
}
.code-input:focus { border-color: var(--accent); }
.code-input::placeholder { color: var(--text-mute); letter-spacing: 6px; }

.or-divider {
    display: flex;
    align-items: center;
    text-align: center;
    color: var(--text-mute);
    font-size: 0.8rem;
    margin: 1.1rem 0 0.9rem;
}
.or-divider::before,
.or-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}
.or-divider span { padding: 0 0.8rem; }

/* ===================================================================
   GAME LAYOUT
   =================================================================== */

#game-section { width: 100%; display: flex; justify-content: center; }

.game-layout {
    display: flex;
    gap: 18px;
    align-items: stretch;
    justify-content: center;
}

.board-area {
    display: flex;
    flex-direction: column;
    width: var(--board-size);
}

/* Player bars */
.player-info {
    height: var(--bar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.6rem;
    background: var(--panel);
    border: 1px solid var(--border);
}
.opponent-info { border-radius: 10px 10px 0 0; border-bottom: none; }
.my-info { border-radius: 0 0 10px 10px; border-top: none; }

.player-info.turn-active { background: var(--panel-3); }

.player-identity { display: flex; align-items: center; gap: 0.55rem; min-width: 0; }

.player-avatar {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border-radius: 7px;
    background: var(--panel-3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    color: var(--text-dim);
}

.player-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.player-label { font-size: 0.92rem; font-weight: 700; color: var(--text); white-space: nowrap; }

.captured-row { display: flex; align-items: center; gap: 4px; height: 18px; }
.captured-pieces { display: flex; align-items: center; gap: 0; font-size: 1rem; line-height: 1; }
.captured-pieces img { width: 16px; height: 16px; margin-right: -3px; opacity: 0.95; }
.material-adv { font-size: 0.78rem; font-weight: 700; color: var(--text-dim); }

.player-timer {
    font-family: "Roboto Mono", ui-monospace, monospace;
    font-size: 1.35rem;
    font-weight: 700;
    padding: 0.35rem 0.85rem;
    background: var(--panel-2);
    border-radius: 7px;
    min-width: 92px;
    text-align: center;
    color: var(--text);
    transition: background 0.15s, color 0.15s;
}
.player-timer.active {
    background: #fff;
    color: #1a1a1a;
    box-shadow: 0 0 0 2px var(--accent);
}
.player-timer.low-time {
    background: var(--danger);
    color: #fff;
    animation: timer-warning 0.6s infinite;
}

@keyframes timer-warning {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}

/* ===================================================================
   CHESS BOARD
   =================================================================== */

.chess-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: var(--board-size);
    height: var(--board-size);
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    position: relative;
}

.chess-board.flipped { transform: rotate(180deg); }
.chess-board.flipped .square { transform: rotate(180deg); }

.square {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    cursor: pointer;
    user-select: none;
}

.square.light { background-color: var(--board-light); }
.square.dark { background-color: var(--board-dark); }

/* Coordinates */
.square .coord-file,
.square .coord-rank {
    position: absolute;
    font-size: clamp(0.5rem, calc(var(--board-size) / 60), 0.8rem);
    font-weight: 700;
    pointer-events: none;
}
.square.light .coord-file,
.square.light .coord-rank { color: var(--board-dark); }
.square.dark .coord-file,
.square.dark .coord-rank { color: var(--board-light); }
.square .coord-file { bottom: 2px; right: 4px; }
.square .coord-rank { top: 2px; left: 3px; }

/* Highlights */
.square.selected { background-color: var(--hl-select) !important; }
.square.light.selected { background-color: #f6f682 !important; }
.square.dark.selected { background-color: #bbcb45 !important; }

.square.last-move-from,
.square.last-move-to { background-color: var(--hl-move) !important; }
.square.light.last-move-from,
.square.light.last-move-to { background-color: #f6eb72 !important; }
.square.dark.last-move-from,
.square.dark.last-move-to { background-color: #bcca44 !important; }

.square.premove-from,
.square.premove-to { box-shadow: inset 0 0 0 4px rgba(255, 214, 102, 0.9); }
.square.premove-to::before {
    content: '';
    position: absolute;
    width: 38%;
    height: 38%;
    border: 3px solid rgba(255, 214, 102, 0.95);
    border-radius: 50%;
    pointer-events: none;
    z-index: 1;
}

.square.valid-move::after {
    content: '';
    position: absolute;
    width: 32%;
    height: 32%;
    background: var(--valid-move);
    border-radius: 50%;
    pointer-events: none;
}
.square.valid-capture::after {
    content: '';
    position: absolute;
    width: 92%;
    height: 92%;
    border: 5px solid var(--valid-move);
    border-radius: 50%;
    box-sizing: border-box;
    pointer-events: none;
}
.square.in-check {
    background: radial-gradient(circle, var(--check-color), transparent 72%) !important;
}
.square.fun-bomb-square::before,
.square.fun-frozen-square::before,
.square.fun-mine-square::before {
    content: '';
    position: absolute;
    inset: 5%;
    border-radius: 8px;
    pointer-events: none;
    z-index: 1;
}
.square.fun-bomb-square::before {
    border: 3px solid rgba(211, 107, 88, 0.82);
    box-shadow: inset 0 0 18px rgba(211, 107, 88, 0.4), 0 0 16px rgba(211, 107, 88, 0.35);
}
.square.fun-frozen-square::before {
    border: 3px solid rgba(94, 195, 224, 0.78);
    box-shadow: inset 0 0 18px rgba(94, 195, 224, 0.34), 0 0 16px rgba(94, 195, 224, 0.28);
}
.square.fun-mine-square::before {
    border: 3px dashed rgba(245, 196, 95, 0.88);
    background: radial-gradient(circle, rgba(245, 196, 95, 0.22), transparent 58%);
}
.fun-square-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    z-index: 4;
    border-radius: 4px;
    padding: 0.08rem 0.22rem;
    background: #151412;
    color: #fff;
    font-size: clamp(0.42rem, calc(var(--board-size) / 92), 0.62rem);
    font-weight: 900;
    letter-spacing: 0;
    line-height: 1.2;
    pointer-events: none;
}
.fun-badge-bomb { color: #f0a99a; border: 1px solid rgba(211, 107, 88, 0.72); }
.fun-badge-lock { color: #9edbed; border: 1px solid rgba(94, 195, 224, 0.72); }
.fun-badge-mine { color: #f5c45f; border: 1px solid rgba(245, 196, 95, 0.78); }
.square.fun-square-blast,
.square.fun-square-mine-hit {
    animation: fun-square-hit 1.1s ease-out;
}
@keyframes fun-square-hit {
    0% { box-shadow: inset 0 0 0 0 rgba(255, 255, 255, 0); filter: brightness(1); }
    20% { box-shadow: inset 0 0 0 999px rgba(255, 244, 204, 0.85); filter: brightness(1.8); }
    55% { box-shadow: inset 0 0 0 999px rgba(211, 107, 88, 0.45); filter: brightness(1.25); }
    100% { box-shadow: inset 0 0 0 0 rgba(211, 107, 88, 0); filter: brightness(1); }
}

/* ===================================================================
   PIECES
   =================================================================== */

.piece {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    cursor: grab;
    user-select: none;
    position: relative;
    z-index: 2;
}
.piece:active { cursor: grabbing; }

/* SVG pieces (default) */
img.piece.piece-img {
    width: 92%;
    height: 92%;
    object-fit: contain;
    filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.28));
    -webkit-user-drag: element;
}

/* Unicode pieces */
span.piece {
    font-size: calc(var(--board-size) / 8 * 0.82);
    text-shadow: 2px 2px 3px rgba(0, 0, 0, 0.3);
}
span.piece.white {
    color: #fff;
    text-shadow: 0 0 1px #000, 1px 1px 0 #4a4a4a, -1px 1px 0 #4a4a4a,
        1px -1px 0 #4a4a4a, -1px -1px 0 #4a4a4a, 2px 3px 4px rgba(0, 0, 0, 0.4);
}
span.piece.black {
    color: #2b2b2b;
    text-shadow: 0 0 1px #000, 1px 1px 0 rgba(255, 255, 255, 0.18), 2px 3px 4px rgba(0, 0, 0, 0.35);
}

.pieces-minimalist span.piece { font-family: Arial, sans-serif; }
.pieces-minimalist span.piece.white { color: #f5f5f5; -webkit-text-stroke: 1px #333; text-shadow: none; }
.pieces-minimalist span.piece.black { color: #2a2a2a; text-shadow: none; }

@keyframes piece-land {
    0% { transform: scale(1.16); }
    100% { transform: scale(1); }
}
.piece.piece-moved { animation: piece-land 0.14s ease-out; }

/* ===================================================================
   BOARD THEMES
   =================================================================== */

.board-classic { --board-light: #f0d9b5; --board-dark: #b58863; }
.board-green { --board-light: #eeeed2; --board-dark: #769656; }
.board-blue { --board-light: #dee3e6; --board-dark: #8ca2ad; }
.board-purple { --board-light: #e8d0f0; --board-dark: #9b72cf; }
.board-wood { --board-light: #e8c99b; --board-dark: #a17a4d; }
.board-dark { --board-light: #6f6f6f; --board-dark: #3a3a3a; }

/* ===================================================================
   SIDE PANEL
   =================================================================== */

.side-panel {
    width: var(--panel-w);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    height: calc(var(--board-size) + 2 * var(--bar-h));
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
}

.status-display {
    text-align: center;
    font-size: 1rem;
    font-weight: 700;
    padding: 0.7rem 1rem;
    background: var(--panel-2);
    border-radius: 9px;
    color: var(--text);
    flex-shrink: 0;
}
.status-display.check {
    background: rgba(211, 107, 88, 0.22);
    color: #f0a99a;
    animation: pulse-check 1s infinite;
}
@keyframes pulse-check {
    0%, 100% { box-shadow: 0 0 0 0 rgba(211, 107, 88, 0.4); }
    50% { box-shadow: 0 0 18px 3px rgba(211, 107, 88, 0.4); }
}

.fun-status-panel {
    flex-shrink: 0;
    background: linear-gradient(135deg, rgba(211, 107, 88, 0.14), rgba(245, 196, 95, 0.1));
    border: 1px solid rgba(245, 196, 95, 0.26);
    border-radius: 9px;
    padding: 0.65rem 0.75rem;
    transform-origin: top center;
    animation: fun-panel-in 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes fun-panel-in {
    from { opacity: 0; transform: translateY(-10px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.fun-status-title {
    color: #f5c45f;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.9px;
    text-transform: uppercase;
    margin-bottom: 0.35rem;
}
.fun-status-list {
    color: var(--text-dim);
    font-size: 0.78rem;
}
.fun-status-effect {
    display: flex;
    flex-direction: column;
    gap: 0.12rem;
    padding: 0.3rem 0;
    border-top: 1px solid rgba(245, 196, 95, 0.12);
}
.fun-status-effect:first-child {
    border-top: none;
}
.fun-status-effect-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}
.fun-status-effect span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #fff;
    font-weight: 700;
}
.fun-status-effect strong {
    color: #f5c45f;
    font-size: 0.72rem;
    white-space: nowrap;
}
.fun-status-effect-desc {
    margin: 0;
    font-size: 0.7rem;
    line-height: 1.3;
    color: var(--text-dim);
}

.move-history-panel {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--panel-2);
    border-radius: 9px;
    overflow: hidden;
}
.move-history-header {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-mute);
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid var(--border);
}
.move-history-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.move-history-list::-webkit-scrollbar { width: 8px; }
.move-history-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.move-row {
    display: grid;
    grid-template-columns: 34px 1fr 1fr;
    gap: 4px;
    padding: 4px 0.75rem;
    font-size: 0.85rem;
    font-family: "Roboto Mono", ui-monospace, monospace;
    color: var(--text-dim);
}
.move-row:nth-child(odd) { background: rgba(255, 255, 255, 0.02); }
.move-row-last { color: #fff; }
.move-row-last .move-white,
.move-row-last .move-black { background: rgba(129, 182, 76, 0.18); border-radius: 4px; padding: 0 4px; }
.move-num { color: var(--text-mute); }

/* Multiplayer chat */
.chat-panel {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--panel-2);
    border-radius: 9px;
    overflow: hidden;
}
.chat-header {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-mute);
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid var(--border);
}
.chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0.55rem 0.65rem;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.chat-messages::-webkit-scrollbar { width: 8px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.chat-empty {
    margin: auto;
    color: var(--text-mute);
    font-size: 0.78rem;
}
.chat-message {
    max-width: 88%;
    align-self: flex-start;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.chat-message.mine { align-self: flex-end; text-align: right; }
.chat-meta {
    font-size: 0.64rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-mute);
}
.chat-bubble {
    background: var(--panel-3);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.42rem 0.58rem;
    color: var(--text);
    font-size: 0.82rem;
    line-height: 1.25;
    overflow-wrap: anywhere;
}
.chat-message.mine .chat-bubble {
    background: rgba(129, 182, 76, 0.2);
    border-color: rgba(129, 182, 76, 0.45);
}
.chat-form {
    display: flex;
    gap: 6px;
    padding: 0.55rem;
    border-top: 1px solid var(--border);
}
.chat-form input {
    min-width: 0;
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 0.42rem 0.55rem;
    font-size: 0.85rem;
}
.chat-form input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(129, 182, 76, 0.2);
}
.chat-form input::placeholder { color: var(--text-mute); }
.chat-form button {
    width: 38px;
    flex-shrink: 0;
    border: 1px solid var(--accent);
    border-radius: 8px;
    background: var(--accent);
    color: #18260f;
    cursor: pointer;
}
.chat-form button:hover { background: var(--accent-hover); }

/* Invite section */
.invite-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
    background: var(--panel-2);
    border-radius: 9px;
    flex-shrink: 0;
}
.invite-hint { margin: 0 0 2px; font-size: 0.82rem; color: var(--text-dim); text-align: center; }
.invite-flex { display: flex; gap: 8px; margin-bottom: 2px; }
.invite-flex input {
    flex: 1;
    min-width: 0;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: #fff;
    font-size: 1.2rem;
    text-align: center;
    font-weight: 700;
    letter-spacing: 3px;
    padding: 0.4rem;
}
.btn-icon {
    flex-shrink: 0;
    width: 44px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel-3);
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s;
}
.btn-icon:hover { background: var(--border); }
.btn-sm-full { font-size: 0.85rem; padding: 0.55rem; }
.login-warning { font-size: 0.78rem; color: var(--danger); text-align: center; }

/* Game controls */
.game-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    flex-shrink: 0;
}
.ctrl-btn {
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--panel-3);
    color: var(--text);
    padding: 0.6rem 0.5rem;
    font-weight: 600;
    font-size: 0.88rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    transition: all 0.15s ease;
}
.ctrl-btn:hover { background: var(--border); }
.ctrl-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.ctrl-accent { background: var(--accent); border-color: var(--accent); color: #18260f; grid-column: 1 / -1; }
.ctrl-accent:hover { background: var(--accent-hover); }

/* ===================================================================
   ANALYSIS
   =================================================================== */

#analysis-section {
    width: 100%;
    min-height: calc(100vh - 36px);
    display: flex;
    justify-content: center;
}

.analysis-shell {
    width: min(1320px, 100%);
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.analysis-topbar {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.8rem;
}

.analysis-title {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 800;
    color: #fff;
}

.analysis-subtitle {
    margin: 0.15rem 0 0;
    color: var(--text-dim);
    font-size: 0.82rem;
}

.analysis-run-btn {
    margin-left: auto;
    border: 1px solid var(--accent);
    border-radius: 9px;
    background: var(--accent);
    color: #18260f;
    padding: 0.58rem 0.8rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.analysis-run-btn:hover { background: var(--accent-hover); }
.analysis-run-btn:disabled { opacity: 0.55; cursor: wait; }

.analysis-layout {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    gap: 14px;
    align-items: start;
}

.analysis-games-panel,
.analysis-dashboard {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.analysis-games-panel {
    min-height: 260px;
    overflow: hidden;
}

.analysis-panel-heading {
    padding: 0.8rem 0.9rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: var(--text-mute);
}

.analysis-games-list {
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 150px);
    overflow-y: auto;
}

.analysis-game-item {
    border: 0;
    border-bottom: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    text-align: left;
    padding: 0.75rem 0.9rem;
    cursor: pointer;
}

.analysis-game-item:hover,
.analysis-game-item.active {
    background: var(--panel-3);
}

.analysis-game-main {
    display: flex;
    justify-content: space-between;
    gap: 0.6rem;
    font-size: 0.88rem;
    font-weight: 700;
}

.analysis-game-meta {
    margin-top: 0.25rem;
    color: var(--text-mute);
    font-size: 0.74rem;
}

.analysis-main {
    display: grid;
    grid-template-columns: minmax(360px, 560px) minmax(320px, 1fr);
    gap: 14px;
    align-items: start;
}

.analysis-board-block {
    --board-size: min(calc(52vw - 36px), 524px, calc(100vh - 188px));
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.analysis-board-row {
    display: flex;
    gap: 10px;
    align-items: stretch;
}

.analysis-eval-bar {
    position: relative;
    flex-shrink: 0;
    width: 26px;
    height: var(--board-size);
    background: #3a3733;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}

.analysis-eval-fill {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 50%;
    background: #ece7dd;
    transition: height 0.35s ease;
}

.analysis-eval-label {
    position: absolute;
    left: 0;
    bottom: 4px;
    width: 100%;
    text-align: center;
    font-size: 0.58rem;
    font-weight: 800;
    line-height: 1;
    color: #2b2825;
    pointer-events: none;
}

.analysis-eval-label.top {
    bottom: auto;
    top: 4px;
    color: #ece7dd;
}

.analysis-board {
    width: var(--board-size);
    height: var(--board-size);
}

.analysis-board .piece { cursor: default; }

.analysis-replay-controls {
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
}

#analysis-replay-label {
    min-width: 160px;
    text-align: center;
    color: var(--text-dim);
    font-size: 0.86rem;
    font-weight: 700;
}

.analysis-dashboard {
    padding: 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.analysis-status {
    min-height: 40px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--panel-2);
    color: var(--text-dim);
    padding: 0.65rem 0.75rem;
    font-size: 0.84rem;
    display: flex;
    align-items: center;
}

.analysis-status.warning { border-color: rgba(211, 107, 88, 0.55); color: #f0b4a8; }

.analysis-summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
}

.analysis-summary-card {
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.65rem;
}

.analysis-summary-card span {
    display: block;
    color: var(--text-mute);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.7px;
    text-transform: uppercase;
}

.analysis-summary-card strong {
    display: block;
    margin-top: 0.25rem;
    color: #fff;
    font-size: 1.15rem;
}

.analysis-eval-canvas {
    width: 100%;
    height: 180px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.analysis-move-list {
    max-height: calc(100vh - 515px);
    min-height: 180px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel-2);
}

.analysis-move-row {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
    border-bottom: 1px solid var(--border);
    padding: 0.55rem 0.65rem;
    cursor: pointer;
}

.analysis-move-row:hover,
.analysis-move-row.active {
    background: var(--panel-3);
}

.analysis-move-num {
    color: var(--text-mute);
    font-size: 0.76rem;
    font-weight: 700;
}

.analysis-move-notation {
    min-width: 0;
    color: var(--text);
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.move-label {
    border-radius: 999px;
    padding: 0.2rem 0.48rem;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.3px;
    color: #141414;
}

.move-label.label-brilliant { background: #2dd4bf; }
.move-label.label-best { background: #81b64c; }
.move-label.label-excellent { background: #a3d977; }
.move-label.label-good { background: #f1d36b; }
.move-label.label-inaccuracy { background: #f1a34f; }
.move-label.label-mistake { background: #e07658; }
.move-label.label-blunder { background: #d84c4c; color: #fff; }
.move-label.label-pending { background: var(--border); color: var(--text-dim); }

.analysis-empty {
    padding: 1rem;
    color: var(--text-mute);
    font-size: 0.85rem;
}

/* ===================================================================
   SETTINGS BUTTON + MODALS (dark)
   =================================================================== */

#settings-button {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    font-size: 1.35rem;
    color: var(--text-dim);
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 3.4rem;
    height: 3.4rem;
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.15s;
}
#settings-button:hover { color: #fff; background: var(--panel-3); transform: rotate(30deg); }

.modal-content {
    background-color: var(--panel);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 14px;
}
.modal-header { border-bottom: 1px solid var(--border); }
.modal-title { color: #fff; }
.btn-close { filter: invert(1) grayscale(1) brightness(1.6); }

.modal-subtitle {
    color: var(--text-dim);
    font-weight: 700;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
}

/* Tabs */
.nav-tabs { border-bottom: 1px solid var(--border); }
.nav-tabs .nav-link { color: var(--text-dim); border: none; font-weight: 600; }
.nav-tabs .nav-link.active {
    color: #fff;
    background-color: transparent;
    border-bottom: 2px solid var(--accent);
}
.nav-tabs .nav-link:hover { color: #fff; border-color: transparent; }
.tab-content { padding-top: 1rem; }

/* Theme swatches */
.theme-options { display: flex; justify-content: center; flex-wrap: wrap; gap: 14px; padding: 0.5rem 0; }
.theme-swatch {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 3px solid transparent;
    cursor: pointer;
    transition: transform 0.15s, border-color 0.15s;
}
.theme-swatch:hover { transform: scale(1.1); }
.theme-swatch.active { border-color: var(--accent); box-shadow: 0 0 12px rgba(129, 182, 76, 0.5); }

.theme-swatch.theme-default { background: #302e2b; }
.theme-swatch.theme-digital { background: linear-gradient(135deg, #1f2a1c, #16140f); }
.theme-swatch.theme-ocean { background: linear-gradient(135deg, #14323f, #0c1d24); }
.theme-swatch.theme-sunset { background: linear-gradient(135deg, #3a2420, #241715); }
.theme-swatch.theme-forest { background: linear-gradient(135deg, #1c2b1a, #11160f); }
.theme-swatch.theme-elegant { background: linear-gradient(135deg, #2a2724, #161412); }

.custom-color-swatch {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 3px solid var(--border);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    background: conic-gradient(red, yellow, lime, aqua, blue, magenta, red);
    position: relative;
    overflow: hidden;
    transition: transform 0.15s;
}
.custom-color-swatch:hover { transform: scale(1.1); }
.custom-color-swatch i { color: #fff; text-shadow: 0 0 3px #000; }
.custom-color-swatch input[type="color"] {
    position: absolute;
    width: 90px;
    height: 90px;
    top: -22px;
    left: -22px;
    opacity: 0;
    cursor: pointer;
}

/* Piece style options */
.piece-style-options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 0.5rem 0; }
.piece-style-btn {
    background: var(--panel-2);
    border: 2px solid var(--border);
    border-radius: 11px;
    padding: 0.9rem;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    color: var(--text);
}
.piece-style-btn:hover { background: var(--panel-3); }
.piece-style-btn.active { border-color: var(--accent); box-shadow: 0 0 12px rgba(129, 182, 76, 0.25); }
.piece-preview { font-size: 1.6rem; line-height: 1; }
.svg-preview { display: flex; gap: 1px; }
.svg-preview img { width: 26px; height: 26px; }
.style-name { font-size: 0.82rem; color: var(--text-dim); }

/* Board style options */
.board-style-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; padding: 0.5rem 0; }
.board-style-btn {
    background: var(--panel-2);
    border: 2px solid var(--border);
    border-radius: 11px;
    padding: 0.7rem;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.45rem;
    color: var(--text);
}
.board-style-btn:hover { background: var(--panel-3); }
.board-style-btn.active { border-color: var(--accent); box-shadow: 0 0 12px rgba(129, 182, 76, 0.25); }
.board-preview { display: grid; grid-template-columns: repeat(2, 1fr); width: 40px; height: 40px; border-radius: 5px; overflow: hidden; }
.preview-light, .preview-dark { width: 20px; height: 20px; }
.board-style-btn span { font-size: 0.74rem; color: var(--text-dim); }

/* Custom board colors */
.custom-board-colors { display: flex; justify-content: center; gap: 2rem; padding: 0.5rem 0; }
.color-input-group { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; }
.color-input-group label { font-size: 0.82rem; color: var(--text-dim); }
.color-input-group input[type="color"] { width: 50px; height: 38px; border: none; border-radius: 8px; cursor: pointer; background: none; }

/* List items / forms */
.list-group-item {
    padding-left: 0;
    padding-right: 0;
    background: transparent;
    color: var(--text);
    border-color: var(--border);
}
.form-check-label { cursor: pointer; }
.form-check-input:checked { background-color: var(--accent); border-color: var(--accent); }
.modal-content .form-control {
    background-color: var(--panel-2);
    color: #fff;
    border-color: var(--border);
}
.modal-content .form-control:focus {
    background-color: var(--panel-2);
    color: #fff;
    border-color: var(--accent);
    box-shadow: 0 0 0 0.2rem rgba(129, 182, 76, 0.25);
}
.modal-content .form-control::placeholder { color: var(--text-mute); }

/* Promotion modal */
.promotion-options { display: flex; justify-content: center; gap: 0.75rem; }
.promotion-btn {
    width: 64px;
    height: 64px;
    border: 2px solid var(--border);
    border-radius: 10px;
    background: var(--panel-2);
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}
.promotion-btn:hover { background: rgba(129, 182, 76, 0.18); border-color: var(--accent); transform: translateY(-2px); }
.promotion-btn .piece-symbol { font-size: 2.4rem; color: #fff; }
.promotion-btn img { width: 80%; height: 80%; object-fit: contain; }

/* Friend invite modal */
.invite-modal {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    max-width: 400px;
    width: 90%;
    padding: 1.75rem;
    color: var(--text);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.invite-modal h3 { margin-top: 0; color: #fff; }
.invite-modal .modal-buttons { display: flex; gap: 0.6rem; justify-content: flex-end; }

/* ===================================================================
   TOASTS
   =================================================================== */

.toast-container {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10001;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}
.game-toast {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.2rem 2rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    color: var(--text);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
    animation: fadeInScale 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: auto;
    max-width: 90vw;
}
.game-toast.with-actions { flex-direction: column; text-align: center; }
.game-toast .toast-message { font-size: 1.05rem; font-weight: 600; }
.game-toast .toast-actions { display: flex; gap: 1rem; margin-top: 1rem; }
.game-toast .toast-actions .btn { padding: 0.5rem 1.5rem !important; font-size: 0.95rem !important; border-radius: 8px; }

/* ===================================================================
   FUN MODE OVERLAYS
   =================================================================== */

.fun-choice-overlay,
.fun-cinematic-overlay {
    position: fixed;
    inset: 0;
    z-index: 10020;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background:
        radial-gradient(circle at 50% 42%, rgba(245, 196, 95, 0.16), transparent 32%),
        rgba(9, 8, 7, 0.86);
    backdrop-filter: blur(7px);
}
.fun-choice-card {
    width: min(760px, 96vw);
    border: 1px solid rgba(245, 196, 95, 0.36);
    border-radius: 14px;
    background: #181613;
    box-shadow: 0 28px 90px rgba(0, 0, 0, 0.78), 0 0 60px rgba(211, 107, 88, 0.18);
    padding: 1.35rem;
    animation: fun-choice-in 0.28s ease-out;
}
.fun-choice-kicker {
    color: #f5c45f;
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    text-align: center;
}
.fun-choice-card h2 {
    margin: 0.35rem 0 0;
    color: #fff;
    text-align: center;
    font-size: clamp(1.7rem, 4vw, 3rem);
    font-weight: 950;
    letter-spacing: 0;
}
.fun-choice-card p {
    margin: 0.35rem 0 1.15rem;
    color: var(--text-dim);
    text-align: center;
}
.fun-choice-options {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}
.fun-choice-option {
    min-height: 160px;
    border: 1px solid rgba(245, 196, 95, 0.24);
    border-radius: 10px;
    background:
        linear-gradient(180deg, rgba(245, 196, 95, 0.12), transparent 46%),
        var(--panel-2);
    color: var(--text);
    padding: 0.95rem;
    cursor: pointer;
    text-align: left;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 0.9rem;
    transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), border-color 0.28s ease, background 0.28s ease, box-shadow 0.28s ease;
}
.fun-choice-option:hover:not(:disabled) {
    transform: translateY(-4px);
    border-color: #f5c45f;
    background:
        linear-gradient(180deg, rgba(245, 196, 95, 0.22), rgba(211, 107, 88, 0.08)),
        var(--panel-3);
}
.fun-choice-option:disabled {
    cursor: wait;
    opacity: 0.72;
}
.fun-choice-option span {
    color: #fff;
    font-size: 1rem;
    font-weight: 900;
}
.fun-choice-option strong {
    color: var(--text-dim);
    font-size: 0.86rem;
    font-weight: 600;
    line-height: 1.35;
}
@keyframes fun-choice-in {
    from { opacity: 0; transform: scale(0.96) translateY(12px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}
.fun-cinematic-overlay {
    overflow: hidden;
    background: #070605;
}
.fun-cinematic-light {
    position: absolute;
    inset: -20%;
    background:
        conic-gradient(from 90deg, transparent, rgba(245, 196, 95, 0.42), transparent, rgba(211, 107, 88, 0.34), transparent),
        radial-gradient(circle, rgba(255, 244, 204, 0.36), transparent 42%);
    animation: fun-light-spin 1.45s linear;
}
.fun-cinematic-shockwave {
    position: absolute;
    width: 18vw;
    height: 18vw;
    min-width: 160px;
    min-height: 160px;
    border: 5px solid rgba(245, 196, 95, 0.7);
    border-radius: 50%;
    animation: fun-shockwave 1.2s ease-out forwards;
}
.fun-cinematic-content {
    position: relative;
    z-index: 2;
    width: min(820px, 94vw);
    text-align: center;
    text-transform: uppercase;
    animation: fun-title-slam 1.25s cubic-bezier(0.19, 1, 0.22, 1);
}
.fun-cinematic-content span {
    display: block;
    color: #f5c45f;
    font-size: 0.8rem;
    font-weight: 950;
    letter-spacing: 2px;
}
.fun-cinematic-content strong {
    display: block;
    margin-top: 0.25rem;
    color: #fff;
    font-size: clamp(2.2rem, 9vw, 6.8rem);
    font-weight: 1000;
    letter-spacing: 0;
    line-height: 0.95;
    text-shadow: 0 0 22px rgba(245, 196, 95, 0.46), 0 8px 0 rgba(0, 0, 0, 0.55);
}
.fun-cinematic-content p {
    margin: 0.85rem auto 0;
    max-width: 620px;
    color: var(--text-dim);
    font-size: clamp(0.85rem, 2vw, 1.05rem);
    font-weight: 700;
    text-transform: none;
}
.fun-board-shake {
    animation: fun-board-shake 0.62s cubic-bezier(0.36, 0.07, 0.19, 0.97) 2;
}
.chess-board.flipped.fun-board-shake {
    animation-name: fun-board-shake-flipped;
}
@keyframes fun-light-spin {
    from { transform: rotate(0deg) scale(1.2); opacity: 0; }
    18% { opacity: 1; }
    to { transform: rotate(210deg) scale(1.6); opacity: 0; }
}
@keyframes fun-shockwave {
    from { transform: scale(0.2); opacity: 0.95; }
    to { transform: scale(7); opacity: 0; }
}
@keyframes fun-title-slam {
    0% { opacity: 0; transform: scale(0.55) translateY(28px); filter: blur(8px); }
    28% { opacity: 1; transform: scale(1.08) translateY(0); filter: blur(0); }
    100% { opacity: 1; transform: scale(1); }
}
@keyframes fun-board-shake {
    10%, 90% { transform: translate3d(-2px, 1px, 0); }
    20%, 80% { transform: translate3d(4px, -2px, 0); }
    30%, 50%, 70% { transform: translate3d(-7px, 3px, 0); }
    40%, 60% { transform: translate3d(7px, -3px, 0); }
}
@keyframes fun-board-shake-flipped {
    10%, 90% { transform: rotate(180deg) translate3d(-2px, 1px, 0); }
    20%, 80% { transform: rotate(180deg) translate3d(4px, -2px, 0); }
    30%, 50%, 70% { transform: rotate(180deg) translate3d(-7px, 3px, 0); }
    40%, 60% { transform: rotate(180deg) translate3d(7px, -3px, 0); }
}

@keyframes fadeInScale {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}
@keyframes fadeOutScale {
    from { opacity: 1; transform: scale(1); }
    to { opacity: 0; transform: scale(0.9); }
}
.game-toast.hiding { animation: fadeOutScale 0.2s ease-in forwards; }

/* ===================================================================
   FUN MODE — BOARD ANIMATION PIPELINE
   =================================================================== */

/* Choice overlay entrance + selection */
.fun-choice-overlay.entering .fun-choice-option {
    animation: fun-card-rise 0.42s cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
}
.fun-choice-overlay.entering .fun-choice-option:nth-child(1) { animation-delay: 0.05s; }
.fun-choice-overlay.entering .fun-choice-option:nth-child(2) { animation-delay: 0.13s; }
.fun-choice-overlay.entering .fun-choice-option:nth-child(3) { animation-delay: 0.21s; }
@keyframes fun-card-rise {
    from { opacity: 0; transform: translateY(18px) scale(0.96); }
    to { opacity: 1; transform: none; }
}
.fun-choice-option.selected {
    border-color: #f5c45f;
    box-shadow: 0 0 0 1px #f5c45f, 0 0 34px rgba(245, 196, 95, 0.5);
    z-index: 2;
    animation: fun-card-pop 0.42s ease forwards;
}
@keyframes fun-card-pop {
    0% { transform: none; }
    45% { transform: scale(1.08); }
    100% { transform: scale(1.04); }
}
.fun-choice-option.dismissed {
    animation: fun-card-drop 0.42s ease forwards;
    pointer-events: none;
}
@keyframes fun-card-drop {
    to { opacity: 0; transform: translateY(18px) scale(0.9); }
}

/* Full-viewport effect layer (created on demand) */
.fun-animation-layer {
    position: fixed;
    inset: 0;
    z-index: 10030;
    pointer-events: none;
    overflow: hidden;
}

/* Flying option card */
.fun-flying-card {
    position: absolute;
    left: 0;
    top: 0;
    min-width: 110px;
    max-width: 230px;
    padding: 0.55rem 0.85rem;
    border-radius: 10px;
    border: 1px solid rgba(245, 196, 95, 0.6);
    background: linear-gradient(180deg, rgba(245, 196, 95, 0.3), rgba(24, 22, 19, 0.96));
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.6), 0 0 38px rgba(245, 196, 95, 0.45);
    color: #fff;
    font-weight: 900;
    font-size: 0.9rem;
    line-height: 1.2;
    text-align: center;
    will-change: transform, opacity;
}

/* Radial wave from board centre / target square */
.fun-board-wave {
    position: absolute;
    width: var(--wave-size, 360px);
    height: var(--wave-size, 360px);
    margin-left: calc(var(--wave-size, 360px) / -2);
    margin-top: calc(var(--wave-size, 360px) / -2);
    border-radius: 50%;
    border: 3px solid rgba(245, 196, 95, 0.65);
    box-shadow: inset 0 0 40px rgba(245, 196, 95, 0.4), 0 0 32px rgba(211, 107, 88, 0.4);
    transform: scale(0.05);
    opacity: 0.9;
    animation: fun-wave-expand 1.3s ease-out forwards;
    will-change: transform, opacity;
}
@keyframes fun-wave-expand {
    from { transform: scale(0.05); opacity: 0.9; }
    to { transform: scale(1); opacity: 0; }
}

/* Single-square impact pulse */
.fun-field-impact {
    position: absolute;
    border-radius: 8px;
    box-shadow: inset 0 0 0 3px currentColor, 0 0 22px currentColor;
    animation: fun-impact-pulse 1.35s ease-out forwards;
    will-change: transform, opacity;
}
@keyframes fun-impact-pulse {
    0% { transform: scale(0.6); opacity: 0; }
    24% { transform: scale(1.06); opacity: 1; }
    100% { transform: scale(1); opacity: 0; }
}
.fun-impact-bomb { color: #ff6a4d; background: radial-gradient(circle, rgba(255, 106, 77, 0.5), transparent 70%); }
.fun-impact-ice { color: #7fd6f5; background: radial-gradient(circle, rgba(127, 214, 245, 0.5), transparent 70%); }
.fun-impact-betray { color: #c08bff; background: radial-gradient(circle, rgba(192, 139, 255, 0.5), transparent 70%); }
.fun-impact-upgrade { color: #f5c45f; background: radial-gradient(circle, rgba(245, 196, 95, 0.5), transparent 70%); }
.fun-impact-mine { color: #f5c45f; background: radial-gradient(circle, rgba(245, 196, 95, 0.45), transparent 70%); }

/* Spawn light beam */
.fun-spawn-burst {
    position: absolute;
    border-radius: 8px;
    background: radial-gradient(circle at 50% 100%, rgba(245, 196, 95, 0.75), transparent 72%);
    box-shadow: 0 0 30px rgba(245, 196, 95, 0.6);
    transform-origin: 50% 100%;
    animation: fun-spawn-rise 0.8s ease-out forwards;
    will-change: transform, opacity;
}
@keyframes fun-spawn-rise {
    0% { opacity: 0; transform: scaleY(0.2); }
    45% { opacity: 1; transform: scaleY(1.05); }
    100% { opacity: 0; transform: scaleY(1.12); }
}

/* Moving ghost piece */
.fun-piece-ghost {
    position: absolute;
    left: 0;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.5));
    will-change: transform;
}
.fun-piece-ghost .piece,
.fun-piece-ghost .piece-img {
    width: 100%;
    height: 100%;
}

/* Bomb / mine explosion ring */
.fun-explosion-ring {
    position: absolute;
    width: 40px;
    height: 40px;
    margin-left: -20px;
    margin-top: -20px;
    border-radius: 50%;
    border: 4px solid rgba(255, 106, 77, 0.85);
    box-shadow: 0 0 30px rgba(255, 106, 77, 0.6);
    transform: scale(0.3);
    opacity: 0.95;
    animation: fun-explode 1.05s ease-out forwards;
    will-change: transform, opacity;
}
@keyframes fun-explode {
    from { transform: scale(0.3); opacity: 0.95; }
    to { transform: scale(6); opacity: 0; }
}

/* Mirror sweep flash */
.fun-mirror-flash {
    position: absolute;
    border-radius: 8px;
    background: linear-gradient(90deg, transparent, rgba(245, 196, 95, 0.5), transparent);
    animation: fun-mirror-sweep 1.0s ease-out forwards;
    will-change: transform, opacity;
}
@keyframes fun-mirror-sweep {
    0% { opacity: 0; transform: translateX(-28%) scaleX(0.6); }
    40% { opacity: 1; }
    100% { opacity: 0; transform: translateX(28%) scaleX(1.1); }
}

/* Clock heist pulses */
.player-timer.fun-clock-rob { animation: fun-clock-rob 1.1s ease-out; }
.player-timer.fun-clock-gain { animation: fun-clock-gain 1.1s ease-out; }
@keyframes fun-clock-rob {
    0%, 100% { box-shadow: none; }
    30%, 70% { box-shadow: 0 0 0 2px rgba(255, 80, 60, 0.9), 0 0 24px rgba(255, 80, 60, 0.7); color: #ff6a4d; }
}
@keyframes fun-clock-gain {
    0%, 100% { box-shadow: none; }
    30%, 70% { box-shadow: 0 0 0 2px rgba(245, 196, 95, 0.9), 0 0 24px rgba(245, 196, 95, 0.7); color: #f5c45f; }
}

/* ===================================================================
   RESPONSIVE
   =================================================================== */

/* Stack panel below board on narrower viewports */
@media (max-width: 920px) {
    :root {
        --board-size: min(96vw, calc(100vh - 230px), 560px);
        --panel-w: min(96vw, var(--board-size));
    }
    body { justify-content: flex-start; }
    .game-layout { flex-direction: column; align-items: center; }
    .side-panel {
        width: var(--board-size);
        height: auto;
    }
    .move-history-panel { max-height: 180px; }
    .chat-panel { max-height: 180px; }
    .analysis-layout {
        grid-template-columns: 1fr;
    }
    .analysis-games-list {
        max-height: 190px;
    }
    .analysis-main {
        grid-template-columns: 1fr;
    }
    .analysis-board-block {
        --board-size: min(calc(96vw - 36px), 524px);
        align-items: center;
    }
    .analysis-dashboard {
        width: min(96vw, 560px);
        margin: 0 auto;
    }
    .analysis-move-list {
        max-height: 260px;
    }
}

@media (max-width: 560px) {
    :root {
        --board-size: min(98vw, calc(100vh - 210px));
        --bar-h: 48px;
    }
    body { padding: 10px; }
    .lobby-card { padding: 1.25rem; }
    .player-timer { font-size: 1.15rem; min-width: 74px; padding: 0.3rem 0.55rem; }
    .game-controls { grid-template-columns: 1fr 1fr; }
    #settings-button { width: 3rem; height: 3rem; font-size: 1.15rem; bottom: 1rem; right: 1rem; }
    .time-btn .t-sub { display: none; }
    .fun-mode-toggle { align-items: flex-start; }
    .fun-choice-options { grid-template-columns: 1fr; }
    .fun-choice-option { min-height: 116px; }
    .analysis-topbar {
        align-items: flex-start;
        flex-wrap: wrap;
    }
    .analysis-run-btn {
        width: 100%;
        justify-content: center;
        margin-left: 0;
    }
    .analysis-summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .analysis-move-row {
        grid-template-columns: 28px minmax(0, 1fr);
    }
    .analysis-move-row .move-label {
        grid-column: 2;
        justify-self: start;
    }
}

@media (max-width: 380px) {
    .time-control-grid { gap: 6px; }
    .time-btn { padding: 0.5rem 0.2rem; }
}

@media (prefers-reduced-motion: reduce) {
    .fun-choice-card,
    .fun-cinematic-light,
    .fun-cinematic-shockwave,
    .fun-cinematic-content,
    .fun-board-shake,
    .square.fun-square-blast,
    .square.fun-square-mine-hit,
    .fun-choice-overlay.entering .fun-choice-option,
    .fun-choice-option.selected,
    .fun-choice-option.dismissed,
    .fun-spawn-burst,
    .fun-mirror-flash,
    .fun-explosion-ring,
    .player-timer.fun-clock-rob,
    .player-timer.fun-clock-gain {
        animation: none !important;
    }
    /* Keep a single short ring instead of the dramatic wave. */
    .fun-board-wave {
        animation-duration: 0.4s;
        box-shadow: none;
    }
}
