*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-body: #0f1117;
    --bg-header: #161822;
    --bg-card: #1a1d2b;
    --bg-input: #12141e;
    --accent: #4ecca3;
    --accent-hover: #3db88e;
    --danger: #e94560;
    --danger-hover: #d63350;
    --text: #e8e8ed;
    --text-dim: #8b8da3;
    --border: #2a2d3e;
    --border-light: #343750;
    --radius: 10px;
    --radius-lg: 14px;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-body);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    background: var(--bg-header);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
}

.header-inner {
    max-width: 960px;
    margin: 0 auto;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo-icon {
    font-size: 2.2rem;
    line-height: 1;
    color: var(--accent);
    filter: drop-shadow(0 0 8px rgba(78, 204, 163, 0.3));
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.3px;
    color: var(--text);
}

.subtitle {
    font-size: 0.8rem;
    color: var(--text-dim);
    font-weight: 400;
    margin-top: 1px;
}

.header-stats {
    display: flex;
    gap: 20px;
}

.stat {
    text-align: center;
}

.stat-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--accent);
    line-height: 1.2;
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Main */
.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 24px;
    flex: 1;
    width: 100%;
}

/* Card */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.card-title {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-dim);
    margin-bottom: 16px;
}

/* Add player form */
.add-form {
    display: flex;
    gap: 10px;
}

.add-form input {
    flex: 1;
    padding: 11px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.add-form input::placeholder {
    color: var(--text-dim);
}

.add-form input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(78, 204, 163, 0.15);
}

.add-form button {
    padding: 11px 28px;
    border: none;
    border-radius: var(--radius);
    background: var(--accent);
    color: var(--bg-body);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s, transform 0.1s;
}

.add-form button:hover {
    background: var(--accent-hover);
}

.add-form button:active {
    transform: scale(0.97);
}

.add-form button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Players table */
.players-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.players-table th {
    padding: 10px 16px;
    text-align: left;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border);
}

.players-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.players-table tbody tr {
    transition: background 0.15s;
}

.players-table tbody tr:hover {
    background: rgba(78, 204, 163, 0.04);
}

.players-table tbody tr:last-child td {
    border-bottom: none;
}

.player-name {
    font-weight: 500;
}

.players-table .rating {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    text-align: center;
    font-size: 0.95rem;
    color: var(--text);
}

.rating-label {
    display: none;
}

.players-table .actions {
    text-align: right;
    width: 1%;
    white-space: nowrap;
}

/* Buttons */
.btn-icon {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
    font-size: 0.95rem;
    transition: all 0.15s;
    margin-left: 6px;
}

.btn-icon.edit {
    color: var(--text-dim);
}

.btn-icon.edit:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: rgba(78, 204, 163, 0.08);
}

.btn-icon.delete {
    color: var(--text-dim);
}

.btn-icon.delete:hover {
    color: var(--danger);
    border-color: var(--danger);
    background: rgba(233, 69, 96, 0.08);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-dim);
}

.empty-state .icon {
    font-size: 3rem;
    margin-bottom: 12px;
    opacity: 0.35;
}

.empty-state p {
    font-size: 0.95rem;
}

/* Toast notifications */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 0.88rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: toast-in 0.3s ease, toast-out 0.3s ease 2.7s forwards;
    max-width: 340px;
}

.toast.success {
    background: var(--accent);
    color: var(--bg-body);
}

.toast.error {
    background: var(--danger);
    color: #fff;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateX(30px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
    from { opacity: 1; }
    to   { opacity: 0; transform: translateY(-8px); }
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 900;
    animation: fade-in 0.2s ease;
    overflow-y: auto;
    padding: 24px 16px;
}

@keyframes fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px;
    width: 90%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    animation: modal-in 0.25s ease;
    margin: auto;
    flex-shrink: 0;
}

.modal-wide {
    max-width: 520px;
}

