:root {
    --bg: #ffffff;
    --fg: #111;
    --muted: #666;
    --card: #ffffff;
    --border: #eee;
    --accent: #2563eb;
    --btn: #007BFF;
}

body.dark {
    --bg: #0f0f0f;
    --card: #181818;
    --fg: #f1f1f1;
    --muted: #aaaaaa;
    --border: #303030;
    --accent: #ff0000;
    --accent-glow: #ff000030;
}

.chat a {
    color: #2563eb;
    text-decoration: underline;
}

.chat a:hover {
    opacity: 0.8;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    font-family: Inter, Arial, Helvetica, sans-serif;
    background: var(--bg);
    color: var(--fg);
}

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 28px;
    border-bottom: 1px solid var(--border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer
}

.logo svg {
    display: block
}

nav {
    display: flex;
    align-items: center;
    gap: 18px
}

nav a {
    cursor: pointer;
    text-decoration: none;
    color: var(--fg);
    font-weight: 500
}

.icon-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 18px
}

#root {
    padding: 18px 28px;
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 22px
}

.panel {
    border: 1px solid var(--border);
    background: var(--card);
    border-radius: 10px;
    padding: 14px
}

.big {
    min-height: 420px;
    display: flex;
    align-items: center;
    justify-content: center
}

.photo img {
    width: 100%;
    border-radius: 6px
}

h2 {
    margin: 0 0 8px 0
}

.chat {
    height: 280px;
    display: flex;
    flex-direction: column
}

.messages {
    overflow: auto;
    flex: 1;
    padding-right: 8px
}

.msg {
    margin-bottom: 10px;
    padding: 6px 8px;
    border-radius: 6px;
    transition: background-color 0.3s ease
}

.msg b {
    font-size: 13px
}

form.row {
    display: flex;
    gap: 8px
}

input,
textarea,
button {
    font: inherit
}

input,
textarea {
    padding: 8px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--fg)
}

button {
    padding: 8px 12px;
    border-radius: 8px;
    border: none;
    background: var(--accent);
    color: #fff;
    cursor: pointer
}

.muted {
    color: var(--muted);
    font-size: 13px
}

.small {
    font-size: 12px;
    color: var(--muted)
}

footer {
    text-align: center;
    padding: 14px;
    border-top: 1px solid var(--border);
    margin-top: 18px
}

@media(max-width:980px) {
    #root {
        grid-template-columns: 1fr
    }
}

@media(max-width:768px) {
    header {
        flex-wrap: wrap;
        padding: 8px 12px;
        gap: 8px
    }

    nav {
        order: 3;
        width: 100%;
        flex-wrap: wrap;
        gap: 8px;
        font-size: 14px
    }

    nav a {
        flex: 1;
        min-width: 100px;
        text-align: center;
        padding: 6px
    }

    .logo img {
        height: 48px
    }

    #root {
        padding: 12px;
        gap: 12px
    }

    .panel {
        padding: 10px
    }

    .chat {
        height: 200px
    }

    .square {
        font-size: 36px !important
    }
}

@media(max-width:480px) {
    nav {
        display: none
    }

    .mobile-nav-toggle {
        display: flex !important
    }

    #root {
        padding: 8px
    }

    .square {
        font-size: 28px !important
    }
}

.mobile-nav-toggle {
    display: none;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 24px;
    padding: 8px
}

.mobile-nav {
    display: none;
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    z-index: 100;
    padding: 12px;
    flex-direction: column;
    gap: 8px
}

.mobile-nav.open {
    display: flex
}

#board-wrapper {
    width: 100%;
    justify-content: center;
    touch-action: manipulation
}

#myBoard {
    max-width: 100%;
    height: auto
}

.game-mode-btn.active {
    opacity: 1;
    font-weight: 600
}

.game-mode-btn:not(.active) {
    opacity: 0.7
}

.account-btn {
    width: 36px;
    height: 36px;
    border-radius: 18px;
    border: 1px solid var(--border);
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700
}

