/* ===== Reset & Base ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

:root {
    --accent-h: 252; --accent-s: 80%; --accent-l: 67%;
    --accent: hsl(var(--accent-h), var(--accent-s), var(--accent-l));
    --accent-light: hsl(var(--accent-h), var(--accent-s), calc(var(--accent-l) + 12%));
    --bg: #0f0f1a;
    --surface: #1a1a2e;
    --surface-light: #252542;
    --x-color: #ff6b6b;
    --o-color: #4ecdc4;
    --text: #e8e8f0;
    --text-muted: #8888a0;
    --win-glow: rgba(126, 214, 223, 0.4);
    --hint-line: #7c4dff;
    --shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    --overlay: rgba(0, 0, 0, 0.6);
    --surface-hover: color-mix(in srgb, var(--surface-light) 80%, var(--text) 10%);
    --contrast: 1;
    --anim-scale: 1;
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

:root[data-theme="light"] {
    --bg: #f4f6fa;
    --surface: #ffffff;
    --surface-light: #eef1f7;
    --text: #1f2937;
    --text-muted: #6b7280;
    --shadow: 0 20px 50px rgba(0, 0, 0, 0.12);
    --overlay: rgba(0, 0, 0, 0.35);
    --hint-line: #5e35b1;
}

@media (prefers-color-scheme: light) {
    :root[data-theme="auto"] {
        --bg: #f4f6fa;
        --surface: #ffffff;
        --surface-light: #eef1f7;
        --text: #1f2937;
        --text-muted: #6b7280;
        --shadow: 0 20px 50px rgba(0, 0, 0, 0.12);
        --overlay: rgba(0, 0, 0, 0.35);
        --hint-line: #5e35b1;
    }
}

html, body { height: 100%; }

/* ===== Splash Screen ===== */
.splash-screen {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    transition: opacity 0.6s ease, visibility 0.6s ease;
}
.splash-screen.fade-out {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
.splash-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.2rem;
    text-align: center;
    padding: 2rem;
}
.splash-brand {
    font-family: 'Quicksand', var(--font-family);
    font-size: 1rem;
    font-weight: 500;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    color: var(--text-muted);
    opacity: 0;
    animation: splashFadeIn 0.8s ease 0.2s forwards;
}
.splash-pieces {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    font-family: 'Quicksand', var(--font-family);
    font-size: 3.5rem;
    font-weight: 700;
    line-height: 1;
    margin: 0.5rem 0;
}
.splash-x {
    color: var(--x-color);
    display: inline-block;
    opacity: 0;
    transform: scale(0.5) rotate(-45deg);
    animation: splashPieceIn 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) 0.5s forwards;
}
.splash-o {
    color: var(--o-color);
    display: inline-block;
    opacity: 0;
    transform: scale(0.5) rotate(45deg);
    animation: splashPieceIn 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) 0.7s forwards;
}
.splash-divider {
    display: inline-block;
    width: 2px;
    height: 2.5rem;
    background: var(--surface-light);
    border-radius: 1px;
    opacity: 0;
    animation: splashFadeIn 0.5s ease 0.6s forwards;
}
.splash-title {
    font-family: 'Quicksand', var(--font-family);
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--text);
    opacity: 0;
    animation: splashFadeIn 0.8s ease 0.9s forwards;
}
.splash-subtitle {
    font-size: 1rem;
    font-weight: 400;
    color: var(--text-muted);
    opacity: 0;
    animation: splashFadeIn 0.8s ease 1.1s forwards;
}
.splash-dots {
    display: flex;
    gap: 0.4rem;
    margin-top: 1rem;
    opacity: 0;
    animation: splashFadeIn 0.5s ease 1.3s forwards;
}
.splash-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    animation: splashBounce 1.2s ease-in-out infinite;
}
.splash-dots span:nth-child(2) { animation-delay: 0.15s; }
.splash-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes splashFadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes splashPieceIn {
    from { opacity: 0; transform: scale(0.3) rotate(0deg); }
    to   { opacity: 1; transform: scale(1) rotate(0deg); }
}
@keyframes splashBounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-10px); }
}

body {
    font-family: var(--font-family);
    background: var(--bg);
    color: var(--text);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    position: relative;
    transition: background 0.35s ease, color 0.35s ease;
}

.game-wrapper {
    filter: contrast(var(--contrast));
}

.bg-glow {
    filter: contrast(var(--contrast));
}

body[data-font="serif"] { --font-family: 'Merriweather', Georgia, serif; }
body[data-font="mono"] { --font-family: 'JetBrains Mono', 'Fira Code', monospace; }
body[data-font="rounded"] { --font-family: 'Quicksand', 'Nunito', sans-serif; }

/* ===== Reduced Motion ===== */
body.animations-off *,
body.animations-off *::before,
body.animations-off *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
}
body.animations-off .win-line,
body.animations-off .c4-win-line,
body.animations-off .gomoku-win-line { opacity: 1 !important; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        transition-delay: 0ms !important;
    }
}

/* ===== Background Glow ===== */
.bg-glow {
    position: absolute;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, hsla(var(--accent-h), var(--accent-s), var(--accent-l), 0.15) 0%, transparent 70%);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    animation: pulse-glow calc(6s * var(--anim-scale)) ease-in-out infinite;
    z-index: 0;
}

@keyframes pulse-glow {
    0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.6; }
    50% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
}

/* ===== Layout ===== */
.game-wrapper {
    width: 90vw;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    position: relative;
    z-index: 1;
    animation: fade-in-up calc(0.8s * var(--anim-scale)) ease-out both;
}

@keyframes fade-in-up {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== Header ===== */
.game-header { text-align: center; }

.title {
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
}

.x-mark { color: var(--x-color); text-shadow: 0 0 20px rgba(255, 107, 107, 0.4); }
.o-mark { color: var(--o-color); text-shadow: 0 0 20px rgba(78, 205, 196, 0.4); }
.divider { color: var(--text-muted); font-weight: 300; }

.subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-top: 0.25rem;
    letter-spacing: 1px;
}
.misere-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: #ff6b6b;
    background: hsla(0, 80%, 60%, 0.1);
    padding: 0.2rem 0.6rem;
    border-radius: 8px;
    border: 1px solid hsla(0, 80%, 60%, 0.2);
    opacity: 1;
    visibility: visible;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}
.misere-indicator.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
.misere-indicator::before {
    content: '↻';
    font-size: 0.85rem;
}
.game-wrapper.misere-mode .board,
.game-wrapper.misere-mode .connect4-board,
.game-wrapper.misere-mode .gomoku-board {
    border-color: hsla(0, 80%, 60%, 0.3);
    box-shadow: 0 0 0 1px hsla(0, 80%, 60%, 0.15), var(--shadow);
}
.game-wrapper.misere-mode .cell:hover:not(.disabled):not(.x):not(.o),
.game-wrapper.misere-mode .c4-cell:hover:not(.disabled),
.game-wrapper.misere-mode .gomoku-cell:hover:not(.disabled) {
    background: hsla(0, 80%, 60%, 0.08);
}

/* ===== Mode Switch ===== */
.mode-switch,
.battle-switch {
    display: flex;
    background: var(--surface);
    border-radius: 14px;
    padding: 4px;
    gap: 3px;
    box-shadow: var(--shadow);
    width: 100%;
    flex-wrap: wrap;
}

.battle-switch {
    display: flex;
    margin-top: -0.25rem;
    animation: fade-in-up calc(0.4s * var(--anim-scale)) ease-out both;
}

.mode-btn,
.battle-btn {
    flex: 1;
    min-width: 52px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    padding: 0.5rem 0.1rem;
    border-radius: 10px;
    font-size: 0.68rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.25s ease, color 0.25s ease, box-shadow 0.25s ease, transform 0.25s ease;
    font-family: inherit;
    white-space: nowrap;
}

.mode-btn:hover,
.battle-btn:hover { color: var(--text); }

.mode-btn.active,
.battle-btn.active {
    background: var(--surface-light);
    color: var(--text);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.mode-btn:focus-visible,
.battle-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.battle-btn.active {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 2px 8px hsla(var(--accent-h), var(--accent-s), var(--accent-l), 0.4);
}

/* ===== Scoreboard ===== */
.elo-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    font-weight: 600;
    background: var(--surface);
    border-radius: 12px;
    padding: 0.4rem 0.8rem;
    box-shadow: var(--shadow);
    width: fit-content;
    margin-left: auto;
    margin-right: auto;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.3s ease, box-shadow 0.3s ease;
    white-space: nowrap;
}
.elo-badge.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
.elo-badge:hover { transform: translateY(-2px); }
.elo-tier-icon { font-size: 1rem; }
.elo-value { font-family: 'JetBrains Mono', monospace; font-size: 0.9rem; }
.elo-tier-name { font-size: 0.8rem; opacity: 0.8; }

.scoreboard {
    display: flex;
    gap: 0.75rem;
    width: 100%;
}

