:root {
    --rank-bg: #07111f;
    --rank-bg-2: #0b1730;
    --rank-panel: rgba(10, 18, 36, 0.92);
    --rank-panel-2: rgba(12, 24, 47, 0.94);
    --rank-border: rgba(96, 165, 250, 0.16);
    --rank-text: #ecf4ff;
    --rank-muted: #9eb0cb;
    --rank-blue: #3b82f6;
    --rank-teal: #14b8a6;
    --rank-gold: #f59e0b;
    --rank-silver: #cbd5e1;
    --rank-bronze: #fb923c;
    --rank-danger: #f87171;
}

* {
    box-sizing: border-box;
    font-family: "Trebuchet MS", "Segoe UI", sans-serif;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, 0.3), transparent 24%),
        radial-gradient(circle at top right, rgba(20, 184, 166, 0.16), transparent 22%),
        linear-gradient(180deg, #040914 0%, #07111f 36%, #09182e 100%);
    color: var(--rank-text);
}

.container {
    max-width: 1060px;
    margin: 32px auto;
    background: linear-gradient(180deg, rgba(10, 18, 36, 0.95) 0%, rgba(8, 17, 34, 0.9) 100%);
    border-radius: 30px;
    padding: 28px;
    box-shadow: 0 30px 90px rgba(2, 6, 23, 0.46);
    border: 1px solid rgba(148, 163, 184, 0.14);
    position: relative;
    overflow: hidden;
}

.container::before {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at top right, rgba(96, 165, 250, 0.12), transparent 30%);
    pointer-events: none;
}

.history-page .container {
    max-width: 1240px;
}

h1 {
    margin-top: 0;
    margin-bottom: 12px;
    font-size: clamp(34px, 4vw, 48px);
    letter-spacing: -0.05em;
    color: #f8fbff;
}

.subtitle {
    color: var(--rank-muted);
    line-height: 1.65;
    margin-bottom: 24px;
    max-width: 720px;
}

.toolbar,
.topbar {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.topbar {
    justify-content: flex-end;
    margin-bottom: 20px;
}

.toolbar {
    margin-bottom: 24px;
}

.section-title {
    margin: 32px 0 16px;
    font-size: 24px;
    color: #f4f8ff;
    letter-spacing: -0.03em;
}

.button-link,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 13px 18px;
    border: none;
    border-radius: 16px;
    font-size: 15px;
    cursor: pointer;
    background: linear-gradient(135deg, #2563eb 0%, #3b82f6 100%);
    color: white;
    font-weight: 800;
    text-decoration: none;
    box-shadow: 0 16px 28px rgba(37, 99, 235, 0.24);
    transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.button-link:hover,
button:hover {
    transform: translateY(-2px);
    filter: brightness(1.05);
}

.button-secondary {
    background: linear-gradient(135deg, #0f766e 0%, #14b8a6 100%);
    box-shadow: 0 16px 28px rgba(20, 184, 166, 0.18);
}

.status {
    padding: 14px 16px;
    border-radius: 16px;
    font-weight: 800;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.info {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.14) 0%, rgba(10, 18, 36, 0.9) 100%);
    color: #d9e8ff;
    border: 1px solid rgba(96, 165, 250, 0.24);
}

.error {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.14) 0%, rgba(28, 12, 18, 0.9) 100%);
    color: #ffd4d4;
    border: 1px solid rgba(248, 113, 113, 0.28);
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    overflow: hidden;
    border-radius: 22px;
    border: 1px solid var(--rank-border);
    background: rgba(8, 15, 30, 0.72);
    box-shadow: 0 18px 34px rgba(2, 6, 23, 0.24);
}

thead {
    background: linear-gradient(135deg, rgba(16, 33, 65, 0.98) 0%, rgba(13, 25, 49, 0.98) 100%);
}

th,
td {
    padding: 16px 16px;
    text-align: left;
    border-bottom: 1px solid rgba(96, 165, 250, 0.08);
    vertical-align: middle;
}

th {
    color: #b6daff;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    white-space: normal;
    overflow-wrap: normal;
    word-break: normal;
    hyphens: none;
}

td {
    color: #edf4ff;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.history-table th {
    white-space: nowrap;
}

tbody tr {
    background: rgba(8, 15, 30, 0.66);
    transition: transform 0.18s ease, background 0.18s ease;
}

tbody tr:nth-child(even) {
    background: rgba(10, 18, 36, 0.82);
}

tbody tr:hover {
    background: rgba(17, 30, 58, 0.96);
}

