/*
 * Shared styling for login, admin, setup and schedule pages.
 * No framework, no build step, no web font: the system font stack loads instantly and there is
 * no third party left that could be unreachable during the tournament.
 *
 * Everything scales from the root font size, which itself follows the viewport. That is what
 * makes the same markup work one handed on a phone and on a 4K desktop screen.
 *
 * The palette echoes the club's own colours: a deep bottle green as the brand colour, with a
 * muted antique gold as a secondary accent for dividers and highlights.
 */

:root {
    --bg: #f2f6f2;
    --card: #ffffff;
    --ink: #142018;
    --ink-muted: #57685c;
    --border: #d3ddd2;
    --accent: #1f6e42;
    --accent-dark: #144d2d;
    --accent-ink: #ffffff;
    --gold: #b8912f;
    --gold-dark: #8f7024;
    --ok: #15803d;
    --warn: #b45309;
    --error: #b91c1c;
    --dark: #11251a;

    --radius: 0.875rem;
    --touch: 3rem; /* 48 px minimum touch target */
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    /* 16 px on a phone, up to 22 px on a large desktop screen. */
    font-size: clamp(16px, 0.45vw + 14.5px, 22px);
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--ink);
    line-height: 1.45;
    padding-bottom: 2rem;
}

h1, h2, h3 {
    line-height: 1.2;
    margin: 0 0 0.5rem;
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }

a { color: var(--accent); }

/* ------------------------------------------------------------------- layout */

.content {
    width: 100%;
    max-width: 62rem;
    margin: 0 auto;
    padding: 1rem;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
}

.card > h2:first-child {
    margin-top: 0;
}

.muted {
    color: var(--ink-muted);
    font-size: 0.85rem;
}

.grid {
    display: grid;
    gap: 0.75rem;
    grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
}

.row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: center;
}

/* ------------------------------------------------------------------- topbar */

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--dark);
    color: #e2e8f0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 0.75rem;
    padding: 0.4rem 0.9rem;
}

.topbar .brand {
    font-weight: 700;
    letter-spacing: 0.02em;
    margin-right: auto;
    font-size: 0.95rem;
    white-space: nowrap;
}

.topbar nav {
    display: flex;
    gap: 0.2rem;
    flex-wrap: wrap;
}

.topbar nav a {
    color: #cbd5e1;
    text-decoration: none;
    padding: 0.5rem 0.7rem;
    border-radius: 0.6rem;
    min-height: var(--touch);
    display: inline-flex;
    align-items: center;
    font-weight: 600;
    font-size: 0.9rem;
}

.topbar nav a:hover { background: rgba(255, 255, 255, 0.08); }
.topbar nav a.current { background: rgba(255, 255, 255, 0.16); color: #fff; }

/* -------------------------------------------------------- connection status */

.connection {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 0.3rem 0.6rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.1);
    white-space: nowrap;
}

.connection::before {
    content: "";
    width: 0.6rem;
    height: 0.6rem;
    border-radius: 50%;
    background: #facc15;
}

