/* SilatQu — International competition scoring platform */

:root {
    /* Olympic-inspired palette */
    --navy: #0b1f3a;
    --navy-mid: #142d4f;
    --navy-light: #1e3a5f;
    --gold: #c5a028;
    --gold-light: #dbb84a;
    --ring-blue: #0085c7;
    --ring-yellow: #fab300;
    --ring-black: #1a1a1a;
    --ring-green: #009f3d;
    --ring-red: #df0024;

    /* Legacy aliases (match panels) */
    --red: #df0024;
    --red-dark: #a8001c;
    --blue: #0085c7;
    --blue-dark: #005a8a;
    --green: #009f3d;
    --yellow: #fab300;

    /* UI surfaces */
    --bg: #f1f5f9;
    --bg-subtle: #e8edf4;
    --card: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --radius: 10px;
    --radius-lg: 16px;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 4px 6px rgba(15, 23, 42, 0.04), 0 20px 48px rgba(15, 23, 42, 0.1);
    --touch-min: 48px;
    --container: 1140px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
    -webkit-font-smoothing: antialiased;
}

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

img, svg { max-width: 100%; height: auto; }

.container {
    width: 100%;
    max-width: var(--container);
    margin: 0 auto;
    padding: 0 clamp(1rem, 3vw, 1.5rem);
}

/* ── Olympic rings (logo accent) ── */
.ring {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2.5px solid currentColor;
    border-radius: 50%;
    flex-shrink: 0;
}
.ring-blue { color: var(--ring-blue); }
.ring-yellow { color: var(--ring-yellow); }
.ring-black { color: var(--ring-black); }
.ring-green { color: var(--ring-green); }
.ring-red { color: var(--ring-red); }

.logo-rings,
.auth-rings,
.hero-rings {
    display: flex;
    gap: 3px;
    align-items: center;
}
.hero-rings { justify-content: center; margin-bottom: 1rem; }
.hero-rings .ring { width: 18px; height: 18px; border-width: 3px; }
.auth-rings .ring { width: 20px; height: 20px; border-width: 3px; }

/* ══════════════════════════════════════
   SITE LAYOUT (header · main · footer)
   ══════════════════════════════════════ */
.site-layout { min-height: 100vh; display: flex; flex-direction: column; }

.site-header {
    background: var(--navy);
    color: #fff;
    padding: calc(0.75rem + var(--safe-top)) 0 0.75rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.15);
}

.header-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.logo {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    font-weight: 800;
    font-size: 1.2rem;
    color: #fff;
    text-decoration: none;
    letter-spacing: -0.02em;
}
.logo:hover { color: #fff; opacity: 0.92; }
.logo-text { line-height: 1; }

.nav-toggle {
    display: none;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    font-size: 1.25rem;
    color: #fff;
    cursor: pointer;
    min-width: var(--touch-min);
    min-height: var(--touch-min);
    line-height: 1;
}

.site-nav {
    display: flex;
    align-items: center;
    gap: 0.35rem 1.25rem;
    flex-wrap: wrap;
}

.nav-link {
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.4rem 0;
}
.nav-link:hover { color: #fff; }

.logout-form { display: inline; margin: 0; }

.site-main {
    flex: 1;
    padding: clamp(1.5rem, 4vw, 2.5rem) 0 clamp(2rem, 5vw, 3rem);
}

.site-footer {
    background: var(--navy);
    color: rgba(255, 255, 255, 0.75);
    padding: 2rem 0 calc(1.5rem + var(--safe-bottom));
    margin-top: auto;
}

.footer-inner { text-align: center; }
.footer-brand .logo-text {
    font-size: 1.1rem;
    font-weight: 800;
    color: #fff;
}
.footer-tagline {
    margin: 0.35rem 0 1rem;
    font-size: 0.85rem;
    opacity: 0.7;
}
.footer-disciplines {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.5rem 1.25rem;
    margin-bottom: 1rem;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--gold-light);
}
.footer-copy { margin: 0; font-size: 0.75rem; opacity: 0.5; }

/* ══════════════════════════════════════
   AUTH LAYOUT (login)
   ══════════════════════════════════════ */
.auth-layout {
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bg);
}