.rank-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    height: 38px;
    border-radius: 999px;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.22) 0%, rgba(37, 99, 235, 0.18) 100%);
    color: #dcecff;
    font-weight: 900;
    box-shadow: inset 0 0 0 1px rgba(96, 165, 250, 0.16);
}

.title-badge {
    display: inline-flex;
    align-items: center;
    padding: 8px 12px;
    border-radius: 999px;
    font-weight: 800;
    font-size: 12px;
    white-space: nowrap;
}

.title-badge-contested {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.18) 0%, rgba(17, 30, 58, 0.92) 100%);
    color: #ffe0a1;
    border: 1px solid rgba(245, 158, 11, 0.22);
}

.title-badge-muted {
    background: linear-gradient(135deg, rgba(118, 89, 28, 0.18) 0%, rgba(17, 30, 58, 0.92) 100%);
    color: #b89b62;
    border: 1px solid rgba(133, 102, 37, 0.2);
}

.title-badge-training {
    background: linear-gradient(135deg, rgba(76, 63, 34, 0.12) 0%, rgba(16, 25, 44, 0.92) 100%);
    color: #85724c;
    border: 1px solid rgba(98, 82, 46, 0.14);
}

.title-stack {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.empty-state {
    padding: 18px;
    border: 1px dashed rgba(96, 165, 250, 0.18);
    border-radius: 16px;
    background: rgba(8, 15, 30, 0.68);
    color: var(--rank-muted);
}

.hidden {
    display: none !important;
}

.top-rank {
    position: relative;
}

.top-rank-gold {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.2) 0%, rgba(17, 30, 58, 0.98) 50%, rgba(245, 158, 11, 0.08) 100%);
    box-shadow: inset 0 0 0 1px rgba(245, 158, 11, 0.24), 0 0 0 1px rgba(245, 158, 11, 0.08);
}

.top-rank-silver {
    background: linear-gradient(135deg, rgba(203, 213, 225, 0.16) 0%, rgba(17, 30, 58, 0.98) 50%, rgba(203, 213, 225, 0.08) 100%);
    box-shadow: inset 0 0 0 1px rgba(203, 213, 225, 0.18), 0 0 0 1px rgba(203, 213, 225, 0.08);
}

.top-rank-bronze {
    background: linear-gradient(135deg, rgba(251, 146, 60, 0.18) 0%, rgba(17, 30, 58, 0.98) 50%, rgba(251, 146, 60, 0.08) 100%);
    box-shadow: inset 0 0 0 1px rgba(251, 146, 60, 0.2), 0 0 0 1px rgba(251, 146, 60, 0.08);
}

.top-rank-gold .rank-badge {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.38) 0%, rgba(251, 191, 36, 0.2) 100%);
    color: #fff1ca;
    box-shadow: inset 0 0 0 1px rgba(251, 191, 36, 0.24), 0 8px 18px rgba(245, 158, 11, 0.18);
}

.top-rank-silver .rank-badge {
    background: linear-gradient(135deg, rgba(203, 213, 225, 0.32) 0%, rgba(148, 163, 184, 0.18) 100%);
    color: #f8fbff;
    box-shadow: inset 0 0 0 1px rgba(226, 232, 240, 0.22), 0 8px 18px rgba(148, 163, 184, 0.14);
}

.top-rank-bronze .rank-badge {
    background: linear-gradient(135deg, rgba(251, 146, 60, 0.32) 0%, rgba(194, 65, 12, 0.16) 100%);
    color: #ffe3d1;
    box-shadow: inset 0 0 0 1px rgba(251, 146, 60, 0.2), 0 8px 18px rgba(194, 65, 12, 0.16);
}

.current-user-row {
    box-shadow: inset 3px 0 0 rgba(20, 184, 166, 0.95), inset 0 0 0 1px rgba(20, 184, 166, 0.2);
    background: linear-gradient(135deg, rgba(20, 184, 166, 0.14) 0%, rgba(12, 24, 47, 0.96) 100%);
}

.current-room-row {
    box-shadow: inset 3px 0 0 rgba(96, 165, 250, 0.92), inset 0 0 0 1px rgba(96, 165, 250, 0.16);
}

.panel-badge {
    display: inline-flex;
    align-items: center;
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(59, 130, 246, 0.14);
    border: 1px solid rgba(96, 165, 250, 0.18);
    color: #9fd1ff;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    margin-bottom: 10px;
}

