:root {
    --bg: #0f1117;
    --bg-soft: #151923;
    --panel: #1b202b;
    --panel-strong: #222938;
    --text: #f4f7fb;
    --muted: #9aa7b7;
    --line: #303849;
    --green: #2ee59d;
    --blue: #4cc9f0;
    --red: #ff4d6d;
    --yellow: #ffd166;
    --shadow: 0 18px 45px rgba(0, 0, 0, 0.35);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(46, 229, 157, 0.14), transparent 34rem),
        linear-gradient(135deg, #0f1117 0%, #151923 54%, #241820 100%);
    font-family: Arial, Helvetica, sans-serif;
    transition: background 0.55s ease, color 0.35s ease;
}

.theme-transition,
.theme-transition * {
    transition:
        background-color 0.45s ease,
        color 0.35s ease,
        border-color 0.45s ease,
        box-shadow 0.45s ease;
}

.theme-fade-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.6s ease;
}

.theme-fade-overlay-hide {
    opacity: 0;
}

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

input,
select,
button,
textarea {
    font: inherit;
}

.site-shell {
    width: min(1440px, calc(100% - 32px));
    min-height: 100vh;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: 82px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}

.brand,
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand {
    font-weight: 800;
    letter-spacing: 0;
}

.brand-mark {
    width: 44px;
    height: 44px;
    display: inline-grid;
    place-items: center;
    color: #07100d;
    background: linear-gradient(135deg, var(--green), var(--blue));
    border-radius: 8px;
    box-shadow: 0 0 22px rgba(46, 229, 157, 0.25);
}

.nav-link {
    color: var(--muted);
    padding: 10px 14px;
    border-radius: 8px;
}

.nav-link-strong {
    color: var(--text);
    background: rgba(255, 255, 255, 0.07);
}