.auth-shell {
    display: grid;
    min-height: 100vh;
    min-height: 100dvh;
    grid-template-columns: 1fr;
}

.auth-brand {
    background: linear-gradient(145deg, var(--navy) 0%, var(--navy-mid) 55%, var(--navy-light) 100%);
    color: #fff;
    padding: clamp(2rem, 6vw, 4rem) clamp(1.5rem, 5vw, 3rem);
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-brand-inner { max-width: 22rem; text-align: center; }

.auth-brand-title {
    margin: 1.25rem 0 0.75rem;
    font-size: clamp(2rem, 6vw, 2.75rem);
    font-weight: 800;
    letter-spacing: -0.03em;
}

.auth-brand-lead {
    margin: 0 0 1.5rem;
    font-size: 1rem;
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.8);
}

.auth-disciplines {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
}
.auth-disciplines li {
    padding: 0.35rem 0.85rem;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: rgba(255, 255, 255, 0.9);
}

.auth-main {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(1.5rem, 5vw, 3rem);
}

.auth-card {
    width: 100%;
    max-width: 26rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: clamp(1.5rem, 4vw, 2.25rem);
    box-shadow: var(--shadow-lg);
}

.auth-card-header { margin-bottom: 1.5rem; }
.auth-card-header h2 {
    margin: 0 0 0.35rem;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.auth-footer-link {
    margin: 1.25rem 0 0;
    text-align: center;
    font-size: 0.9rem;
}

@media (min-width: 900px) {
    .auth-shell { grid-template-columns: 1fr 1fr; }
    .auth-brand-inner { text-align: left; }
    .auth-rings { justify-content: flex-start; }
    .auth-disciplines { justify-content: flex-start; }
}

/* ── Typography & sections ── */
.hero {
    text-align: center;
    padding: clamp(2rem, 6vw, 3.5rem) clamp(1rem, 4vw, 2rem);
    background: linear-gradient(180deg, var(--card) 0%, var(--bg) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
}
.hero-olympic { position: relative; overflow: hidden; }
.hero-eyebrow {
    margin: 0 0 0.5rem;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--gold);
}
.hero h1 {
    font-size: clamp(2rem, 7vw, 3.25rem);
    margin: 0 0 0.75rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--navy);
}
.lead {
    color: var(--muted);
    font-size: clamp(1rem, 2.5vw, 1.125rem);
    max-width: 36rem;
    margin: 0 auto 1.25rem;
}

.discipline-badges {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
}
.discipline-badge {
    padding: 0.4rem 1rem;
    background: var(--navy);
    color: #fff;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.section-header { margin-bottom: 1.25rem; }
.section-header h2 { margin: 0 0 0.25rem; }

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    padding-bottom: 1.25rem;
    border-bottom: 2px solid var(--border);
}
.page-header h1 {
    margin: 0;
    font-size: clamp(1.35rem, 4vw, 1.85rem);
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--navy);
}

.btn-group { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ── Buttons ── */
.btn,
button.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    min-height: var(--touch-min);
    padding: 0.65rem 1.25rem;
    background: var(--navy);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}
.btn:active { transform: scale(0.98); }
.btn:hover { text-decoration: none; color: #fff; filter: none; }

.btn-primary,
.btn.btn-primary,
button.btn.btn-primary {
    background: var(--navy);
}
.btn-primary:hover,
.btn.btn-primary:hover,
button.btn.btn-primary:hover {
    background: var(--navy-light);
}

.btn-nav {
    background: var(--gold);
    color: var(--navy);
    padding: 0.5rem 1.1rem;
    min-height: 40px;
    font-size: 0.85rem;
}
.btn-nav:hover { background: var(--gold-light); color: var(--navy); }

.btn-nav-outline {
    background: transparent;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.35);
    padding: 0.5rem 1rem;
    min-height: 40px;
    font-size: 0.85rem;
    box-shadow: none;
}
.btn-nav-outline:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }

.btn-secondary,
.btn.btn-secondary,
button.btn.btn-secondary { background: #475569; }
.btn-secondary:hover,
.btn.btn-secondary:hover,
button.btn.btn-secondary:hover { background: #334155; }

.btn-red,
.btn.btn-red,
button.btn.btn-red { background: var(--red); }
.btn-blue,
.btn.btn-blue,
button.btn.btn-blue { background: var(--blue); }
.btn-green,
.btn.btn-green,
button.btn.btn-green { background: var(--green); }
.btn-yellow,
.btn.btn-yellow,
button.btn.btn-yellow { background: var(--yellow); color: #1a1a2e; }
.btn-yellow:hover,
.btn.btn-yellow:hover,
button.btn.btn-yellow:hover { color: #1a1a2e; }

.btn-block { width: 100%; }
.btn-sm { min-height: 40px; padding: 0.4rem 0.85rem; font-size: 0.8rem; }
.btn-lg { min-height: 52px; padding: 0.85rem 1.35rem; font-size: 0.95rem; }
.btn-xl { min-height: 64px; padding: 1.1rem 1.5rem; font-size: 1.05rem; font-weight: 700; }

.btn-link {
    background: none;
    border: none;
    color: var(--navy-light);
    cursor: pointer;
    padding: 0.35rem 0;
    min-height: auto;
    font-weight: 500;
    box-shadow: none;
}
.btn-link:hover { color: var(--gold); background: none; }
.btn-link.danger { color: var(--red); }

.btn-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 10rem), 1fr));
    gap: 0.6rem;
    width: 100%;
}
.btn-grid .btn { width: 100%; }

/* ── Cards & panels ── */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
    gap: 1.25rem;
}
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.35rem;
    box-shadow: var(--shadow);
    transition: box-shadow 0.2s, border-color 0.2s;
}
.card:hover { box-shadow: var(--shadow-lg); border-color: var(--border-strong); }
.card h3 {
    margin: 0 0 0.5rem;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--navy);
}
.card-top { margin-bottom: 0.75rem; }
.card-meta { margin: 0; font-weight: 500; }
.card-date { margin: 0.25rem 0 0; font-size: 0.875rem; }
.card-actions { margin-top: 1.25rem; display: flex; gap: 0.5rem; flex-wrap: wrap; }

.panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: clamp(1.25rem, 3vw, 1.75rem);
    box-shadow: var(--shadow);
}
.panel-empty { text-align: center; padding: 3rem 1.5rem; }
.panel-empty h2 { margin-top: 0; }

/* ── Forms ── */
.form label,
.form .field { display: block; margin-bottom: 1.1rem; }

.form label:not(.field) {
    font-weight: 600;
    font-size: 0.9rem;
}
.form label:not(.field) input,
.form label:not(.field) select {
    margin-top: 0.4rem;
}

.field-label,
.form label > span:first-child {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}

