:root {
    --bg: #0f172a;
    --panel: #1e293b;
    --accent: #38bdf8;
    --accent-dark: #0ea5e9;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --danger: #ef4444;
    --success: #22c55e;
    --border: #334155;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

.topbar {
    display: flex;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--panel);
    border-bottom: 2px solid var(--accent-dark);
    gap: 1rem;
}

.brand { display: flex; align-items: center; gap: .9rem; }
.logo {
    height: 38px;
    width: auto;
    background: #fff;
    padding: 5px 8px;
    border-radius: 8px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-title { font-size: 1.2rem; font-weight: 700; }
.brand-sub { font-size: .8rem; color: var(--accent); letter-spacing: .03em; }

/* Sidebar layout */
.layout { display: flex; align-items: flex-start; min-height: calc(100vh - 72px); }
.sidebar {
    width: 230px;
    flex-shrink: 0;
    background: var(--panel);
    border-right: 1px solid var(--border);
    padding: 1.5rem 0;
    min-height: calc(100vh - 72px);
    position: sticky;
    top: 0;
}
.side-heading {
    color: var(--text);
    font-size: .95rem;
    font-weight: 700;
    letter-spacing: .02em;
    padding: 0 1.5rem .4rem;
}
.side-season {
    color: var(--accent);
    font-size: .82rem;
    font-weight: 600;
    padding: .25rem 1.5rem .5rem 2.3rem;   /* indented under "Table Tennis" */
    cursor: pointer;
    list-style: none;
    user-select: none;
    display: flex;
    align-items: center;
    gap: .4rem;
}
.side-season::-webkit-details-marker { display: none; }
.side-season:hover { color: var(--text); }
.season-chev { font-size: .7rem; transition: transform .15s ease; display: inline-block; }
.side-season-group:not([open]) .season-chev { transform: rotate(-90deg); }
.side-nav { display: flex; flex-direction: column; }
.side-nav a {
    color: var(--muted);
    text-decoration: none;
    padding: .6rem 1.5rem .6rem 3rem;  /* indented under "Season 1" */
    border-left: 3px solid transparent;
    transition: color .15s, background .15s, border-color .15s;
}
.side-nav a:hover { color: var(--text); background: #0e1a2e; }
.side-nav a.active {
    color: var(--accent);
    border-left-color: var(--accent);
    background: #0e1a2e;
    font-weight: 600;
}

.container { flex: 1; max-width: 960px; margin: 2rem auto; padding: 0 2rem; width: 100%; }

@media (max-width: 760px) {
    .layout { flex-direction: column; }
    .sidebar {
        width: 100%;
        min-height: auto;
        position: static;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: .75rem 0;
    }
    .side-nav { flex-direction: row; flex-wrap: wrap; }
    .side-nav a { border-left: none; border-bottom: 3px solid transparent; padding: .5rem 1rem; }
    .side-nav a.active { border-left: none; border-bottom-color: var(--accent); }
}

h1 { margin-top: 0; }
.subtitle { color: var(--muted); margin-top: -0.5rem; }

.flash {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-weight: 500;
}
.flash-success { background: rgba(34,197,94,.15); border: 1px solid var(--success); color: #bbf7d0; }
.flash-error { background: rgba(239,68,68,.15); border: 1px solid var(--danger); color: #fecaca; }

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.5rem;
}
.predraw-intro { margin-top: 0; color: var(--muted); }
.predraw-teams {
    list-style: none;
    padding: 0;
    margin: 0 0 1.25rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: .6rem;
    counter-reset: team;
}
.predraw-teams li {
    counter-increment: team;
    background: #0b1424;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .7rem .9rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: .6rem;
}
.predraw-teams li::before {
    content: counter(team);
    background: var(--accent-dark);
    color: #04202e;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: .8rem;
    flex-shrink: 0;
}

.lock-banner { display: flex; align-items: center; gap: .75rem; color: var(--muted); }
.lock-icon { font-size: 1.2rem; }

.danger-panel { border-color: var(--danger); }
.danger-panel h3 { margin-top: 0; color: #fecaca; }

.btn {
    background: var(--accent-dark);
    color: #04202e;
    border: none;
    padding: 0.6rem 1.1rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
}
.btn:hover { background: var(--accent); }
.btn-primary { font-size: 1rem; }
.btn-small { padding: 0.4rem 0.75rem; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }

/* Teams */
.team-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.25rem;
}
.team-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.1rem 1.25rem;
}
.team-card h2 { margin: 0 0 .5rem; font-size: 1.15rem; color: var(--accent); }
.member-list { margin: 0; padding-left: 1.2rem; }
.member-list li { padding: 2px 0; }

/* Tables */
.data-table, .match-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--panel);
    border-radius: 12px;
    overflow: hidden;
}
.data-table th, .data-table td,
.match-table th, .match-table td {
    padding: 0.7rem 0.9rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.data-table th, .match-table th {
    background: #0b1424;
    color: var(--muted);
    text-transform: uppercase;
    font-size: .78rem;
    letter-spacing: .04em;
}
.data-table tbody tr:last-child td,
.match-table tbody tr:last-child td { border-bottom: none; }
.team-name { font-weight: 600; }
.points-cell { font-weight: 700; color: var(--accent); }

/* Fixtures */
.section-title { margin: 1.75rem 0 .75rem; font-size: 1.15rem; }

.fixture-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: .9rem;
    overflow: hidden;
}
.fixture-head {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.9rem 1.25rem;
    background: #0b1424;
    font-weight: 700;
    cursor: pointer;
    list-style: none;            /* hide default disclosure triangle */
    user-select: none;
}
.fixture-head::-webkit-details-marker { display: none; }
.fixture-head .team { color: var(--accent); }
.fixture-head .vs { color: var(--muted); font-weight: 400; }
.fixture-head .chev {
    color: var(--muted);
    font-size: .7rem;
    transition: transform .15s ease;
}
details[open] > .fixture-head .chev { transform: rotate(90deg); }
.fixture-head:hover { background: #0e1a2e; }
.fixture-meta { margin-left: auto; font-weight: 500; font-size: .85rem; }

.status-done { color: var(--success); }
.status-part { color: var(--accent); }

.draw-list .vs { color: var(--muted); font-weight: 400; }

.result-form { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.result-form select, .result-form input {
    background: #0b1424;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.4rem 0.5rem;
    border-radius: 6px;
}

.winner-badge {
    background: rgba(34,197,94,.15);
    border: 1px solid var(--success);
    color: #bbf7d0;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: .85rem;
}
.pending { color: var(--muted); font-style: italic; }

.match-label { font-weight: 600; }
.match-type { color: var(--muted); font-size: .8rem; }
.set-tally { color: var(--accent); font-size: .82rem; margin-top: .25rem; }
.score-summary { color: var(--muted); font-size: .8rem; }

.scorecards { padding: .75rem 1rem 1rem; display: flex; flex-direction: column; gap: 1rem; }
.scorecard {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: .85rem 1rem;
    background: #0d1626;
}
.scorecard-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: .5rem;
    margin-bottom: .6rem;
}
.scorecard-head .match-label { font-weight: 700; margin-right: .5rem; }
.scorecard-head .match-type { color: var(--muted); font-size: .8rem; }
.scorecard-status .set-tally { color: var(--muted); font-size: .82rem; margin-left: .3rem; }
.live-link { margin-left: .6rem; text-decoration: none; }

.score-head-row, .set-line {
    display: grid;
    grid-template-columns: 150px 70px 18px 70px 1fr;
    align-items: center;
    gap: .5rem;
    padding: .18rem 0;
}
.score-head-row .score-team { color: var(--muted); font-size: .78rem; text-align: center; }
.set-label { color: var(--muted); font-size: .85rem; }
.set-label em { color: #64748b; font-style: normal; font-size: .76rem; }
.set-line input[type="number"] {
    width: 100%;
    background: #0b1424;
    border: 1px solid var(--border);
    color: var(--text);
    padding: .35rem .4rem;
    border-radius: 6px;
    text-align: center;
}
.set-line input[type="number"]:disabled { opacity: .4; }
.set-line .dash { color: var(--muted); text-align: center; }
.set-actions { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.set-actions input[type="password"] {
    background: #0b1424;
    border: 1px solid var(--border);
    color: var(--text);
    padding: .35rem .5rem;
    border-radius: 6px;
    width: 130px;
}
.locked-note { color: #64748b; font-size: .78rem; font-style: italic; }

.clear-line { margin-top: .6rem; display: flex; gap: .5rem; align-items: center; }
.clear-line input[type="password"] {
    background: #0b1424;
    border: 1px solid var(--border);
    color: var(--text);
    padding: .35rem .5rem;
    border-radius: 6px;
    width: 130px;
}

.footer {
    text-align: center;
    color: var(--muted);
    padding: 1.5rem;
    font-size: .85rem;
    border-top: 1px solid var(--border);
    margin-top: 2rem;
}

/* ---------- Live scorecard ---------- */
.live-top { margin-bottom: 1rem; }
.back-link { color: var(--muted); text-decoration: none; font-size: .9rem; }
.back-link:hover { color: var(--accent); }
.live-fixture { color: var(--muted); margin-top: .25rem; }
.live-fixture .team { color: var(--accent); font-weight: 600; }

.pick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.pick-col h3 { margin: 0 0 .6rem; color: var(--accent); font-size: 1.05rem; }
.pick-item {
    display: flex; align-items: center; gap: .6rem;
    padding: .55rem .7rem; margin-bottom: .45rem;
    background: #0b1424; border: 1px solid var(--border); border-radius: 8px;
    cursor: pointer;
}
.pick-item input { width: 18px; height: 18px; }
.pick-item input:disabled + span { opacity: .45; }
.pick-item.used { opacity: .6; cursor: not-allowed; }
.used-tag { color: var(--muted); font-style: italic; font-size: .76rem; }
.pick-hint { color: var(--muted); font-size: .85rem; }

.players-strip { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; color: var(--muted); }
.players-strip strong { color: var(--text); }

.scoreboard {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: .75rem;
    align-items: stretch;
    margin: 1rem 0;
}
.score-side {
    background: var(--panel);
    border: 2px solid var(--border);
    border-radius: 16px;
    padding: 2rem 1rem;
    text-align: center;
    cursor: pointer;
    user-select: none;
    transition: background .1s, border-color .1s, transform .05s;
}
.score-side:hover { border-color: var(--accent); }
.score-side:active { transform: scale(.99); background: #13233c; }
.side-a { }
.side-b { }
.score-team-name { color: var(--accent); font-weight: 700; font-size: 1.1rem; }
.score-value { font-size: 5rem; font-weight: 800; line-height: 1.1; margin: .5rem 0; }
.tap-hint { color: var(--muted); font-size: .8rem; }
.score-mid {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-width: 120px; gap: .5rem;
}
.set-indicator { color: var(--muted); font-weight: 600; }
.live-status {
    color: var(--accent);
    font-weight: 700;
    min-height: 1.4em;
    text-align: center;
    font-size: 1.05rem;
}

.live-controls { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.inline-form { display: inline; }

@media (max-width: 640px) {
    .scoreboard { grid-template-columns: 1fr; }
    .score-value { font-size: 4rem; }
    .pick-grid { grid-template-columns: 1fr; }
}

/* ---------- Live Matches list ---------- */
.lm-fixture { font-weight: 700; margin-bottom: .4rem; }
.lm-fixture .team { color: var(--accent); }
.lm-fixture .vs { color: var(--muted); font-weight: 400; margin: 0 .4rem; }

.group-result {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem 1rem;
    margin-bottom: .8rem;
    padding: .5rem .75rem;
    background: #0b1424;
    border: 1px solid var(--border);
    border-radius: 8px;
}
.group-score { font-weight: 600; }
.group-winner { color: var(--success); font-weight: 700; }
.group-progress { color: var(--muted); font-size: .85rem; }
.lm-table .lm-action { text-align: right; }
.lm-players { font-size: .85rem; }
.lm-players .lm-side { color: var(--muted); }
.status-legacy { color: #fbbf24; font-weight: 600; }
.stage-chip {
    display: inline-block;
    padding: 1px 9px;
    border-radius: 999px;
    font-size: .74rem;
    font-weight: 700;
    letter-spacing: .02em;
    margin-right: .4rem;
    border: 1px solid var(--border);
}
.stage-league { background: rgba(148,163,184,.15); color: #cbd5e1; }
.stage-semifinal { background: rgba(14,165,233,.18); color: #7dd3fc; border-color: var(--accent-dark); }
.stage-final { background: rgba(234,179,8,.18); color: #fde047; border-color: #ca8a04; }
.edit-box summary { display: inline-block; list-style: none; cursor: pointer; }
.edit-box summary::-webkit-details-marker { display: none; }
.edit-form {
    margin-top: .6rem;
    text-align: left;
    background: #0b1424;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .75rem;
    min-width: 230px;
}
.edit-head { color: var(--accent); font-weight: 600; margin-bottom: .5rem; font-size: .85rem; }
.edit-set { display: flex; align-items: center; gap: .4rem; margin-bottom: .35rem; font-size: .82rem; }
.edit-set > span:first-child { width: 90px; color: var(--muted); }
.edit-set em { color: #64748b; font-style: normal; font-size: .75rem; }
.edit-set input[type="number"] {
    width: 48px; background: #0e1a2e; border: 1px solid var(--border);
    color: var(--text); padding: .3rem; border-radius: 6px; text-align: center;
}
.edit-actions { display: flex; gap: .4rem; margin-top: .5rem; flex-wrap: wrap; }
.edit-actions input[type="password"] {
    background: #0e1a2e; border: 1px solid var(--border); color: var(--text);
    padding: .3rem .5rem; border-radius: 6px; width: 120px;
}
.set-chip {
    display: inline-block;
    background: #0b1424;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1px 7px;
    margin: 1px 2px;
    font-size: .8rem;
}
.live-pill {
    color: #fecaca;
    background: rgba(239,68,68,.18);
    border: 1px solid var(--danger);
    padding: 2px 10px;
    border-radius: 999px;
    font-weight: 600;
    font-size: .82rem;
}

/* ---------- Report ---------- */
.best-panel {
    background: linear-gradient(135deg, rgba(14,165,233,.18), rgba(34,197,94,.12));
    border: 1px solid var(--accent-dark);
}
.best-title { color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; }
.best-team { font-size: 1.6rem; font-weight: 800; color: var(--accent); margin: .2rem 0; }
.best-stats { color: var(--text); font-size: .9rem; }
.data-table tr.top-row td { background: rgba(34,197,94,.08); }
.legend { color: var(--muted); font-size: .78rem; margin: .75rem 0 0; }
.best-line { color: var(--success); margin: 0 0 .6rem; font-size: .9rem; }
.topscorer-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
@media (max-width: 760px) { .topscorer-grid { grid-template-columns: 1fr; } }

/* Add Match form */
.addmatch-row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.addmatch-row label { display: flex; flex-direction: column; gap: .25rem; color: var(--muted); font-size: .8rem; }
.addmatch-row select {
    background: #0b1424; border: 1px solid var(--border); color: var(--text);
    padding: .45rem .5rem; border-radius: 6px; min-width: 150px;
}

/* ---------- Auth ---------- */
.side-auth {
    margin-top: auto;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: .6rem;
    flex-wrap: wrap;
}
.admin-tag { color: var(--success); font-size: .82rem; font-weight: 600; }
.sidebar { display: flex; flex-direction: column; }
.login-label { display: block; color: var(--muted); font-size: .85rem; margin-bottom: .3rem; }
.login-input {
    width: 100%;
    background: #0b1424;
    border: 1px solid var(--border);
    color: var(--text);
    padding: .5rem .6rem;
    border-radius: 8px;
}

/* ---------- Champion banner ---------- */
.champion-banner {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    padding: 1.4rem 1.6rem;
    margin-bottom: 1.5rem;
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(234,179,8,.22), rgba(14,165,233,.14));
    border: 1px solid #ca8a04;
}
.champion-trophy { font-size: 3rem; line-height: 1; }
.champion-head { font-size: 1.5rem; font-weight: 800; color: #fde047; }
.champion-sub { color: var(--text); font-weight: 600; margin: .15rem 0 .4rem; }
.champion-members { color: var(--muted); font-size: .9rem; }

/* ---------- Live match popup ---------- */
.live-popup {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, .72);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}
.live-popup[hidden] { display: none; }
.live-popup-card {
    position: relative;
    width: 100%;
    max-width: 560px;
    background: var(--panel);
    border: 1px solid var(--accent-dark);
    border-radius: 16px;
    padding: 1.5rem 1.5rem 1.75rem;
    box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.live-popup-close {
    position: absolute;
    top: .6rem; right: .8rem;
    background: none; border: none;
    color: var(--muted); font-size: 1.6rem; line-height: 1;
    cursor: pointer;
}
.live-popup-close:hover { color: var(--text); }
.live-popup-stage { color: var(--muted); font-size: .85rem; margin-bottom: .25rem; }
.live-popup-live {
    color: #fecaca; font-weight: 800; letter-spacing: .08em;
    font-size: .85rem; margin-bottom: 1rem;
}
.live-popup-score {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 1rem;
}
.lp-side { text-align: center; }
.lp-team { color: var(--accent); font-weight: 700; font-size: 1.1rem; }
.lp-players { color: var(--muted); font-size: .8rem; min-height: 1.1em; margin: .15rem 0 .4rem; }
.lp-num { font-size: 4rem; font-weight: 800; line-height: 1; }
.lp-mid { text-align: center; color: var(--muted); }
.lp-set { font-size: .85rem; font-weight: 600; }
.lp-dash { font-size: 2rem; color: var(--border); }
.lp-status { color: var(--accent); font-weight: 700; font-size: .85rem; min-height: 1.1em; }

@media (max-width: 560px) {
    .live-popup-score { grid-template-columns: 1fr; gap: .4rem; }
    .lp-num { font-size: 3rem; }
    .lp-dash { display: none; }
}

/* ---------- Responsive polish ---------- */
@media (max-width: 760px) {
    .topbar { padding: .75rem 1rem; }
    .brand-title { font-size: 1rem; }
    .brand-sub { font-size: .72rem; }
    .container { margin: 1rem auto; padding: 0 1rem; }
    h1 { font-size: 1.4rem; }

    /* Wide tables scroll horizontally instead of breaking the layout. */
    .panel { overflow-x: auto; }
    .data-table, .match-table { min-width: 520px; }

    /* Add Match form stacks. */
    .addmatch-row { flex-direction: column; align-items: stretch; }
    .addmatch-row select { min-width: 0; width: 100%; }

    /* Live Matches: let the action column wrap. */
    .lm-table { min-width: 560px; }

    /* Champion banner compresses nicely. */
    .champion-banner { flex-direction: column; text-align: center; gap: .6rem; padding: 1.1rem; }
    .champion-head { font-size: 1.25rem; }
}

@media (max-width: 480px) {
    .brand-sub { display: none; }
    .btn { padding: .5rem .8rem; }
    .champion-trophy { font-size: 2.2rem; }
}