.my-ranking-card {
    margin-top: 18px;
    padding: 22px;
    border-radius: 24px;
    background: linear-gradient(180deg, rgba(10, 18, 36, 0.94) 0%, rgba(8, 17, 34, 0.88) 100%);
    border: 1px solid rgba(20, 184, 166, 0.16);
    box-shadow: 0 20px 40px rgba(2, 6, 23, 0.26);
}

.my-ranking-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 18px;
}

.my-ranking-header h3 {
    margin: 0;
    font-size: 22px;
    letter-spacing: -0.03em;
}

.my-ranking-hint {
    max-width: 320px;
    color: var(--rank-muted);
    line-height: 1.5;
    text-align: right;
}

.my-ranking-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.my-ranking-item {
    padding: 14px 15px;
    border-radius: 18px;
    background: rgba(8, 15, 30, 0.72);
    border: 1px solid rgba(96, 165, 250, 0.12);
}

.my-ranking-item strong {
    display: block;
    font-size: 17px;
    color: #f8fbff;
}

.my-ranking-titles .title-stack {
    gap: 7px;
}

.my-ranking-titles .title-badge {
    font-size: 11px;
    padding: 7px 10px;
}

.my-ranking-label {
    display: block;
    margin-bottom: 6px;
    color: var(--rank-muted);
    font-size: 12px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-weight: 700;
}

.title-board {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin-top: 8px;
}

.title-card {
    padding: 18px;
    border-radius: 22px;
    background: linear-gradient(180deg, rgba(10, 18, 36, 0.94) 0%, rgba(8, 17, 34, 0.88) 100%);
    border: 1px solid rgba(96, 165, 250, 0.14);
    box-shadow: 0 18px 34px rgba(2, 6, 23, 0.22);
}

.title-card-name {
    font-size: 18px;
    font-weight: 900;
    letter-spacing: -0.02em;
    color: #ffe0a1;
    margin-bottom: 14px;
}

.title-card-holders {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.title-holder {
    padding: 12px 13px;
    border-radius: 16px;
    background: rgba(8, 15, 30, 0.72);
    border: 1px solid rgba(96, 165, 250, 0.12);
}

.title-holder strong {
    display: block;
    margin-bottom: 4px;
    color: #f8fbff;
}

.title-holder span {
    color: var(--rank-muted);
    font-size: 13px;
    line-height: 1.45;
}

.title-holder.empty {
    color: var(--rank-muted);
    font-weight: 700;
}

.room-link-button {
    padding: 0;
    border: none;
    background: transparent;
    color: #7dd3fc;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
    box-shadow: none;
}

.room-link-button:hover {
    background: transparent;
    color: #a5f3fc;
    text-decoration: underline;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(2, 6, 23, 0.8);
    z-index: 30;
}

.modal-card {
    width: min(100%, 820px);
    max-height: 90vh;
    overflow: auto;
    background: linear-gradient(180deg, rgba(10, 18, 36, 0.98) 0%, rgba(8, 17, 34, 0.96) 100%);
    border-radius: 28px;
    padding: 24px;
    box-shadow: 0 30px 80px rgba(2, 6, 23, 0.5);
    border: 1px solid rgba(96, 165, 250, 0.16);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
}

.modal-badge {
    display: inline-flex;
    align-items: center;
    padding: 9px 14px;
    border-radius: 999px;
    background: rgba(59, 130, 246, 0.14);
    border: 1px solid rgba(96, 165, 250, 0.18);
    color: #9fd1ff;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    margin-bottom: 12px;
}

@media (max-width: 860px) {
    .container {
        margin: 16px;
        padding: 20px;
        border-radius: 24px;
    }

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

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

@media (max-width: 680px) {
    .modal-card {
        padding: 18px;
    }

    .modal-header {
        flex-direction: column;
    }

    .my-ranking-header {
        flex-direction: column;
    }

    .my-ranking-hint {
        max-width: none;
        text-align: left;
    }

    .my-ranking-grid {
        grid-template-columns: 1fr;
    }

    .title-board {
        grid-template-columns: 1fr;
    }

    table,
    thead,
    tbody,
    th,
    td,
    tr {
        display: block;
    }

    thead {
        display: none;
    }

    tbody tr {
        border: 1px solid rgba(96, 165, 250, 0.12);
        border-radius: 18px;
        margin-bottom: 14px;
        padding: 10px 0;
        overflow: hidden;
    }

    td {
        border-bottom: none;
        padding: 9px 12px;
    }

    td::before {
        content: attr(data-label);
        display: block;
        font-size: 11px;
        font-weight: 800;
        color: #8ea5c9;
        text-transform: uppercase;
        letter-spacing: 0.12em;
        margin-bottom: 4px;
    }
}