.score-card {
    flex: 1;
    background: var(--surface);
    border-radius: 16px;
    padding: 0.75rem 0.5rem;
    text-align: center;
    box-shadow: var(--shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease, background 0.3s ease;
}

.score-card:hover { transform: translateY(-3px); }

.score-card.player-x { border-bottom: 3px solid var(--x-color); }
.score-card.player-o { border-bottom: 3px solid var(--o-color); }
.score-card.draws { border-bottom: 3px solid var(--text-muted); }

.score-card .label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.score-card .score {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.score.pop {
    transform: scale(1.4);
    color: var(--accent);
}

/* ===== Timer ===== */
.timer {
    display: block;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-muted);
    margin: 0.15rem 0;
    letter-spacing: 0.5px;
    transition: color 0.3s ease, transform 0.3s ease;
    min-height: 1.2em;
}

.timer.active-x {
    color: var(--x-color);
    text-shadow: 0 0 8px rgba(255, 107, 107, 0.35);
    animation: timer-pulse calc(1.5s * var(--anim-scale)) ease-in-out infinite;
}

.timer.active-o {
    color: var(--o-color);
    text-shadow: 0 0 8px rgba(78, 205, 196, 0.35);
    animation: timer-pulse calc(1.5s * var(--anim-scale)) ease-in-out infinite;
}

.timer.danger {
    color: #ff4757;
    text-shadow: 0 0 10px rgba(255, 71, 87, 0.5);
    animation: timer-danger calc(0.6s * var(--anim-scale)) ease-in-out infinite;
}

.timer.paused {
    opacity: 0.5;
    animation: none !important;
}

.timer-presets {
    margin-top: 0.5rem;
    animation: fade-in-up calc(0.3s * var(--anim-scale)) ease-out both;
}

@keyframes timer-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.85; }
}

@keyframes timer-danger {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.08); opacity: 0.7; }
}

/* ===== Status ===== */
.status-bar {
    background: var(--surface-light);
    padding: 0.5rem 1.25rem;
    border-radius: 999px;
    font-size: 0.9rem;
    color: var(--text-muted);
    transition: color 0.3s ease, box-shadow 0.3s ease;
}

.status-bar.active-x {
    color: var(--x-color);
    box-shadow: 0 0 15px rgba(255, 107, 107, 0.2) inset;
}

.status-bar.active-o {
    color: var(--o-color);
    box-shadow: 0 0 15px rgba(78, 205, 196, 0.2) inset;
}

/* ===== Tic Tac Toe Board ===== */
.board {
    position: relative;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 10px;
    width: 100%;
    aspect-ratio: 1 / 1;
    background: var(--surface);
    border-radius: 24px;
    padding: 12px;
    box-shadow: var(--shadow);
    border: 1px solid transparent;
    transition: background 0.35s ease, border-color 0.35s ease, box-shadow 0.35s ease;
    transform-style: preserve-3d;
}

