:root {
    --page-bg: #f8fafc;
    --canvas-bg: #d6d6d6;
    --panel-bg: rgba(255, 255, 255, 0.96);
    --panel-border: #d8dee9;
    --panel-soft: #f4f6fa;
    --panel-raised: #ffffff;
    --text-main: #151922;
    --text-muted: #687181;
    --shadow-soft: rgba(15, 23, 42, 0.12);
    --shadow-panel: rgba(15, 23, 42, 0.16);
    --accent: #3f7cff;
    --accent-soft: rgba(63, 124, 255, 0.12);
}

body {
    margin: 0;
    background: var(--page-bg);
    color: var(--text-main);
}

.topbar-tools {
    position: absolute;
    top: 50%;
    left: 24px;
    z-index: 4;
    transform: translateY(-50%);
    font-family: Inter, Arial, sans-serif;
}

.tools-menu-button {
    height: 40px;
    padding: 0 16px 0 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--text-main);
    background:
            linear-gradient(135deg, rgba(255, 255, 255, 0.98), rgba(246, 249, 255, 0.94)) padding-box,
            linear-gradient(135deg, #3f7cff 0%, #42d66b 68%, #ffca3a 100%) border-box;
    border: 1.5px solid transparent;
    border-radius: 12px;
    box-shadow:
            0 10px 26px rgba(15, 23, 42, 0.12),
            0 2px 7px rgba(63, 124, 255, 0.08),
            inset 0 1px 0 rgba(255, 255, 255, 0.96);
    cursor: pointer;
    font: inherit;
    font-size: 13px;
    font-weight: 850;
    line-height: 1;
    letter-spacing: 0;
    overflow: hidden;
    white-space: nowrap;
    transition: background 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease, color 0.16s ease;
}

.tools-menu-button:hover,
.side-panel.menu-open .tools-menu-button {
    background:
            linear-gradient(135deg, #ffffff, #eff6ff) padding-box,
            linear-gradient(135deg, #2f6dff 0%, #37c96a 64%, #ffbf24 100%) border-box;
    border-color: transparent;
    box-shadow:
            0 14px 30px rgba(15, 23, 42, 0.16),
            0 5px 14px rgba(63, 124, 255, 0.13),
            inset 0 1px 0 rgba(255, 255, 255, 1);
    transform: translateY(-2px);
}

.tools-menu-button:active {
    transform: translateY(0) scale(0.98);
}

.tools-menu-button:focus-visible,
.side-action:focus-visible {
    outline: 3px solid rgba(63, 124, 255, 0.28);
    outline-offset: 2px;
}

.tools-menu-button svg,
.side-action svg {
    width: 20px;
    height: 20px;
    flex: 0 0 auto;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.tools-menu-button svg {
    width: 18px;
    height: 18px;
    padding: 4px;
    color: #2f6dff;
    background: rgba(63, 124, 255, 0.12);
    border: 1px solid rgba(63, 124, 255, 0.22);
    border-radius: 8px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.76);
}

.tools-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    display: grid;
    grid-template-columns: 176px 0;
    min-width: 176px;
    max-width: calc(100vw - 48px);
    color: var(--text-main);
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    box-shadow: 0 18px 48px var(--shadow-panel);
    backdrop-filter: blur(12px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-4px) scale(0.98);
    transform-origin: top left;
    transition:
            grid-template-columns 0.18s ease,
            opacity 0.14s ease,
            transform 0.14s ease,
            visibility 0.14s ease;
}

.side-panel.menu-open .tools-dropdown {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.side-panel.expanded .tools-dropdown {
    grid-template-columns: 176px 320px;
}

.side-panel[data-active-panel="statistics"].expanded .tools-dropdown {
    grid-template-columns: 176px 286px;
}

.side-panel[data-active-panel="admin"].expanded .tools-dropdown {
    grid-template-columns: 176px 340px;
}

.side-actions {
    width: 176px;
    padding: 8px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.side-action {
    width: 100%;
    height: 42px;
    padding: 0 10px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    color: var(--text-muted);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    font: inherit;
    text-align: left;
    transition:
            background 0.14s ease,
            color 0.14s ease,
            border-color 0.14s ease,
            transform 0.12s ease;
}

.side-action:hover,
.side-action.active {
    color: var(--text-main);
    background: var(--panel-soft);
    border-color: var(--panel-border);
}

.side-action:active {
    transform: scale(0.98);
}

.side-action-label {
    overflow: hidden;
    font-size: 13px;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.side-panel .admin-only {
    display: none;
}

.side-panel.admin-mode .admin-only {
    display: flex;
}

.side-content {
    min-width: 0;
    max-height: calc(100vh - 88px);
    padding: 0;
    box-sizing: border-box;
    overflow: hidden;
    color: var(--text-main);
    border-left: 1px solid transparent;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.14s ease, visibility 0.14s ease;
}

.side-panel.expanded .side-content {
    padding: 16px;
    overflow: auto;
    border-left-color: var(--panel-border);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.side-content::-webkit-scrollbar,
.leaderboard-list::-webkit-scrollbar {
    width: 8px;
}

.side-content::-webkit-scrollbar-thumb,
.leaderboard-list::-webkit-scrollbar-thumb {
    background: rgba(104, 113, 129, 0.35);
    border-radius: 999px;
}

.side-section {
    display: none;
}

.side-section.active {
    display: block;
}

.side-section h2 {
    margin: 0 0 13px;
    color: var(--text-main);
    font-family: Inter, Arial, sans-serif;
    font-size: 17px;
    font-weight: 850;
    line-height: 1.15;
}

.side-summary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
}

.side-summary div {
    min-height: 62px;
    padding: 10px;
    background: var(--panel-soft);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    box-sizing: border-box;
}

.side-summary span {
    display: block;
    margin-bottom: 7px;
    color: var(--text-muted);
    font-family: Inter, Arial, sans-serif;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.2;
}

.side-summary strong {
    color: var(--text-main);
    font-family: Inter, Arial, sans-serif;
    font-size: 21px;
    font-weight: 900;
    line-height: 1;
}

.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: min(54vh, 430px);
    margin: -5px -3px -8px 0;
    padding: 5px 3px 8px 0;
    overflow: auto;
    list-style: none;
}

.leaderboard-item,
.leaderboard-empty {
    background: var(--panel-raised);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    box-sizing: border-box;
}

.leaderboard-item {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr);
    align-items: center;
    gap: 5px 8px;
    min-height: 66px;
    padding: 10px;
    transition: border-color 0.14s ease, transform 0.14s ease, box-shadow 0.14s ease;
}

.leaderboard-item:hover {
    border-color: rgba(63, 124, 255, 0.35);
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.08);
    transform: translateY(-1px);
}

.leaderboard-empty {
    padding: 16px 12px;
    color: var(--text-muted);
    font-family: Inter, Arial, sans-serif;
    font-size: 12px;
    font-weight: 700;
    text-align: center;
}

.leaderboard-rank {
    grid-row: span 3;
    align-self: stretch;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    background: var(--accent-soft);
    border-radius: 7px;
    font-family: Inter, Arial, sans-serif;
    font-size: 12px;
    font-weight: 850;
}

.leaderboard-name,
.leaderboard-count,
.leaderboard-detail,
.stats-user,
.stats-grid strong {
    font-family: Inter, Arial, sans-serif;
}

.leaderboard-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-main);
    font-size: 13px;
    font-weight: 800;
}

