:root {
    --bg: #0b1f17;
    --bg-2: #123528;
    --panel: rgba(18, 53, 40, 0.88);
    --ink: #f3f7f1;
    --muted: #9db5a8;
    --line: rgba(255, 255, 255, 0.1);
    --accent: #c8f542;
    --accent-2: #ff6b3d;
    --up: #7dffb3;
    --down: #ff8f8f;
    --on-accent: #102016;
    --shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
    --radius: 18px;
    --font: "Manrope", sans-serif;
    --display: "Bebas Neue", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: var(--font);
    color: var(--ink);
    background:
        radial-gradient(1200px 600px at 10% -10%, rgba(200, 245, 66, 0.16), transparent 55%),
        radial-gradient(900px 500px at 100% 0%, rgba(255, 107, 61, 0.18), transparent 50%),
        linear-gradient(160deg, var(--bg), var(--bg-2) 55%, #0a1812);
    background-attachment: fixed;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell { max-width: 920px; margin: 0 auto; padding: 1rem 1rem 3rem; }

.topbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1rem;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    padding: 0.85rem 1rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(8, 24, 18, 0.7);
    backdrop-filter: blur(10px);
}

.brand { display: flex; align-items: center; gap: 0.55rem; color: var(--ink); text-decoration: none; }
.brand-mark {
    width: 2rem; height: 2rem; border-radius: 50%;
    display: grid; place-items: center;
    background: var(--accent); color: var(--on-accent); font-weight: 800; font-size: 0.85rem;
}
.brand-text { font-family: var(--display); letter-spacing: 0.04em; font-size: 1.35rem; }

.nav { display: flex; flex-wrap: wrap; gap: 0.65rem; }
.nav a {
    color: var(--muted);
    font-weight: 700;
    font-size: 0.92rem;
    text-decoration: none;
    padding: 0.25rem 0.45rem;
}
.nav a.active, .nav a:hover { color: var(--ink); }

.user-chip { display: flex; align-items: center; gap: 0.6rem; color: var(--muted); font-size: 0.9rem; }
.nav-user { display: inline-flex; text-decoration: none; }
.nav-user:hover { text-decoration: none; }
.avatar-nav {
    width: 2.15rem;
    height: 2.15rem;
    border: 2px solid rgba(200, 245, 66, 0.45);
}
.inline { display: inline; }
.linkish {
    background: none; border: none; color: var(--accent); cursor: pointer;
    font: inherit; padding: 0; text-decoration: underline;
}

.main { animation: rise 0.45s ease both; }
@keyframes rise {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: none; }
}

.page-head { margin-bottom: 1.25rem; }
.page-head.row-between { display: flex; justify-content: space-between; align-items: end; gap: 1rem; }
.eyebrow {
    margin: 0 0 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-size: 0.75rem;
    color: var(--accent);
    font-weight: 800;
}
h1 {
    margin: 0;
    font-family: var(--display);
    font-size: clamp(2.4rem, 8vw, 3.6rem);
    letter-spacing: 0.03em;
    line-height: 0.95;
}
h2 { margin: 0 0 0.85rem; font-size: 1.15rem; }
.lede { color: var(--muted); margin: 0.45rem 0 0; max-width: 36rem; }
.points-big { color: var(--accent); font-weight: 800; font-size: 1.4rem; }

.section { margin-top: 2rem; }
.empty, .muted, .hint { color: var(--muted); }
.hint { font-size: 0.85rem; margin-top: 1rem; }