.board.is-3d {
    transform: perspective(900px) rotateX(var(--rot-x, 15deg)) rotateY(var(--rot-y, -5deg));
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.board.is-3d.dragging,
.connect4-board.is-3d.dragging,
.gomoku-board.is-3d.dragging {
    transition: none;
    cursor: grabbing;
}

.board.is-3d:not(.dragging),
.connect4-board.is-3d:not(.dragging),
.gomoku-board.is-3d:not(.dragging) {
    cursor: grab;
}

/* ===== Board Themes ===== */
[data-board-theme="neon"] .board,
[data-board-theme="neon"] .connect4-board,
[data-board-theme="neon"] .gomoku-board {
    background: linear-gradient(135deg, #0a0a1a, #1a0a2e);
    box-shadow: 0 0 30px rgba(123, 104, 238, 0.15), var(--shadow);
    border: 1px solid rgba(123, 104, 238, 0.2);
}
[data-board-theme="neon"] .cell,
[data-board-theme="neon"] .c4-cell,
[data-board-theme="neon"] .gomoku-cell {
    background: rgba(20, 20, 40, 0.8);
    border: 1px solid rgba(123, 104, 238, 0.15);
}
[data-board-theme="neon"] .cell:hover,
[data-board-theme="neon"] .c4-cell:hover,
[data-board-theme="neon"] .gomoku-cell:hover {
    background: rgba(123, 104, 238, 0.15);
    box-shadow: inset 0 0 12px rgba(123, 104, 238, 0.2);
}

[data-board-theme="nature"] .board,
[data-board-theme="nature"] .connect4-board,
[data-board-theme="nature"] .gomoku-board {
    background: linear-gradient(135deg, #2d4a3e, #3d5a4e);
    box-shadow: 0 8px 32px rgba(46, 139, 87, 0.2), var(--shadow);
}
[data-board-theme="nature"] .cell,
[data-board-theme="nature"] .c4-cell,
[data-board-theme="nature"] .gomoku-cell {
    background: rgba(60, 90, 70, 0.7);
    border-radius: 14px;
}
[data-board-theme="nature"] .cell:hover,
[data-board-theme="nature"] .c4-cell:hover,
[data-board-theme="nature"] .gomoku-cell:hover {
    background: rgba(80, 120, 90, 0.6);
}

[data-board-theme="minimal"] .board,
[data-board-theme="minimal"] .connect4-board,
[data-board-theme="minimal"] .gomoku-board {
    background: transparent;
    box-shadow: none;
    border: 2px solid var(--surface-light);
    padding: 10px;
}
[data-board-theme="minimal"] .cell,
[data-board-theme="minimal"] .c4-cell,
[data-board-theme="minimal"] .gomoku-cell {
    background: transparent;
    border: 1px solid var(--surface-light);
    border-radius: 0;
}
[data-board-theme="minimal"] .cell:hover,
[data-board-theme="minimal"] .c4-cell:hover,
[data-board-theme="minimal"] .gomoku-cell:hover {
    background: hsla(var(--accent-h), var(--accent-s), var(--accent-l), 0.06);
}

[data-board-theme="space"] .board,
[data-board-theme="space"] .connect4-board,
[data-board-theme="space"] .gomoku-board {
    background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
    box-shadow: 0 0 40px rgba(100, 80, 200, 0.12), var(--shadow);
}
[data-board-theme="space"] .cell,
[data-board-theme="space"] .c4-cell,
[data-board-theme="space"] .gomoku-cell {
    background: rgba(30, 25, 60, 0.6);
    border: 1px solid rgba(150, 130, 255, 0.1);
    border-radius: 18px;
}
[data-board-theme="space"] .cell:hover,
[data-board-theme="space"] .c4-cell:hover,
[data-board-theme="space"] .gomoku-cell:hover {
    background: rgba(60, 50, 100, 0.4);
    box-shadow: inset 0 0 15px rgba(150, 130, 255, 0.1);
}

.cell {
    background: var(--surface-light);
    border-radius: 16px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.cell:hover {
    background: color-mix(in srgb, var(--surface-light) 80%, var(--text) 5%);
    transform: scale(1.02);
}

.cell.disabled {
    cursor: default;
    pointer-events: none;
}

.cell.disabled:hover {
    transform: none;
    background: var(--surface-light);
}

/* ===== Marks (SVG) ===== */
.cell .mark {
    width: 60%;
    height: 60%;
    animation: pop-in calc(0.35s * var(--anim-scale)) cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes pop-in {
    from { opacity: 0; transform: scale(0.3) rotate(-20deg); }
    to { opacity: 1; transform: scale(1) rotate(0deg); }
}

.cell .mark-x path {
    stroke: var(--x-color);
    stroke-width: 10;
    stroke-linecap: round;
    fill: none;
    stroke-dasharray: 100;
    stroke-dashoffset: 100;
    animation: draw calc(0.4s * var(--anim-scale)) ease forwards;
}

.cell .mark-o circle {
    stroke: var(--o-color);
    stroke-width: 10;
    fill: none;
    stroke-dasharray: 160;
    stroke-dashoffset: 160;
    animation: draw calc(0.5s * var(--anim-scale)) ease forwards;
}

@keyframes draw {
    to { stroke-dashoffset: 0; }
}

/* ===== Win Line ===== */
.win-line {
    position: absolute;
    top: 12px;
    left: 12px;
    width: calc(100% - 24px);
    height: calc(100% - 24px);
    pointer-events: none;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.1s ease;
}

.win-line.show { opacity: 1; }

.win-line line {
    stroke: var(--text);
    filter: drop-shadow(0 0 6px var(--win-glow));
    stroke-dasharray: 300;
    stroke-dashoffset: 300;
    animation: line-draw calc(0.5s * var(--anim-scale)) ease-out forwards;
}

@keyframes line-draw {
    to { stroke-dashoffset: 0; }
}

/* ===== Connect Four ===== */
.connect4-board {
    position: relative;
    display: none;
    width: 100%;
    aspect-ratio: 7 / 6;
    background: var(--surface);
    border-radius: 24px;
    padding: 10px;
    box-shadow: var(--shadow);
    border: 1px solid transparent;
    transition: background 0.35s ease, border-color 0.35s ease, box-shadow 0.35s ease;
    transform-style: preserve-3d;
    overflow: hidden;
}

.connect4-board.is-3d {
    transform: perspective(900px) rotateX(var(--rot-x, 12deg)) rotateY(var(--rot-y, -3deg));
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.connect4-board.show { display: block; }

.c4-cells {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-template-rows: repeat(6, 1fr);
    gap: 6px;
    width: 100%;
    height: 100%;
}

.c4-cell {
    aspect-ratio: 1;
    border-radius: 50%;
    background: var(--surface-light);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    transition: transform 0.2s ease, background 0.2s ease;
    overflow: hidden;
}

.c4-cell:hover {
    background: color-mix(in srgb, var(--surface-light) 80%, var(--text) 5%);
}

.c4-cell.disabled {
    cursor: default;
    pointer-events: none;
}

.c4-cell .c4-piece {
    width: 78%;
    height: 78%;
    border-radius: 50%;
    animation: c4-drop calc(0.4s * var(--anim-scale)) cubic-bezier(0.5, 0, 0.5, 1.3) forwards;
    box-shadow: inset 0 -3px 6px rgba(0,0,0,0.3), inset 0 3px 6px rgba(255,255,255,0.15);
}

.c4-piece.x-piece {
    background: linear-gradient(135deg, var(--x-color), color-mix(in srgb, var(--x-color) 70%, #000));
}

.c4-piece.o-piece {
    background: linear-gradient(135deg, var(--o-color), color-mix(in srgb, var(--o-color) 70%, #000));
}

@keyframes c4-drop {
    from { transform: translateY(-300%) scale(0.5); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

.c4-win-line {
    position: absolute;
    top: 10px;
    left: 10px;
    width: calc(100% - 20px);
    height: calc(100% - 20px);
    pointer-events: none;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.1s ease;
}

.c4-win-line.show { opacity: 1; }

.c4-win-line line {
    stroke: var(--text);
    filter: drop-shadow(0 0 6px var(--win-glow));
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
    animation: c4-line-draw calc(0.5s * var(--anim-scale)) ease-out forwards;
}

@keyframes c4-line-draw {
    to { stroke-dashoffset: 0; }
}

/* ===== Gomoku Board ===== */
.gomoku-board {
    position: relative;
    display: none;
    width: 100%;
    max-width: 340px;
    background: var(--surface);
    border-radius: 16px;
    padding: 6px;
    box-shadow: var(--shadow);
    border: 1px solid transparent;
    transition: background 0.35s ease, border-color 0.35s ease, box-shadow 0.35s ease;
    transform-style: preserve-3d;
    overflow: hidden;
}

.gomoku-board.is-3d {
    transform: perspective(900px) rotateX(var(--rot-x, 10deg)) rotateY(var(--rot-y, -4deg));
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.gomoku-board.show { display: block; }

.gomoku-cells {
    display: grid;
    width: 100%;
    height: 100%;
    gap: 1px;
}

.gomoku-cell {
    background: var(--surface-light);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    transition: background 0.15s ease;
    border-radius: 2px;
    min-width: 0;
    min-height: 0;
    aspect-ratio: 1;
}

.gomoku-cell:hover {
    background: color-mix(in srgb, var(--surface-light) 80%, var(--text) 8%);
}

.gomoku-cell.disabled {
    cursor: default;
    pointer-events: none;
}

.gomoku-piece {
    width: 72%;
    height: 72%;
    border-radius: 50%;
    animation: gmk-pop calc(0.2s * var(--anim-scale)) ease-out forwards;
}

.gomoku-piece.x-piece {
    background: linear-gradient(135deg, var(--x-color), color-mix(in srgb, var(--x-color) 70%, #000));
    box-shadow: 0 1px 4px rgba(255, 107, 107, 0.3);
}

.gomoku-piece.o-piece {
    background: linear-gradient(135deg, var(--o-color), color-mix(in srgb, var(--o-color) 70%, #000));
    box-shadow: 0 1px 4px rgba(78, 205, 196, 0.3);
}

@keyframes gmk-pop {
    from { transform: scale(0.4); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.gomoku-win-line {
    position: absolute;
    top: 6px;
    left: 6px;
    width: calc(100% - 12px);
    height: calc(100% - 12px);
    pointer-events: none;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.1s ease;
}

.gomoku-win-line.show { opacity: 1; }

.gomoku-win-line line {
    stroke: var(--text);
    filter: drop-shadow(0 0 4px var(--win-glow));
    stroke-dasharray: 1500;
    stroke-dashoffset: 1500;
    animation: gmk-line-draw calc(0.5s * var(--anim-scale)) ease-out forwards;
}

@keyframes gmk-line-draw {
    to { stroke-dashoffset: 0; }
}

/* ===== Controls ===== */
.controls {
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.btn {
    border: none;
    outline: none;
    font-family: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    transition: background 0.25s ease, color 0.25s ease, transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}

.btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn-restart {
    background: transparent;
    color: var(--text-muted);
    padding: 0.6rem 1.2rem;
    border-radius: 12px;
    border: 1px solid var(--surface-light);
    flex: 1;
    white-space: nowrap;
}

.btn-restart:hover {
    color: var(--text);
    border-color: var(--text-muted);
    background: var(--surface);
}

.btn-settings, .btn-changelog {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--surface);
    color: var(--text-muted);
    border: 1px solid var(--surface-light);
    box-shadow: var(--shadow);
    position: relative;
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}
.btn-settings:focus-visible,
.btn-changelog:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.btn-settings:hover {
    color: var(--accent);
    transform: rotate(30deg);
}

.btn-changelog:hover {
    color: var(--text);
    transform: scale(1.08);
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), hsl(var(--accent-h), var(--accent-s), calc(var(--accent-l) - 10%)));
    color: #fff;
    padding: 0.85rem 2rem;
    border-radius: 14px;
    box-shadow: 0 8px 25px hsla(var(--accent-h), var(--accent-s), var(--accent-l), 0.35);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 30px hsla(var(--accent-h), var(--accent-s), var(--accent-l), 0.5);
}

.btn .icon { width: 18px; height: 18px; }

.btn-secondary {
    background: var(--surface-light);
    color: var(--text);
    padding: 0.75rem 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--surface-hover);
    font-size: 0.95rem;
    font-weight: 600;
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
    cursor: pointer;
}
.btn-secondary:hover {
    background: var(--surface-hover);
    border-color: var(--accent);
    transform: translateY(-1px);
}

/* ===== Modal & Overlay ===== */
.modal, .drawer-overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay);
    backdrop-filter: blur(6px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 100;
}

.modal { z-index: 120; }

.modal.show, .drawer-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--surface);
    padding: 2rem 2.5rem;
    border-radius: 24px;
    text-align: center;
    box-shadow: var(--shadow), 0 0 60px hsla(var(--accent-h), var(--accent-s), var(--accent-l), 0.2);
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    max-width: 320px;
    width: 90%;
    position: absolute;
    top: 50%;
    left: 50%;
    translate: -50% -50%;
}

.modal.show .modal-content { transform: scale(1); }

.modal-icon {
    font-size: 3rem;
    margin-bottom: 0.5rem;
    animation: pop-in calc(0.5s * var(--anim-scale)) ease both;
}

.modal-content h2 { font-size: 1.5rem; margin-bottom: 0.5rem; }
.modal-content p { color: var(--text-muted); margin-bottom: 1.5rem; font-size: 0.95rem; }
.modal-elo { font-weight: 600; font-size: 1rem !important; margin-bottom: 1rem !important; opacity: 0; transform: translateY(8px); transition: opacity 0.3s ease 0.15s, transform 0.3s ease 0.15s; }
.modal.show .modal-elo { opacity: 1; transform: translateY(0); }
.modal-elo.positive { color: #2ecc71; }
.modal-elo.negative { color: #e74c3c; }
.modal-elo.neutral { color: var(--text-muted); }

/* ===== Settings Drawer ===== */
.settings-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: min(380px, 90vw);
    height: 100%;
    background: var(--surface);
    box-shadow: var(--shadow);
    z-index: 110;
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.34, 1.2, 0.64, 1);
    display: flex;
    flex-direction: column;
}

.settings-drawer.show { transform: translateX(0); }

.drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--surface-light);
}

.drawer-header h2 { font-size: 1.25rem; }

.drawer-close {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: none;
    background: var(--surface-light);
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.drawer-close:hover { background: color-mix(in srgb, var(--surface-light) 80%, var(--text) 10%); }
.drawer-close:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.drawer-close svg { width: 20px; height: 20px; }

.drawer-body {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    overflow-y: auto;
}

/* ===== Settings UI Components ===== */
.setting-group { display: flex; flex-direction: column; gap: 0.5rem; }
.setting-row { display: flex; justify-content: space-between; align-items: center; }

.setting-label {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
}

.setting-label.sub {
    font-size: 0.8rem;
    color: var(--text-muted);
}
.setting-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.4;
    opacity: 0.8;
    font-weight: 500;
}

.segmented {
    display: flex;
    background: var(--surface-light);
    border-radius: 10px;
    padding: 3px;
    gap: 3px;
    flex-wrap: wrap;
}

.seg-btn {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-muted);
    padding: 0.45rem 0.15rem;
    border-radius: 8px;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
    font-family: inherit;
    white-space: nowrap;
    min-width: 0;
}

.seg-btn:hover { color: var(--text); }

.seg-btn.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}
.seg-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Language Grid */
.lang-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
}

.lang-btn {
    border: none;
    background: var(--surface-light);
    color: var(--text-muted);
    padding: 0.5rem 0.1rem;
    border-radius: 8px;
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
    font-family: inherit;
}

.lang-btn:hover { color: var(--text); background: color-mix(in srgb, var(--surface-light) 80%, var(--text) 5%); }

.lang-btn.active {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 2px 8px hsla(var(--accent-h), var(--accent-s), var(--accent-l), 0.4);
}
.lang-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Color Picker */
.color-picker {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

.color-swatch {
    aspect-ratio: 1;
    border-radius: 10px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.2s ease, border-color 0.2s ease;
    position: relative;
}

.color-swatch:hover { transform: scale(1.1); }
.color-swatch:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.color-swatch.active {
    border-color: var(--text);
    transform: scale(1.1);
}

.color-swatch.active::after {
    content: '';
    position: absolute;
    inset: 3px;
    border-radius: 6px;
    border: 2px solid #fff;
}

.custom-color-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.25rem;
}

.custom-color-row input[type="color"] {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    background: none;
    padding: 2px;
}

.custom-color-row input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.custom-color-row input[type="color"]::-webkit-color-swatch { border-radius: 6px; border: 2px solid var(--surface-light); }

/* Range Slider */
.slider-header { display: flex; justify-content: space-between; align-items: center; }
.slider-value { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; }

.range-slider {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--surface-light);
    outline: none;
    margin-top: 4px;
}

.range-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    transition: transform 0.15s ease;
}

.range-slider::-webkit-slider-thumb:hover { transform: scale(1.2); }
.range-slider:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 3px;
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--surface-light);
    border-radius: 34px;
    transition: background 0.25s ease;
}

.slider::before {
    content: "";
    position: absolute;
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.25s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(22px); }
.switch input:focus-visible + .slider {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Sound Custom Panel */
.sound-custom-panel {
    background: var(--surface-light);
    border-radius: 12px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.btn-test-sound {
    background: var(--surface);
    color: var(--text);
    padding: 0.6rem;
    border-radius: 10px;
    border: 1px solid var(--surface-light);
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

.btn-test-sound:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.btn-test-sound:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Custom Game Settings */
.custom-game-row {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.custom-input {
    background: var(--surface);
    border: 1px solid var(--surface-light);
    border-radius: 8px;
    padding: 0.4rem 0.6rem;
    color: var(--text);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    width: 80px;
    text-align: center;
    outline: none;
}

.custom-input:focus {
    border-color: var(--accent);
}

.custom-game-row .segmented {
    flex-wrap: wrap;
}

/* ===== Changelog ===== */
.changelog-content {
    max-width: 480px;
    width: 92%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
}

.changelog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--surface-light);
}

.changelog-header h2 { font-size: 1.25rem; }

.changelog-body {
    padding: 1rem 1.5rem 1.5rem;
    overflow-y: auto;
    text-align: left;
}

.version-block {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--surface-light);
}

.version-block:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.version-header {
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    margin-bottom: 0.6rem;
}

.version-badge {
    background: var(--accent);
    color: #fff;
    font-size: 0.8rem;
    font-weight: 700;
    padding: 0.25rem 0.6rem;
    border-radius: 6px;
}

.version-date {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.version-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.version-list li {
    font-size: 0.9rem;
    color: var(--text);
    padding-left: 1.2rem;
    position: relative;
}

.version-list li::before {
    content: '•';
    position: absolute;
    left: 0.3rem;
    color: var(--accent);
    font-weight: 700;
}

/* ===== Hotkey Modal ===== */
.hotkey-content {
    max-width: 420px;
    width: 92%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    text-align: left;
}

.hotkey-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--surface-light);
}

.hotkey-header h2 { font-size: 1.25rem; }

.hotkey-body {
    padding: 1rem 1.5rem 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.hotkey-section-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.25rem;
}

.hotkey-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--surface-light);
}

.hotkey-row:last-child { border-bottom: none; }

.hotkey-kbd {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.75rem;
    font-weight: 700;
    background: var(--surface-light);
    color: var(--text);
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    border: 1px solid color-mix(in srgb, var(--surface-light) 80%, var(--text) 10%);
    min-width: 48px;
    text-align: center;
    flex-shrink: 0;
}

.hotkey-desc {
    font-size: 0.9rem;
    color: var(--text);
}

/* Enhanced focus ring for board cells during keyboard nav */
.cell:focus-visible,
.c4-cell:focus-visible,
.gomoku-cell:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: -3px;
    z-index: 2;
}

.about-links {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.about-links a {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.85rem;
    padding: 0.4rem 0.6rem;
    border-radius: 8px;
    background: var(--surface-light);
    transition: background 0.2s ease;
}

.about-links a:hover {
    background: var(--surface-hover);
}
.about-links a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

.btn-back-to-lobby {
    width: 100%;
    padding: 0.6rem 1rem;
    border-radius: 10px;
    border: none;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}

.btn-back-to-lobby:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}
.btn-back-to-lobby:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ===== Responsive ===== */
@media (max-width: 400px) {
    .title { font-size: 2rem; }
    .score-card { padding: 0.5rem 0.25rem; }
    .score-card .score { font-size: 1.2rem; }
    .board { gap: 6px; padding: 8px; border-radius: 18px; }
    .cell { border-radius: 12px; }
    .game-wrapper { gap: 0.75rem; }
    .lang-grid { grid-template-columns: repeat(5, 1fr); }
    .color-picker { grid-template-columns: repeat(5, 1fr); }
    .mode-btn,
    .battle-btn { font-size: 0.58rem; padding: 0.4rem 0.05rem; }
    .gomoku-piece { width: 60%; height: 60%; }
    .gomoku-board { max-width: 300px; }
    .eval-bar-wrap { max-width: 300px; }
}

/* ===== History Button ===== */
.btn-history {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--surface);
    color: var(--text-muted);
    border: 1px solid var(--surface-light);
    box-shadow: var(--shadow);
    position: relative;
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}
.btn-history:hover {
    color: var(--accent);
    transform: scale(1.08);
}
.btn-history:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ===== History Drawer ===== */
.history-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: min(420px, 92vw);
    height: 100%;
    background: var(--surface);
    box-shadow: var(--shadow);
    z-index: 110;
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.34, 1.2, 0.64, 1);
    display: flex;
    flex-direction: column;
}

