:root {
    --green: #1fff87;
    --purple: #a044ff;
    --gold: #ffca28;
    --bg: #080510;
    --card: #100c18;
    --card2: #130f1e;
    --border: rgba(160, 68, 255, 0.18);
    --red: #ff4d4d;
    --blue: #4fc3f7;

    --ink-1: #f4f4f8;
    --ink-2: #a8adc2;
    --ink-3: #767c94;
    --ink-4: #4a4f66;
    --purple-soft: #c9a3ff;
    --green-soft: #7dffbf;
    --gold-soft: #ffdb7a;

    --panel: #0e0a18;
    --panel-border: #241a3a;
    --line: rgba(160, 68, 255, 0.35);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    background: var(--bg);
    color: var(--ink-1);
    font-family: 'Inter', sans-serif;
    height: 100%;
    overflow: hidden;
}

::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--panel-border); border-radius: 7px; }
::-webkit-scrollbar-thumb:hover { background: var(--purple); }

/* ── AMBIENT BACKGROUND ─────────────────────────── */
.bg-glow {
    position: fixed; inset: 0; z-index: 0; pointer-events: none;
    background:
        radial-gradient(50% 40% at 15% 0%, rgba(160,68,255,0.14), transparent 60%),
        radial-gradient(45% 35% at 100% 100%, rgba(31,255,135,0.08), transparent 60%);
}
.bg-particles { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.bg-particle {
    position: absolute; border-radius: 50%;
    background: var(--purple);
    animation: floaty linear infinite;
}
@keyframes floaty {
    0%   { transform: translateY(0) translateX(0); }
    50%  { transform: translateY(-30px) translateX(12px); }
    100% { transform: translateY(0) translateX(0); }
}

/* ── LAYOUT ──────────────────────────────────────── */
.main-layout { position: relative; z-index: 1; display: flex; height: 100vh; }

/* ── SIDEBAR ─────────────────────────────────────── */
.sidebar {
    width: 320px; flex-shrink: 0;
    background: #0b0715;
    border-right: 1px solid var(--border);
    padding: 26px 22px 22px;
    display: flex; flex-direction: column;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 26px; padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}
.sidebar-brand img { width: 30px; height: 30px; border-radius: 7px; object-fit: cover; }
.sidebar-brand span {
    font-family: 'Rajdhani', sans-serif; font-size: 20px; font-weight: 800;
    letter-spacing: 2.5px; color: var(--purple-soft);
}

.control-group { margin-bottom: 22px; }
.label-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 9px; }
.label-row label {
    font-size: 10px; font-weight: 800; color: var(--ink-3);
    text-transform: uppercase; letter-spacing: 1.8px;
}

.count-badge {
    font-family: 'Rajdhani', sans-serif; font-size: 13px; font-weight: 800;
    color: var(--ink-3); background: var(--panel); border: 1px solid var(--panel-border);
    padding: 2px 9px; border-radius: 20px; transition: 0.2s;
}
.count-badge.valid   { color: #05170c; background: var(--green); border-color: var(--green); }
.count-badge.invalid { color: var(--red); border-color: rgba(255,77,77,0.4); background: rgba(255,77,77,0.08); }

.input-hint { font-size: 10.5px; color: var(--ink-4); margin-bottom: 9px; line-height: 1.5; }

textarea#playerInput {
    width: 100%; min-height: 180px; resize: vertical;
    background: var(--panel); border: 1px solid var(--panel-border); color: var(--ink-1);
    padding: 12px 13px; border-radius: var(--radius-md);
    font-size: 13px; font-weight: 600; font-family: 'Inter', sans-serif;
    line-height: 1.7; transition: border-color 0.2s;
}
textarea#playerInput:focus { border-color: var(--purple); outline: none; }
textarea#playerInput::placeholder { color: var(--ink-4); }
textarea#playerInput.flash { animation: flashField 0.4s ease; }
@keyframes flashField {
    0%, 100% { border-color: var(--panel-border); }
    40% { border-color: var(--green); box-shadow: 0 0 0 3px rgba(31,255,135,0.15); }
}

