* {
    box-sizing: border-box;
}

:root {
    --accent: #00bf63;
    --accent-hover: #00a956;
    --background: #0b1118;
    --surface: #121b24;
    --surface-muted: #182431;
    --border: #2a3a48;
    --text: #f2f7f5;
    --text-muted: #a9b8c2;
}

:root[data-theme="light"] {
    --background: #f5f7fa;
    --surface: #fff;
    --surface-muted: #edf2f7;
    --border: #d9e2ec;
    --text: #1f2933;
    --text-muted: #52606d;
}

body {
    margin: 0;
    background: var(--background);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    line-height: 1.45;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.site-nav {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 0 auto;
    max-width: 1200px;
    padding: 14px 24px;
}

.site-nav a {
    color: var(--text);
    font-weight: 600;
}

.site-nav-left,
.site-nav-right {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.site-nav-right {
    margin-left: auto;
}

.nav-auth-form {
    margin: 0;
}

.site-main {
    margin: 0 auto;
    max-width: 1200px;
    padding: 24px;
}

.site-footer {
    align-items: center;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    display: flex;
    font-size: 14px;
    justify-content: space-between;
    margin: 32px auto 0;
    max-width: 1200px;
    padding: 18px 24px;
}

.page-header {
    margin-bottom: 20px;
}

.page-header h1 {
    margin: 0 0 6px;
}

.page-header p {
    color: var(--text-muted);
    margin: 0;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: 20px;
    padding: 18px;
}

.tournament-card-list {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.tournament-list-card {
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 14px;
}

.tournament-list-card h3,
.tournament-list-card p {
    margin: 0;
}

.tournament-list-card p {
    color: var(--text-muted);
    margin-top: 6px;
}

.home-logo-heading {
    margin: 0 0 12px;
}

.home-logo {
    display: block;
    height: auto;
    max-width: 360px;
    width: 100%;
}

.error-page {
    margin-top: 24px;
}

.error-code {
    color: #627d98;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0;
    margin: 0 0 8px;
    text-transform: uppercase;
}

.error-card {
    max-width: 680px;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 12px 0;
}

.btn,
button,
input[type="submit"] {
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--text);
    cursor: pointer;
    display: inline-flex;
    font: inherit;
    font-weight: 600;
    justify-content: center;
    min-height: 42px;
    padding: 9px 14px;
    text-decoration: none;
    touch-action: manipulation;
}

.btn:hover,
button:hover,
input[type="submit"]:hover {
    background: #f0f4f8;
    text-decoration: none;
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

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

.btn-secondary {
    background: var(--surface-muted);
    color: var(--text);
}

.theme-toggle {
    min-height: 36px;
    padding: 6px 10px;
}

.btn-large {
    font-size: 16px;
    min-height: 50px;
    padding: 12px 18px;
}

.table,
table {
    background: var(--surface);
    border-collapse: collapse;
    margin: 12px 0 24px;
    width: 100%;
}

.table-wrap {
    max-height: 70vh;
    overflow: auto;
}

.table-compact th,
.table-compact td {
    font-size: 14px;
    padding: 6px 8px;
}

.table-sticky thead th {
    position: sticky;
    top: 0;
    z-index: 2;
}

.table-hover tbody tr:hover {
    background: #f8fbff;
}

.table th,
.table td,
table th,
table td {
    border: 1px solid #d9e2ec;
    padding: 9px 10px;
    text-align: left;
    vertical-align: top;
}

.table th,
table th {
    background: var(--surface-muted);
    color: var(--text);
    font-weight: 700;
}

.filter-bar {
    align-items: end;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 10px 0 14px;
}

.filter-bar input {
    min-width: 260px;
}

.sticky-col {
    background: inherit;
    position: sticky;
    z-index: 1;
}

.sticky-col-1 {
    left: 0;
}

.sticky-col-2 {
    left: 58px;
}

.sticky-col-3 {
    left: 136px;
}

.score-table {
    min-width: 900px;
}

.score-table th:nth-child(-n+3) {
    z-index: 3;
}

.score-table .score-input {
    text-align: center;
    width: 82px;
}

.score-table td,
.score-table th {
    white-space: nowrap;
}

form {
    margin: 14px 0 22px;
}

label {
    font-weight: 600;
}

input,
select,
textarea {
    border: 1px solid #bcccdc;
    border-radius: 4px;
    font: inherit;
    min-height: 40px;
    padding: 8px 10px;
}

input[type="checkbox"] {
    height: 24px;
    min-height: 24px;
    width: 24px;
}

input:focus,
select:focus,
textarea:focus,
.btn:focus,
button:focus,
input[type="submit"]:focus {
    box-shadow: 0 0 0 3px rgba(31, 95, 159, 0.25);
    outline: 2px solid #1f5f9f;
    outline-offset: 2px;
}

textarea {
    max-width: 100%;
}

.messages {
    list-style: none;
    margin: 0 0 18px;
    padding: 0;
}

.messages li {
    background: #e3f8e8;
    border: 1px solid #9ae6b4;
    border-radius: 5px;
    color: #22543d;
    margin-bottom: 8px;
    padding: 10px 12px;
}

.status-success {
    color: #22543d;
    font-weight: 700;
}

.status-warning {
    color: #8a5a00;
    font-weight: 700;
}

.status-danger {
    color: #9b2c2c;
    font-weight: 700;
}

.stats-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.stat {
    background: #fff;
    border: 1px solid #d9e2ec;
    border-radius: 6px;
    padding: 14px;
}

.stat strong {
    display: block;
    font-size: 22px;
}

.dashboard-status-grid,
.dashboard-warnings {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    margin-bottom: 20px;
}

.status-card,
.warning-card {
    background: #fff;
    border: 1px solid #d9e2ec;
    border-radius: 6px;
    padding: 16px;
}

.status-card span {
    color: #627d98;
    display: block;
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 6px;
    text-transform: uppercase;
}

.status-card strong {
    color: #102a43;
    display: block;
    font-size: 26px;
}

.status-badge {
    border-radius: 999px;
    display: inline-flex;
    font-size: 14px;
    line-height: 1.2;
    padding: 7px 10px;
}

.status-badge-draft {
    background: #edf2f7;
    color: #243b53;
}

.status-badge-registration_open {
    background: #e0f2fe;
    color: #075985;
}

.status-badge-check_in {
    background: #fef3c7;
    color: #92400e;
}

.status-badge-live {
    background: #dcfce7;
    color: #166534;
}

.status-badge-completed {
    background: #ede9fe;
    color: #5b21b6;
}

.status-banner {
    border: 1px solid #d9e2ec;
    border-radius: 6px;
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 18px;
    padding: 14px 16px;
}

.status-banner-draft {
    background: #f8fafc;
    border-color: #cbd5e1;
    color: #334155;
}

.status-banner-registration_open {
    background: #eff6ff;
    border-color: #93c5fd;
    color: #1d4ed8;
}

.status-banner-check_in {
    background: #fffbeb;
    border-color: #fbbf24;
    color: #92400e;
}

.status-banner-live {
    background: #ecfdf5;
    border-color: #86efac;
    color: #166534;
}

.status-banner-completed {
    background: #f5f3ff;
    border-color: #c4b5fd;
    color: #5b21b6;
}

.dashboard-action-emphasis {
    box-shadow: 0 0 0 3px rgba(31, 95, 159, 0.16);
}

.warning-card {
    background: #fff8e6;
    border-color: #f0c36d;
    color: #744210;
    font-weight: 700;
}

.dashboard-actions {
    gap: 12px;
}

.readiness-card {
    border-left: 5px solid #1f5f9f;
}

.readiness-summary {
    align-items: center;
    display: flex;
    gap: 16px;
    justify-content: space-between;
}

.readiness-summary h2 {
    margin-bottom: 4px;
}

.readiness-summary p {
    color: #52606d;
    margin: 0;
}

.readiness-score {
    color: #102a43;
    font-size: 36px;
}

.readiness-meter {
    background: #edf2f7;
    border-radius: 999px;
    height: 12px;
    margin: 14px 0;
    overflow: hidden;
}

.readiness-meter-fill {
    background: #1f5f9f;
    height: 100%;
}

.readiness-checklist {
    display: grid;
    gap: 8px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.readiness-checklist li {
    align-items: center;
    border: 1px solid #d9e2ec;
    border-radius: 5px;
    display: grid;
    gap: 10px;
    grid-template-columns: 28px 1fr auto;
    min-height: 44px;
    padding: 8px 10px;
}

.readiness-icon {
    font-weight: 700;
    text-align: center;
}

.readiness-item-passed .readiness-icon {
    color: #22543d;
}

.readiness-item-missing {
    background: #fff8e6;
    border-color: #f0c36d;
}

.readiness-item-missing .readiness-icon {
    color: #8a5a00;
}

.dashboard-actions .btn,
.dashboard-actions button,
.warning-card .btn {
    min-width: 160px;
}

.dashboard-round-table .table-action-link {
    align-items: center;
    border: 1px solid #bcccdc;
    border-radius: 5px;
    color: #243b53;
    display: inline-flex;
    font-weight: 700;
    justify-content: center;
    min-height: 38px;
    min-width: 76px;
    padding: 7px 10px;
}

.dashboard-round-table .table-action-link:hover {
    background: #f0f4f8;
    text-decoration: none;
}

.card .actions .btn,
.card .actions button {
    margin-bottom: 2px;
}

.inline-action-form {
    margin: 0;
}

.live-header {
    margin-bottom: 24px;
}

.live-header h1 {
    font-size: 42px;
    line-height: 1.1;
}

.live-refresh-note {
    color: #627d98;
    font-size: 14px;
    margin-top: 8px;
}

.live-round-card {
    border-left: 5px solid #1f5f9f;
}

.live-cut-summary {
    background: #fff6d6;
    border: 1px solid #f0c36d;
    border-radius: 5px;
    color: #744210;
    display: inline-block;
    font-weight: 700;
    padding: 8px 12px;
}

.live-leaders {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    margin-bottom: 20px;
}

.leader-card {
    background: #fff;
    border: 1px solid #d9e2ec;
    border-radius: 6px;
    padding: 14px;
}

.leader-card-first {
    border-color: #1f5f9f;
    box-shadow: inset 0 3px 0 #1f5f9f;
}

.leader-place {
    color: #627d98;
    display: block;
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 4px;
    text-transform: uppercase;
}

.leader-card strong {
    display: block;
    margin-bottom: 4px;
}

.live-table-wrap {
    max-height: none;
}

.leader-row {
    background: #f8fbff;
}

.leader-row-first {
    background: #eef8ff;
}

.cut-line-row td {
    background: #fff6d6;
    color: #744210;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-align: center;
}

.lane-card-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.lane-card {
    background: #fff;
    border: 1px solid #d9e2ec;
    border-radius: 6px;
    padding: 14px;
}

.lane-card h2 {
    border-bottom: 1px solid #d9e2ec;
    margin: 0 0 10px;
    padding-bottom: 8px;
}

.lane-card ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.lane-card li {
    align-items: center;
    border-bottom: 1px solid #edf2f7;
    display: grid;
    gap: 8px;
    grid-template-columns: 42px 1fr auto;
    padding: 8px 0;
}

.lane-card li:last-child {
    border-bottom: 0;
}

.lane-position {
    background: #edf2f7;
    border-radius: 4px;
    font-weight: 700;
    padding: 4px 6px;
    text-align: center;
}

.lane-bowler {
    font-weight: 700;
}

.lane-seed {
    color: #627d98;
    font-size: 13px;
}

.live-bracket-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.live-bracket-match-card {
    background: #fff;
    border: 1px solid #d9e2ec;
    border-radius: 6px;
    padding: 14px;
}

.live-bracket-match-card header {
    align-items: center;
    border-bottom: 1px solid #edf2f7;
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    padding-bottom: 8px;
}

.live-bracket-match-card header span,
.live-bracket-match-card footer {
    color: #627d98;
    font-size: 13px;
    font-weight: 700;
}

.live-bracket-player {
    align-items: center;
    border-bottom: 1px solid #edf2f7;
    display: grid;
    gap: 10px;
    grid-template-columns: 1fr auto;
    min-height: 48px;
    padding: 8px 0;
}

.live-bracket-player strong {
    background: #edf2f7;
    border-radius: 4px;
    min-width: 44px;
    padding: 5px 8px;
    text-align: center;
}

.live-bracket-winner span {
    font-weight: 700;
}

.live-bracket-winner strong {
    background: #dcfce7;
    color: #166534;
}

.live-bracket-match-card footer {
    padding-top: 10px;
}

@media (pointer: coarse) {
    .btn,
    button,
    input[type="submit"] {
        min-height: 48px;
        padding: 11px 16px;
    }

    input,
    select,
    textarea {
        min-height: 46px;
    }

    input[type="checkbox"] {
        height: 30px;
        min-height: 30px;
        width: 30px;
    }

    .table-compact th,
    .table-compact td {
        padding: 10px 12px;
    }

    .score-table .score-input {
        font-size: 18px;
        min-height: 48px;
        width: 94px;
    }

    .score-table tbody tr {
        height: 58px;
    }
}

@media (min-width: 721px) and (max-width: 834px) {
    .site-main {
        padding: 20px;
    }

    .actions {
        gap: 12px;
    }

    .dashboard-actions .btn,
    .dashboard-actions button {
        flex: 1 1 220px;
        min-width: 0;
    }

    .table-wrap {
        max-height: 72vh;
    }

    .score-table {
        min-width: 980px;
    }

    .score-table .score-input {
        width: 92px;
    }
}

@media (min-width: 835px) and (max-width: 1194px) {
    .dashboard-actions .btn,
    .dashboard-actions button {
        flex: 0 1 210px;
    }

    .score-table {
        min-width: 1040px;
    }
}

@media (max-width: 720px) {
    .site-nav {
        padding: 12px 16px;
    }

    .site-nav-right {
        justify-content: flex-end;
    }

    .site-main {
        padding: 16px;
    }

    .actions .btn,
    .actions button,
    .actions input[type="submit"] {
        flex: 1 1 100%;
    }

    .live-header h1 {
        font-size: 30px;
    }

    .live-standings-table,
    .live-standings-table thead,
    .live-standings-table tbody,
    .live-standings-table th,
    .live-standings-table td,
    .live-standings-table tr {
        display: block;
    }

    .live-standings-table thead {
        display: none;
    }

    .live-standings-table tr {
        border: 1px solid #d9e2ec;
        border-radius: 6px;
        margin-bottom: 12px;
        padding: 10px;
    }

    .live-standings-table td {
        border: 0;
        display: flex;
        justify-content: space-between;
        padding: 5px 0;
    }

    .live-standings-table td:nth-child(1)::before { content: "Place"; font-weight: 700; }
    .live-standings-table td:nth-child(2)::before { content: "Seed"; font-weight: 700; }
    .live-standings-table td:nth-child(3)::before { content: "Lane"; font-weight: 700; }
    .live-standings-table td:nth-child(4)::before { content: "Position"; font-weight: 700; }
    .live-standings-table td:nth-child(5)::before { content: "Bowler"; font-weight: 700; }
    .live-standings-table td:nth-last-child(3)::before { content: "Scratch"; font-weight: 700; }
    .live-standings-table td:nth-last-child(2)::before { content: "HDCP/Game"; font-weight: 700; }
    .live-standings-table td:nth-last-child(1)::before { content: "Total"; font-weight: 700; }

    .cut-line-row td {
        display: block;
        text-align: center;
    }

    .cut-line-row td::before {
        content: "";
    }

    .lane-card-grid {
        grid-template-columns: 1fr;
    }
}

@media print {
    body {
        background: #fff;
        color: #000;
    }

    .site-header,
    .site-footer,
    .no-print {
        display: none;
    }

    .site-main {
        max-width: none;
        padding: 0;
    }

    a {
        color: #000;
        text-decoration: none;
    }

    .final-results-report .card {
        border: 0;
        break-inside: avoid;
        margin-bottom: 14px;
        padding: 0;
    }

    .final-results-report .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .final-results-report .stat {
        border-color: #999;
        padding: 8px;
    }

    .final-results-report .table-wrap {
        max-height: none;
        overflow: visible;
    }

    .final-results-report table {
        font-size: 11px;
        page-break-inside: auto;
    }

    .final-results-report tr {
        break-inside: avoid;
    }

    .final-results-report th,
    .final-results-report td {
        padding: 5px 6px;
    }
}