.leaderboard-count {
    color: var(--text-main);
    font-size: 12px;
    font-weight: 750;
}

.leaderboard-detail {
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 650;
    line-height: 1.25;
}

.stats-user {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: 100%;
    margin: 0 0 12px;
    padding: 7px 10px;
    box-sizing: border-box;
    overflow: hidden;
    color: var(--accent);
    background: var(--accent-soft);
    border: 1px solid rgba(63, 124, 255, 0.2);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 850;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stats-user::before {
    content: "";
    width: 8px;
    height: 8px;
    flex: 0 0 auto;
    background: var(--accent);
    border-radius: 50%;
}

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

.stats-grid div {
    display: flex;
    min-height: 76px;
    padding: 10px;
    flex-direction: column;
    justify-content: center;
    gap: 7px;
    background: var(--panel-raised);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    box-sizing: border-box;
}

.stats-grid div:first-child {
    grid-column: 1 / -1;
    min-height: 88px;
    background: linear-gradient(135deg, rgba(63, 124, 255, 0.14), rgba(49, 199, 95, 0.1)), var(--panel-raised);
    border-color: rgba(63, 124, 255, 0.24);
}

.stats-grid div:nth-child(n+4) {
    grid-column: 1 / -1;
    min-height: 48px;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
}

.stats-grid span {
    color: var(--text-muted);
    font-family: Inter, Arial, sans-serif;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.25;
}

.stats-grid strong {
    color: var(--text-main);
    font-size: 19px;
    font-weight: 900;
    line-height: 1;
}

.stats-grid div:first-child strong {
    font-size: 30px;
}

.last-color-value {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 7px;
    min-width: 0;
    font-size: 13px;
}

.last-color-swatch {
    width: 16px;
    height: 16px;
    flex: 0 0 auto;
    border: 1px solid var(--panel-border);
    border-radius: 4px;
    background: transparent;
}

.admin-controls {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-bottom: 10px;
}

.admin-controls input {
    width: 100%;
    min-width: 0;
    height: 38px;
    padding: 0 11px;
    box-sizing: border-box;
    color: var(--text-main);
    background: var(--panel-raised);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    font: inherit;
    font-size: 13px;
    font-weight: 650;
    outline: none;
}

.admin-controls input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.admin-status {
    margin-bottom: 10px;
    color: var(--text-muted);
    font-family: Inter, Arial, sans-serif;
    font-size: 12px;
    font-weight: 700;
}

.admin-status.error {
    color: #d63a2f;
}

.admin-user-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.admin-user-empty,
.admin-user-item {
    background: var(--panel-raised);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    box-sizing: border-box;
}

.admin-user-empty {
    padding: 14px 12px;
    color: var(--text-muted);
    font-family: Inter, Arial, sans-serif;
    font-size: 12px;
    font-weight: 700;
    text-align: center;
}

.admin-user-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    min-height: 64px;
    padding: 10px;
}