.history-drawer.show { transform: translateX(0); }

.history-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 3rem 1rem;
    color: var(--text-muted);
    text-align: center;
}

.history-empty-icon { font-size: 2.5rem; opacity: 0.6; }

.history-empty-sub {
    font-size: 0.8rem;
    opacity: 0.7;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    flex: 1;
}

.history-item {
    background: var(--surface-light);
    border-radius: 14px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.history-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.history-item-meta {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.history-mode {
    background: var(--accent);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
}

.history-battle {
    background: var(--surface);
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
}

.history-diff {
    background: var(--surface);
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
}

.history-date {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-left: auto;
}

.history-item-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-result {
    font-size: 0.9rem;
    font-weight: 700;
}

.history-result.result-x { color: var(--x-color); }
.history-result.result-o { color: var(--o-color); }
.history-result.result-draw { color: var(--text-muted); }

.history-moves {
    font-size: 0.8rem;
    color: var(--text-muted);
}
.history-elo {
    font-size: 0.8rem;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
}
.history-elo.positive { color: #2ecc71; }
.history-elo.negative { color: #e74c3c; }
.history-elo.neutral { color: var(--text-muted); }

.history-item-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-history-replay {
    flex: 1;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 0.5rem;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: filter 0.2s ease, transform 0.2s ease;
    font-family: inherit;
}

.btn-history-replay:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.btn-history-analysis {
    background: var(--surface);
    color: var(--accent);
    border: 1px solid var(--surface-light);
    border-radius: 10px;
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
    font-family: inherit;
}
.btn-history-analysis:hover {
    color: var(--accent);
    background: color-mix(in srgb, var(--accent), transparent 90%);
}
.btn-history-delete {
    background: var(--surface);
    color: var(--text-muted);
    border: 1px solid var(--surface-light);
    border-radius: 10px;
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
    font-family: inherit;
}

.btn-history-delete:hover {
    color: var(--x-color);
    background: color-mix(in srgb, var(--x-color), transparent 90%);
}
.btn-history-replay:focus-visible,
.btn-history-analysis:focus-visible,
.btn-history-delete:focus-visible,
.btn-clear-history:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn-clear-history {
    width: 100%;
    background: var(--surface-light);
    color: var(--text-muted);
    border: 1px solid var(--surface-light);
    border-radius: 10px;
    padding: 0.6rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
    font-family: inherit;
    margin-top: 0.5rem;
}

.btn-clear-history:hover {
    color: var(--x-color);
    background: color-mix(in srgb, var(--x-color), transparent 92%);
}

/* ===== Replay Modal ===== */
.replay-content {
    max-width: 420px;
    width: 92%;
    max-height: 85vh;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.replay-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.replay-header h2 { font-size: 1.25rem; }

.replay-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}

.replay-board-wrap {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 120px;
}

/* Replay TTT Board */
.replay-board-ttt {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 6px;
    width: 220px;
    aspect-ratio: 1 / 1;
    background: var(--surface-light);
    border-radius: 16px;
    padding: 8px;
}

.replay-cell-ttt {
    background: var(--surface);
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.replay-cell-ttt .mark {
    width: 55%;
    height: 55%;
    animation: pop-in calc(0.3s * var(--anim-scale)) cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.replay-cell-ttt .mark-x path {
    stroke: var(--x-color);
    stroke-width: 10;
    stroke-linecap: round;
    fill: none;
    stroke-dasharray: 100;
    stroke-dashoffset: 100;
    animation: draw calc(0.4s * var(--anim-scale)) ease forwards;
}

.replay-cell-ttt .mark-o circle {
    stroke: var(--o-color);
    stroke-width: 10;
    fill: none;
    stroke-dasharray: 160;
    stroke-dashoffset: 160;
    animation: draw calc(0.5s * var(--anim-scale)) ease forwards;
}

.replay-pop {
    animation: replay-cell-pop calc(0.25s * var(--anim-scale)) ease both;
}

@keyframes replay-cell-pop {
    from { transform: scale(0.6); opacity: 0.5; }
    to { transform: scale(1); opacity: 1; }
}

/* Replay C4 Board */
.replay-board-c4 {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-template-rows: repeat(6, 1fr);
    gap: 4px;
    width: 280px;
    aspect-ratio: 7 / 6;
    background: var(--surface-light);
    border-radius: 16px;
    padding: 8px;
}

.replay-cell-c4 {
    aspect-ratio: 1;
    border-radius: 50%;
    background: var(--surface);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.replay-c4-piece {
    width: 78%;
    height: 78%;
    border-radius: 50%;
    animation: c4-drop calc(0.35s * var(--anim-scale)) cubic-bezier(0.5, 0, 0.5, 1.3) forwards;
    box-shadow: inset 0 -2px 4px rgba(0,0,0,0.3), inset 0 2px 4px rgba(255,255,255,0.15);
}

/* Replay Gomoku Board */
.replay-board-gmk {
    display: grid;
    width: 300px;
    max-height: 300px;
    gap: 1px;
    background: var(--surface-light);
    border-radius: 12px;
    padding: 4px;
    overflow: auto;
}

.replay-cell-gmk {
    background: var(--surface);
    display: flex;
    justify-content: center;
    align-items: center;
    aspect-ratio: 1;
    min-width: 0;
    min-height: 0;
    border-radius: 2px;
}

.replay-gmk-piece {
    width: 72%;
    height: 72%;
    border-radius: 50%;
    animation: gmk-pop calc(0.2s * var(--anim-scale)) ease-out forwards;
}

/* Replay Controls */
.replay-progress {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.replay-progress span {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    min-width: 60px;
    text-align: center;
}

.replay-bar {
    flex: 1;
    height: 6px;
    background: var(--surface-light);
    border-radius: 3px;
    overflow: hidden;
}

.replay-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    width: 0%;
    transition: width 0.3s ease;
}

.replay-controls {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
}

.replay-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: none;
    background: var(--surface-light);
    color: var(--text);
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
    font-family: inherit;
}

.replay-btn:hover {
    background: var(--surface);
    transform: scale(1.08);
}

.replay-btn.replay-play {
    background: var(--accent);
    color: #fff;
    font-size: 1rem;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    margin-top: -4px;
    box-shadow: 0 4px 12px hsla(var(--accent-h), var(--accent-s), var(--accent-l), 0.4);
}

.replay-btn.replay-play:hover {
    filter: brightness(1.1);
    transform: scale(1.1);
}
.replay-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ===== Responsive History ===== */
@media (max-width: 400px) {
    .history-drawer { width: 96vw; }
    .replay-content { max-width: 96vw; padding: 1.25rem; }
    .replay-board-ttt { width: 180px; }
    .replay-board-c4 { width: 240px; }
    .replay-board-gmk { width: 260px; max-height: 260px; }
    .controls { gap: 0.5rem; }
}

/* Replay piece colors */
.replay-c4-piece.x-piece,
.replay-gmk-piece.x-piece {
    background: linear-gradient(135deg, var(--x-color), color-mix(in srgb, var(--x-color) 70%, #000));
}

.replay-c4-piece.o-piece,
.replay-gmk-piece.o-piece {
    background: linear-gradient(135deg, var(--o-color), color-mix(in srgb, var(--o-color) 70%, #000));
}

.replay-gmk-piece.x-piece {
    box-shadow: 0 1px 4px rgba(255, 107, 107, 0.3);
}

.replay-gmk-piece.o-piece {
    box-shadow: 0 1px 4px rgba(78, 205, 196, 0.3);
}

/* Focus styles for history and replay buttons */
.replay-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn-history-replay:focus-visible,
.btn-history-analysis:focus-visible,
.btn-history-delete:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ===== Undo Button ===== */
.btn-undo {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--surface);
    color: var(--text-muted);
    border: 1px solid var(--surface-light);
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-undo:not(.disabled):hover {
    color: var(--accent);
    transform: scale(1.08);
}

.btn-undo.disabled {
    opacity: 0.4;
    pointer-events: none;
    cursor: default;
}

.btn-undo:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
#undo-btn {
    position: relative;
}
.undo-tooltip {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: var(--surface);
    color: var(--text);
    padding: 0.4rem 0.7rem;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.25s ease, transform 0.25s ease;
    box-shadow: var(--shadow);
    border: 1px solid var(--surface-light);
    z-index: 10;
}
#undo-btn:hover .undo-tooltip,
#undo-btn:focus-visible .undo-tooltip {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ===== Hint Button ===== */
.btn-hint {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--surface);
    color: var(--text-muted);
    border: 1px solid var(--surface-light);
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn-hint:not(.disabled):hover {
    color: var(--accent);
    transform: scale(1.08);
}
.btn-hint.disabled {
    opacity: 0.4;
    pointer-events: none;
    cursor: default;
}
.btn-hint:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.cell.hint-glow::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: var(--hint-line);
    opacity: 0.35;
    transform: scale(1);
    animation: hint-glow-anim calc(0.6s * var(--anim-scale)) ease-in-out 3;
    pointer-events: none;
    z-index: 1;
    will-change: transform, opacity;
}
@keyframes hint-glow-anim {
    0%, 100% { transform: scale(1); opacity: 0.35; }
    50% { transform: scale(1.05); opacity: 0.6; }
}

/* ===== Achievements Button ===== */
.btn-achievements {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--surface);
    color: var(--text-muted);
    border: 1px solid var(--surface-light);
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-achievements:hover {
    color: var(--accent);
    transform: scale(1.08);
}

.btn-achievements:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ===== Achievements Drawer ===== */
.achievements-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: min(420px, 92vw);
    height: 100%;
    background: var(--surface);
    box-shadow: var(--shadow);
    z-index: 110;
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.34, 1.2, 0.64, 1);
    display: flex;
    flex-direction: column;
}

.achievements-drawer.show { transform: translateX(0); }

/* Achievement Summary */
.achievement-summary {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.achievement-summary-card {
    flex: 1;
    background: var(--surface-light);
    border-radius: 12px;
    padding: 0.75rem;
    text-align: center;
}

.achievement-summary-card .value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
}

.achievement-summary-card .label {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

/* Category */
.achievement-category {
    margin-top: 1rem;
}

.achievement-category-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.5rem;
    padding-left: 0.25rem;
}

/* Achievement Item */
.achievement-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--surface-light);
    border-radius: 14px;
    padding: 0.85rem 1rem;
    margin-bottom: 0.5rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.3s ease;
    border: 1px solid transparent;
}

.achievement-item:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.achievement-item.locked {
    opacity: 0.55;
}

.achievement-item.unlocked {
    border-color: hsla(var(--accent-h), var(--accent-s), var(--accent-l), 0.35);
    background: color-mix(in srgb, var(--surface-light) 92%, var(--accent) 8%);
}

.achievement-icon {
    font-size: 1.6rem;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    filter: grayscale(0);
    transition: filter 0.3s ease;
}

.achievement-item.locked .achievement-icon {
    filter: grayscale(1);
    opacity: 0.7;
}

.achievement-info {
    flex: 1;
    min-width: 0;
}

.achievement-name {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.15rem;
}

.achievement-item.locked .achievement-name {
    color: var(--text-muted);
}

.achievement-desc {
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.3;
}

.achievement-progress-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.35rem;
}

.achievement-progress-bar {
    flex: 1;
    height: 5px;
    background: var(--surface);
    border-radius: 3px;
    overflow: hidden;
}

.achievement-progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.4s ease;
}

.achievement-progress-text {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    min-width: 36px;
    text-align: right;
}

.achievement-unlock-date {
    font-size: 0.7rem;
    color: var(--accent);
    font-weight: 600;
    margin-top: 0.2rem;
}

/* ===== Achievement Toast ===== */
.achievement-toast-container {
    position: fixed;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
    width: min(360px, 90vw);
}

.achievement-toast {
    background: var(--surface);
    border: 1px solid hsla(var(--accent-h), var(--accent-s), var(--accent-l), 0.4);
    border-radius: 16px;
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow), 0 0 40px hsla(var(--accent-h), var(--accent-s), var(--accent-l), 0.15);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    pointer-events: auto;
    animation: toast-in calc(0.4s * var(--anim-scale, 1)) cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.achievement-toast.out {
    animation: toast-out calc(0.3s * var(--anim-scale, 1)) ease forwards;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-20px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toast-out {
    from { opacity: 1; transform: translateY(0) scale(1); }
    to { opacity: 0; transform: translateY(-10px) scale(0.95); }
}

.achievement-toast-icon {
    font-size: 2rem;
    flex-shrink: 0;
}

.achievement-toast-text {
    flex: 1;
}

.achievement-toast-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.1rem;
}

.achievement-toast-name {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
}

/* ===== Tactics Trainer ===== */
.tactics-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: min(420px, 92vw);
    height: 100%;
    background: var(--surface);
    z-index: 110;
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.34, 1.2, 0.64, 1);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}
.tactics-drawer.show { transform: translateX(0); }