/* ── MODE SWITCH (solo / duo) ───────────────────── */
.mode-switch {
    position: relative; display: flex;
    background: var(--panel); border: 1px solid var(--panel-border); border-radius: 999px;
    padding: 3px;
}
.mode-thumb {
    position: absolute; top: 3px; left: 3px;
    width: calc(50% - 3px); height: calc(100% - 6px);
    background: var(--purple); border-radius: 999px;
    transition: transform 0.28s cubic-bezier(0.65,0,0.35,1);
    z-index: 0;
}
.mode-switch.is-duo .mode-thumb { transform: translateX(100%); background: var(--gold); }
.mode-btn {
    position: relative; z-index: 1; flex: 1;
    background: none; border: none; cursor: pointer;
    padding: 9px 0; font-family: 'Inter', sans-serif;
    font-size: 11.5px; font-weight: 800; letter-spacing: 1px;
    color: var(--ink-3); transition: color 0.25s; border-radius: 999px;
}
.mode-btn.active { color: #0a0612; }

/* ── ACTION BUTTONS ──────────────────────────────── */
.action-stack { display: flex; flex-direction: column; gap: 9px; margin-bottom: 10px; }
.action-stack button {
    display: flex; align-items: center; justify-content: center; gap: 9px;
    width: 100%; padding: 13px; border-radius: var(--radius-md);
    font-family: 'Inter', sans-serif; font-size: 12.5px; font-weight: 800;
    letter-spacing: 0.8px; cursor: pointer; border: none; transition: 0.2s;
}
.action-stack svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary { background: var(--purple); color: white; }
.btn-primary:hover { background: #b560ff; transform: translateY(-1px); }

.btn-shuffle { background: var(--panel); border: 1px solid var(--panel-border) !important; color: var(--ink-2); }
.btn-shuffle:hover { border-color: var(--blue) !important; color: var(--blue); }

.btn-outline { background: transparent; border: 1px solid var(--panel-border) !important; color: var(--ink-3); font-size: 11px !important; padding: 10px !important; }
.btn-outline:hover { border-color: rgba(255,77,77,0.4) !important; color: var(--red); }

.sidebar.shake { animation: shakeX 0.5s ease; }
@keyframes shakeX {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(7px); }
    60% { transform: translateX(-5px); }
    80% { transform: translateX(3px); }
}

/* ── SIDEBAR FOOTER: legend + history ───────────── */
.sidebar-footer { margin-top: auto; padding-top: 20px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 20px; }

.round-legend { display: flex; flex-direction: column; gap: 7px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 11.5px; font-weight: 700; color: var(--ink-3); }
.legend-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--panel-border); flex-shrink: 0; }
.legend-item.done { color: var(--green-soft); }
.legend-item.done .legend-dot { background: var(--green); box-shadow: 0 0 6px var(--green); }

.history-block { display: flex; flex-direction: column; }
.history-clear {
    background: none; border: none; cursor: pointer;
    font-size: 9px; font-weight: 800; letter-spacing: 1px;
    color: var(--ink-4); transition: color 0.2s;
}
.history-clear:hover { color: var(--red); }