.admin-user-copy {
    min-width: 0;
}

.admin-user-name,
.admin-user-mail,
.admin-user-state,
.admin-user-stats,
.admin-user-details {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-user-name {
    color: var(--text-main);
    font-family: Inter, Arial, sans-serif;
    font-size: 13px;
    font-weight: 850;
}

.admin-user-mail,
.admin-user-state,
.admin-user-stats,
.admin-user-details {
    margin-top: 3px;
    color: var(--text-muted);
    font-family: Inter, Arial, sans-serif;
    font-size: 11px;
    font-weight: 650;
}

.admin-user-stats {
    color: var(--text-main);
    font-weight: 760;
}

.admin-user-details {
    color: var(--text-muted);
}

.admin-ban-btn {
    height: 32px;
    padding: 0 10px;
    color: #b42318;
    background: #fff4f2;
    border: 1px solid #f8c9c3;
    border-radius: 8px;
    cursor: pointer;
    font: inherit;
    font-size: 12px;
    font-weight: 850;
    transition: background 0.14s ease, border-color 0.14s ease, transform 0.12s ease;
}

.admin-ban-btn:hover:not(:disabled) {
    background: #ffe7e3;
    border-color: #f3a49a;
}

.admin-ban-btn:active:not(:disabled) {
    transform: scale(0.98);
}

.admin-ban-btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.admin-unban-btn {
    color: #287a3e;
    background: #f2fbf3;
    border-color: #cdebd2;
}

.admin-unban-btn:hover:not(:disabled) {
    background: #e3f7e7;
    border-color: #9fd7aa;
}

.admin-snapshot-panel {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--panel-border);
}

.admin-snapshot-actions {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    margin-bottom: 10px;
}

.admin-snapshot-btn {
    min-width: 0;
    height: 34px;
    padding: 0 10px;
    color: #ffffff;
    background: #202733;
    border: 1px solid #202733;
    border-radius: 8px;
    cursor: pointer;
    font: inherit;
    font-size: 12px;
    font-weight: 850;
}

.admin-snapshot-btn-soft {
    color: var(--text-main);
    background: var(--panel-soft);
    border-color: var(--panel-border);
}

.admin-snapshot-btn-danger {
    grid-column: 1 / -1;
    color: #9f1d1d;
    background: #fff4f2;
    border-color: #f3b3ac;
}

.admin-snapshot-btn-danger:hover:not(:disabled) {
    background: #ffe2dd;
    border-color: #e67b70;
}

.admin-snapshot-btn:disabled,
.admin-snapshot-restore-btn:disabled {
    cursor: wait;
    opacity: 0.62;
}

.admin-snapshot-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.admin-snapshot-empty,
.admin-snapshot-item {
    background: var(--panel-raised);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    box-sizing: border-box;
}

.admin-snapshot-empty {
    padding: 12px;
    color: var(--text-muted);
    font-family: Inter, Arial, sans-serif;
    font-size: 12px;
    font-weight: 700;
    text-align: center;
}

.admin-snapshot-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    min-height: 58px;
    padding: 10px;
}

.admin-snapshot-item-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.admin-snapshot-delete-btn {
    color: #9f1d1d;
    background: #fff4f2;
    border-color: #f3b3ac;
}

.admin-snapshot-delete-btn:hover:not(:disabled) {
    background: #ffe2dd;
    border-color: #e67b70;
}

@media (max-width: 760px) {
    .topbar-tools {
        left: 12px;
    }

    .tools-menu-button {
        width: 42px;
        height: 40px;
        padding: 0;
    }

    .tools-menu-button span {
        display: none;
    }

    .tools-dropdown,
    .side-panel.expanded .tools-dropdown,
    .side-panel[data-active-panel="statistics"].expanded .tools-dropdown,
    .side-panel[data-active-panel="admin"].expanded .tools-dropdown {
        grid-template-columns: 1fr;
        width: min(330px, calc(100vw - 24px));
        max-width: calc(100vw - 24px);
    }

    .side-actions {
        width: auto;
    }

    .side-panel.expanded .side-content {
        border-top: 1px solid var(--panel-border);
        border-left: 0;
    }
}

@media (max-width: 560px) {
    .title {
        display: none;
    }

    .brand {
        gap: 0;
    }
}

@media (max-width: 420px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stats-grid div,
    .stats-grid div:first-child,
    .stats-grid div:nth-child(n+4) {
        grid-column: 1;
    }
}
