:root {
    --bg: #0f1115;
    --fg: #f2f4f8;
    --muted: #9aa3b2;
    --accent: #3b82f6;
    --ok: #16a34a;
    --fail: #dc2626;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--fg);
}

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

.page {
    padding: 1rem;
    max-width: 1100px;
    margin: 0 auto;
}

#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.75rem 1rem;
    background: #fde68a;
    color: #111;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 1rem;
}

/* ---------- Organizer UI (basic; visual design comes in Phase 8) ---------- */
:root {
    --surface: #181b22;
    --border: #2a2f3a;
    --warn: #d97706;
}

h1 { font-size: 1.6rem; margin: 0.5rem 0; }
h2 { font-size: 1.15rem; margin: 0 0 0.75rem; }
.muted { color: var(--muted); }

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

.subnav { display: flex; gap: 1rem; flex-wrap: wrap; padding: 0.5rem 0 1rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.subnav a { text-decoration: none; }
.subnav a.active { font-weight: 700; text-decoration: underline; }

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

.toolbar { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; margin: 0.75rem 0; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

.btn {
    display: inline-block; padding: 0.55rem 1rem; border-radius: 8px; border: 1px solid var(--border);
    background: #232834; color: var(--fg); cursor: pointer; text-decoration: none; font: inherit; min-height: 44px;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { background: transparent; border-color: var(--fail); color: #fca5a5; }
.btn-small { padding: 0.3rem 0.65rem; min-height: 36px; font-size: 0.9rem; }
button.link { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font: inherit; }
form.inline { display: inline; }

.form .field, .field { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.8rem; }
.field-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.field label { font-weight: 600; }
label.radio { display: flex; gap: 0.5rem; align-items: center; font-weight: 400; }
input, textarea, select {
    font: inherit; color: var(--fg); background: #0b0d11; border: 1px solid var(--border);
    border-radius: 6px; padding: 0.5rem; min-height: 40px;
}
input[type=checkbox], input[type=radio] { min-height: auto; width: 1.1rem; height: 1.1rem; }
fieldset { border: none; padding: 0; margin: 0; }
.validation-message { color: #fca5a5; font-size: 0.9rem; }

.alert { padding: 0.7rem 1rem; border-radius: 8px; margin: 0.75rem 0; }
.alert ul { margin: 0.4rem 0 0; }
.alert-error, .error { background: #3b1414; border: 1px solid var(--fail); color: #fecaca; }
.alert-success { background: #0f2e1b; border: 1px solid var(--ok); color: #bbf7d0; }
.alert-warning { background: #3a2a0c; border: 1px solid var(--warn); color: #fde68a; }

.confirm { margin-top: 0.75rem; padding: 0.75rem; border: 1px dashed var(--warn); border-radius: 8px; }

.badge { padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.85rem; font-weight: 600; background: #2a2f3a; }
.status-draft { background: #374151; }
.status-registration { background: #1e3a8a; }
.status-running { background: #166534; }
.status-finished { background: #7c2d12; }
.status-archived { background: #27272a; color: var(--muted); }

.grid { width: 100%; border-collapse: collapse; }
.grid th, .grid td { text-align: left; padding: 0.5rem; border-bottom: 1px solid var(--border); }
.grid.points input { width: 5rem; }
.table-scroll { overflow-x: auto; margin-bottom: 1rem; }
.pager { display: flex; gap: 0.75rem; align-items: center; margin-top: 1rem; }

.stats { display: flex; gap: 1.5rem; flex-wrap: wrap; margin: 0 0 0.75rem; }
.stats div { min-width: 6rem; }
.stats dt { color: var(--muted); font-size: 0.85rem; }
.stats dd { margin: 0; font-size: 1.5rem; font-weight: 700; }

.station-header h2 { display: flex; align-items: center; gap: 0.6rem; }
.station-no {
    display: inline-flex; align-items: center; justify-content: center; width: 2rem; height: 2rem;
    border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700;
}
.levels { list-style: none; padding: 0; margin: 0.75rem 0; }
.level { border-top: 1px solid var(--border); padding: 0.6rem 0; }
.level-row { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.instructions { font-size: 0.9rem; white-space: pre-line; margin-top: 0.25rem; }
.inline-form { background: #11141a; padding: 0.75rem; border-radius: 8px; }
textarea.export { width: 100%; font-family: ui-monospace, monospace; font-size: 0.85rem; }

/* ---------- Public mobile pages (bracelet / competitor) ---------- */
.mobile { max-width: 480px; margin: 0 auto; padding: 0.5rem 0 2rem; }
.mobile h1 { font-size: 1.5rem; }
.center { text-align: center; }
.small { font-size: 0.85rem; }
.btn-block { display: block; width: 100%; text-align: center; margin: 0.5rem 0; }
.btn-big { min-height: 56px; font-size: 1.15rem; font-weight: 700; }
.btn-choice { min-height: 56px; font-size: 1.1rem; }
.choice-list { margin: 0.75rem 0; }
.participant-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1.25rem; margin: 1rem 0; text-align: center; }
.participant-card h1 { font-size: 1.9rem; margin: 0.3rem 0; text-transform: uppercase; }
.start-number { font-size: 1.3rem; font-weight: 700; color: var(--accent); }
.stats dd.small-dd { font-size: 1.05rem; }

/* ---------- Judge pairing (organizer) ---------- */
.judge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.judge-card { margin: 0; }
.qr { background: #fff; padding: 0.5rem; border-radius: 8px; max-width: 240px; margin: 0.5rem 0; }
.qr svg { width: 100%; height: auto; display: block; }
code.break { word-break: break-all; font-size: 0.75rem; }
.devices { list-style: none; padding: 0; margin: 0.25rem 0; }
.devices li { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; padding: 0.3rem 0; border-top: 1px solid var(--border); }
.dot-ok { color: var(--ok); }
.dot-off { color: var(--fail); }

/* ---------- Judge phone ---------- */
.judge-header { text-align: center; padding: 0.5rem 0 1rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.judge-station { font-size: 2rem; font-weight: 800; letter-spacing: 0.03em; }
.judge-idle { text-align: center; padding: 2rem 0; color: var(--muted); }
.judge-idle-icon { font-size: 3rem; }
.judge-footer { margin-top: 3rem; color: var(--muted); }

/* ---------- Judge attempts ---------- */
.level-list { list-style: none; padding: 0; margin: 0.75rem 0; display: grid; gap: 0.35rem; }
.level-list .level { display: grid; grid-template-columns: auto 1fr auto; gap: 0.5rem; align-items: center;
         padding: 0.5rem 0.75rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.level-passed { border-color: var(--ok); }
.level-available { border-color: var(--accent); font-weight: 700; }
.level-exhausted { border-color: var(--fail); opacity: 0.8; }
.level-locked { opacity: 0.5; }
.level-status { font-weight: 700; }
.current-level { text-align: center; margin: 1rem 0 0.5rem; }
.current-level-title { font-size: 1.4rem; font-weight: 800; }
.attempt-counter { font-size: 1.2rem; margin-top: 0.25rem; }
.judge-buttons { display: grid; gap: 0.75rem; margin: 1rem 0; }
.btn-judge { min-height: 5.5rem; font-size: 1.8rem; font-weight: 800; border: 0; border-radius: 14px; color: #fff;
             cursor: pointer; touch-action: manipulation; letter-spacing: 0.04em; }
.btn-judge:disabled { opacity: 0.6; cursor: wait; }
.btn-pass { background: var(--ok); }
.btn-fail { background: var(--fail); }
.feedback { text-align: center; padding: 1rem; border-radius: 12px; margin: 0.75rem 0; color: #fff; }
.feedback-pass { background: var(--ok); }
.feedback-fail { background: #4b5563; }
.feedback-title { font-size: 1.5rem; font-weight: 800; }
.feedback-points { font-size: 2rem; font-weight: 800; }
.correction { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; justify-content: space-between; margin: 0.5rem 0; }
.history ul { padding-left: 1.2rem; }
.pre { white-space: pre-wrap; }

/* ---------- Accessibility ---------- */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn-judge:focus-visible { outline-color: #fff; outline-offset: -6px; }
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- Organizer live dashboard ---------- */
.text-ok { color: #4ade80; }
.text-warn { color: #fbbf24; }
.station-status { list-style: none; padding: 0; margin: 0.5rem 0; display: grid; gap: 0.4rem;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.station-status li { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; padding: 0.45rem 0.6rem;
    border: 1px solid var(--border); border-radius: 8px; background: #11141a; }
.station-status .station-no { width: 1.7rem; height: 1.7rem; font-size: 0.9rem; }
.station-status-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.station-status-label { font-weight: 700; font-size: 0.9rem; }
.station-status-ok { border-color: var(--ok) !important; }
.station-status-ok .station-status-label { color: #4ade80; }
.station-status-warn { border-color: var(--warn) !important; }
.station-status-warn .station-status-label { color: #fbbf24; }
.station-status-off .station-status-label { color: #fca5a5; }
.station-status-off .station-no { background: #4b5563; }

/* ---------- Reconnect modal (classes toggled by Blazor) ---------- */
.reconnect { display: none; position: fixed; inset: 0; z-index: 2000; background: rgba(0, 0, 0, 0.72);
    align-items: center; justify-content: center; padding: 1rem; }
.reconnect.components-reconnect-show,
.reconnect.components-reconnect-failed,
.reconnect.components-reconnect-rejected { display: flex; }
.reconnect-box { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 1.25rem;
    width: 100%; max-width: 360px; text-align: center; }
.reconnect-state { display: none; }
.reconnect.components-reconnect-show .reconnect-state-show,
.reconnect.components-reconnect-failed .reconnect-state-failed,
.reconnect.components-reconnect-rejected .reconnect-state-rejected { display: block; }
.reconnect-spinner { width: 2.5rem; height: 2.5rem; margin: 0 auto 0.75rem; border-radius: 50%;
    border: 4px solid var(--border); border-top-color: var(--accent); animation: reconnect-spin 0.9s linear infinite; }
@keyframes reconnect-spin { to { transform: rotate(360deg); } }

/* ---------- Results / corrections / audit ---------- */
.level-chip { display: inline-block; margin-right: 0.75rem; }
.attempt-voided td { text-decoration: line-through; opacity: 0.6; }
.attempt-ignored td { opacity: 0.6; }
.correction-history td { border-bottom: 1px solid var(--border); padding-top: 0; font-size: 0.85rem; color: var(--muted); }
.correction-history ul { margin: 0; padding-left: 1.2rem; }
.audit-correction { background: rgba(217, 119, 6, 0.12); }
.audit-value { display: block; max-width: 28rem; white-space: pre-wrap; word-break: break-word; font-size: 0.75rem; color: var(--muted); }
.nowrap { white-space: nowrap; }

/* ---------- Scoreboard (TV / projector, fullscreen) ---------- */
.scoreboard-page { min-height: 100vh; padding: 2vh 3vw; font-size: clamp(1rem, 1.6vw, 2.2rem); }
.sb-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap;
    border-bottom: 2px solid var(--border); padding-bottom: 1vh; margin-bottom: 1.5vh; }
.sb-header h1 { font-size: 2.2em; margin: 0; text-transform: uppercase; letter-spacing: 0.03em; }
.sb-meta { display: flex; flex-direction: column; gap: 0.3rem; align-items: end; }
.sb-status { display: flex; gap: 1rem; align-items: center; }
.sb-timestamps { display: flex; gap: 0.5rem; align-items: center; color: var(--muted); font-size: 0.3em; }
.sb-live { color: var(--ok); font-weight: 800; }
.sb-stale { color: #fde68a; font-weight: 700; font-size: 0.8em; }
.sb-message { text-align: center; font-size: 1.6em; color: var(--muted); margin-top: 20vh; }
.sb-table { width: 100%; border-collapse: collapse; }
.sb-table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 0.75em; padding: 0.3em 0.5em; }
.sb-table td { padding: 0.35em 0.5em; border-bottom: 1px solid var(--border); }
.sb-rank { width: 3.5em; font-weight: 800; }
.sb-name { font-weight: 700; }
.sb-start { color: var(--muted); font-weight: 400; font-size: 0.75em; margin-left: 0.5em; }
.sb-station { text-align: center; width: 3em; color: var(--muted); }
.sb-table th.sb-station { text-align: center; }
.sb-station.sb-done { color: var(--fg); font-weight: 700; }
.sb-total { text-align: right; width: 4em; font-weight: 800; font-size: 1.25em; }
.sb-table th.sb-total { text-align: right; }
.sb-gold .sb-rank { color: #facc15; }
.sb-silver .sb-rank { color: #d1d5db; }
.sb-bronze .sb-rank { color: #d97706; }
.sb-changed { animation: sb-flash 2s ease-out; }
@keyframes sb-flash { from { background: rgba(59, 130, 246, 0.45); } to { background: transparent; } }
@media (prefers-reduced-motion: reduce) { .sb-changed { animation: none; } }
.sb-footer { display: flex; gap: 2rem; justify-content: flex-end; color: var(--muted); font-size: 0.7em; margin-top: 1.5vh; }

/* ---------- Commentator live feed (reuses scoreboard layout) ---------- */
.cm-stations { display: flex; flex-wrap: wrap; gap: 0.4em; margin-bottom: 1.5vh; font-size: 0.75em; }
.cm-station-btn { display: inline-flex; align-items: center; gap: 0.4em; padding: 0.35em 0.8em; border: 1px solid var(--border);
    border-radius: 999px; color: var(--fg); text-decoration: none; }
.cm-station-btn:hover { border-color: var(--accent); }
.cm-station-btn.cm-active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.cm-station-no { font-weight: 800; }
.cm-station-name { max-width: 12em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cm-latest { border: 2px solid var(--border); border-left-width: 0.5em; border-radius: 12px; padding: 1vh 1.5vw; margin-bottom: 2vh; }
.cm-latest.cm-pass { border-color: rgba(22, 163, 74, 0.7); background: rgba(22, 163, 74, 0.1); }
.cm-latest.cm-fail { border-color: rgba(220, 38, 38, 0.7); background: rgba(220, 38, 38, 0.1); }
.cm-latest-result { font-weight: 800; font-size: 1.1em; }
.cm-latest-name { font-weight: 800; font-size: 2.6em; line-height: 1.15; overflow-wrap: anywhere; }
.cm-latest-detail { display: flex; flex-wrap: wrap; gap: 0.5em; color: var(--muted); font-size: 0.85em; }
.cm-pass { color: #86efac; }
.cm-fail { color: #fca5a5; }
.cm-latest.cm-pass .cm-latest-name, .cm-latest.cm-fail .cm-latest-name { color: var(--fg); }
.cm-result { font-weight: 800; white-space: nowrap; width: 6em; }
.cm-time { color: var(--muted); white-space: nowrap; }
.cm-feed .cm-time { width: 5em; font-size: 0.8em; }
.cm-level { color: var(--muted); font-size: 0.8em; }


/* ---------- Profiles ---------- */
.profile-media { display: block; max-width: 100%; max-height: 360px; border-radius: 8px; border: 1px solid var(--border); margin: 0.5rem 0; }

/* ---------- Country select ---------- */
.country-select { position: relative; }
.country-select input { width: 100%; }
.country-list { position: absolute; z-index: 20; left: 0; right: 0; top: 100%; max-height: 260px; overflow-y: auto; margin: 2px 0 0; padding: 0.25rem 0; list-style: none; background: #0b0d11; border: 1px solid var(--border); border-radius: 6px; }
.country-item { padding: 0.45rem 0.6rem; cursor: pointer; }
.country-item:hover, .country-item.selected { background: #1b2030; }
.country-flag { display: inline-block; width: 1.6em; }
.points-input { width: 6rem; }

/* ---------- Competitor's own progress (bracelet page) ---------- */
.pc-status { margin-top: 0.5rem; }
.pc-hero { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; margin: 0 0 1rem; }
.pc-hero-item { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 0.9rem; text-align: center; }
.pc-hero-label { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
.pc-hero-value { font-size: 2.6rem; font-weight: 800; line-height: 1.1; margin: 0.2rem 0; }
.pc-hero-sub { color: var(--muted); font-size: 0.8rem; }
.pc-gold { color: #facc15; }
.pc-silver { color: #d1d5db; }
.pc-bronze { color: #d97706; }
.pc-overview { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 0.9rem; margin-bottom: 1rem; }
.pc-progress-label { display: flex; justify-content: space-between; font-size: 0.9rem; margin-bottom: 0.4rem; }
.pc-progress { height: 10px; border-radius: 999px; background: var(--border); overflow: hidden; }
.pc-progress-bar { height: 100%; background: linear-gradient(90deg, var(--accent), var(--ok)); border-radius: 999px; transition: width 0.4s ease; }
.pc-mini-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; margin: 0.8rem 0 0.4rem; text-align: center; }
.pc-mini-stats dt { color: var(--muted); font-size: 0.75rem; }
.pc-mini-stats dd { margin: 0; font-size: 1.15rem; font-weight: 700; }
.pc-station { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--border); border-radius: 12px; padding: 0.8rem; margin-bottom: 0.75rem; }
.pc-station-active { border-left-color: var(--accent); }
.pc-station-done { border-left-color: var(--ok); }
.pc-station-new { opacity: 0.85; }
.pc-station-head { display: flex; align-items: center; gap: 0.6rem; }
.pc-station-title { flex: 1; min-width: 0; }
.pc-station-name { font-weight: 700; font-size: 1.05rem; overflow-wrap: anywhere; }
.pc-station-points strong { font-size: 1.5rem; }
.pc-state-done { color: var(--ok); font-weight: 600; }
.pc-state-active { color: var(--accent); font-weight: 600; }
.pc-levels { list-style: none; padding: 0; margin: 0.7rem 0 0; display: grid; gap: 0.3rem; }
.pc-level { display: grid; grid-template-columns: 1.4rem 2rem 1fr auto; gap: 0.4rem; align-items: center;
    padding: 0.4rem 0.55rem; border-radius: 8px; border: 1px solid var(--border); font-size: 0.9rem; }
.pc-level-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pc-level-order { color: var(--muted); font-weight: 700; }
.pc-level-info { color: var(--muted); font-size: 0.8rem; text-align: right; white-space: nowrap; }
.pc-level-passed { border-color: rgba(22, 163, 74, 0.6); background: rgba(22, 163, 74, 0.12); }
.pc-level-passed .pc-level-icon, .pc-level-passed .pc-level-info { color: #86efac; }
.pc-level-available { border-color: var(--accent); background: rgba(59, 130, 246, 0.12); font-weight: 700; }
.pc-level-available .pc-level-icon { color: var(--accent); }
.pc-level-exhausted { border-color: rgba(220, 38, 38, 0.6); background: rgba(220, 38, 38, 0.1); }
.pc-level-exhausted .pc-level-icon, .pc-level-exhausted .pc-level-info { color: #fca5a5; }
.pc-level-locked { opacity: 0.45; }
.pc-next { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem;
    padding: 0.5rem 0.6rem; border-radius: 8px; background: rgba(59, 130, 246, 0.1); font-size: 0.9rem; }
.pc-next-left { color: #93c5fd; font-weight: 600; }
.pc-attempts { margin-top: 0.6rem; }
.pc-attempts summary { cursor: pointer; color: var(--accent); font-size: 0.9rem; padding: 0.2rem 0; }
.pc-attempts ul { list-style: none; padding: 0; margin: 0.3rem 0 0; }
.pc-attempt { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; padding: 0.35rem 0; border-top: 1px solid var(--border); font-size: 0.9rem; }
.pc-result { font-weight: 800; }
.pc-pass { color: #86efac; }
.pc-fail { color: #fca5a5; }
.pc-attempt-points { margin-left: auto; font-weight: 700; color: #86efac; }
.pc-attempt-voided > span:not(.badge) { text-decoration: line-through; opacity: 0.55; }
.pc-attempt-ignored > span:not(.badge) { opacity: 0.55; }