.form input,
.form select,
.form textarea {
    display: block;
    width: 100%;
    margin-top: 0;
    padding: 0.75rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 16px;
    min-height: var(--touch-min);
    background: #fff;
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form input:focus,
.form select:focus,
.form textarea:focus {
    outline: none;
    border-color: var(--navy-light);
    box-shadow: 0 0 0 3px rgba(20, 45, 79, 0.12);
}
.form input::placeholder { color: #94a3b8; }

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
    gap: 1rem;
}
.inline-form {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: 1rem;
}
.inline-form input,
.inline-form select {
    width: auto;
    min-width: 0;
    flex: 1 1 auto;
    margin-top: 0;
}

/* ── Tables ── */
.table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    margin-bottom: 0.75rem;
    background: var(--card);
}
.data-table {
    width: 100%;
    min-width: 520px;
    border-collapse: collapse;
    background: var(--card);
}
.data-table th,
.data-table td {
    padding: 0.85rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
    vertical-align: middle;
}
.data-table th {
    background: var(--bg-subtle);
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    white-space: nowrap;
}
.data-table tbody tr:hover { background: #f8fafc; }
.data-table tr:last-child td { border-bottom: none; }
.data-table a { font-weight: 600; }

/* ── Alerts & misc ── */
.alert {
    padding: 0.9rem 1.1rem;
    border-radius: var(--radius);
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
    font-weight: 500;
    border: 1px solid transparent;
}
.alert-success {
    background: #ecfdf5;
    color: #065f46;
    border-color: #a7f3d0;
}
.alert-error {
    background: #fef2f2;
    color: #991b1b;
    border-color: #fecaca;
}
.muted { color: var(--muted); }

.section {
    margin-bottom: 2rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: clamp(1.25rem, 3vw, 1.75rem);
    box-shadow: var(--shadow);
}
.section h2 {
    margin: 0 0 1rem;
    font-size: clamp(1rem, 3vw, 1.2rem);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--navy);
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}
.badge-active, .badge-in_progress { background: #dcfce7; color: #166534; }
.badge-draft, .badge-scheduled { background: #dbeafe; color: #1e40af; }
.badge-finished, .badge-walkover { background: #f1f5f9; color: #475569; }
.badge-paused { background: #fef9c3; color: #a16207; }

.token-box {
    display: block;
    padding: 0.85rem 1rem;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin: 0.5rem 0 1rem;
    word-break: break-all;
    font-size: 0.85rem;
    font-family: ui-monospace, "Cascadia Code", monospace;
}

.error-page {
    text-align: center;
    padding: clamp(2rem, 8vw, 4rem) 1rem;
    max-width: 28rem;
    margin: 0 auto;
}
.error-code {
    margin: 0 0 0.5rem;
    font-size: 4rem;
    font-weight: 800;
    color: var(--border-strong);
    line-height: 1;
}
.error-page h1 { margin: 0 0 0.75rem; color: var(--navy); }
.error-page .btn { margin-top: 1.25rem; }

/* ── QR codes (panel distribution) ── */
.qr-match-info { margin-bottom: 1.5rem; text-align: center; }
.qr-match-meta {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}
.qr-match-versus {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
}
.qr-side-red { color: var(--red); }
.qr-side-blue { color: var(--blue); }
.qr-vs { color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 0.85rem; }
.qr-scan-hint { margin: 0; font-size: 0.9rem; }

.qr-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
    gap: 1.25rem;
}

.qr-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.1rem;
    text-align: center;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.65rem;
}
.qr-card-referee { border-top: 3px solid var(--red); }
.qr-card-judge { border-top: 3px solid var(--blue); }
.qr-card-display { border-top: 3px solid var(--gold); }

.qr-card-header { width: 100%; }
.qr-role-badge {
    display: inline-block;
    font-weight: 800;
    font-size: 1rem;
    color: var(--navy);
    letter-spacing: -0.01em;
}
.qr-card-hint {
    margin: 0.25rem 0 0;
    font-size: 0.78rem;
    color: var(--muted);
}

.qr-canvas-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 168px;
    min-width: 168px;
    padding: 0.35rem;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.qr-canvas-wrap img,
.qr-canvas-wrap canvas { display: block; max-width: 100%; height: auto; }

.qr-url {
    margin: 0;
    font-size: 0.65rem;
    color: var(--muted);
    word-break: break-all;
    line-height: 1.35;
    max-width: 100%;
}

.qr-scoreboard-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    align-items: flex-start;
}
.qr-card-compact { max-width: 220px; flex: 0 0 auto; }
.qr-scoreboard-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: flex-start;
    padding-top: 0.5rem;
}

@media print {
    .qr-print-hide { display: none !important; }
    .qr-print-layout .site-main { padding: 0; }
    .qr-print-layout .container { max-width: none; padding: 0; }
    .qr-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.75rem;
    }
    .qr-card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ccc;
        padding: 0.75rem;
    }
    .qr-canvas-wrap { border: none; }
    .qr-url { font-size: 0.6rem; }
}

code {
    font-family: ui-monospace, monospace;
    font-size: 0.85em;
    background: var(--bg-subtle);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
}

/* Legacy auth-box (unused but kept) */
.auth-box {
    max-width: 24rem;
    margin: clamp(1.5rem, 8vw, 3rem) auto;
    background: var(--card);
    padding: clamp(1.25rem, 4vw, 2rem);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
}

/* ══════════════════════════════════════
   MATCH PANELS (wasit / juri)
   ══════════════════════════════════════ */
.match-layout {
    background: #111827;
    min-height: 100vh;
    min-height: 100dvh;
    padding-bottom: var(--safe-bottom);
}