@keyframes modal-in {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal h2 {
    margin-bottom: 20px;
    font-size: 1.1rem;
    font-weight: 600;
}

.modal label {
    display: block;
    color: var(--text-dim);
    font-size: 0.8rem;
    font-weight: 500;
    margin-bottom: 6px;
    margin-top: 14px;
}

.modal label:first-of-type {
    margin-top: 0;
}

.modal input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.modal input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(78, 204, 163, 0.15);
}

.modal-buttons {
    display: flex;
    gap: 10px;
    margin-top: 24px;
    justify-content: flex-end;
}

.modal-buttons button {
    padding: 10px 22px;
    border: none;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.15s;
}

.btn-save {
    background: var(--accent);
    color: var(--bg-body);
}

.btn-save:hover {
    background: var(--accent-hover);
}

.btn-cancel {
    background: transparent;
    border: 1px solid var(--border) !important;
    color: var(--text-dim);
}

.btn-cancel:hover {
    border-color: var(--border-light) !important;
    color: var(--text);
}

/* ═══════════════════════════════════════════════════════════════
   TOURNAMENT STYLES
   ═══════════════════════════════════════════════════════════════ */

/* New tournament button */
.action-card {
    text-align: center;
    padding: 16px;
}

.btn-new-tournament {
    padding: 14px 36px;
    border: 2px dashed var(--accent);
    border-radius: var(--radius);
    background: rgba(78, 204, 163, 0.06);
    color: var(--accent);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
}

.btn-new-tournament:hover {
    background: rgba(78, 204, 163, 0.12);
    border-color: var(--accent-hover);
}

/* Modal: select + row layout */
.modal select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.modal select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(78, 204, 163, 0.15);
}

.modal select option {
    background: var(--bg-card);
    color: var(--text);
}

.modal-row {
    display: flex;
    gap: 12px;
    margin-top: 14px;
}

.modal-col {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.modal-col label {
    margin-top: 0 !important;
}

.rounds-info {
    margin-top: 10px;
    font-size: 0.85rem;
    color: var(--accent);
    font-weight: 600;
    text-align: center;
    min-height: 20px;
}

/* Player checkboxes */
.player-checkboxes {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 8px;
    max-height: 240px;
    overflow-y: auto;
    padding: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    scrollbar-width: thin;
    scrollbar-color: var(--border-light) transparent;
}

.player-checkboxes::-webkit-scrollbar {
    width: 6px;
}

.player-checkboxes::-webkit-scrollbar-track {
    background: transparent;
}

.player-checkboxes::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: 3px;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    font-size: 0.9rem;
    text-transform: none;
    letter-spacing: 0;
}

.checkbox-item:hover {
    background: rgba(78, 204, 163, 0.06);
}

.checkbox-item input[type="checkbox"] {
    accent-color: var(--accent);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.checkbox-name {
    flex: 1;
    font-weight: 500;
    color: var(--text);
}

.checkbox-rating {
    font-size: 0.82rem;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
}

.btn-start {
    padding: 12px 32px;
    border: none;
    border-radius: var(--radius);
    background: var(--accent);
    color: var(--bg-body);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    width: 100%;
}

.btn-start:hover {
    background: var(--accent-hover);
}

.btn-start:active {
    transform: scale(0.98);
}

.btn-start:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Match rows */
.match-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.match-row:last-child {
    border-bottom: none;
}

.match-board {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-input);
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-dim);
    flex-shrink: 0;
}

.match-player {
    flex: 1;
    font-weight: 500;
    font-size: 0.95rem;
}

.match-player.winner {
    color: var(--accent);
}

.black-player {
    text-align: right;
}

.match-result-buttons {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.result-btn {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-input);
    color: var(--text-dim);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    min-width: 42px;
    text-align: center;
}

.result-btn:hover {
    border-color: var(--border-light);
    color: var(--text);
}

.result-btn.active.win {
    background: rgba(78, 204, 163, 0.15);
    border-color: var(--accent);
    color: var(--accent);
}

.result-btn.active.draw {
    background: rgba(255, 193, 7, 0.15);
    border-color: #ffc107;
    color: #ffc107;
}

.result-btn.active.loss {
    background: rgba(233, 69, 96, 0.15);
    border-color: var(--danger);
    color: var(--danger);
}