.history-list { display: flex; flex-direction: column; gap: 7px; max-height: 220px; overflow-y: auto; }
.history-empty { font-size: 11px; color: var(--ink-4); font-weight: 600; padding: 6px 0; }
.history-item {
    display: flex; align-items: center; gap: 10px;
    background: var(--panel); border: 1px solid var(--panel-border); border-radius: var(--radius-sm);
    padding: 9px 11px;
}
.history-trophy { font-size: 16px; flex-shrink: 0; filter: grayscale(0.15); }
.history-info { min-width: 0; }
.history-winner { font-size: 12.5px; font-weight: 800; color: var(--gold-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-sub { font-size: 9.5px; color: var(--ink-4); font-weight: 700; margin-top: 1px; }

/* ── MAIN CONTENT AREA ───────────────────────────── */
.content-area { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.scroll-wrapper { flex: 1; overflow-y: auto; }

.tourney-header { text-align: center; padding: 48px 24px 28px; }
.header-eyebrow { font-size: 11px; font-weight: 800; letter-spacing: 4px; color: var(--purple-soft); margin-bottom: 10px; }
.tourney-title {
    font-family: 'Rajdhani', sans-serif; font-size: 46px; font-weight: 800;
    letter-spacing: 2px; color: var(--ink-1); line-height: 1;
}
.tourney-title span {
    background: linear-gradient(90deg, var(--purple-soft), var(--gold-soft));
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
.header-line { width: 70px; height: 3px; margin: 18px auto 0; border-radius: 3px; background: linear-gradient(90deg, var(--purple), var(--gold)); }
.bracket-meta {
    margin-top: 14px; font-size: 11px; font-weight: 800; letter-spacing: 1.4px;
    color: var(--ink-3); text-transform: uppercase; min-height: 14px;
}

/* ── BRACKET LAYOUT (connector-line converging tree) ── */
.bracket-scroll { overflow-x: auto; overflow-y: hidden; padding: 10px 40px 30px; }
.bracket-container {
    display: flex; align-items: center;
    gap: 56px;
    min-width: max-content;
    padding: 20px 10px;
}

.round-column {
    width: 234px; flex-shrink: 0;
    display: flex; flex-direction: column;
    animation: colIn 0.5s cubic-bezier(0.2,0.7,0.3,1) both;
}
@keyframes colIn {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: translateY(0); }
}

.round-label {
    display: flex; align-items: center; gap: 8px;
    font-size: 11px; font-weight: 800; letter-spacing: 1.8px; color: var(--ink-3);
    text-transform: uppercase; margin-bottom: 14px; white-space: nowrap;
}
.round-label-num {
    font-family: 'Rajdhani', sans-serif; font-size: 11px; font-weight: 800;
    color: var(--purple-soft); background: rgba(160,68,255,0.14);
    border: 1px solid rgba(160,68,255,0.3); border-radius: 5px;
    padding: 2px 6px;
}

.round-matches { display: flex; flex-direction: column; justify-content: space-around; align-items: stretch; }

.match-wrapper { position: relative; }

/* connector stubs: incoming from previous round */
.round-column:not(.r-0) .match-wrapper::before {
    content: ''; position: absolute; top: 50%; left: -28px;
    width: 28px; height: 1px; background: var(--line);
}
/* connector stubs: outgoing toward next round */
.round-column:not(.champion-col) .match-wrapper::after {
    content: ''; position: absolute; top: 50%; right: -28px;
    width: 28px; height: 1px; background: var(--line);
}

.bracket-container.reshuffled,
#bracketDisplay.reshuffled .round-column { animation: reshuffleFlash 0.5s ease; }
@keyframes reshuffleFlash {
    0%, 100% { filter: brightness(1); }
    35% { filter: brightness(1.35); }
}

/* ── MATCHUP CARD ────────────────────────────────── */
.matchup-box {
    background: var(--card2); border: 1px solid rgba(255,255,255,0.07);
    border-radius: var(--radius-md); overflow: hidden;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.matchup-box:hover { border-color: rgba(160,68,255,0.4); }
.matchup-box.decided { border-color: rgba(31,255,135,0.3); }

.player-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: 8px; padding: 11px 13px;
    background: transparent; transition: background 0.2s, opacity 0.2s;
}
.player-row.active { background: rgba(255,255,255,0.015); }
.player-row.winner { background: rgba(31,255,135,0.09); }
.player-row.loser { opacity: 0.42; }

.p-name {
    font-size: 12.5px; font-weight: 700; color: var(--ink-1);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0;
}
.player-row.winner .p-name { color: var(--green-soft); font-weight: 800; }
.player-row.loser .p-name { text-decoration: line-through; text-decoration-color: var(--ink-4); color: var(--ink-3); }
.player-row:not(.active) .p-name { color: var(--ink-4); font-style: italic; }

.p-score {
    width: 46px; flex-shrink: 0;
    background: var(--panel); border: 1px solid var(--panel-border); color: var(--ink-1);
    border-radius: 6px; padding: 5px 4px; text-align: center;
    font-family: 'Rajdhani', sans-serif; font-weight: 800; font-size: 14px;
    transition: border-color 0.2s;
}
.p-score:focus { border-color: var(--purple); outline: none; }
.p-score:disabled { opacity: 0.3; cursor: not-allowed; }
.player-row.winner .p-score { border-color: rgba(31,255,135,0.4); color: var(--green-soft); }

.vs-divider {
    display: flex; align-items: center; gap: 8px;
    padding: 0 13px; height: 1px; background: rgba(255,255,255,0.06);
    position: relative;
}
.vs-divider span {
    position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
    background: var(--card2); padding: 0 8px;
    font-family: 'Rajdhani', sans-serif; font-size: 9.5px; font-weight: 800;
    color: var(--ink-4); letter-spacing: 1px;
}

/* ── CHAMPION COLUMN ─────────────────────────────── */
.champion-col { width: 200px; }
.champion-display {
    display: flex; flex-direction: column; align-items: center; text-align: center;
    background: var(--card2); border: 2px dashed var(--panel-border);
    border-radius: var(--radius-lg); padding: 22px 14px;
    position: relative; transition: 0.3s;
}
.champion-display.revealed {
    border: 2px solid var(--gold);
    background: radial-gradient(120% 100% at 50% 0%, rgba(255,202,40,0.14), transparent 70%), var(--card2);
    box-shadow: 0 0 34px rgba(255,202,40,0.22);
}
.champ-trophy-wrap { width: 40px; height: 40px; margin-bottom: 10px; opacity: 0.35; transition: 0.3s; }
.champion-display.revealed .champ-trophy-wrap { opacity: 1; }
.trophy-icon { width: 100%; height: 100%; fill: var(--gold); }
.champ-name {
    font-family: 'Rajdhani', sans-serif; font-size: 17px; font-weight: 800;
    color: var(--ink-4); text-transform: uppercase; word-break: break-word;
    transition: color 0.3s;
}
.champion-display.revealed .champ-name { color: var(--gold-soft); }
.champ-glow-ring {
    position: absolute; inset: -2px; border-radius: var(--radius-lg);
    box-shadow: 0 0 0 1px rgba(255,202,40,0.4);
    animation: ringPulse 2s ease-in-out infinite;
    pointer-events: none;
}
@keyframes ringPulse {
    0%, 100% { box-shadow: 0 0 0 1px rgba(255,202,40,0.4); }
    50% { box-shadow: 0 0 0 5px rgba(255,202,40,0.12); }
}

/* ── EMPTY STATE ─────────────────────────────────── */
.empty-state { text-align: center; padding: 90px 40px; color: var(--ink-4); }
.empty-icon { width: 52px; height: 52px; margin: 0 auto 18px; opacity: 0.35; }
.empty-icon svg { width: 100%; height: 100%; }
.empty-text { font-size: 15px; font-weight: 800; letter-spacing: 0.8px; color: var(--ink-3); }
.empty-sub { font-size: 12px; color: var(--ink-4); margin-top: 8px; }

/* ── FOOTER ──────────────────────────────────────── */
.footer-v2 { border-top: 1px solid var(--border); padding: 24px 40px; margin-top: 40px; }
.footer-content { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.footer-brand { display: flex; align-items: center; gap: 10px; }
.footer-brand img { width: 22px; height: 22px; border-radius: 5px; object-fit: cover; }
.footer-brand p { font-size: 11px; color: var(--ink-4); font-weight: 600; }
.footer-links { display: flex; gap: 20px; }
.footer-links a { font-size: 11px; font-weight: 800; letter-spacing: 1px; color: var(--ink-3); text-decoration: none; transition: color 0.2s; }
.footer-links a:hover { color: var(--purple-soft); }
.footer-credit { font-size: 10.5px; color: var(--ink-4); }
.footer-credit .vman { color: var(--purple-soft); text-decoration: none; font-weight: 700; }

/* ── CHAMPION MODAL ──────────────────────────────── */
.champ-modal {
    position: fixed; inset: 0; z-index: 999;
    background: rgba(4, 2, 9, 0.85); backdrop-filter: blur(6px);
    display: flex; align-items: center; justify-content: center;
    opacity: 0; pointer-events: none; transition: opacity 0.3s;
}
.champ-modal.open { opacity: 1; pointer-events: auto; }
.champ-modal-inner {
    position: relative; width: min(90vw, 380px);
    background: linear-gradient(180deg, #150c26, #0c0716);
    border: 1px solid rgba(255,202,40,0.4); border-radius: 22px;
    padding: 44px 30px 30px; text-align: center;
    box-shadow: 0 30px 80px rgba(0,0,0,0.6), 0 0 60px rgba(255,202,40,0.15);
    transform: scale(0.9); transition: transform 0.3s;
}
.champ-modal.open .champ-modal-inner { transform: scale(1); }
.champ-fireworks { position: absolute; inset: 0; overflow: hidden; border-radius: 22px; pointer-events: none; }
.fw-particle {
    position: absolute; width: 5px; height: 5px; border-radius: 50%;
    animation: fw 1s ease-out forwards;
}
@keyframes fw {
    0% { transform: translate(0,0) scale(1); opacity: 1; }
    100% { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; }
}
.champ-crown { width: 46px; height: 46px; margin: 0 auto 12px; }
.champ-crown svg { width: 100%; height: 100%; fill: var(--gold); filter: drop-shadow(0 0 12px rgba(255,202,40,0.6)); }
.champ-label { font-size: 11px; font-weight: 800; letter-spacing: 4px; color: var(--purple-soft); margin-bottom: 10px; }
.champ-name-display {
    font-family: 'Rajdhani', sans-serif; font-size: 30px; font-weight: 800;
    color: var(--gold-soft); text-transform: uppercase; word-break: break-word; margin-bottom: 26px;
}
.champ-close {
    background: var(--purple); color: white; border: none; cursor: pointer;
    padding: 12px 30px; border-radius: 10px; font-weight: 800; font-size: 12px;
    letter-spacing: 1px; transition: 0.2s;
}
.champ-close:hover { background: #b560ff; }

/* ── RESPONSIVE ──────────────────────────────────── */
@media (max-width: 900px) {
    .main-layout { flex-direction: column; height: auto; overflow: visible; }
    html, body { overflow: auto; height: auto; }
    .sidebar { width: 100%; }
    .tourney-title { font-size: 32px; }
}