.tactics-summary {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}
.tactics-summary-card {
    flex: 1;
    background: var(--surface-light);
    border-radius: 12px;
    padding: 0.75rem;
    text-align: center;
}
.tactics-summary-card .value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
}
.tactics-summary-card .label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

.tactics-filter {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}
.tactics-filter-btn {
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    border: 1px solid var(--surface-light);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}
.tactics-filter-btn:hover {
    background: var(--surface-light);
    color: var(--text);
}
.tactics-filter-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.tactics-filter-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.tactics-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.6rem;
}
.tactics-card {
    background: var(--surface-light);
    border-radius: 12px;
    padding: 0.85rem;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    border: 1px solid transparent;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    position: relative;
}
.tactics-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px color-mix(in srgb, var(--text), transparent 75%);
    border-color: var(--accent-light);
}
.tactics-card.completed {
    border-color: color-mix(in srgb, var(--o-color), transparent 70%);
}
.tactics-card:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.tactics-card.completed::after {
    content: '✓';
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 20px;
    height: 20px;
    background: var(--o-color);
    color: #fff;
    border-radius: 50%;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
}
.tactics-card-difficulty {
    display: flex;
    gap: 0.15rem;
}
.tactics-card-difficulty .star {
    font-size: 0.75rem;
    color: var(--text-muted);
}
.tactics-card-difficulty .star.active {
    color: var(--accent);
}
.tactics-card-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
}
.tactics-card-desc {
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.3;
}
.tactics-card-mode {
    font-size: 0.72rem;
    color: var(--accent);
    font-weight: 600;
    margin-top: auto;
    padding-top: 0.3rem;
}

