:root {
    color-scheme: light;
    --ink: #07111f;
    --muted: #9aa8bb;
    --line: #253a58;
    --paper: #08182f;
    --panel: #ffffff;
    --primary: #123f7a;
    --primary-ink: #ffffff;
    --accent: #1f6feb;
    --soft-blue: #142a49;
    --steel: #263547;
    --shadow: 0 22px 55px rgba(3, 8, 16, 0.28);
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at 18% 10%, rgba(31, 111, 235, 0.18), transparent 30%),
        radial-gradient(circle at 82% 18%, rgba(18, 63, 122, 0.26), transparent 28%),
        linear-gradient(180deg, #0e2442 0%, var(--paper) 48%, #061122 100%);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0;
}

a {
    color: inherit;
    text-decoration: none;
}

.pwa-install-btn {
    position: fixed;
    right: max(14px, env(safe-area-inset-right));
    bottom: max(14px, env(safe-area-inset-bottom));
    z-index: 45;
    display: grid;
    gap: 2px;
    min-width: min(250px, calc(100vw - 28px));
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 8px;
    padding: 13px 16px;
    background: linear-gradient(135deg, #07111f, #123f7a 70%, #1f6feb);
    color: #fff;
    box-shadow: 0 18px 42px rgba(7, 17, 31, 0.34), var(--shadow);
    text-align: left;
}

.pwa-install-btn span {
    color: rgba(255, 255, 255, 0.76);
    font-size: 12px;
    font-weight: 700;
}

.pwa-install-btn strong {
    font-size: 16px;
}

.pwa-install-help {
    position: fixed;
    right: max(14px, env(safe-area-inset-right));
    bottom: calc(max(14px, env(safe-area-inset-bottom)) + 78px);
    z-index: 46;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    width: min(430px, calc(100vw - 28px));
    border: 1px solid #7f9fca;
    border-radius: 8px;
    padding: 14px;
    background: #f8fbff;
    box-shadow: var(--shadow);
}

.pwa-install-help strong {
    color: var(--ink);
}

.pwa-install-help p {
    margin-top: 5px;
    font-size: 14px;
}

.install-close {
    display: inline-flex;
    width: 32px;
    height: 32px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #e8eef6;
    color: var(--ink);
    cursor: pointer;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 14px;
    align-items: center;
    padding: 14px clamp(16px, 4vw, 40px);
    border-bottom: 1px solid var(--line);
    background: rgba(8, 24, 47, 0.9);
    backdrop-filter: blur(12px);
}

.brand {
    font-weight: 800;
    color: #f8fbff;
}

.nav {
    display: flex;
    gap: 12px;
    align-items: center;
    font-size: 14px;
    color: #d7e1ef;
}

.inline-form {
    margin: 0;
}

.inline-form button {
    border: 0;
    padding: 0;
    background: transparent;
    color: #d7e1ef;
    cursor: pointer;
}

.inline-form .logout-btn {
    border: 1px solid rgba(248, 113, 113, 0.5);
    border-radius: 8px;
    padding: 8px 11px;
    background: rgba(127, 29, 29, 0.9);
    color: #fff;
    font-weight: 800;
}

.inline-form .logout-btn:hover {
    background: #b91c1c;
}

input,
select,
button {
    font: inherit;
}

input,
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: #07111f;
}

.lang {
    display: flex;
    gap: 6px;
    align-items: center;
}

.flag-link {
    display: inline-flex;
    width: 38px;
    height: 38px;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    line-height: 1;
}

.flag-link:hover,
.flag-link.active {
    border-color: #74a6ee;
    background: var(--soft-blue);
    box-shadow: 0 8px 20px rgba(18, 63, 122, 0.18);
}

.flag {
    display: block;
    position: relative;
    width: 24px;
    height: 17px;
    overflow: hidden;
    border-radius: 3px;
    box-shadow: inset 0 0 0 1px rgba(16, 32, 51, 0.16);
}