.ranking-list { display: grid; gap: 0.55rem; }
.rank-row {
    display: grid;
    grid-template-columns: 2.2rem 2.5rem 1fr auto auto auto;
    gap: 0.75rem;
    align-items: center;
    padding: 0.9rem 1rem;
    border-radius: var(--radius);
    background: var(--panel);
    border: 1px solid var(--line);
    color: inherit;
    text-decoration: none;
    transition: transform 0.15s ease, border-color 0.15s ease;
}
.avatar {
    width: 2.4rem;
    height: 2.4rem;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--line);
    background: rgba(0, 0, 0, 0.25);
    display: inline-block;
}
.avatar-lg { width: 4.5rem; height: 4.5rem; }
.avatar-xl { width: 5.5rem; height: 5.5rem; flex-shrink: 0; }
.avatar-fallback {
    display: grid;
    place-items: center;
    font-weight: 800;
    color: var(--accent);
    background: rgba(200, 245, 66, 0.15);
}
.avatar-edit { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.player-hero { display: flex; gap: 1rem; align-items: center; }
.avatar-picker {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 0.85rem;
    margin: 0;
}
.avatar-picker legend {
    padding: 0 0.35rem;
    font-weight: 800;
}
.avatar-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(3.4rem, 1fr));
    gap: 0.55rem;
    margin-top: 0.55rem;
    max-height: 18rem;
    overflow-y: auto;
    padding: 0.15rem;
}
.avatar-option {
    position: relative;
    cursor: pointer;
    margin: 0;
}
.avatar-option input {
    position: absolute;
    opacity: 0;
    inset: 0;
    cursor: pointer;
}
.avatar-pick {
    width: 3.2rem;
    height: 3.2rem;
    display: grid;
    place-items: center;
    transition: transform 0.12s ease, box-shadow 0.12s ease, outline-color 0.12s ease;
    outline: 2px solid transparent;
}
.avatar-option input:checked + .avatar-pick,
.avatar-option input:checked + img.avatar-pick {
    outline-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(200, 245, 66, 0.25);
    transform: scale(1.06);
}
.avatar-option:hover .avatar-pick {
    transform: scale(1.04);
}
.rank-meta {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
}
.rank-row:hover {
    transform: translateY(-2px);
    border-color: rgba(200, 245, 66, 0.35);
    text-decoration: none;
}
.rank-pos {
    width: 2rem; height: 2rem; border-radius: 50%;
    display: grid; place-items: center;
    background: rgba(200, 245, 66, 0.15);
    color: var(--accent); font-weight: 800;
}
.rank-name { font-weight: 700; }
.rank-points {
    font-family: var(--display);
    font-size: 1.6rem;
    letter-spacing: 0.03em;
    min-width: 2.5rem;
    text-align: right;
}
.rank-week { font-size: 0.85rem; font-weight: 700; }
.rank-badge {
    display: grid;
    place-items: center;
    min-width: 1.8rem;
}
.up { color: var(--up); }
.down { color: var(--down); }

.score-badge {
    display: inline-grid;
    place-items: center;
    width: 1.85rem;
    height: 1.85rem;
    border-radius: 50%;
    flex-shrink: 0;
    border: none;
    padding: 0;
    cursor: pointer;
    font: inherit;
    background: transparent;
    transition: transform 0.15s ease, filter 0.15s ease;
}
.score-badge:hover { transform: scale(1.1); filter: brightness(1.08); }
.score-badge-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    pointer-events: none;
}
.score-badge--lg { width: 2.25rem; height: 2.25rem; }
.badge-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem 0.9rem;
    align-items: center;
    margin: 0.75rem 0 0;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
}
.badge-legend .score-badge { margin-right: 0.15rem; }

.score-modal {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: grid;
    place-items: center;
    padding: 1.25rem;
}
.score-modal[hidden] { display: none !important; }
.score-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(4, 12, 8, 0.72);
    backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 0.28s ease;
}
.score-modal-dialog {
    position: relative;
    z-index: 1;
    width: min(100%, 420px);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: calc(var(--radius) + 8px);
    box-shadow: var(--shadow);
    padding: 1.6rem 1.35rem 1.4rem;
    text-align: center;
    opacity: 0;
    transform: translateY(18px) scale(0.94);
    transition: opacity 0.28s ease, transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}
.score-modal.is-open .score-modal-backdrop { opacity: 1; }
.score-modal.is-open .score-modal-dialog {
    opacity: 1;
    transform: translateY(0) scale(1);
}
.score-modal.is-closing .score-modal-backdrop { opacity: 0; }
.score-modal.is-closing .score-modal-dialog {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
}
.score-modal-close {
    position: absolute;
    top: 0.55rem;
    right: 0.7rem;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
}
.score-modal-close:hover { color: var(--ink); }
.score-modal-icon {
    width: 7rem;
    height: 7rem;
    margin: 0.2rem auto 1rem;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: transparent;
}
.score-modal-icon .score-badge-img,
.score-modal-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}
.score-modal-title {
    margin: 0 0 0.55rem;
    font-family: var(--display);
    font-size: 2.2rem;
    letter-spacing: 0.03em;
    line-height: 1;
}
.score-modal-desc {
    margin: 0;
    color: var(--muted);
    font-size: 0.98rem;
    line-height: 1.45;
}