/* Tactics Modal */
.tactics-content {
    max-width: 420px;
    width: 92vw;
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
}
.tactics-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--surface-light);
    padding-bottom: 0.5rem;
}
.tactics-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}
.tactics-instruction {
    background: var(--surface-light);
    border-radius: 10px;
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
    color: var(--text);
    margin-bottom: 1rem;
    text-align: center;
    border-left: 3px solid var(--accent);
}
.tactics-board-wrap {
    display: flex;
    justify-content: center;
    margin-bottom: 1rem;
}
.tactics-board {
    width: min(260px, 70vw);
    aspect-ratio: 1 / 1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 8px;
    padding: 10px;
    background: var(--surface);
    border-radius: 16px;
}
.tactics-board .cell {
    cursor: pointer;
    transition: background 0.15s ease;
}
.tactics-board .cell:hover {
    background: hsla(var(--accent-h), var(--accent-s), var(--accent-l), 0.12);
}
.tactics-board .cell.disabled {
    cursor: default;
    pointer-events: none;
}
.tactics-board .cell.hint-correct {
    animation: tactics-correct-pulse calc(0.6s * var(--anim-scale)) ease;
    background: color-mix(in srgb, var(--o-color), transparent 75%);
    border-radius: 16px;
}
.tactics-board .cell.hint-wrong {
    animation: tactics-wrong-shake calc(0.5s * var(--anim-scale)) ease;
    background: color-mix(in srgb, var(--x-color), transparent 80%);
    border-radius: 16px;
}
.tactics-board .cell:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
    z-index: 2;
}

@keyframes tactics-correct-pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(78, 205, 196, 0.5); }
    50% { transform: scale(1.05); box-shadow: 0 0 20px 4px rgba(78, 205, 196, 0.3); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(78, 205, 196, 0); }
}
@keyframes tactics-wrong-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

.tactics-feedback {
    text-align: center;
    min-height: 2.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
}
.tactics-feedback.correct { color: var(--o-color); }
.tactics-feedback.wrong { color: var(--x-color); }
.tactics-feedback .feedback-explanation {
    font-size: 0.82rem;
    font-weight: 400;
    color: var(--text-muted);
    display: block;
    margin-top: 0.3rem;
}

.tactics-actions {
    display: flex;
    gap: 0.6rem;
    justify-content: center;
}
.btn-tactics-skip, .btn-tactics-next {
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.55rem 1.2rem;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}
.btn-tactics-skip {
    background: var(--surface-light);
    color: var(--text-muted);
}
.btn-tactics-skip:focus-visible,
.btn-tactics-next:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.btn-tactics-skip:hover {
    background: var(--surface-hover);
    color: var(--text);
}
.btn-tactics-next {
    background: var(--accent);
    color: #fff;
}
.btn-tactics-next:hover {
    background: var(--accent-light);
}

.btn-tactics {
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--surface);
    color: var(--text-muted);
    border: 1px solid var(--surface-light);
    box-shadow: var(--shadow);
    padding: 0;
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}
.btn-tactics:hover {
    color: var(--text);
    transform: scale(1.08);
}
.btn-tactics:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.btn-tactics:active {
    transform: scale(0.96);
}

/* ===== Daily Challenge ===== */
.btn-daily {
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--surface);
    color: var(--text-muted);
    border: 1px solid var(--surface-light);
    box-shadow: var(--shadow);
    padding: 0;
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}
.btn-daily:hover {
    color: var(--text);
    transform: scale(1.08);
}
.btn-daily:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.daily-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: 9px;
    background: var(--accent);
    color: var(--bg);
    font-size: 0.65rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    transition: transform 0.3s cubic-bezier(0.34, 1.2, 0.64, 1);
}
.daily-badge.pulse {
    animation: daily-badge-pulse calc(0.6s * var(--anim-scale)) ease;
}
@keyframes daily-badge-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.3); }
}
.daily-badge.completed {
    background: var(--o-color);
    color: var(--bg);
}
:root[data-theme="light"] .daily-badge.completed {
    color: var(--surface);
}
@media (prefers-color-scheme: light) {
    :root[data-theme="auto"] .daily-badge.completed {
        color: var(--surface);
    }
}
.daily-content {
    max-width: 420px;
    width: 92vw;
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
}
.daily-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--surface-light);
    padding-bottom: 0.5rem;
}
.daily-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}
.daily-streak-bar {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    background: var(--surface-light);
    border-radius: 10px;
    padding: 0.4rem 0.7rem;
    margin-bottom: 0.75rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
    width: fit-content;
    max-width: 100%;
}
.daily-streak-icon {
    font-size: 1rem;
    line-height: 1;
}
.daily-instruction {
    background: var(--surface-light);
    border-radius: 10px;
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
    color: var(--text);
    margin-bottom: 1rem;
    text-align: center;
    border-left: 3px solid var(--accent);
    line-height: 1.5;
}
.daily-board-wrap {
    display: flex;
    justify-content: center;
    margin-bottom: 1rem;
}
.daily-board {
    width: min(260px, 70vw);
    aspect-ratio: 1 / 1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 8px;
    padding: 10px;
    background: var(--surface);
    border-radius: 16px;
}
.daily-board .cell {
    transition: background 0.15s ease;
}
.daily-board .cell:hover {
    background: hsla(var(--accent-h), var(--accent-s), var(--accent-l), 0.12);
}
.daily-board .cell.disabled {
    pointer-events: none;
    cursor: default;
}
.daily-board .cell.disabled:hover {
    background: var(--surface-light);
    transform: none;
}
.daily-board .cell.hint-correct {
    animation: tactics-correct-pulse calc(0.6s * var(--anim-scale)) ease;
    background: color-mix(in srgb, var(--o-color), transparent 75%);
}
.daily-board .cell.hint-wrong {
    animation: tactics-wrong-shake calc(0.5s * var(--anim-scale)) ease;
    background: color-mix(in srgb, var(--x-color), transparent 80%);
}
.daily-board .cell:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
    z-index: 2;
}
.daily-feedback {
    text-align: center;
    min-height: 2.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    flex-direction: column;
}
.daily-feedback.correct { color: var(--o-color); }
.daily-feedback.wrong { color: var(--x-color); }
.daily-actions {
    display: flex;
    gap: 0.6rem;
    justify-content: center;
}
.btn-daily-skip, .btn-daily-share {
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.55rem 1.2rem;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
    font-family: inherit;
}
.btn-daily-skip {
    background: var(--surface-light);
    color: var(--text-muted);
}
.btn-daily-skip:hover {
    background: var(--surface-hover);
}
.btn-daily-share {
    background: var(--accent);
    color: var(--bg);
}
.btn-daily-share:hover {
    background: var(--accent-light);
}

