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

body {
    font-family: system-ui, -apple-system, sans-serif;
    font-size: 15px;
    background: #f0f2f5;
    color: #1a1a2e;
    min-height: 100vh;
    -webkit-text-size-adjust: 100%;
}

/* ── Header ── */
header {
    background: #1a1a2e;
    color: #fff;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.logo {
    font-size: 1.05rem;
    font-weight: 700;
    color: #e2b714;
    text-decoration: none;
    letter-spacing: .5px;
    white-space: nowrap;
}

.breadcrumb {
    font-size: .82rem;
    color: #aab;
    line-height: 1.4;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.breadcrumb a { color: #c5c7d8; text-decoration: none; }
.breadcrumb a:hover { color: #e2b714; }
.breadcrumb span { color: #778; }

/* ── Layout ── */
main {
    max-width: 900px;
    margin: 20px auto;
    padding: 0 12px 60px;
}

h1 { font-size: 1.35rem; margin-bottom: 4px; }
h2 { font-size: 1.1rem;  margin-bottom: 12px; color: #2c2c54; }
h3 { font-size: 1rem;    margin-bottom: 8px;  color: #444; }

/* ── Cards ── */
.card {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
    padding: 16px;
    margin-bottom: 16px;
}

.card-title {
    font-size: .95rem;
    font-weight: 600;
    color: #2c2c54;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 2px solid #f0f2f5;
}

/* ── Tables ── */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -16px;
    padding: 0 16px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9rem;
    min-width: 380px;
}
th {
    text-align: left;
    padding: 8px 10px;
    background: #f7f8fc;
    color: #556;
    font-weight: 600;
    border-bottom: 2px solid #e8eaf0;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .5px;
    white-space: nowrap;
}
td {
    padding: 10px;
    border-bottom: 1px solid #f0f2f5;
    vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbff; }

.rank { font-weight: 700; color: #888; width: 32px; }
.rank-1 { color: #d4a017; }
.rank-2 { color: #7a7a7a; }
.rank-3 { color: #a0522d; }

.player-name { font-weight: 500; }
.score-cell { font-weight: 700; font-size: 1rem; }
.buchholz-cell { color: #888; font-size: .85rem; }

/* ── Badges ── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
    white-space: nowrap;
}
.badge-registration { background: #e8f4fd; color: #2196f3; }
.badge-active       { background: #e8f5e9; color: #388e3c; }
.badge-completed    { background: #f3e5f5; color: #7b1fa2; }
.badge-dropped      { background: #fce4ec; color: #c62828; }
.badge-ongoing      { background: #fff3e0; color: #e65100; }
.badge-bye          { background: #e3f2fd; color: #0277bd; }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 9px 16px;
    min-height: 40px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: .88rem;
    font-weight: 600;
    text-decoration: none;
    transition: opacity .15s, transform .1s;
    line-height: 1.2;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.btn:hover  { opacity: .85; transform: translateY(-1px); }
.btn:active { transform: translateY(0); opacity: .75; }

.btn-primary   { background: #1a1a2e; color: #fff; }
.btn-success   { background: #388e3c; color: #fff; }
.btn-warning   { background: #e65100; color: #fff; }
.btn-danger    { background: #c62828; color: #fff; }
.btn-secondary { background: #e0e3ef; color: #2c2c54; }
.btn-gold      { background: #e2b714; color: #1a1a2e; }
.btn-sm { padding: 6px 12px; min-height: 34px; font-size: .82rem; }

.btn-group {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}

form.inline { display: inline; }

/* ── Inputs ── */
input[type="text"], input[type="number"], select, textarea {
    padding: 10px 12px;
    min-height: 44px;
    border: 1.5px solid #d0d4e0;
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    color: #1a1a2e;
    background: #fff;
    transition: border-color .15s;
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
}
input[type="text"]:focus, input[type="number"]:focus {
    outline: none;
    border-color: #1a1a2e;
    box-shadow: 0 0 0 3px rgba(26,26,46,.1);
}

.form-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    margin-bottom: 4px;
}
.form-row .form-group { flex: 1; min-width: 0; }
.form-group { margin-bottom: 12px; }
.form-group label {
    display: block;
    font-size: .78rem;
    font-weight: 600;
    color: #556;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: .4px;
}

/* ── Alerts ── */
.alert {
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 14px;
    font-size: .9rem;
    line-height: 1.5;
}
.alert a { color: inherit; font-weight: 600; }
.alert-error   { background: #fce4ec; color: #b71c1c; border-left: 4px solid #c62828; }
.alert-success { background: #e8f5e9; color: #1b5e20; border-left: 4px solid #388e3c; }
.alert-info    { background: #e3f2fd; color: #0d47a1; border-left: 4px solid #1976d2; }
.alert-warning { background: #fff3e0; color: #e65100; border-left: 4px solid #f57c00; }

/* ── Pairing Cards ── */
.pairings-list { display: flex; flex-direction: column; gap: 10px; }

.pairing-card {
    border: 1.5px solid #e8eaf0;
    border-radius: 10px;
    padding: 12px 14px;
    transition: border-color .15s;
    background: #fff;
}
.pairing-card.has-result  { border-color: #d4f0d8; background: #fafffe; }
.pairing-card.is-bye      { opacity: .7; background: #f9f9fc; }
.pairing-card.is-editing  { border-color: #1a1a2e; box-shadow: 0 0 0 3px rgba(26,26,46,.07); }

.pairing-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.pairing-board-label {
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: #aab;
}
.pairing-result-label {
    font-size: .82rem;
    font-weight: 600;
}
.pairing-result-label.win  { color: #388e3c; }
.pairing-result-label.draw { color: #e65100; }

.pairing-players {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}
.pairing-name {
    font-weight: 600;
    font-size: .95rem;
    line-height: 1.3;
    overflow-wrap: break-word;
    word-break: break-word;
}
.pairing-name.p2 { text-align: right; }
.pairing-name.winner { color: #388e3c; }
.pairing-name.loser  { color: #bbb; }

.pairing-vs {
    background: #f0f2f5;
    border-radius: 20px;
    padding: 4px 10px;
    font-size: .72rem;
    font-weight: 700;
    color: #aaa;
    text-align: center;
    white-space: nowrap;
    flex-shrink: 0;
}

.pairing-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.pairing-btn-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 6px;
    align-items: center;
}
.pairing-btn-row .btn {
    width: 100%;
    font-size: .82rem;
    padding: 8px 6px;
    min-height: 38px;
}
.pairing-btn-row .btn-draw {
    background: #e0e3ef;
    color: #2c2c54;
    font-size: .78rem;
    padding: 8px 4px;
}

.pairing-edit-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.result-pending { color: #aaa; font-style: italic; font-size: .85rem; }

/* ── Round Link ── */
.round-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: #f7f8fc;
    border-radius: 8px;
    margin-bottom: 8px;
    text-decoration: none;
    color: #1a1a2e;
    border: 1.5px solid #e8eaf0;
    transition: border-color .15s, background .15s;
    min-height: 52px;
}
.round-link:hover { border-color: #1a1a2e; background: #fff; }
.round-link .round-info   { font-weight: 600; }
.round-link .round-status { font-size: .85rem; color: #888; }

/* ── Dropped rows ── */
.dropped-row td { color: #bbb !important; text-decoration: line-through; }
.dropped-row td:last-child { text-decoration: none; }

/* ── Tabs ── */
.tabs {
    display: flex;
    gap: 2px;
    margin-bottom: 16px;
    border-bottom: 2px solid #e8eaf0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab-link {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    text-decoration: none;
    color: #778;
    font-weight: 600;
    font-size: .88rem;
    border-radius: 8px 8px 0 0;
    margin-bottom: -2px;
    border: 2px solid transparent;
    border-bottom: none;
    white-space: nowrap;
    min-height: 44px;
}
.tab-link:hover  { color: #2c2c54; background: #f0f2f5; }
.tab-link.active {
    color: #1a1a2e;
    background: #fff;
    border-color: #e8eaf0;
    border-bottom-color: #fff;
}

/* ── Page title ── */
.page-title {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 10px;
}
.page-title .btn-group { margin-top: 2px; }

.meta-info { color: #888; font-size: .85rem; margin-top: 4px; line-height: 1.5; }

/* ── Empty state ── */
.empty-state {
    text-align: center;
    padding: 36px 20px;
    color: #aaa;
}
.empty-state .icon { font-size: 2.2rem; margin-bottom: 10px; }
.empty-state p { font-size: .92rem; }

/* ── Tournament grid ── */
.tournament-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
}

.tournament-card {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
    padding: 16px 18px;
    text-decoration: none;
    color: #1a1a2e;
    border: 2px solid transparent;
    transition: border-color .15s, box-shadow .15s;
    display: block;
    -webkit-tap-highlight-color: transparent;
}
.tournament-card:hover { border-color: #1a1a2e; box-shadow: 0 4px 16px rgba(0,0,0,.1); }
.tournament-card h3 { font-size: .97rem; margin-bottom: 8px; }
.tournament-card .meta { font-size: .82rem; color: #888; margin-top: 8px; }

/* ── Scoring legend ── */
.scoring-legend {
    font-size: .82rem;
    color: #778;
    padding: 10px 14px;
    background: #f7f8fc;
    border-radius: 8px;
    line-height: 1.6;
}

/* ── Mobile ── */
@media (max-width: 600px) {
    main { padding: 0 10px 50px; margin-top: 14px; }

    h1 { font-size: 1.2rem; }

    .card { padding: 14px 12px; }
    .card-title { font-size: .9rem; }

    /* Stack page title vertically on very small screens */
    .page-title { flex-direction: column; gap: 8px; }
    .page-title .btn-group { width: 100%; }
    .page-title .btn-group .btn { flex: 1; justify-content: center; }

    /* Stack form rows */
    .form-row { flex-direction: column; }
    .form-row .btn { width: 100%; }

    /* Tabs scroll */
    .tab-link { padding: 10px 13px; font-size: .84rem; }

    /* Pairing players: keep side-by-side but allow wrapping names */
    .pairing-players { gap: 6px; }
    .pairing-name { font-size: .88rem; }

    /* Result buttons fill full width */
    .pairing-btn-row .btn { font-size: .78rem; padding: 8px 4px; }

    /* Table: allow scroll */
    .table-scroll { margin: 0 -12px; padding: 0 12px; }

    /* Tournament grid single column */
    .tournament-grid { grid-template-columns: 1fr; }

    /* Btn group in header area stack */
    .btn-group { gap: 5px; }
}

@media (max-width: 380px) {
    /* Extremely small: stack pairing players vertically */
    .pairing-players {
        grid-template-columns: 1fr;
        text-align: center;
        gap: 4px;
    }
    .pairing-name.p2 { text-align: center; }
    .pairing-vs { justify-self: center; }

    .pairing-btn-row {
        grid-template-columns: 1fr;
    }
    .pairing-btn-row .btn-draw { order: -1; }
}