.form-panel, .duel-card, .login-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: calc(var(--radius) + 4px);
    padding: 1.15rem;
    box-shadow: var(--shadow);
}

.stack { display: grid; gap: 0.9rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.85rem; }
label { display: grid; gap: 0.35rem; font-weight: 700; font-size: 0.92rem; }
input, select, button, textarea {
    font: inherit;
}
input, select {
    width: 100%;
    border: 1px solid var(--line);
    background: rgba(0, 0, 0, 0.25);
    color: var(--ink);
    border-radius: 12px;
    padding: 0.75rem 0.85rem;
}
input:focus, select:focus {
    outline: 2px solid rgba(200, 245, 66, 0.45);
    outline-offset: 1px;
}
.check {
    display: flex; align-items: center; gap: 0.55rem;
    font-weight: 600; color: var(--muted);
}
.check input { width: auto; }
.inline-check { display: inline-flex; margin-right: 0.5rem; }

.actions { display: flex; flex-wrap: wrap; gap: 0.65rem; }
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    border: none; border-radius: 999px;
    padding: 0.75rem 1.15rem;
    font-weight: 800;
    cursor: pointer;
    text-decoration: none;
}
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { filter: brightness(1.05); text-decoration: none; }
.btn-ghost {
    background: transparent; color: var(--ink);
    border: 1px solid var(--line);
}
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.85rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.alert {
    padding: 0.85rem 1rem;
    border-radius: 14px;
    margin-bottom: 1rem;
    font-weight: 600;
}
.alert-success { background: rgba(125, 255, 179, 0.12); color: var(--up); }
.alert-error { background: rgba(255, 143, 143, 0.12); color: var(--down); }

.preview-box {
    border: 1px dashed rgba(200, 245, 66, 0.4);
    border-radius: 14px;
    padding: 0.9rem 1rem;
    background: rgba(200, 245, 66, 0.06);
}
.preview-box h3 { margin: 0 0 0.35rem; }

.event-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.55rem; }
.event-list li {
    display: flex; flex-wrap: wrap; gap: 0.45rem 0.7rem; align-items: center;
    padding: 0.75rem 0.9rem;
    border-radius: 14px;
    background: rgba(0, 0, 0, 0.18);
    border: 1px solid var(--line);
}
.match-no-item {
    display: inline-grid;
    place-items: center;
    width: 1.85rem;
    height: 1.85rem;
    color: var(--muted);
    font-weight: 800;
}

.tag {
    display: inline-flex;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: rgba(255, 255, 255, 0.08);
    color: var(--muted);
}
.tag-remount { background: rgba(200, 245, 66, 0.15); color: var(--accent); }
.tag-win { background: rgba(196, 125, 255, 0.18); color: #d7b3ff; }
.tag-repeat_win { background: rgba(125, 255, 179, 0.15); color: var(--up); }
.tag-improve { background: rgba(255, 107, 61, 0.15); color: var(--accent-2); }
.tag-buff { background: rgba(125, 255, 179, 0.18); color: var(--up); }
.tag-nerf { background: rgba(255, 107, 61, 0.18); color: var(--accent-2); }
.tag-baseline { background: rgba(255, 255, 255, 0.08); color: var(--muted); }

.duel-list { display: grid; gap: 0.75rem; }
.duel-names {
    display: flex; flex-wrap: wrap; gap: 0.4rem 0.65rem;
    align-items: center; font-weight: 800; font-size: 1.05rem;
}
.vs { color: var(--muted); font-size: 0.85rem; font-weight: 700; }
.duel-score {
    font-family: var(--display);
    font-size: 2rem;
    letter-spacing: 0.04em;
    margin: 0.35rem 0;
}
.revancha {
    margin: 0.4rem 0 0;
    color: var(--accent-2);
    font-weight: 800;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.matrix-wrap {
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(0, 0, 0, 0.18);
    max-width: 100%;
}
.matrix-table {
    border-collapse: separate;
    border-spacing: 0;
    min-width: 100%;
    font-size: 0.78rem;
}
.matrix-table th,
.matrix-table td {
    padding: 0.45rem 0.4rem;
    text-align: center;
    white-space: nowrap;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}
.matrix-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #0f2a1f;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: none;
    letter-spacing: 0;
    min-width: 3.6rem;
    vertical-align: bottom;
}
.matrix-table tbody th {
    position: sticky;
    left: 0;
    z-index: 1;
    background: #0f2a1f;
    color: var(--ink);
    font-weight: 800;
    text-align: center;
    padding: 0.45rem 0.55rem;
    min-width: 4.8rem;
    vertical-align: middle;
}
.matrix-player {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    pointer-events: none;
    line-height: 1;
}
.matrix-row-head .matrix-player {
    width: 100%;
    min-height: 100%;
}
.avatar-matrix {
    width: 1.85rem;
    height: 1.85rem;
    font-size: 0.75rem;
    flex-shrink: 0;
}
.matrix-player-name {
    line-height: 1.1;
    max-width: 4.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
}
.matrix-corner {
    position: sticky;
    left: 0;
    top: 0;
    z-index: 3 !important;
}
.matrix-diag {
    color: var(--muted);
    background: rgba(255, 255, 255, 0.03);
}
.matrix-empty { color: rgba(157, 181, 168, 0.45); }
.matrix-cell {
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}
.matrix-win {
    background: rgba(125, 255, 179, 0.14);
    color: var(--up);
}
.matrix-loss {
    background: rgba(255, 143, 143, 0.12);
    color: var(--down);
}
.matrix-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem 1rem;
    margin-top: 0.75rem;
}
.matrix-swatch {
    display: inline-block;
    width: 0.85rem;
    height: 0.85rem;
    border-radius: 4px;
    margin-right: 0.3rem;
    vertical-align: -0.1rem;
}