.match-flash {
    max-width: 900px;
    margin: 0.75rem auto;
    padding: 0 0.75rem;
}

.match-panel {
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    padding: clamp(0.75rem, 3vw, 1.25rem);
    color: #f9fafb;
}

.match-header {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
        "info status"
        "timer timer";
    gap: 0.5rem 1rem;
    align-items: center;
    margin-bottom: 1rem;
}
.match-header > div:first-child { grid-area: info; }
.match-header .timer-display { grid-area: timer; justify-self: center; }
.match-header .status-badge { grid-area: status; justify-self: end; }

.timer-display {
    font-size: clamp(2rem, 8vw, 3rem);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}

.status-badge {
    background: #374151;
    padding: 0.35rem 0.85rem;
    border-radius: 999px;
    font-size: 0.75rem;
    text-transform: uppercase;
    font-weight: 600;
}

.scoreboard-mini {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: clamp(0.5rem, 2vw, 1rem);
    margin-bottom: 1.25rem;
}

.side-red,
.side-blue {
    padding: clamp(0.85rem, 3vw, 1.25rem);
    border-radius: var(--radius);
    text-align: center;
    color: #fff;
}
.side-red { background: var(--red); }
.side-blue { background: var(--blue); }

.scoreboard-mini .name {
    font-size: clamp(0.9rem, 2.5vw, 1.15rem);
    font-weight: 700;
    line-height: 1.2;
    word-break: break-word;
}
.scoreboard-mini .team {
    font-size: clamp(0.7rem, 2vw, 0.85rem);
    opacity: 0.88;
    margin-top: 0.15rem;
}
.scoreboard-mini .score {
    font-size: clamp(2.25rem, 10vw, 3.5rem);
    font-weight: 900;
    line-height: 1.05;
    font-variant-numeric: tabular-nums;
    margin-top: 0.35rem;
}

.center-info {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    opacity: 0.65;
    font-size: clamp(0.85rem, 2vw, 1rem);
}

.control-section {
    background: #1f2937;
    border-radius: var(--radius);
    padding: clamp(0.85rem, 3vw, 1.15rem);
    margin-bottom: 0.85rem;
}
.control-section h3 {
    margin: 0 0 0.75rem;
    font-size: 0.8rem;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: stretch;
}
.side-label { font-weight: 700; min-width: 3rem; align-self: center; }

