/* === Reset & Base === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-card: #1e2130;
    --bg-hover: #252839;
    --border: #2a2d3e;
    --text-primary: #e8e9ed;
    --text-secondary: #b4b8c8;
    --text-muted: #8e93a8;
    --accent: #4d8ef7;
    --accent-hover: #3a7ae8;
    --gold: #f0c040;
    --gold-dark: #c9982a;
    --white-square: #f0f0f0;
    --black-square: #3a3a3a;
    --bye-color: #9b6dff;
    --win: #4ade80;
    --draw: #facc15;
    --loss: #f87171;
    --mono: 'JetBrains Mono', monospace;
    --sans: 'Inter', system-ui, -apple-system, sans-serif;
}

html {
    overflow-x: hidden;
}

body {
    font-family: var(--sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    /* Subtle chess-board pattern */
    background-image:
        linear-gradient(45deg, #12141e 25%, transparent 25%),
        linear-gradient(-45deg, #12141e 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #12141e 75%),
        linear-gradient(-45deg, transparent 75%, #12141e 75%);
    background-size: 60px 60px;
    background-position: 0 0, 0 30px, 30px -30px, 30px 0px;
}

a {
    color: var(--gold);
    text-decoration: none;
    transition: color 0.15s;
}

a:hover {
    color: var(--gold-dark);
    text-decoration: underline;
}

/* === Header === */
.header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 1.25rem 1.5rem;
    overflow: hidden;
}

.header-inner {
    max-width: 960px;
    margin: 0 auto;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    font-size: 2.25rem;
    background: linear-gradient(135deg, var(--gold), var(--gold-dark));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 2px 4px rgba(240, 192, 64, 0.3));
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.alpha-badge {
    font-size: 0.6rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    background: var(--gold-dark);
    color: #1a1a2e;
    padding: 0.15em 0.5em;
    border-radius: 4px;
    vertical-align: middle;
    position: relative;
    top: -0.15em;
}

.tagline {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: -0.1rem;
}

.intro {
    margin-bottom: 1rem;
}

.intro p {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.6;
}

.intro .disclaimer {
    margin-top: 0.5rem;
    font-size: 0.78rem;
    opacity: 0.7;
}

/* === Main === */
.main {
    flex: 1;
    max-width: 960px;
    width: 100%;
    min-width: 0;
    margin: 0 auto;
    padding: 1.5rem;
    overflow-x: hidden;
}

/* === Input Section === */
.input-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

.input-card label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.input-row {
    display: flex;
    gap: 0.75rem;
}

.input-row input {
    flex: 1;
    padding: 0.7rem 1rem;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: var(--mono);
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s;
}

.input-row input:focus {
    border-color: var(--accent);
}

.input-row input::placeholder {
    color: var(--text-muted);
}

.input-row button {
    padding: 0.7rem 1.5rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s, transform 0.1s;
}

.input-row button:hover {
    background: var(--accent-hover);
}

.input-row button:active {
    transform: scale(0.97);
}

.input-row button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.input-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

/* === Error Banner === */
.error-banner {
    background: rgba(248, 113, 113, 0.1);
    border: 1px solid rgba(248, 113, 113, 0.3);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    margin-top: 1rem;
    color: var(--loss);
    font-size: 0.85rem;
    animation: fadeIn 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.error-banner span {
    flex: 1;
}

.error-retry-btn {
    background: rgba(248, 113, 113, 0.2);
    border: 1px solid rgba(248, 113, 113, 0.4);
    color: var(--loss);
    padding: 0.3rem 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    white-space: nowrap;
    transition: background 0.2s;
}

.error-retry-btn:hover {
    background: rgba(248, 113, 113, 0.35);
}

.error-dismiss-btn {
    background: none;
    border: none;
    color: var(--loss);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0 0.25rem;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.error-dismiss-btn:hover {
    opacity: 1;
}

/* === Loading === */
.loading {
    text-align: center;
    padding: 3rem 1rem;
    animation: fadeIn 0.3s ease;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    margin: 0 auto 1rem;
    animation: spin 0.8s linear infinite;
}

#loading-text {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* === Results === */
.results {
    margin-top: 1.5rem;
    animation: fadeIn 0.4s ease;
    min-width: 0;
    overflow: hidden;
}

.tournament-header {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
    margin-bottom: 1rem;
}

.tournament-header h2 {
    font-size: 1.15rem;
    font-weight: 600;
}

.tournament-header .meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* === Round Picker (completed tournaments) === */
.round-picker {
    margin-top: 1.5rem;
    animation: fadeIn 0.4s ease;
}

.round-picker-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    text-align: center;
}

.round-picker-card h2 {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.round-picker-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.round-picker-prompt {
    font-size: 0.9rem;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.round-picker-row {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    align-items: center;
}

.round-picker-row select,
.round-switcher select {
    padding: 0.55rem 0.75rem;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: var(--mono);
    font-size: 0.85rem;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
    appearance: auto;
}

.round-picker-row select:focus,
.round-switcher select:focus {
    border-color: var(--accent);
}

.round-picker-row button {
    padding: 0.55rem 1.5rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.round-picker-row button:hover {
    background: var(--accent-hover);
}

.round-picker-row button:active {
    transform: scale(0.97);
}

/* === Round Switcher (in header for completed tournaments) === */
.round-switcher {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.round-switcher select {
    font-size: 0.8rem;
    padding: 0.35rem 0.5rem;
}

/* === Tabs === */
.tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0;
}

.tab {
    padding: 0.6rem 1.25rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
}

.tab:hover {
    color: var(--text-primary);
}

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* === Tab Content === */
.tab-content {
    animation: fadeIn 0.3s ease;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* === Tables === */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}

.data-table th {
    background: var(--bg-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    padding: 0.65rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: 0.6rem 0.75rem;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border);
}

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

.data-table tbody tr:hover {
    background: var(--bg-hover);
}

.data-table .num {
    font-family: var(--mono);
    font-size: 0.8rem;
}

.data-table .text-center {
    text-align: center;
}

.data-table .text-right {
    text-align: right;
}

/* === Pairings Table Specific === */
.vs-cell {
    text-align: center;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.75rem;
}

.player-cell {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.player-cell.align-right {
    justify-content: flex-end;
    text-align: right;
}

.color-indicator {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.color-indicator.white {
    background: var(--white-square);
}

.color-indicator.black {
    background: var(--black-square);
}

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

.player-meta {
    font-family: var(--mono);
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* === Bye Card === */
.bye-card {
    background: rgba(155, 109, 255, 0.08);
    border: 1px solid rgba(155, 109, 255, 0.2);
    border-radius: 8px;
    padding: 0.65rem 1rem;
    margin-top: 0.75rem;
    font-size: 0.85rem;
    color: var(--bye-color);
}

/* === Color History Strip === */
.color-strip {
    display: flex;
    gap: 3px;
}

.color-strip .square {
    width: 22px;
    height: 22px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 600;
    border: 1px solid var(--border);
}

.color-strip .square.w {
    background: var(--white-square);
    color: #1a1a1a;
}

.color-strip .square.b {
    background: var(--black-square);
    color: #e0e0e0;
}

.color-strip .square.bye {
    background: rgba(155, 109, 255, 0.25);
    color: var(--bye-color);
}

.result-win { color: var(--win); }
.result-draw { color: var(--draw); }
.result-loss { color: var(--loss); }

/* === Bye Selector === */
.bye-selector {
    margin-bottom: 1rem;
}

.bye-selector-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
}

.bye-selector-card .bye-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--bye-color);
    margin-bottom: 0.25rem;
}

.bye-selector-card .bye-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.bye-input-wrap {
    position: relative;
}

.bye-input-wrap input {
    width: 100%;
    padding: 0.55rem 0.75rem;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: var(--sans);
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s;
}

.bye-input-wrap input:focus {
    border-color: var(--bye-color);
}

.bye-input-wrap input::placeholder {
    color: var(--text-muted);
}

.bye-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-top: 4px;
    max-height: 240px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.bye-option {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 0.85rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.15s;
}

.bye-option:hover {
    background: var(--bg-hover);
}

.bye-option .bye-opt-name {
    font-weight: 500;
}

.bye-option .bye-opt-meta {
    font-family: var(--mono);
    font-size: 0.75rem;
    color: var(--text-muted);
}

.bye-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.bye-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: rgba(155, 109, 255, 0.12);
    border: 1px solid rgba(155, 109, 255, 0.25);
    color: var(--bye-color);
    padding: 0.3rem 0.6rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
    animation: fadeIn 0.2s ease;
}

.bye-chip button {
    background: none;
    border: none;
    color: var(--bye-color);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0;
    opacity: 0.7;
    transition: opacity 0.15s;
}

.bye-chip button:hover {
    opacity: 1;
}

.manual-bye-card {
    background: rgba(155, 109, 255, 0.05);
    border: 1px dashed rgba(155, 109, 255, 0.25);
    border-radius: 8px;
    padding: 0.65rem 1rem;
    margin-top: 0.75rem;
    font-size: 0.85rem;
    color: var(--bye-color);
}

/* === Hidden === */
.hidden {
    display: none !important;
}

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

.footer a {
    color: var(--text-secondary);
}

.footer a:hover {
    color: var(--text-primary);
}

/* === Animations === */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* === Responsive === */
@media (max-width: 640px) {
    .main {
        padding: 0.75rem;
    }

    .input-card {
        padding: 1rem;
    }

    .input-row {
        flex-direction: column;
    }

    .input-row button {
        width: 100%;
    }

    .tournament-header {
        padding: 0.75rem 1rem;
    }

    /* Tabs: compact to fit all three */
    .tabs {
        gap: 0;
    }

    .tab {
        padding: 0.45rem 0.5rem;
        font-size: 0.7rem;
        flex: 1;
        text-align: center;
        white-space: nowrap;
    }

    /* Tables: tighter padding and smaller text */
    .data-table th {
        padding: 0.4rem 0.35rem;
        font-size: 0.65rem;
        letter-spacing: 0.02em;
    }

    .data-table td {
        padding: 0.35rem 0.35rem;
        font-size: 0.75rem;
    }

    .data-table .num {
        font-size: 0.7rem;
    }

    /* Pairings table: compact player cells */
    .player-cell {
        gap: 0.25rem;
        min-width: 0;
    }

    .player-name {
        font-size: 0.72rem;
    }

    .player-meta {
        font-size: 0.62rem;
    }

    .color-indicator {
        width: 10px;
        height: 10px;
    }

    .vs-cell {
        font-size: 0.6rem;
    }

    /* History table: smaller color squares */
    .color-strip .square {
        width: 16px;
        height: 16px;
        font-size: 0.55rem;
    }

    .bye-card,
    .manual-bye-card {
        font-size: 0.75rem;
        padding: 0.5rem 0.75rem;
    }
}

/* === Scrollbar === */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}