.link-btn {
    background: transparent;
    border: 1px solid var(--border);
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer
}

.center {
    text-align: center
}

body:not(.dark) .account-btn {
    background: #000;
    color: #fff;
    border-color: #000;
    transition: 0.2s;
}

body:not(.dark) .account-btn:hover {
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.6);
    transform: scale(1.05);
}

body.dark .account-btn {
    background: #fff;
    color: #000;
    border-color: #fff;
    transition: 0.2s;
}

body.dark .account-btn:hover {
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.7);
    transform: scale(1.05);
}

body:not(.dark) .link-btn {
    background: #000;
    color: #fff;
    border-color: #000;
    transition: 0.3s;
}

body:not(.dark) .link-btn:hover {
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.6);
    transform: scale(1.05);
}

body.dark .link-btn {
    background: #fff;
    color: #000;
    border-color: #fff;
    transition: 0.3s;
}

body.dark .link-btn:hover {
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.7);
    transform: scale(1.05);
}

.logo {
    background-color: transparent;
    background-repeat: no-repeat;
    background-size: contain;
}

.square.light {
    background: #f0d9b5;
}

.square.dark {
    background: #b58863;
}

#chessboard .square {
    user-select: none;
    cursor: pointer;
    transition: background 0.2s, box-shadow 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 48px;
    line-height: 1;
}

#chessboard .square.highlight {
    box-shadow: 0 0 10px 2px #ffff00;
}

#chessboard .selected {
    box-shadow: 0 0 12px 4px #00f0ff;
    border-radius: 6px;
}

#chessboard .square.check {
    background-color: #ff4d4d !important;
}

#chessboard .square.check mat-king {
    transform: rotate(-20deg);
}

#chessboard .square .king-mate {
    display: inline-block;
    transition: transform 0.3s;
    transform-origin: center bottom;
}

body.dark img,
body.dark .square img,
body.dark .piece {
    filter: none !important;
    mix-blend-mode: normal !important;
    opacity: 1 !important;
}

body.dark .square {
    color: inherit !important;
}

#chessboard .square {
    color: #000 !important;
}

#chessboard .square.dark {
    color: #000 !important;
}

#chessboard .square.light {
    color: #000 !important;
}

#game-result {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 42px;
    font-weight: 900;
    padding: 18px 32px;
    border-radius: 14px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    text-shadow: 0 0 12px #000;
    box-shadow: 0 0 18px rgba(255, 255, 255, 0.7);
    animation: fadeIn 0.6s ease forwards;
    z-index: 999;
    pointer-events: none;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translate(-50%, -60%);
    }

    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

.nickname-special {
    font-weight: 700;
    transition: text-shadow 0.3s, color 0.3s;
}

.username {
    font-family: "Inter", sans-serif;
    font-weight: 600;
}

.msg-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.msg-user-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ping-button {
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    font-size: 14px;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.2s;
    opacity: 0;
    visibility: hidden;
    font-weight: bold;
}

.msg:hover .ping-button {
    opacity: 1;
    visibility: visible;
}

.ping-button:hover {
    background-color: rgba(37, 99, 235, 0.1);
    color: var(--accent);
}

.msg-mentioned {
    background-color: rgba(76, 175, 80, 0.15) !important;
    border-left: 3px solid #4CAF50 !important;
    animation: pulse 1.5s ease-in-out;
}

@keyframes pulse {
    0% {
        background-color: rgba(76, 175, 80, 0.05);
    }

    50% {
        background-color: rgba(76, 175, 80, 0.25);
    }

    100% {
        background-color: rgba(76, 175, 80, 0.15);
    }
}

.mention {
    color: #2563eb;
    font-weight: 600;
    background-color: rgba(37, 99, 235, 0.1);
    padding: 0 4px;
    border-radius: 3px;
}

body.dark .mention {
    color: #3b82f6;
    background-color: rgba(59, 130, 246, 0.2);
}