.bye-row {
    opacity: 0.6;
}

.match-bye-label {
    font-size: 0.85rem;
    color: var(--text-dim);
    font-style: italic;
}

/* Standings table */
.standings-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.standings-table th {
    padding: 10px 16px;
    text-align: left;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border);
}

.standings-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.standings-table tbody tr:last-child td {
    border-bottom: none;
}

.standings-table tbody tr:hover {
    background: rgba(78, 204, 163, 0.04);
}

.standings-table .rank {
    width: 40px;
    font-weight: 600;
    color: var(--text-dim);
    text-align: center;
}

.standings-table .points {
    font-weight: 700;
    text-align: center;
    font-variant-numeric: tabular-nums;
    color: var(--accent);
}

.standings-table .buchholz {
    text-align: center;
    font-variant-numeric: tabular-nums;
    color: var(--text-dim);
}

.standings-table .rating {
    text-align: center;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.standings-table .rating-change {
    text-align: center;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.rating-up {
    color: var(--accent);
}

.rating-down {
    color: var(--danger);
}

.standings-table tr.leader td {
    background: rgba(78, 204, 163, 0.06);
}

.standings-table tr.leader .rank {
    color: var(--accent);
}

/* Round navigation */
.round-nav {
    display: flex;
    gap: 6px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 16px;
}

.round-nav-btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text-dim);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.round-nav-btn:hover {
    border-color: var(--border-light);
    color: var(--text);
}

.round-nav-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--bg-body);
}

/* Finish button */
.btn-finish {
    padding: 14px 40px;
    border: none;
    border-radius: var(--radius);
    background: var(--danger);
    color: #fff;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.btn-finish:hover {
    background: var(--danger-hover);
}

.btn-finish:active {
    transform: scale(0.98);
}

.btn-finish:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Winner display */
.winner-display {
    text-align: center;
    padding: 20px;
}

.winner-trophy {
    font-size: 4rem;
    color: #ffc107;
    filter: drop-shadow(0 0 16px rgba(255, 193, 7, 0.4));
    animation: trophy-bounce 1s ease;
    line-height: 1.2;
}

@keyframes trophy-bounce {
    0% { transform: scale(0.3); opacity: 0; }
    50% { transform: scale(1.15); }
    70% { transform: scale(0.95); }
    100% { transform: scale(1); opacity: 1; }
}

.winner-name {
    font-size: 1.6rem;
    font-weight: 700;
    margin-top: 12px;
    color: var(--accent);
}

.winner-score {
    color: var(--text-dim);
    font-size: 1rem;
    margin-top: 4px;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-classical {
    background: rgba(78, 204, 163, 0.15);
    color: var(--accent);
}

.badge-rapid {
    background: rgba(255, 193, 7, 0.15);
    color: #ffc107;
}

.badge-blitz {
    background: rgba(233, 69, 96, 0.15);
    color: var(--danger);
}

.badge-bullet {
    background: rgba(156, 39, 176, 0.15);
    color: #bb86fc;
}

/* History table */
.history-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.history-table th {
    padding: 10px 16px;
    text-align: left;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border);
}

.history-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.history-table tbody tr:last-child td {
    border-bottom: none;
}

.history-table tbody tr:hover {
    background: rgba(78, 204, 163, 0.04);
}

.history-table .actions {
    text-align: right;
    width: 1%;
    white-space: nowrap;
}

.text-dim {
    color: var(--text-dim);
    font-size: 0.9rem;
}

/* Footer */
footer {
    text-align: center;
    padding: 20px;
    color: var(--text-dim);
    font-size: 0.78rem;
    border-top: 1px solid var(--border);
}