.flag-pl {
    background: linear-gradient(#ffffff 0 50%, #dc143c 50% 100%);
}

.flag-ua {
    background: linear-gradient(#005bbb 0 50%, #ffd500 50% 100%);
}

.flag-de {
    background: linear-gradient(#000000 0 33%, #dd0000 33% 66%, #ffce00 66% 100%);
}

.flag-gb {
    background:
        linear-gradient(26deg, transparent 0 39%, #ffffff 39% 45%, #c8102e 45% 53%, #ffffff 53% 59%, transparent 59%),
        linear-gradient(154deg, transparent 0 39%, #ffffff 39% 45%, #c8102e 45% 53%, #ffffff 53% 59%, transparent 59%),
        linear-gradient(90deg, transparent 0 36%, #ffffff 36% 64%, transparent 64%),
        linear-gradient(transparent 0 27%, #ffffff 27% 73%, transparent 73%),
        linear-gradient(90deg, transparent 0 43%, #c8102e 43% 57%, transparent 57%),
        linear-gradient(transparent 0 38%, #c8102e 38% 62%, transparent 62%),
        #012169;
}

.flag-img {
    object-fit: cover;
}

.shell {
    width: min(1040px, 100%);
    margin: 0 auto;
    padding: clamp(18px, 4vw, 42px);
}

.hero {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(260px, 0.8fr);
    gap: clamp(22px, 6vw, 64px);
    align-items: center;
    min-height: calc(100svh - 170px);
}

.eyebrow {
    color: var(--accent);
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
}

.hero h1 {
    color: #f8fbff;
}

.hero p {
    color: #c3cfdd;
}

h1 {
    margin: 0 0 14px;
    font-size: clamp(34px, 7vw, 68px);
    line-height: 0.98;
}

h2 {
    margin: 0 0 8px;
    font-size: 18px;
}

p {
    margin: 0;
    color: var(--muted);
    line-height: 1.6;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 28px;
}

.button {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 16px;
    background: #ffffff;
    color: #07111f;
    font-weight: 750;
    cursor: pointer;
}

.button.small {
    min-height: 38px;
    padding: 8px 13px;
    font-size: 14px;
}

.collapse-button {
    border-color: #93c5fd;
    background: #dbeafe;
    color: #1d4ed8;
}

.collapse-button.is-open {
    border-color: #fbbf24;
    background: #fef3c7;
    color: #92400e;
}

.button.primary {
    border-color: var(--primary);
    background: linear-gradient(135deg, #10233b, #123f7a 62%, #1f6feb);
    color: var(--primary-ink);
    box-shadow: 0 12px 28px rgba(18, 63, 122, 0.28);
}

.score-card,
.panel,
.features article,
.tournament-item,
.empty {
    border: 1px solid rgba(184, 196, 212, 0.72);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: var(--shadow);
}

.features article {
    background: linear-gradient(180deg, #ffffff 0%, #edf2f8 100%);
}

.score-card {
    display: grid;
    gap: 12px;
    padding: 18px;
}

.score-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 64px;
    border-bottom: 1px solid var(--line);
}

.score-row:last-child {
    border-bottom: 0;
}

.score-row span {
    color: var(--muted);
}

.score-row strong {
    font-size: 32px;
    color: #123f7a;
}

.features {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}

.features article,
.panel,
.empty,
.tournament-item {
    padding: 18px;
}

.panel {
    margin: 0 auto;
}

.panel.narrow {
    max-width: 480px;
}

.form {
    display: grid;
    gap: 16px;
}

.form label,
fieldset {
    display: grid;
    gap: 7px;
    min-width: 0;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
}

.check-line {
    display: inline-flex;
    grid-template-columns: none;
    gap: 10px;
    align-items: center;
    justify-content: flex-start;
    width: fit-content;
    border: 1px solid #c8d4e4;
    border-radius: 8px;
    padding: 10px 12px;
    background: #f8fbff;
    color: #123f7a;
    font-weight: 800;
}

.check-line input {
    width: 18px;
    height: 18px;
    min-height: 18px;
    margin: 0;
}

input,
select {
    min-height: 46px;
    padding: 10px 12px;
}

fieldset {
    margin: 0;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
}

legend {
    padding: 0 6px;
}

.grid-three {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

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

.workbench {
    align-items: start;
    margin-bottom: 14px;
}

.inline-add {
    margin-top: 12px;
}

.round-robin-form {
    margin: 12px 0 16px;
}

.form-warning {
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 10px 12px;
    background: #fff1f2;
    color: #991b1b;
    font-weight: 800;
}

.simple-list {
    display: grid;
    gap: 8px;
    margin: 16px 0 0;
    padding-left: 20px;
}

.simple-list li {
    color: #1d2d44;
    font-weight: 700;
}

.inline-badge {
    display: inline-flex;
    margin-left: 8px;
    border: 1px solid #93c5fd;
    border-radius: 8px;
    padding: 3px 7px;
    background: #dbeafe;
    color: #1d4ed8;
    font-size: 12px;
    font-weight: 800;
}

.guest-badge {
    border-color: #fbbf24;
    background: #fef3c7;
    color: #92400e;
}

.inline-mini-form {
    display: inline-grid;
    grid-template-columns: minmax(140px, 1fr) auto;
    gap: 8px;
    align-items: center;
    width: min(100%, 520px);
    margin: 8px 0 0;
}

.inline-mini-form input,
.inline-mini-form select {
    min-height: 38px;
    padding: 7px 9px;
}

.empty-inline {
    margin-top: 12px;
}

.match-list {
    display: grid;
    gap: 12px;
    margin-top: 14px;
}

.match-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(260px, 0.9fr);
    gap: 14px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    background: #f8fbff;
}

.match-admin {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: -4px 0 12px;
}

.match-edit-form {
    margin: -4px 0 14px;
    border: 1px solid #c8d4e4;
    border-radius: 8px;
    padding: 14px;
    background: #f8fbff;
}

.match-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.match-meta span {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    border: 1px solid #c8d4e4;
    border-radius: 8px;
    padding: 4px 8px;
    background: #edf4ff;
    color: #123f7a;
    font-size: 13px;
    font-weight: 800;
}

.match-meta .match-badge-league {
    border-color: #93c5fd;
    background: #dbeafe;
    color: #1d4ed8;
}

.match-meta .match-badge-cup {
    border-color: #fbbf24;
    background: #fef3c7;
    color: #92400e;
}

.match-meta .cup-round-1 {
    border-color: #c084fc;
    background: #f3e8ff;
    color: #6b21a8;
}

.match-meta .cup-round-2 {
    border-color: #fb7185;
    background: #ffe4e6;
    color: #9f1239;
}

.match-meta .cup-round-3 {
    border-color: #f59e0b;
    background: #fef3c7;
    color: #92400e;
}

.match-meta .cup-round-4,
.match-meta .cup-round-5,
.match-meta .cup-round-6,
.match-meta .cup-round-7,
.match-meta .cup-round-8 {
    border-color: #38bdf8;
    background: #e0f2fe;
    color: #075985;
}

.cup-bracket {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(190px, 1fr);
    gap: 12px;
    overflow-x: auto;
    padding: 12px 0 4px;
}

.cup-round {
    display: grid;
    align-content: start;
    gap: 8px;
}

.cup-round h3 {
    margin: 0;
    border: 1px solid #c8d4e4;
    border-radius: 8px;
    padding: 10px;
    background: #edf4ff;
    color: #123f7a;
    text-align: center;
    font-size: 15px;
}

.cup-slot {
    display: grid;
    gap: 5px;
    min-height: 76px;
    border: 1px solid #c8d4e4;
    border-radius: 8px;
    padding: 9px;
    background: #f8fbff;
    color: #58708f;
}

.cup-slot.filled {
    border-color: #74a6ee;
    background: #edf4ff;
    color: #07111f;
}

.cup-slot span {
    font-size: 12px;
    font-weight: 800;
    color: #123f7a;
}

.cup-slot strong {
    color: #07111f;
}

.cup-slot small {
    color: #58708f;
}

.group-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-top: 12px;
}

.group-card {
    border: 1px solid #c8d4e4;
    border-radius: 8px;
    padding: 12px;
    background: #f8fbff;
}

.group-card h3 {
    margin: 0 0 8px;
    color: #123f7a;
    font-size: 16px;
}

.profile-layout {
    display: grid;
    grid-template-columns: minmax(240px, 0.8fr) minmax(0, 1fr) minmax(0, 1fr);
    gap: 14px;
    align-items: start;
    margin-bottom: 14px;
}

.profile-card {
    display: grid;
    justify-items: start;
    gap: 10px;
}

.avatar-preview {
    width: 104px;
    height: 104px;
    border: 2px solid #74a6ee;
    border-radius: 50%;
    object-fit: cover;
    background: #edf4ff;
    color: #123f7a;
    box-shadow: 0 12px 28px rgba(18, 63, 122, 0.2);
}

.avatar-empty {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 42px;
    font-weight: 900;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
    margin-top: 12px;
}

.stats-grid div {
    border: 1px solid #c8d4e4;
    border-radius: 8px;
    padding: 12px;
    background: #f8fbff;
}

.stats-grid span {
    display: block;
    color: #58708f;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.stats-grid strong {
    display: block;
    margin-top: 6px;
    color: #123f7a;
    font-size: 28px;
}

.score-editor {
    display: grid;
    grid-template-columns: 72px 72px auto;
    gap: 8px;
}

.button.danger {
    border-color: #991b1b;
    background: #991b1b;
    color: #fff;
}

.collapsible-head {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
}

.collapsible-body,
[data-collapse-panel] {
    max-height: 2400px;
    overflow: hidden;
    transform-origin: top;
    transition: transform 0.22s ease, opacity 0.22s ease, max-height 0.22s ease;
}

.collapsible-body.is-collapsed,
[data-collapse-panel].is-collapsed {
    max-height: 0;
    opacity: 0;
    transform: scaleY(0.96);
    pointer-events: none;
}

.ranking-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    overflow: hidden;
    border-radius: 8px;
}

.panel + .panel {
    margin-top: 14px;
}

.ranking-table th,
.ranking-table td {
    border-bottom: 1px solid var(--line);
    padding: 12px 10px;
    text-align: left;
}

.ranking-table.compact th,
.ranking-table.compact td {
    padding: 9px 7px;
    font-size: 13px;
}

.ranking-table th {
    color: #42536b;
    font-size: 13px;
    text-transform: uppercase;
}

.ranking-table td {
    color: #12233a;
    font-weight: 700;
}

button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.conditional[hidden] {
    display: none;
}

.section-head {
    display: flex;
    gap: 14px;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.section-head h1,
.panel h1 {
    font-size: clamp(28px, 5vw, 46px);
}

.section-head h1 {
    color: #f8fbff;
    text-shadow: 0 2px 18px rgba(3, 8, 16, 0.35);
}

.section-head p {
    color: #c3cfdd;
}

.tournament-list {
    display: grid;
    gap: 12px;
}

.tournament-item {
    padding: 0;
    overflow: hidden;
}

.tournament-link {
    display: flex;
    gap: 14px;
    align-items: center;
    justify-content: space-between;
    min-height: 96px;
    padding: 18px;
}

.tournament-link strong {
    display: block;
    color: #07111f;
    font-size: 18px;
}

.tournament-link small {
    display: block;
    margin-top: 10px;
    color: #58708f;
    font-size: 15px;
}

.tournament-item:hover {
    border-color: #74a6ee;
    box-shadow: 0 22px 55px rgba(31, 111, 235, 0.22);
}

.flash {
    margin-bottom: 16px;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    padding: 12px;
    background: #eff6ff;
    color: #1e3a8a;
    font-weight: 700;
}

@media (max-width: 760px) {
    .topbar {
        grid-template-columns: 1fr auto;
    }

    .nav {
        grid-column: 1 / -1;
        order: 3;
    }

    .hero,
    .features,
    .grid-three,
    .grid-two,
    .group-grid,
    .profile-layout,
    .stats-grid,
    .workbench,
    .match-item,
    .score-editor {
        grid-template-columns: 1fr;
    }

    .hero {
        min-height: auto;
        padding-top: 18px;
    }

    .section-head {
        align-items: stretch;
        flex-direction: column;
    }
}