/* ===== Analysis Modal ===== */
.analysis-content { max-width: 420px; width: 92%; max-height: 90vh; display: flex; flex-direction: column; padding: 0; }
.analysis-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem 0.75rem;
    border-bottom: 1px solid var(--surface-light);
}
.analysis-header h2 { font-size: 1.25rem; margin: 0; }
.analysis-body {
    padding: 1rem 1.5rem 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.analysis-accuracy {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.accuracy-card {
    background: var(--surface-light);
    border-radius: 12px;
    padding: 0.6rem 1rem;
    text-align: center;
    min-width: 80px;
}
.accuracy-label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.2rem;
}
.accuracy-value {
    display: block;
    font-size: 1.1rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
}
.analysis-chart {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 60px;
    padding: 0.5rem;
    background: var(--surface-light);
    border-radius: 10px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    min-width: 0;
}
.analysis-bar {
    flex: 1;
    min-width: 6px;
    border-radius: 2px 2px 0 0;
    transition: height 0.3s ease;
    position: relative;
    cursor: pointer;
}
.analysis-bar[data-player="X"] { background: var(--x-color); opacity: 0.6; }
.analysis-bar[data-player="O"] { background: var(--o-color); opacity: 0.6; }
.analysis-bar.active { opacity: 1; }
.analysis-bar.active[data-player="X"] { box-shadow: 0 0 6px var(--x-color); }
.analysis-bar.active[data-player="O"] { box-shadow: 0 0 6px var(--o-color); }
.analysis-bar::after {
    content: '';
    position: absolute;
    inset: -8px 0;
}
.analysis-board-wrap {
    display: flex;
    justify-content: center;
}
.analysis-board-wrap .board,
.analysis-board-wrap .connect4-board,
.analysis-board-wrap .gomoku-board {
    max-width: 220px;
    pointer-events: none;
}
.analysis-board-wrap .cell .mark,
.analysis-board-wrap .c4-piece,
.analysis-board-wrap .gomoku-piece {
    animation: none;
}
.analysis-move-info {
    text-align: center;
    font-size: 0.85rem;
    min-height: 1.5rem;
}
.analysis-move-info .class-tag {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-right: 0.4rem;
}
.class-tag.best { background: #2ecc7133; color: #2ecc71; }
.class-tag.good { background: #f1c40f33; color: #c9a000; }
.class-tag.inaccuracy { background: #e67e2233; color: #e67e22; }
.class-tag.mistake { background: #e74c3c33; color: #e74c3c; }
.class-tag.blunder { background: #c0392b33; color: #c0392b; }
.analysis-move-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    justify-content: center;
    padding: 0.25rem;
}
.analysis-move-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 36px;
    border-radius: 6px;
    border: none;
    font-size: 0.75rem;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    cursor: pointer;
    background: var(--surface-light);
    color: var(--text);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.analysis-move-btn:hover { transform: translateY(-1px); }
.analysis-move-btn.active {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}
.analysis-move-btn.best { background: #2ecc7122; color: #2ecc71; }
.analysis-move-btn.good { background: #f1c40f22; color: #c9a000; }
.analysis-move-btn.inaccuracy { background: #e67e2222; color: #e67e22; }
.analysis-move-btn.mistake { background: #e74c3c22; color: #e74c3c; }
.analysis-move-btn.blunder { background: #c0392b22; color: #c0392b; }
.analysis-nav {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}
.analysis-nav-btn {
    padding: 0.4rem 0.8rem;
    border-radius: 8px;
    border: 1px solid var(--surface-light);
    background: var(--surface);
    color: var(--text);
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s ease;
}
.analysis-nav-btn:hover { background: var(--surface-light); }
.analysis-nav-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.analysis-nav-btn:disabled:hover {
    background: var(--surface);
}

.analysis-key-moments {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.75rem;
    background: var(--surface-light);
    border-radius: 10px;
}
.analysis-key-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-right: 0.3rem;
}
.analysis-key-btn {
    min-width: 36px;
    height: 32px;
    border-radius: 6px;
    border: none;
    font-size: 0.7rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    cursor: pointer;
    background: var(--surface);
    color: var(--text);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.analysis-key-btn:hover { transform: translateY(-1px); }
.analysis-key-btn.best { background: #2ecc7122; color: #2ecc71; }
.analysis-key-btn.good { background: #f1c40f22; color: #c9a000; }
.analysis-key-btn.inaccuracy { background: #e67e2222; color: #e67e22; }
.analysis-key-btn.mistake { background: #e74c3c22; color: #e74c3c; }
.analysis-key-btn.blunder { background: #c0392b22; color: #c0392b; }

/* ===== Puzzle Rush ===== */
.btn-rush {
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--surface);
    color: var(--text-muted);
    border: 1px solid var(--surface-light);
    box-shadow: var(--shadow);
    padding: 0;
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}
.btn-rush:hover {
    color: var(--text);
    transform: scale(1.08);
}
.btn-rush:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.btn-rush:active {
    transform: scale(0.96);
}
.rush-content {
    max-width: 420px;
    width: 92vw;
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
}
.rush-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--surface-light);
    padding-bottom: 0.5rem;
}
.rush-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}
.rush-hud {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.rush-hud-item {
    background: var(--surface-light);
    border-radius: 10px;
    padding: 0.5rem 0.3rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.rush-hud-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.rush-hud-value {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text);
}
.rush-hud-score .rush-hud-value {
    color: var(--accent);
}
#rush-timer.warning {
    color: var(--x-color);
    animation: rush-timer-pulse calc(1s * var(--anim-scale)) ease infinite;
}
@keyframes rush-timer-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}
.rush-start {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.75rem;
    padding: 1rem 0 0.5rem;
}
.rush-start-icon {
    font-size: 3rem;
    line-height: 1;
}
.rush-start-desc {
    font-size: 0.95rem;
    color: var(--text);
    font-weight: 500;
    max-width: 280px;
}
.rush-rules {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.rush-rules li::before {
    content: '•';
    color: var(--accent);
    margin-right: 0.4rem;
}
.btn-rush-start {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 0.7rem 1.8rem;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: filter 0.2s ease, transform 0.2s ease;
    font-family: inherit;
    margin-top: 0.5rem;
}
.btn-rush-start:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}
.btn-rush-start:active {
    transform: scale(0.96);
}
.rush-game {
    display: flex;
    flex-direction: column;
}
.rush-instruction {
    background: var(--surface-light);
    border-radius: 10px;
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
    color: var(--text);
    margin-bottom: 1rem;
    text-align: center;
    border-left: 3px solid var(--accent);
}
.rush-board-wrap {
    display: flex;
    justify-content: center;
    margin-bottom: 1rem;
}
.rush-board {
    width: min(260px, 70vw);
    aspect-ratio: 1 / 1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 8px;
    padding: 10px;
    background: var(--surface);
    border-radius: 16px;
}
.rush-board .cell {
    cursor: pointer;
    transition: background 0.15s ease;
}
.rush-board .cell:hover {
    background: hsla(var(--accent-h), var(--accent-s), var(--accent-l), 0.12);
}
.rush-board .cell.disabled {
    cursor: default;
    pointer-events: none;
}
.rush-board .cell.disabled:hover {
    background: var(--surface-light);
    transform: none;
}
.rush-board .cell.hint-correct {
    animation: tactics-correct-pulse calc(0.6s * var(--anim-scale)) ease;
    background: color-mix(in srgb, var(--o-color), transparent 75%);
}
.rush-board .cell.hint-wrong {
    animation: tactics-wrong-shake calc(0.5s * var(--anim-scale)) ease;
    background: color-mix(in srgb, var(--x-color), transparent 80%);
}
.rush-board .cell:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
    z-index: 2;
}
.rush-feedback {
    text-align: center;
    min-height: 2.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    flex-direction: column;
}
.rush-feedback.correct { color: var(--o-color); }
.rush-feedback.wrong { color: var(--x-color); }
.rush-actions {
    display: flex;
    gap: 0.6rem;
    justify-content: center;
}
.btn-rush-skip {
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.55rem 1.2rem;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    background: var(--surface-light);
    color: var(--text-muted);
}
.btn-rush-skip:hover {
    background: var(--surface-hover);
    color: var(--text);
}
.rush-result {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.6rem;
    padding: 1rem 0 0.5rem;
    animation: rush-result-in calc(0.4s * var(--anim-scale)) ease;
}
@keyframes rush-result-in {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}
.rush-result-icon {
    font-size: 2.5rem;
    line-height: 1;
}
.rush-result-score {
    font-size: 3rem;
    font-weight: 800;
    color: var(--accent);
    line-height: 1;
}
.rush-result-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
}
.rush-result-stats {
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
}
.rush-result-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.1rem;
}
.rush-result-stat-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
}
.rush-result-stat-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
}
.rush-result-best {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}
.rush-result-best.new-record {
    color: var(--accent);
    font-weight: 700;
}
.rush-result-actions {
    display: flex;
    gap: 0.6rem;
    margin-top: 0.75rem;
}
.btn-rush-restart {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 0.6rem 1.4rem;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: filter 0.2s ease, transform 0.2s ease;
    font-family: inherit;
}
.btn-rush-restart:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}
.btn-rush-close {
    background: var(--surface-light);
    color: var(--text-muted);
    border: none;
    border-radius: 10px;
    padding: 0.6rem 1.4rem;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
    font-family: inherit;
}
.btn-rush-close:hover {
    background: var(--surface-hover);
    color: var(--text);
}

/* ===== Board Editor ===== */
.btn-editor {
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--surface);
    color: var(--text-muted);
    border: 1px solid var(--surface-light);
    box-shadow: var(--shadow);
    padding: 0;
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}
.btn-editor:hover {
    color: var(--text);
    transform: scale(1.08);
}
.btn-editor:active {
    transform: scale(0.96);
}
.btn-editor:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.editor-content {
    max-width: 420px;
    width: 92vw;
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
}
.editor-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--surface-light);
    padding-bottom: 0.5rem;
}
.editor-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}
.editor-player-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    margin-bottom: 1rem;
    background: var(--surface-light);
    border-radius: 10px;
    padding: 0.5rem 1rem;
}
.editor-player-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}
.editor-player-toggle {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--surface);
    border: 1px solid var(--surface-light);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.2s ease;
    padding: 0;
}
.editor-player-toggle:hover {
    background: var(--surface-hover);
    transform: scale(1.05);
}
.editor-player-toggle:active {
    transform: scale(0.95);
}
.editor-player-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.editor-player-mark {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
}
.editor-board-wrap {
    display: flex;
    justify-content: center;
    margin-bottom: 1rem;
}
.editor-board {
    width: min(260px, 70vw);
    aspect-ratio: 1 / 1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 8px;
    padding: 10px;
    background: var(--surface);
    border-radius: 16px;
}
.editor-board .cell {
    cursor: pointer;
    transition: background 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}