.mention-current-user {
    color: #d32f2f;
    font-weight: 700;
    background-color: rgba(211, 47, 47, 0.15);
    padding: 0 4px;
    border-radius: 3px;
    animation: mention-pulse 2s infinite;
}

@keyframes mention-pulse {
    0% {
        background-color: rgba(211, 47, 47, 0.1);
    }

    50% {
        background-color: rgba(211, 47, 47, 0.25);
    }

    100% {
        background-color: rgba(211, 47, 47, 0.1);
    }
}
/* Онлайн-виджет */
#online-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    font-size: 14px;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    max-width: 200px;
    max-height: 300px;
    overflow-y: auto;
}

.dark #online-widget {
    background: var(--bg-panel);
    border-color: var(--border);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.online-widget-title {
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--fg);
    font-size: 15px;
}

.online-user {
    padding: 4px 0;
    border-bottom: 1px solid var(--border);
    color: var(--fg);
    display: flex;
    align-items: center;
    gap: 6px;
}

.online-user:last-child {
    border-bottom: none;
}

.online-user.anon {
    color: var(--muted);
    font-style: italic;
}

/* Онлайн-виджет - исправленная версия */
#online-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    font-size: 14px;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    max-width: 200px;
    max-height: 300px;
    overflow-y: auto;
}

.dark #online-widget {
    background: var(--card);
    border-color: var(--border);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.online-widget-title {
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--fg);
    font-size: 15px;
}

.online-user {
    padding: 4px 0;
    border-bottom: 1px solid var(--border);
    color: var(--fg);
    display: flex;
    align-items: center;
    gap: 6px;
}

.online-user:last-child {
    border-bottom: none;
}

.online-user.anon {
    color: var(--muted);
    font-style: italic;
}

/* Индикатор онлайн */
.online-user::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #4CAF50;
    animation: online-pulse 2s infinite;
}

.online-user.anon::before {
    background-color: #FF9800;
}

@keyframes online-pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

/* Мобильная адаптация */
@media (max-width: 768px) {
    #online-widget {
        bottom: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
        font-size: 13px;
        padding: 10px;
    }
}
/* Всплывающее окно с информацией о пользователе */
.user-popup {
    position: absolute;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 13px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 1000;
    min-width: 200px;
    max-width: 250px;
    pointer-events: none;
    animation: popupFadeIn 0.2s ease;
}

.dark .user-popup {
    background: var(--card);
    border-color: var(--border);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.user-popup-header {
    font-weight: 600;
    margin-bottom: 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
    color: var(--fg);
}

.user-popup-content {
    color: var(--muted);
}

.user-popup-content div {
    margin: 4px 0;
    display: flex;
    justify-content: space-between;
}

.user-popup-label {
    color: var(--fg);
    opacity: 0.7;
}

.user-popup-value {
    font-weight: 500;
    color: var(--fg);
}

@keyframes popupFadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Делаем никнеймы кликабельными */
.msg b {
    cursor: pointer;
    position: relative;
    transition: opacity 0.2s;
}

.msg b:hover {
    opacity: 0.8;
    text-decoration: underline;
}
/* Селектор стилей фигур */
.piece-selector {
    background: var(--card);
    border-radius: 8px;
}

.piece-style-btn {
    font-size: 13px;
    transition: all 0.2s;
}

.piece-style-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.piece-style-btn.active {
    background: var(--accent) !important;
    color: white !important;
    border-color: var(--accent) !important;
}

body.dark .piece-style-btn.active {
    background: var(--accent) !important;
    color: white !important;
}
/* Индикатор загрузки движка */
.engine-thinking {
    opacity: 0.7;
    cursor: wait;
}

/* Кнопка подсказки */
#hint-btn {
    background: #ff9800;
    color: #000;
    transition: all 0.2s;
}

#hint-btn:hover {
    background: #f57c00;
    transform: scale(1.02);
}

/* Canvas overlay не блокирует клики */
#board-canvas {
    pointer-events: none;
}