.history-widget {
    min-height: calc(100vh - 90px);
    padding: 32px;
    color: #f8fafc;
    background:
            radial-gradient(circle at top left, rgba(245, 158, 11, 0.18), transparent 32%),
            radial-gradient(circle at top right, rgba(59, 130, 246, 0.13), transparent 34%),
            linear-gradient(135deg, #020617 0%, #0f172a 52%, #1c1917 100%);
    border-radius: 28px;
    overflow: hidden;
}

.history-header {
    max-width: 1180px;
    margin: 0 auto 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
}

.history-kicker {
    display: inline-flex;
    align-items: center;
    padding: 7px 13px;
    border-radius: 999px;
    border: 1px solid rgba(251, 191, 36, 0.32);
    background: rgba(251, 191, 36, 0.1);
    color: #facc15;
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.history-header h2 {
    margin: 14px 0 8px;
    font-size: clamp(2.2rem, 5vw, 4rem);
    line-height: 1;
    letter-spacing: -0.06em;
    font-weight: 950;
}

.history-header p {
    margin: 0;
    max-width: 620px;
    color: #cbd5e1;
    font-size: 1rem;
    line-height: 1.7;
}

.history-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.history-icon-btn {
    width: 48px;
    height: 48px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 16px;
    background: rgba(15, 23, 42, 0.75);
    color: #f8fafc;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.history-icon-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    border-color: rgba(250, 204, 21, 0.55);
    background: rgba(251, 191, 36, 0.12);
}

.history-icon-btn:disabled,
.history-page-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.opponent-card {
    min-width: 230px;
    padding: 16px 18px;
    border-radius: 22px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(15, 23, 42, 0.68);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.24);
    backdrop-filter: blur(16px);
}

.opponent-card span,
.opponent-card small {
    display: block;
    color: #94a3b8;
    font-size: 0.8rem;
}

.opponent-card strong {
    display: block;
    margin: 4px 0;
    color: #fef3c7;
    font-size: 1.15rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-summary-grid {
    max-width: 1180px;
    margin: 0 auto 22px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.summary-card,
.history-game-card,
.history-loading-card,
.history-error-card,
.history-empty-card,
.history-empty-small {
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(15, 23, 42, 0.64);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(18px);
}

.summary-card {
    padding: 20px;
    border-radius: 22px;
}

.summary-card span {
    display: block;
    color: #94a3b8;
    font-size: 0.85rem;
    margin-bottom: 8px;
}

.summary-card strong {
    color: #f8fafc;
    font-size: 1.8rem;
    line-height: 1;
}

.history-games-grid {
    max-width: 1180px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px;
}

.history-game-card {
    position: relative;
    padding: 20px;
    border-radius: 26px;
    overflow: hidden;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.history-game-card::before {
    content: "";
    position: absolute;
    inset: 0;
    opacity: 0.16;
    pointer-events: none;
}

.history-game-card.res-win::before {
    background: radial-gradient(circle at top right, #22c55e, transparent 48%);
}

.history-game-card.res-lose::before {
    background: radial-gradient(circle at top right, #ef4444, transparent 48%);
}

.history-game-card.res-draw::before {
    background: radial-gradient(circle at top right, #f59e0b, transparent 48%);
}

.history-game-card:hover {
    transform: translateY(-5px);
    border-color: rgba(250, 204, 21, 0.35);
    box-shadow: 0 28px 90px rgba(0, 0, 0, 0.36);
}

.game-card-top,
.game-card-footer {
    position: relative;
    z-index: 1;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
}

.game-label {
    color: #94a3b8;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 800;
}

.game-card-top h3 {
    margin: 6px 0 0;
    color: #f8fafc;
    font-size: 1.1rem;
    font-weight: 850;
    word-break: break-word;
}

.result-pill {
    flex: 0 0 auto;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.result-pill.res-win {
    color: #bbf7d0;
    background: rgba(34, 197, 94, 0.14);
    border: 1px solid rgba(34, 197, 94, 0.24);
}

.result-pill.res-lose {
    color: #fecaca;
    background: rgba(239, 68, 68, 0.14);
    border: 1px solid rgba(239, 68, 68, 0.24);
}

.result-pill.res-draw {
    color: #fde68a;
    background: rgba(245, 158, 11, 0.14);
    border: 1px solid rgba(245, 158, 11, 0.24);
}

.game-card-body {
    position: relative;
    z-index: 1;
    display: grid;
    gap: 12px;
    margin: 22px 0;
}

.game-meta-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 16px;
    background: rgba(2, 6, 23, 0.35);
}

.meta-icon {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: rgba(251, 191, 36, 0.12);
}

.game-meta-item small {
    display: block;
    color: #94a3b8;
    font-size: 0.76rem;
}

.game-meta-item strong {
    display: block;
    color: #e5e7eb;
    font-size: 0.92rem;
}

.view-game-btn,
.history-primary-btn,
.history-secondary-btn,
.history-page-btn {
    min-height: 42px;
    padding: 0 16px;
    border-radius: 14px;
    font-weight: 850;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.view-game-btn,
.history-primary-btn {
    border: none;
    color: #111827;
    background: linear-gradient(135deg, #facc15, #f97316);
    box-shadow: 0 16px 34px rgba(249, 115, 22, 0.24);
}

.history-secondary-btn,
.history-page-btn {
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: #f8fafc;
    background: rgba(255, 255, 255, 0.07);
}

.view-game-btn:hover,
.history-primary-btn:hover,
.history-secondary-btn:hover,
.history-page-btn:hover:not(:disabled) {
    transform: translateY(-2px);
}

.game-id-preview {
    color: #64748b;
    font-size: 0.78rem;
    align-self: center;
}

.history-footer {
    max-width: 1180px;
    margin: 22px auto 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    padding: 18px;
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(2, 6, 23, 0.48);
    backdrop-filter: blur(18px);
}

.history-pager {
    display: flex;
    align-items: center;
    gap: 14px;
}

.page-indicator {
    color: #cbd5e1;
    font-size: 0.95rem;
}

.page-indicator strong {
    color: #fef3c7;
}

.history-loading-card,
.history-error-card {
    max-width: 620px;
    margin: 80px auto;
    padding: 26px;
    border-radius: 26px;
    display: flex;
    align-items: center;
    gap: 18px;
}

.history-loading-card h3,
.history-error-card h3,
.history-empty-card h2,
.history-empty-small h3 {
    margin: 0 0 6px;
    color: #f8fafc;
}

.history-loading-card p,
.history-error-card p,
.history-empty-card p,
.history-empty-small p {
    margin: 0;
    color: #cbd5e1;
    line-height: 1.6;
}

.history-spinner {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 4px solid rgba(255, 255, 255, 0.16);
    border-top-color: #facc15;
    animation: history-spin 0.9s linear infinite;
}

@keyframes history-spin {
     to {
         transform: rotate(360deg);
     }
 }

.error-icon {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 16px;
    background: rgba(239, 68, 68, 0.15);
    color: #fecaca;
    font-weight: 950;
    font-size: 1.3rem;
}

.history-empty-card,
.history-empty-small {
    max-width: 680px;
    margin: 70px auto;
    padding: 38px;
    border-radius: 30px;
    text-align: center;
}

.history-empty-small {
    margin: 28px auto;
}

.empty-chess-icon,
.history-empty-small > div {
    width: 76px;
    height: 76px;
    display: grid;
    place-items: center;
    margin: 0 auto 18px;
    border-radius: 24px;
    background: rgba(251, 191, 36, 0.12);
    color: #facc15;
    font-size: 2.5rem;
}

.empty-actions {
    display: flex;
    justify-content: center;
    gap: 14px;
    margin-top: 24px;
    flex-wrap: wrap;
}

@media (max-width: 1100px) {
    .history-games-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 860px) {
    .history-widget {
        padding: 22px;
    }

    .history-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .history-header-actions {
        width: 100%;
    }

    .opponent-card {
        flex: 1;
        min-width: 0;
    }

    .history-summary-grid {
        grid-template-columns: 1fr;
    }

    .history-games-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .history-footer {
        flex-direction: column;
        align-items: stretch;
    }

    .history-pager {
        justify-content: space-between;
    }
}

@media (max-width: 580px) {
    .history-widget {
        padding: 16px;
        border-radius: 20px;
    }

    .history-games-grid {
        grid-template-columns: 1fr;
    }

    .history-header-actions {
        align-items: stretch;
    }

    .history-icon-btn {
        width: 44px;
        height: auto;
    }

    .history-pager {
        flex-direction: column;
    }

    .history-page-btn,
    .history-secondary-btn,
    .history-primary-btn,
    .view-game-btn {
        width: 100%;
    }

    .game-card-footer {
        flex-direction: column;
        align-items: stretch;
    }
}