.flash {
    margin: 0 0 18px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.flash-success {
    border-color: rgba(46, 229, 157, 0.5);
}

.flash-error {
    border-color: rgba(255, 77, 109, 0.55);
}

.auth-layout {
    flex: 1;
    display: grid;
    place-items: center;
    padding: 40px 0 72px;
}

.auth-panel {
    width: min(520px, 100%);
    padding: 34px;
    background: rgba(27, 32, 43, 0.92);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.auth-copy h1,
.hero-band h1 {
    margin: 8px 0 0;
    font-size: clamp(2rem, 4vw, 4.2rem);
    line-height: 1;
    letter-spacing: 0;
}

.auth-copy h1 {
    font-size: clamp(2rem, 5vw, 3.2rem);
}

.eyebrow {
    margin: 0;
    color: var(--green);
    font-size: 0.8rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0;
}

.form-stack,
.form-grid {
    display: grid;
    gap: 16px;
}

.form-stack {
    margin-top: 26px;
}

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

label,
fieldset {
    display: grid;
    gap: 8px;
    margin: 0;
    color: var(--muted);
    font-size: 0.9rem;
    border: 0;
    padding: 0;
}

legend {
    padding: 0;
    margin-bottom: 8px;
}

input[type="text"],
input[type="password"],
select,
textarea {
    width: 100%;
    min-height: 48px;
    color: var(--text);
    background: #10141d;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px 14px;
    outline: none;
}

textarea {
    resize: vertical;
    line-height: 1.45;
}

input[type="file"] {
    width: 100%;
    min-height: 48px;
    color: var(--muted);
    background: #10141d;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
}

input[type="file"]::file-selector-button {
    margin-right: 12px;
    color: #06110d;
    background: var(--green);
    border: 0;
    border-radius: 8px;
    padding: 8px 12px;
    font-weight: 800;
    cursor: pointer;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(46, 229, 157, 0.14);
}

.field-wide {
    grid-column: 1 / -1;
}

.form-note {
    margin: -4px 0 0;
    color: var(--muted);
    font-size: 0.88rem;
}

.field-help {
    color: var(--muted);
    font-size: 0.82rem;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
}

.checkbox-row input {
    width: 18px;
    height: 18px;
    accent-color: var(--green);
}

.button {
    min-height: 44px;
    border: 0;
    border-radius: 8px;
    padding: 11px 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 800;
    cursor: pointer;
}

.button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.button-primary {
    color: #06110d;
    background: var(--green);
}

.button-secondary {
    color: var(--text);
    background: var(--panel-strong);
    border: 1px solid var(--line);
}

.button-accent {
    width: 100%;
    color: #16070b;
    background: var(--red);
}

.button-danger {
    color: var(--text);
    background: rgba(255, 77, 109, 0.16);
    border: 1px solid rgba(255, 77, 109, 0.55);
}

.button-mini {
    width: 100%;
    min-height: 38px;
    color: var(--text);
    background: #252d3c;
    border: 1px solid var(--line);
    font-size: 0.86rem;
}

.auth-switch {
    margin-top: 18px;
    padding-top: 18px;
    color: var(--muted);
    border-top: 1px solid var(--line);
    font-size: 0.9rem;
}

.auth-switch a {
    color: var(--green);
    font-weight: 800;
}

.dashboard-grid,
.tournament-layout {
    display: grid;
    gap: 24px;
    padding-bottom: 42px;
}

.hero-band {
    min-height: 260px;
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 24px;
    padding: 34px;
    background:
        linear-gradient(90deg, rgba(27, 32, 43, 0.86), rgba(27, 32, 43, 0.42)),
        linear-gradient(135deg, rgba(76, 201, 240, 0.24), rgba(255, 77, 109, 0.2));
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.hero-band-compact {
    min-height: 180px;
}

.hero-stats {
    min-width: 140px;
    padding: 18px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    background: rgba(15, 17, 23, 0.64);
    text-align: center;
}

.hero-stats span {
    display: block;
    color: var(--green);
    font-size: 2rem;
    font-weight: 900;
}

.hero-stats small,
.muted {
    color: var(--muted);
}

.panel {
    padding: 24px;
    background: rgba(27, 32, 43, 0.92);
    border: 1px solid var(--line);
    border-radius: 8px;
}

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

.section-heading h2,
.round h2 {
    margin: 0;
    font-size: 1.05rem;
}

.segmented {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-self: end;
}

.segmented-three {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.segmented legend {
    grid-column: 1 / -1;
}

.segmented label {
    cursor: pointer;
}

.segmented input {
    position: absolute;
    opacity: 0;
}

.segmented span {
    min-height: 48px;
    display: grid;
    place-items: center;
    padding: 10px;
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #10141d;
}

.segmented input:checked + span {
    color: #06110d;
    background: var(--green);
    border-color: var(--green);
}

.preset-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
}

.preset-grid legend {
    grid-column: 1 / -1;
}

.preset-card {
    display: block;
    position: relative;
    cursor: pointer;
}

.preset-card > input[type="radio"] {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.preset-card-body {
    min-height: 96px;
    width: 100%;
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    padding: 16px;
    color: var(--text);
    background: #10141d;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.preset-card-body::after {
    content: "";
    width: 14px;
    height: 14px;
    grid-column: 2;
    grid-row: 1 / 4;
    border: 2px solid var(--muted);
    border-radius: 999px;
}

.preset-card input:checked + .preset-card-body {
    border-color: var(--green);
    box-shadow: inset 0 0 0 1px rgba(46, 229, 157, 0.24), 0 0 0 3px rgba(46, 229, 157, 0.12);
}

.preset-card input:checked + .preset-card-body::after {
    border-color: var(--green);
    background: var(--green);
    box-shadow: inset 0 0 0 3px #10141d;
}

.preset-name {
    grid-column: 1;
    font-weight: 900;
}

.preset-description {
    grid-column: 1;
    color: var(--muted);
    font-size: 0.86rem;
    line-height: 1.35;
}

.preset-swatches {
    grid-column: 1;
    display: flex;
    gap: 8px;
}

.preset-swatches span {
    width: 28px;
    height: 28px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 8px;
}

.background-preview {
    display: grid;
    gap: 12px;
    padding: 14px;
    background: #10141d;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.background-preview img {
    width: 100%;
    max-height: 220px;
    object-fit: cover;
    border-radius: 8px;
}

.settings-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
}

.autosave-status {
    color: var(--muted);
    font-size: 0.88rem;
}

.autosave-status[data-state="saving"] {
    color: var(--yellow);
}

.autosave-status[data-state="saved"] {
    color: var(--green);
}

.autosave-status[data-state="error"] {
    color: var(--red);
}

.tournament-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
}

.tournament-card {
    min-height: 210px;
    display: grid;
    gap: 18px;
    align-content: space-between;
    padding: 18px;
    background: #141924;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.tournament-card h3 {
    margin: 0 0 8px;
    font-size: 1.1rem;
}

.tournament-card p {
    margin: 0;
    color: var(--muted);
}

.tournament-actions {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
}

.tournament-actions form {
    min-width: 92px;
}

.tournament-actions .button {
    width: 100%;
}

.status-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.status,
.winner-chip {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 800;
}

.status-setup {
    color: #11100a;
    background: var(--yellow);
}

.status-active {
    color: #06110d;
    background: var(--green);
}

.status-finished {
    color: #13060a;
    background: var(--red);
}

.winner-chip {
    color: var(--text);
    background: #252d3c;
    gap: 14px;
}

.winner-chip .avatar-chip {
    margin-right: 10px;
}

.winner-chip-name {
    display: inline-block;
}

.empty-state {
    padding: 24px;
    color: var(--muted);
    background: #121720;
    border: 1px dashed var(--line);
    border-radius: 8px;
    text-align: center;
}

.setup-grid {
    display: grid;
    grid-template-columns: minmax(280px, 420px) minmax(0, 1fr);
    gap: 24px;
}

.players-list {
    display: grid;
    gap: 10px;
    margin: 0;
    padding-left: 22px;
}

.players-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px;
    background: #141924;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.player-card-body {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
}

.players-list span {
    color: var(--muted);
    font-size: 0.88rem;
}

.roster-box {
    width: 100%;
    max-height: 96px;
    overflow-y: auto;
    display: grid;
    gap: 4px;
    padding: 8px;
    color: var(--muted);
    background: #10141d;
    border: 1px solid var(--line);
    border-radius: 8px;
    scrollbar-width: thin;
    scrollbar-color: var(--green) #10141d;
}

.roster-box-compact {
    max-height: 68px;
    margin-top: 6px;
    padding: 7px;
}

.roster-title {
    color: var(--green);
    font-size: 0.72rem;
    font-weight: 900;
    text-transform: uppercase;
}

.roster-member {
    display: flex;
    align-items: center;
    gap: 6px;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.avatar {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    display: grid;
    place-items: center;
    overflow: hidden;
    color: #06110d;
    background: linear-gradient(135deg, var(--green), var(--blue));
    border-radius: 8px;
    font-weight: 900;
}

.avatar img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.avatar-small {
    width: 32px;
    height: 32px;
    flex-basis: 32px;
    font-size: 0.74rem;
}

.avatar-stack {
    width: 54px;
    min-width: 54px;
    height: 40px;
    display: flex;
    align-items: center;
}

.avatar-stack-small {
    width: 42px;
    min-width: 42px;
    height: 32px;
}

.avatar-stack-item {
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
    border: 2px solid #141924;
}

.avatar-stack-item + .avatar-stack-item {
    margin-left: -16px;
}

.avatar-stack-item-small {
    width: 24px;
    height: 24px;
    flex-basis: 24px;
    border-color: #121720;
    font-size: 0.68rem;
}

.avatar-stack-item-small + .avatar-stack-item-small {
    margin-left: -14px;
}

.avatar-more {
    color: var(--text);
    background: #252d3c;
}

.avatar-member {
    width: 20px;
    height: 20px;
    flex: 0 0 20px;
    border-radius: 6px;
    font-size: 0.62rem;
}

.avatar-chip {
    width: 22px;
    height: 22px;
    flex: 0 0 22px;
    border-radius: 6px;
    font-size: 0.62rem;
}

.avatar-winner-banner {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    border: 2px solid rgba(6, 17, 13, 0.18);
    border-radius: 10px;
    font-size: 0.82rem;
}

.icon-button {
    width: 34px;
    height: 34px;
    color: var(--text);
    background: #252d3c;
    border: 1px solid var(--line);
    border-radius: 8px;
    cursor: pointer;
}

.generate-form {
    margin-top: 18px;
}

.winner-banner {
    min-height: 88px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 20px 24px;
    color: #06110d;
    background: linear-gradient(135deg, var(--green), var(--yellow));
    border-radius: 8px;
}

.winner-banner span {
    font-weight: 800;
    text-transform: uppercase;
}

.winner-banner strong {
    font-size: clamp(1.3rem, 3vw, 2.5rem);
}

.winner-banner-name {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 14px;
}

.bracket {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 18px;
    align-items: start;
}

.round {
    min-width: 0;
    display: grid;
    gap: 16px;
}

.round h2 {
    padding-left: 4px;
}

.match-card {
    display: grid;
    gap: 10px;
    padding: 14px;
    background: rgba(27, 32, 43, 0.96);
    border: 1px solid var(--line);
    border-left: 4px solid var(--blue);
    border-radius: 8px;
}

.match-waiting {
    border-left-color: var(--yellow);
}

.match-finished {
    border-left-color: var(--green);
}

.match-meta,
.participant,
.match-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.match-meta {
    color: var(--muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    font-weight: 800;
}

.participant {
    min-height: 58px;
    padding: 10px;
    background: #121720;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.participant small {
    display: block;
    margin-top: 4px;
    color: var(--muted);
}

.participant-info {
    flex: 1;
    min-width: 0;
}

.participant-info strong,
.player-card-body strong {
    overflow-wrap: anywhere;
}

.participant-winner {
    border-color: rgba(46, 229, 157, 0.65);
    box-shadow: inset 0 0 0 1px rgba(46, 229, 157, 0.15);
}

.score {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    color: #07100d;
    background: var(--green);
    border-radius: 8px;
    font-weight: 900;
}

.match-actions {
    align-items: stretch;
}

.match-actions form {
    flex: 1;
    min-width: 0;
}

.winner-line {
    padding: 10px;
    color: var(--green);
    background: rgba(46, 229, 157, 0.08);
    border-radius: 8px;
    font-weight: 800;
}

.winner-line-with-avatar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.footer {
    margin-top: auto;
    min-height: 58px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    color: var(--muted);
    font-size: 0.86rem;
}

@media (max-width: 840px) {
    .site-shell {
        width: min(100% - 20px, 680px);
    }

    .topbar {
        height: auto;
        padding: 18px 0;
        align-items: flex-start;
        flex-direction: column;
    }

    .hero-band,
    .winner-banner {
        align-items: stretch;
        flex-direction: column;
    }

    .hero-band {
        min-height: 220px;
        padding: 24px;
    }

    .hero-stats {
        width: 100%;
    }

    .form-grid,
    .setup-grid {
        grid-template-columns: 1fr;
    }

    .segmented,
    .segmented-three {
        grid-template-columns: 1fr;
    }

    .bracket {
        grid-template-columns: 1fr;
    }

    .match-actions {
        flex-direction: column;
    }

    .tournament-actions {
        grid-template-columns: 1fr;
    }
}