.connection[data-status="online"] { color: #86efac; }
.connection[data-status="online"]::before { background: #22c55e; }
.connection[data-status="offline"] { color: #fca5a5; }
.connection[data-status="offline"]::before {
    background: #ef4444;
    animation: blink 1.6s ease-in-out infinite;
}

@keyframes blink {
    50% { opacity: 0.25; }
}

/* ---------------------------------------------------------------- test mode */

.test-banner {
    background: repeating-linear-gradient(135deg, #b45309, #b45309 12px, #92400e 12px, #92400e 24px);
    color: #fff;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-align: center;
    padding: 0.35rem 1rem;
    font-size: 0.78rem;
}

.test-banner[hidden] { display: none; }

/* ------------------------------------------------------------------ buttons */

button,
.button {
    font: inherit;
    font-weight: 600;
    min-height: var(--touch);
    padding: 0.7rem 1.05rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--ink);
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    touch-action: manipulation;
}

button:hover,
.button:hover { border-color: #94a3b8; }

button:active { transform: translateY(1px); }

button:disabled {
    opacity: 0.55;
    cursor: progress;
    transform: none;
}

button:focus-visible,
.button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

.button.primary,
button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
}

button.primary:hover {
    background: var(--accent-dark);
    border-color: var(--accent-dark);
}

button.danger {
    background: #fef2f2;
    border-color: #fecaca;
    color: var(--error);
}

button.big {
    min-height: 4.5rem;
    font-size: 1.2rem;
    width: 100%;
}

.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
}

.button-row > * { flex: 1 1 11rem; }

/* -------------------------------------------------------------------- forms */

label {
    display: block;
    font-weight: 600;
    font-size: 0.82rem;
    margin-bottom: 0.25rem;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="file"],
select,
textarea {
    font: inherit;
    width: 100%;
    min-height: var(--touch);
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.7rem;
    background: #fff;
    color: var(--ink);
}

textarea {
    min-height: 4.5rem;
    resize: vertical;
}

.field { margin-bottom: 0.75rem; }

.spaced { margin-top: 1rem; }

.hint {
    margin: 0.35rem 0 0.75rem;
    line-height: 1.35;
}

.choice-row {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.choice-row label {
    flex: 1 1 8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: var(--touch);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    cursor: pointer;
    font-size: 1rem;
    margin: 0;
}

.choice-row label:has(input:checked) {
    border-color: var(--accent);
    background: #eaf4ec;
    color: var(--accent-dark);
}

.checkbox {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-height: var(--touch);
    font-weight: 600;
    font-size: 0.9rem;
}

.checkbox input {
    width: 1.4rem;
    height: 1.4rem;
    flex: none;
}

/* ----------------------------------------------------------------- messages */

.notice {
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    font-weight: 600;
    border: 1px solid;
}

.notice.ok { background: #f0fdf4; border-color: #bbf7d0; color: var(--ok); }
.notice.error { background: #fef2f2; border-color: #fecaca; color: var(--error); }
.notice.warn { background: #fffbeb; border-color: #fde68a; color: var(--warn); }
.notice[hidden] { display: none; }

/* -------------------------------------------------------------- team colour */

.team-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 700;
}

.team-chip::before {
    content: "";
    width: 0.85rem;
    height: 0.85rem;
    border-radius: 0.25rem;
    background: var(--team-color, #94a3b8);
    flex: none;
}

/* -------------------------------------------------------- admin round panel */

.round-headline {
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    margin-bottom: 0.75rem;
}

.round-headline .word {
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--ink-muted);
}

.round-headline .number {
    font-size: clamp(3rem, 12vw, 5rem);
    font-weight: 800;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.round-headline .total {
    font-size: 1rem;
    font-weight: 600;
    color: var(--ink-muted);
}

.pair-card {
    border: 1px solid var(--border);
    border-left: 0.4rem solid var(--team-color, #94a3b8);
    border-radius: var(--radius);
    padding: 0.65rem 0.85rem;
    background: #fbfdff;
}

.pair-card .pair-title {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--ink-muted);
}

.pair-card .lane-row {
    font-size: 0.95rem;
}

.pair-card .lane-row.free {
    color: var(--ink-muted);
    font-style: italic;
}

.preview-line {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0.35rem 0;
    border-top: 1px solid var(--border);
}

.preview-title {
    font-weight: 700;
    margin: 0 0 0.25rem;
}

/* ------------------------------------------------------------------- tables */

.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table.plan {
    border-collapse: collapse;
    width: 100%;
    min-width: 34rem;
}

table.plan th,
table.plan td {
    border: 1px solid var(--border);
    padding: 0.45rem 0.6rem;
    text-align: left;
    vertical-align: middle;
}

table.plan thead th {
    background: var(--dark);
    color: #fff;
    position: sticky;
    top: 0;
}

table.plan td.pair-start {
    border-left-width: 3px;
    border-left-color: #94a3b8;
}

table.plan tr.current td {
    background: #eaf4ec;
}

table.plan .round-number {
    text-align: center;
    font-weight: 700;
    font-size: 1.05rem;
}

.player-name {
    display: block;
    font-weight: 600;
}

.player-team {
    display: block;
    font-size: 0.76rem;
    color: var(--team-color, var(--ink-muted));
    filter: brightness(0.65);
}

.free {
    color: var(--ink-muted);
    font-style: italic;
}

/* -------------------------------------------------------------- setup sheet */

.team-panel {
    border: 1px solid var(--border);
    border-top: 0.35rem solid var(--team-color, #94a3b8);
    border-radius: var(--radius);
    padding: 0.85rem;
    background: var(--card);
}

.player-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
    gap: 0.5rem;
    margin: 0.6rem 0;
}

.player-field {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    position: relative;
    /* Set while a drag is in progress, see setup.js. Above sibling fields so the dragged tile
       visibly floats over them while it follows the pointer. */
    z-index: 1;
    background: var(--card);
    border-radius: 0.5rem;
}

.player-field.dragging {
    z-index: 5;
    box-shadow: 0 0.5rem 1.25rem rgba(15, 23, 42, 0.22);
    transition: none;
}

.player-field:not(.dragging) {
    transition: transform 160ms ease;
}

/* A drop target briefly highlighted while something is being dragged over it. */
.player-field.drop-target .number {
    color: var(--accent);
}

.drag-handle {
    all: unset;
    flex: none;
    width: 1.6rem;
    min-height: var(--touch);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ink-muted);
    font-size: 1.1rem;
    cursor: grab;
    /* Stops the browser from scrolling the page while a touch drag is in progress. */
    touch-action: none;
    border-radius: 0.4rem;
}

.drag-handle:hover,
.drag-handle:focus-visible {
    color: var(--accent);
    background: #eaf4ec;
}

.player-field.dragging .drag-handle {
    cursor: grabbing;
}

.player-field .number {
    flex: none;
    width: 1.5rem;
    text-align: right;
    font-weight: 700;
    color: var(--ink-muted);
    font-variant-numeric: tabular-nums;
}

.save-state {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--ink-muted);
    min-height: 1.2rem;
}

.save-state.ok { color: var(--ok); }
.save-state.error { color: var(--error); }

/* ------------------------------------------------------------------ dialogs */

dialog {
    border: none;
    border-radius: var(--radius);
    padding: 1.25rem;
    max-width: min(28rem, 92vw);
    box-shadow: 0 1.5rem 3rem rgba(15, 23, 42, 0.3);
}

dialog::backdrop { background: rgba(15, 23, 42, 0.55); }

dialog img {
    display: block;
    width: 100%;
    height: auto;
    max-width: 20rem;
    margin: 0 auto 0.75rem;
    border-radius: 0.5rem;
    background: #fff;
}

.qr-url {
    word-break: break-all;
    text-align: center;
    font-size: 0.85rem;
    color: var(--ink-muted);
    margin-bottom: 1rem;
}

/* --------------------------------------------------------------- login page */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    padding: 1rem;
    background:
        radial-gradient(circle at 15% 15%, rgba(184, 145, 47, 0.10), transparent 45%),
        radial-gradient(circle at 85% 85%, rgba(31, 110, 66, 0.12), transparent 45%),
        var(--bg);
}

.login-box {
    width: 100%;
    max-width: 24rem;
}

.login-box .card {
    position: relative;
    overflow: hidden;
    text-align: center;
}

.login-box .card::before {
    /* A quiet green-to-gold band above the form, standing in for a club emblem without trying
       to reproduce anyone's actual artwork. A pseudo-element rather than border-image, which
       would otherwise smear the gradient across the card's plain side borders too. */
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 0.4rem;
    background: linear-gradient(90deg, var(--accent), var(--gold));
}

.login-box h1 {
    color: var(--accent-dark);
    letter-spacing: 0.01em;
}

.login-box form {
    text-align: left;
}

/* -------------------------------------------------------------------- print */

@media print {
    .topbar,
    .button-row,
    button,
    .no-print {
        display: none !important;
    }

    body { background: #fff; }

    .card {
        border: none;
        padding: 0;
        margin: 0;
    }

    table.plan thead th {
        background: #e2e8f0;
        color: #000;
        position: static;
    }
}