.matrix-col-head,
.matrix-row-head,
.matrix-cell,
.matrix-empty {
    cursor: pointer;
}
.matrix-corner { cursor: pointer; }

.matrix-table td.hl-row,
.matrix-table th.hl-row {
    box-shadow: inset 0 2px 0 0 var(--accent), inset 0 -2px 0 0 var(--accent);
}
.matrix-table td.hl-col,
.matrix-table th.hl-col {
    box-shadow: inset 2px 0 0 0 var(--accent), inset -2px 0 0 0 var(--accent);
}
.matrix-table td.hl-row.hl-col,
.matrix-table th.hl-row.hl-col {
    box-shadow:
        inset 0 0 0 2px var(--accent),
        0 0 0 1px rgba(200, 245, 66, 0.35);
    outline: 2px solid var(--accent);
    outline-offset: -2px;
    z-index: 1;
    position: relative;
}
.matrix-col-head.hl-pick,
.matrix-row-head.hl-pick {
    color: var(--accent);
    background: rgba(200, 245, 66, 0.12);
}

.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--line); }
.table { width: 100%; border-collapse: collapse; background: rgba(0, 0, 0, 0.18); }
.table th, .table td { padding: 0.75rem 0.85rem; text-align: left; border-bottom: 1px solid var(--line); }
.table th { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; }

.credit-vecteezy {
    margin: 2rem 0 0;
    text-align: center;
    color: var(--muted);
    font-size: 0.78rem;
}
.credit-vecteezy a { color: var(--muted); text-decoration: underline; }

.login-hero {
    min-height: calc(100vh - 2rem);
    display: grid;
    place-items: center;
    padding: 1rem 0;
}
.login-card { width: min(100%, 420px); }
.login-brand {
    display: grid;
    justify-items: center;
    gap: 0.75rem;
    margin-bottom: 0.35rem;
    text-align: center;
}
.login-logo {
    width: 96px;
    height: 96px;
    object-fit: contain;
    filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.35));
}
.login-card h1 {
    margin: 0;
    font-size: clamp(2.2rem, 9vw, 3.2rem);
    text-align: center;
}
.login-actions { margin-top: 0.15rem; }
.guest-form {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--line);
    display: grid;
    gap: 0.55rem;
}
.btn-block { width: 100%; }
.guest-label {
    font-weight: 800;
    font-size: 0.85rem;
    color: var(--accent-2);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.rank-row-static { cursor: default; }
.rank-row-static:hover {
    transform: none;
    border-color: var(--line);
}

@media (max-width: 640px) {
    .topbar { border-radius: 22px; }
    .grid-2 { grid-template-columns: 1fr; }
    .rank-row { grid-template-columns: 2rem 2.2rem 1fr auto auto; }
    .rank-row .rank-week { display: none; }
    .player-hero { flex-direction: row; }
    .rank-week { display: none; }
    .user-chip span { display: none; }
}