.editor-board .cell:hover {
    background: hsla(var(--accent-h), var(--accent-s), var(--accent-l), 0.12);
}
.editor-board .cell:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
    z-index: 2;
}
.editor-actions {
    display: flex;
    gap: 0.6rem;
    justify-content: center;
}
.btn-editor-clear {
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.55rem 1.2rem;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    background: var(--surface-light);
    color: var(--text-muted);
}
.btn-editor-clear:hover {
    background: var(--surface-hover);
    color: var(--text);
}
.btn-editor-clear:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.btn-editor-start {
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.55rem 1.2rem;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    background: var(--accent);
    color: #fff;
}
.btn-editor-start:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}
.btn-editor-start:active {
    transform: scale(0.96);
}
.btn-editor-start:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ===== Statistics ===== */
.stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.btn-stats-reset {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    background: transparent;
    border: 1px solid var(--surface-light);
    border-radius: 8px;
    padding: 0.35rem 0.7rem;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
    font-family: inherit;
}

.btn-stats-reset:hover {
    color: var(--x-color);
    border-color: rgba(255, 107, 107, 0.35);
    background: rgba(255, 107, 107, 0.08);
}
.btn-stats-reset:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
}

.stats-card {
    background: var(--surface-light);
    border-radius: 12px;
    padding: 0.6rem 0.3rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.stats-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
}

.stats-value.wins { color: var(--x-color); }
.stats-value.losses { color: var(--o-color); }
.stats-value.draws { color: var(--text-muted); }

.stats-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stats-bar-wrap {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.25rem;
}

.stats-bar-track {
    flex: 1;
    height: 8px;
    background: var(--surface-light);
    border-radius: 4px;
    overflow: hidden;
    display: flex;
}

.stats-bar-fill {
    height: 100%;
    transition: width 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.stats-bar-fill.wins { background: var(--x-color); }
.stats-bar-fill.losses { background: var(--o-color); }
.stats-bar-fill.draws { background: var(--text-muted); }

.stats-winrate {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text);
    min-width: 44px;
    text-align: right;
}

.stats-misc {
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
}

.stats-misc-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.stats-misc-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.stats-misc-value {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text);
}

.stats-misc-value.best { color: var(--accent); }

.stats-divider {
    height: 1px;
    background: var(--surface-light);
    margin: 0.5rem 0;
}

.stats-section-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.4rem;
}

.stats-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.stats-list-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.85rem;
}

.stats-list-name {
    width: 64px;
    color: var(--text-muted);
    font-weight: 500;
}

.stats-list-bar-wrap {
    flex: 1;
    height: 6px;
    background: var(--surface-light);
    border-radius: 3px;
    overflow: hidden;
}

.stats-list-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    background: var(--accent);
}

.stats-list-rate {
    width: 40px;
    text-align: right;
    font-weight: 700;
    color: var(--text);
    font-size: 0.8rem;
}

.stats-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
}

.stats-detail {
    background: var(--surface-light);
    border-radius: 10px;
    padding: 0.6rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.stats-detail-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 500;
}

.stats-detail-value {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text);
}

/* ===== Ripple Effect ===== */
.ripple {
    position: absolute;
    border-radius: 50%;
    transform: scale(0);
    opacity: 0.45;
    pointer-events: none;
    animation: ripple-expand calc(0.6s * var(--anim-scale)) ease-out forwards;
    width: 20px;
    height: 20px;
    margin-left: -10px;
    margin-top: -10px;
    z-index: 5;
}

.ripple.x-ripple { background: var(--x-color); }
.ripple.o-ripple { background: var(--o-color); }

@keyframes ripple-expand {
    0% { transform: scale(0); opacity: 0.45; }
    60% { opacity: 0.2; }
    100% { transform: scale(12); opacity: 0; }
}

/* ===== Data Management ===== */
.data-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-data {
    flex: 1;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text);
    background: var(--surface-light);
    border: 1px solid var(--surface-hover);
    border-radius: 10px;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
    font-family: inherit;
    text-align: center;
}

.btn-data:hover {
    background: var(--surface-hover);
    border-color: var(--accent);
    transform: translateY(-1px);
}
.btn-data:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn-data-copy {
    color: var(--accent);
    border-color: hsla(var(--accent-h), var(--accent-s), var(--accent-l), 0.35);
}

.btn-data-copy:hover {
    background: hsla(var(--accent-h), var(--accent-s), var(--accent-l), 0.1);
}

.btn-data-confirm {
    color: var(--x-color);
    border-color: rgba(255, 107, 107, 0.35);
}

.btn-data-confirm:hover {
    background: rgba(255, 107, 107, 0.08);
}

.data-textarea-wrap {
    display: none;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.5rem;
    animation: fade-in-up calc(0.25s * var(--anim-scale)) ease-out both;
}

.data-textarea-wrap.show {
    display: flex;
}

.data-textarea {
    width: 100%;
    min-height: 120px;
    max-height: 200px;
    background: var(--bg);
    border: 1px solid var(--surface-light);
    border-radius: 10px;
    padding: 0.6rem 0.75rem;
    color: var(--text);
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.7rem;
    line-height: 1.4;
    resize: vertical;
    outline: none;
    transition: border-color 0.2s ease;
}

.data-textarea:focus {
    border-color: var(--accent);
}

.data-textarea::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}

/* ===== Live Evaluation Bar ===== */
.eval-bar-wrap {
    width: 100%;
    max-width: 340px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 0 0.5rem;
    transform: scaleY(1);
    opacity: 1;
    transition: transform 0.3s ease, opacity 0.3s ease;
    transform-origin: top center;
}
.eval-bar-wrap.is-hidden {
    transform: scaleY(0);
    opacity: 0;
    pointer-events: none;
}
.eval-bar-track {
    position: relative;
    height: 8px;
    background: var(--surface-light);
    border-radius: 4px;
    overflow: hidden;
}
.eval-bar-fill {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 0%;
    background: var(--text-muted);
    border-radius: 4px;
    transition: left 0.45s cubic-bezier(0.22, 1, 0.36, 1), width 0.45s cubic-bezier(0.22, 1, 0.36, 1), background 0.3s ease;
}
.eval-bar-fill.advantage-x {
    background: var(--x-color);
}
.eval-bar-fill.advantage-o {
    background: var(--o-color);
}
.eval-bar-center {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 2px;
    background: var(--text);
    opacity: 0.18;
    transform: translateX(-50%);
    pointer-events: none;
}
.eval-bar-labels {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.7rem;
    color: var(--text-muted);
    user-select: none;
    white-space: nowrap;
}
.eval-bar-label {
    font-weight: 600;
    letter-spacing: 0.02em;
}
.eval-bar-label.eval-x { color: var(--x-color); }
.eval-bar-label.eval-o { color: var(--o-color); }
.eval-bar-score {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-weight: 700;
    font-size: 0.75rem;
    color: var(--text);
    min-width: 3ch;
    text-align: center;
}

/* ===== Touch Device: Suppress Sticky Hover Transforms ===== */
@media (hover: none) {
    .cell:hover, .c4-cell:hover, .gomoku-cell:hover,
    .score-card:hover, .elo-badge:hover, .btn-settings:hover,
    .tactics-board .cell:hover, .daily-board .cell:hover,
    .rush-board .cell:hover, .editor-board .cell:hover {
        transform: none !important;
    }
}

/* ===== Responsive Achievements ===== */
@media (max-width: 400px) {
    .timer { font-size: 0.72rem; }
    .btn-achievements { width: 38px; height: 38px; }
    .achievements-drawer { width: 96vw; }
    .achievement-toast-container { width: 96vw; top: 0.5rem; }
    .achievement-toast { padding: 0.75rem 1rem; border-radius: 12px; }
    .achievement-icon { font-size: 1.4rem; width: 34px; height: 34px; }
    .achievement-name { font-size: 0.85rem; }
    .achievement-desc { font-size: 0.72rem; }
    .stats-grid { gap: 0.35rem; }
    .stats-card { padding: 0.5rem 0.2rem; }
    .stats-value { font-size: 1rem; }
    .stats-detail-grid { gap: 0.4rem; }
    .tactics-drawer { width: 96vw; }
    .tactics-grid { grid-template-columns: 1fr; }
    .tactics-board { width: 220px; }
    .daily-board { width: 220px; }
    .rush-board { width: 220px; }
    .editor-board { width: 220px; }
    .btn-hint { width: 38px; height: 38px; }
    .btn-undo { width: 38px; height: 38px; }
    .btn-history { width: 38px; height: 38px; }
    .btn-settings { width: 38px; height: 38px; }
    .daily-content { padding: 1.5rem; }
}