.score-log {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 0.875rem;
    max-height: 12rem;
    overflow-y: auto;
}
.score-log li { padding: 0.4rem 0; border-bottom: 1px solid #374151; }
.score-log .side-red { background: none; color: #fca5a5; padding: 0; display: inline; }
.score-log .side-blue { background: none; color: #93c5fd; padding: 0; display: inline; }

/* Judge panel */
.judge-panel .score-input {
    font-size: clamp(1.5rem, 5vw, 2rem);
    padding: 0.75rem;
    width: min(100%, 9rem);
    text-align: center;
    border-radius: var(--radius);
    border: 2px solid var(--border);
    min-height: var(--touch-min);
}
.judge-score-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
}
.judge-score-form .btn { flex: 1 1 auto; min-width: min(100%, 10rem); }

/* Dark match panel tables */
.match-panel .table-wrap { box-shadow: none; }
.match-panel .data-table {
    background: #111827;
    color: #f9fafb;
    min-width: 280px;
}
.match-panel .data-table th { background: #1f2937; color: #d1d5db; }
.match-panel .data-table td { border-color: #374151; }

/* Coarse pointer / touch devices */
@media (pointer: coarse) {
    .btn { min-height: 52px; }
    .btn-xl { min-height: 68px; font-size: 1.1rem; }
    .inline-form .btn { flex: 1 1 auto; }
}
.judge-side { width: 100%; }
.judge-side h4 { margin: 0 0 0.65rem; font-size: 0.95rem; }

/* ══════════════════════════════════════
   TV / ARENA SCOREBOARD
   ══════════════════════════════════════ */
.display-layout {
    background: #050508;
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0;
    overflow: hidden;
}

.display-scoreboard {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    grid-template-rows: auto auto auto 1fr auto;
    padding:
        calc(clamp(1rem, 2vh, 2rem) + var(--safe-top))
        calc(clamp(1rem, 3vw, 3rem) + var(--safe-right))
        calc(clamp(1rem, 2vh, 2rem) + var(--safe-bottom))
        calc(clamp(1rem, 3vw, 3rem) + var(--safe-left));
    color: #fff;
    gap: clamp(0.5rem, 1.5vh, 1.25rem);
}

.display-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.tournament-name {
    font-size: clamp(1rem, 2.5vw, 1.75rem);
    opacity: 0.75;
    font-weight: 500;
}
.mat-label {
    font-size: clamp(1.25rem, 3vw, 2rem);
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.display-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 2rem;
    justify-content: center;
    opacity: 0.8;
    font-size: clamp(0.9rem, 2vw, 1.35rem);
}
.display-meta .display-status {
    text-transform: uppercase;
    font-weight: 600;
    padding: 0.15rem 0.65rem;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 6px;
}

.display-timer {
    text-align: center;
    font-size: clamp(3rem, 12vw, 8rem);
    font-weight: 900;
    font-variant-numeric: tabular-nums;
    line-height: 1;
    letter-spacing: 0.04em;
    text-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
}

.display-scores {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: clamp(0.75rem, 3vw, 2.5rem);
    align-items: stretch;
    flex: 1;
    min-height: 0;
}

.display-side {
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: center;
    padding: clamp(1rem, 4vw, 3rem);
    border-radius: clamp(12px, 2vw, 24px);
    min-height: clamp(10rem, 35vh, 28rem);
}
.display-red {
    background: linear-gradient(165deg, #d32f2f 0%, var(--red-dark) 100%);
    box-shadow: 0 8px 40px rgba(198, 40, 40, 0.35);
}
.display-blue {
    background: linear-gradient(165deg, #1976d2 0%, var(--blue-dark) 100%);
    box-shadow: 0 8px 40px rgba(21, 101, 192, 0.35);
}

.display-name {
    font-size: clamp(1.1rem, 4vw, 3rem);
    font-weight: 800;
    line-height: 1.15;
    word-break: break-word;
    margin-bottom: 0.35rem;
}
.display-team {
    font-size: clamp(0.8rem, 2vw, 1.5rem);
    opacity: 0.85;
    margin-bottom: clamp(0.5rem, 2vh, 1.5rem);
}
.display-score {
    font-size: clamp(4rem, 18vw, 14rem);
    font-weight: 900;
    line-height: 0.95;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s ease;
}
.display-score.score-flash { transform: scale(1.06); }

.display-vs {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.25rem, 4vw, 3rem);
    font-weight: 800;
    opacity: 0.45;
}

.display-winner {
    text-align: center;
    font-size: clamp(1.1rem, 3.5vw, 2.5rem);
    font-weight: 800;
    padding: clamp(0.75rem, 2vh, 1.25rem);
    background: linear-gradient(90deg, transparent, rgba(255, 215, 0, 0.2), transparent);
    border-top: 2px solid rgba(255, 215, 0, 0.5);
    border-bottom: 2px solid rgba(255, 215, 0, 0.5);
    color: #ffd700;
    letter-spacing: 0.04em;
}

.display-idle {
    grid-row: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    text-align: center;
    padding: 2rem;
}
.display-idle-title {
    margin: 0;
    font-size: clamp(1.75rem, 5vw, 3rem);
    font-weight: 800;
    color: #fff;
    letter-spacing: 0.02em;
}
.display-idle-sub {
    margin: 0;
    font-size: clamp(1rem, 2.5vw, 1.5rem);
    color: rgba(255, 255, 255, 0.65);
}

/* ── Mobile (phones, < 640px) ── */
@media (max-width: 639px) {
    .nav-toggle { display: flex; align-items: center; justify-content: center; }

    .site-nav {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--navy-mid);
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        flex-direction: column;
        align-items: stretch;
        padding: 0.75rem 1rem 1rem;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    }
    .site-nav.is-open { display: flex; }
    .site-nav .nav-link {
        padding: 0.75rem 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        color: #fff;
    }
    .site-nav .logout-form,
    .site-nav .btn-nav {
        margin-top: 0.5rem;
        width: 100%;
    }
    .site-nav .btn-nav-outline { width: 100%; }

    .header-inner { position: relative; flex-wrap: wrap; }

    .page-header { flex-direction: column; }
    .btn-group { width: 100%; }
    .btn-group .btn { flex: 1 1 auto; }

    .scoreboard-mini {
        grid-template-columns: 1fr 1fr;
        grid-template-areas:
            "red blue"
            "vs vs";
    }
    .scoreboard-mini .side-red { grid-area: red; }
    .scoreboard-mini .center-info { grid-area: vs; padding: 0.25rem; }
    .scoreboard-mini .side-blue { grid-area: blue; }

    .match-header {
        grid-template-columns: 1fr;
        grid-template-areas: "info" "timer" "status";
    }
    .match-header .status-badge { justify-self: start; }

    .display-scores {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
    }
    .display-vs { padding: 0.25rem; }
    .display-side { min-height: auto; padding: 1.25rem 1rem; }
}

/* ── iPad portrait (768–1023px) ── */
@media (min-width: 768px) and (max-width: 1023px) {
    .auth-card { max-width: 28rem; }
    .card-grid { grid-template-columns: repeat(2, 1fr); }
    .inline-form input,
    .inline-form select { min-width: 8rem; }
}

/* ── Tablet / iPad portrait (640–1023px) ── */
@media (min-width: 640px) and (max-width: 1023px) {
    .match-panel { max-width: 100%; padding: 1rem 1.5rem; }

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

    .judge-panel .btn-grid { grid-template-columns: repeat(2, 1fr); }

    .display-scores { gap: 1.5rem; }
}

/* ── iPad landscape & small desktop (1024–1279px) ── */
@media (min-width: 1024px) and (max-width: 1279px) {
    .match-panel { max-width: 900px; }
    .btn-grid { grid-template-columns: repeat(3, 1fr); }
    .match-header {
        grid-template-columns: 1fr auto 1fr;
        grid-template-areas: "info timer status";
    }
    .match-header .timer-display { justify-self: center; }
}

/* ── Desktop (1280px+) ── */
@media (min-width: 1280px) {
    .container { padding: 0 2rem; }
    .match-panel { max-width: 1000px; }
    .btn-grid { grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); }
}

/* ── Large TV / arena display (1600px+, landscape) ── */
@media (min-width: 1600px) and (min-height: 800px) {
    .display-scoreboard {
        grid-template-rows: auto auto auto 1fr auto;
        padding: 2.5vh 4vw;
    }
    .display-timer { font-size: clamp(5rem, 10vh, 9rem); }
    .display-score { font-size: clamp(8rem, 22vh, 16rem); }
    .display-name { font-size: clamp(2rem, 4.5vh, 4rem); }
    .display-team { font-size: clamp(1rem, 2.5vh, 2rem); }
    .display-vs { font-size: clamp(2rem, 5vh, 4rem); }
    .display-winner { font-size: clamp(1.75rem, 4vh, 3rem); }
    .display-side { min-height: 38vh; border-radius: 24px; }
}

/* ── Full HD TV (1920×1080) ── */
@media (min-width: 1920px) and (min-height: 1000px) {
    body.display-layout { font-size: 18px; }
    .display-timer { font-size: 10rem; }
    .display-score { font-size: 18rem; }
    .display-name { font-size: 3.5rem; }
    .mat-label { font-size: 2.25rem; }
}

/* ── 4K TV ── */
@media (min-width: 2560px) {
    .display-timer { font-size: 12rem; }
    .display-score { font-size: 22rem; }
    .display-name { font-size: 4.5rem; }
}

/* ── Landscape phones ── */
@media (max-height: 500px) and (orientation: landscape) {
    .display-scoreboard {
        grid-template-rows: auto auto 1fr;
        gap: 0.35rem;
    }
    .display-timer { font-size: clamp(2rem, 12vh, 3.5rem); margin: 0; }
    .display-meta { font-size: 0.85rem; margin: 0; }
    .display-side { min-height: auto; padding: 0.75rem; }
    .display-score { font-size: clamp(2.5rem, 20vh, 4rem); }
    .display-name { font-size: 1rem; }
    .display-team { display: none; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
