/* style.css */
:root {
    --bg: #f1dfc8;
    --bg-2: #f7ead8;
    --card: rgba(255, 255, 255, 0.92);
    --text: #111827;
    --muted: #667085;
    --line: #e8edf4;
    --primary: #f47a3d;
    --primary-dark: #dd5f1f;
    --accent-red: #ef4444;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --soft-red: #fee2e2;
    --soft-red-2: #fecaca;
    --soft-green: #dcfce7;
    --shadow: 0 18px 44px rgba(150, 97, 38, 0.10);
    --radius: 22px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at top left, rgba(255,255,255,0.55), transparent 32rem),
        linear-gradient(180deg, var(--bg-2), var(--bg));
    color: var(--text);
}

a {
    color: inherit;
    text-decoration: none;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 18px;
    background: rgba(255,255,255,0.86);
    border-bottom: 1px solid rgba(232, 237, 244, 0.9);
    backdrop-filter: blur(12px);
}

.brand {
    font-weight: 900;
    font-size: 18px;
    display: inline-flex;
    align-items: center;
    gap: 12px;
}

.brand-logo {
    width: 86px;
    height: auto;
    display: block;
}

.topnav {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.topnav a {
    padding: 8px 10px;
    border-radius: 999px;
    color: var(--muted);
    font-weight: 650;
    font-size: 14px;
}

.topnav a:hover,
.topnav .admin-link {
    background: #fff3ec;
    color: var(--primary-dark);
}

.container {
    width: min(1180px, calc(100% - 24px));
    margin: 18px auto 42px;
}

.card {
    background: var(--card);
    border: 1px solid rgba(232, 237, 244, 0.9);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 18px;
}

.narrow {
    max-width: 520px;
    margin-left: auto;
    margin-right: auto;
}

.hero h1,
.card h1,
.card h2 {
    margin-top: 0;
}

.muted {
    color: var(--muted);
}

.grid.cards {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.action-card {
    transition: transform .15s ease, border-color .15s ease;
}

.action-card:hover {
    transform: translateY(-2px);
    border-color: #b7cdfd;
}

.form,
.search-row,
.filters {
    display: grid;
    gap: 12px;
}

.form label,
.filters label,
.timing-race-hint {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-weight: 650;
}

input,
select {
    width: 100%;
    padding: 12px 13px;
    border: 1px solid var(--line);
    border-radius: 12px;
    font: inherit;
    color: var(--text);
    background: #fff;
}

input:focus,
select:focus {
    outline: 3px solid #dbeafe;
    border-color: #93c5fd;
}

.grid-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-actions {
    display: flex;
    gap: 10px;
    align-items: end;
    flex-wrap: wrap;
}

.btn {
    border: 0;
    border-radius: 12px;
    padding: 12px 15px;
    background: #e8eef7;
    color: var(--text);
    font-weight: 800;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
}

.btn:hover {
    filter: brightness(0.98);
}

.btn.primary {
    background: linear-gradient(90deg, #f59e0b, var(--primary), var(--accent-red));
    color: white;
}

.btn.primary:hover {
    filter: saturate(1.08) brightness(0.97);
}

.btn.ghost {
    background: transparent;
    border: 1px solid var(--line);
}

.btn.small {
    padding: 7px 10px;
    min-height: 32px;
    font-size: 13px;
    border-radius: 10px;
}

.btn.big {
    font-size: 17px;
    padding: 14px 18px;
}

.danger-btn {
    background: #fee2e2;
    color: #991b1b;
}

.alert {
    padding: 12px 14px;
    border-radius: 14px;
    margin: 14px 0;
    font-weight: 650;
}

.alert.success {
    background: #dcfce7;
    color: #166534;
}

.alert.error {
    background: #fee2e2;
    color: #991b1b;
}

.error-text {
    color: #b91c1c;
    font-weight: 800;
}

.success-text {
    color: #15803d;
    font-weight: 800;
}

.split-head,
.results-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
    flex-wrap: wrap;
}

.search-row {
    grid-template-columns: 1fr auto auto;
}

.filters {
    grid-template-columns: 1fr 140px 140px auto;
    align-items: end;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

th,
td {
    border-bottom: 1px solid var(--line);
    text-align: left;
    padding: 10px;
    vertical-align: middle;
}

th {
    color: var(--muted);
    font-size: 13px;
}

.actions-cell {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.actions-cell form {
    margin: 0;
}

.code {
    white-space: pre-wrap;
    background: #0f172a;
    color: #e2e8f0;
    padding: 14px;
    border-radius: 12px;
    overflow-x: auto;
}

.counter-grid,
.start-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.counter-card,
.start-card {
    background: rgba(248, 250, 252, 0.82);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 16px;
}

.counter-label {
    color: var(--muted);
    font-weight: 800;
}

.counter-time {
    font-size: clamp(34px, 7vw, 64px);
    line-height: 1;
    font-weight: 900;
    letter-spacing: -0.04em;
    margin-top: 8px;
}

.switch-line {
    display: flex;
    gap: 8px;
    align-items: center;
    font-weight: 750;
    color: var(--muted);
}

.switch-line input {
    width: 22px;
    height: 22px;
}

.results-list {
    display: grid;
    gap: 10px;
    margin-top: 16px;
}

.result-row {
    display: grid;
    grid-template-columns: 42px 1fr 110px 130px;
    gap: 10px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 12px;
    background: #fff;
}

.result-rank {
    width: 34px;
    height: 34px;
    border-radius: 999px;
    background: #fff3ec;
    color: var(--primary-dark);
    display: grid;
    place-items: center;
    font-weight: 900;
}

.result-title {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.bib {
    background: #f1f5f9;
    color: #475569;
    border-radius: 999px;
    padding: 3px 8px;
    font-weight: 800;
    font-size: 12px;
}

.result-meta {
    color: var(--muted);
    font-size: 14px;
    margin-top: 2px;
}

.result-time {
    font-size: 20px;
    font-weight: 900;
    font-variant-numeric: tabular-nums;
}

.result-place {
    display: grid;
    gap: 2px;
    text-align: right;
}

.result-place span {
    color: var(--muted);
    font-size: 13px;
}

.unknown-live,
.unknown-row {
    background: var(--soft-red);
    animation: blinkRed 1.1s infinite alternate;
}

.bad-status {
    opacity: .78;
}

@keyframes blinkRed {
    from { background: var(--soft-red); }
    to { background: var(--soft-red-2); }
}

.pos-card {
    max-width: 560px;
    margin-left: auto;
    margin-right: auto;
}

.pos-display {
    min-height: 72px;
    background: #0f172a;
    color: #fff;
    border-radius: 18px;
    display: grid;
    place-items: center;
    font-size: clamp(38px, 12vw, 62px);
    font-weight: 900;
    letter-spacing: 0.08em;
    margin: 16px 0;
    user-select: none;
}

.pos-keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.pos-keypad button {
    border: 0;
    border-radius: 18px;
    min-height: 78px;
    font-size: 28px;
    font-weight: 900;
    background: #334155;
    color: white;
    cursor: pointer;
    box-shadow: inset 0 -3px 0 rgba(0,0,0,0.18);
}

.pos-keypad button:active {
    transform: translateY(1px);
}

.pos-keypad .success {
    background: var(--success);
}

.pos-keypad .danger {
    background: var(--danger);
}

.pos-keypad .warn {
    background: var(--warning);
    color: #1f2937;
}

.pos-keypad .wide {
    grid-column: span 3;
}

.participant-preview {
    min-height: 42px;
    border-radius: 14px;
    padding: 12px 14px;
    margin: -4px 0 16px;
    background: #f8fafc;
    border: 1px solid var(--line);
    font-weight: 850;
    text-align: center;
}

.participant-preview.preview-ok {
    background: #dcfce7;
    border-color: #86efac;
    color: #166534;
}

.participant-preview.preview-bad {
    background: #fee2e2;
    border-color: #fecaca;
    color: #991b1b;
    animation: blinkRed 1.1s infinite alternate;
}

.timing-message {
    min-height: 28px;
    margin-top: 14px;
    text-align: center;
}

@media (max-width: 760px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .brand-logo {
        width: 76px;
    }

    .topnav {
        justify-content: flex-start;
    }

    .grid.cards,
    .grid-form,
    .counter-grid,
    .start-grid,
    .filters,
    .search-row {
        grid-template-columns: 1fr;
    }

    .result-row {
        grid-template-columns: 36px 1fr;
    }

    .result-time,
    .result-place {
        grid-column: 2;
        text-align: left;
    }

    .pos-keypad button {
        min-height: 72px;
    }
}