/* Mobile */
@media (max-width: 640px) {
    /* Header */
    .header-inner {
        padding: 12px 16px;
        gap: 10px;
    }

    .logo {
        gap: 10px;
        min-width: 0;
    }

    .logo-icon {
        font-size: 1.6rem;
    }

    .logo h1 {
        font-size: 1rem;
    }

    .subtitle {
        font-size: 0.7rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 180px;
    }

    .header-stats {
        gap: 12px;
        flex-shrink: 0;
    }

    .stat-value {
        font-size: 1.1rem;
    }

    /* Layout */
    .container {
        padding: 12px;
    }

    .card {
        padding: 16px;
        border-radius: var(--radius);
    }

    .add-form {
        flex-direction: column;
    }

    /* Players table → mobile cards */
    .players-table,
    .players-table thead,
    .players-table tbody,
    .players-table th,
    .players-table td,
    .players-table tr {
        display: block;
    }

    .players-table thead {
        display: none;
    }

    .players-table tbody tr {
        background: var(--bg-input);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        margin-bottom: 10px;
        padding: 14px;
    }

    .players-table td {
        padding: 3px 0;
        border: none;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .player-name {
        font-size: 1.05rem;
        margin-bottom: 4px;
    }

    .players-table td::before {
        content: attr(data-label);
        color: var(--text-dim);
        font-size: 0.75rem;
        text-transform: uppercase;
        font-weight: 500;
    }

    .players-table td.player-name-cell::before {
        display: none;
    }

    .players-table td.actions {
        justify-content: flex-end;
        padding-top: 10px;
        margin-top: 6px;
        border-top: 1px solid var(--border);
        gap: 6px;
    }

    .players-table td.actions::before {
        display: none;
    }

    .players-table td.actions .btn-icon {
        margin-left: 0;
    }

    .btn-icon {
        width: 40px;
        height: 40px;
    }

    /* Modal - scrollable on mobile */
    .modal-overlay {
        align-items: flex-start;
        padding: 16px 12px;
    }

    .modal {
        width: 100%;
        padding: 20px;
        max-width: none;
    }

    .modal-wide {
        max-width: none;
    }

    .modal-row {
        flex-direction: column;
        gap: 0;
    }

    .modal-col label {
        margin-top: 14px !important;
    }

    .modal-buttons {
        flex-direction: column-reverse;
    }

    .modal-buttons button {
        width: 100%;
        padding: 12px;
    }

    /* Player checkboxes in modal */
    .player-checkboxes {
        grid-template-columns: 1fr;
        max-height: 200px;
    }

    .checkbox-item {
        padding: 10px 8px;
    }

    /* Match rows */
    .match-row {
        gap: 8px;
        padding: 10px 0;
    }

    .match-board {
        width: 24px;
        height: 24px;
        font-size: 0.72rem;
    }

    .match-player {
        font-size: 0.85rem;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .black-player {
        text-align: right;
    }

    .match-result-buttons {
        gap: 3px;
    }

    .result-btn {
        padding: 8px 8px;
        font-size: 0.75rem;
        min-width: 36px;
    }

    /* Standings */
    .standings-table td,
    .standings-table th {
        padding: 8px 6px;
        font-size: 0.82rem;
    }

    .standings-table .rank {
        width: 28px;
    }

    /* History table */
    .history-table,
    .history-table thead,
    .history-table tbody,
    .history-table th,
    .history-table td,
    .history-table tr {
        display: block;
    }

    .history-table thead {
        display: none;
    }

    .history-table tbody tr {
        background: var(--bg-input);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        margin-bottom: 10px;
        padding: 14px;
    }

    .history-table td {
        padding: 3px 0;
        border: none;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .history-table td::before {
        content: attr(data-label);
        color: var(--text-dim);
        font-size: 0.75rem;
        text-transform: uppercase;
        font-weight: 500;
    }

    .history-table .actions {
        justify-content: flex-end;
        padding-top: 8px;
        margin-top: 4px;
        border-top: 1px solid var(--border);
    }

    .history-table .actions::before {
        display: none;
    }

    /* Winner */
    .winner-trophy {
        font-size: 3rem;
    }

    .winner-name {
        font-size: 1.3rem;
    }

    /* New tournament button */
    .btn-new-tournament {
        padding: 12px 20px;
        font-size: 0.95rem;
    }

    .action-card {
        padding: 12px;
    }
}
