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

:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface2: #1e1e1e;
  --border: #2a2a2a;
  --accent: #c9a84c;
  --accent-dim: rgba(201,168,76,0.15);
  --text: #f0f0f0;
  --text-sub: #888;
  --danger: #c0392b;
  --danger-dim: rgba(192,57,43,0.15);
  --success: #27ae60;
  --warning: #e67e22;
  --locked: #555;
  --radius: 12px;
  --radius-sm: 8px;
}

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 16px; -webkit-tap-highlight-color: transparent; }

#app { height: 100%; display: flex; flex-direction: column; }

/* Screens */
.screen { display: none; flex-direction: column; height: 100%; overflow: hidden; }
.screen.active { display: flex; }

/* Loading */
#loading { align-items: center; justify-content: center; gap: 16px; }
.loader-wrap { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.loader-ring { width: 48px; height: 48px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Header */
.screen-header { background: var(--surface); border-bottom: 1px solid var(--border); padding: 16px 20px; display: flex; align-items: center; gap: 12px; flex-shrink: 0; min-height: 64px; }
.screen-header h1 { font-size: 1.3rem; font-weight: 700; color: var(--accent); flex: 1; }
.screen-header h2 { font-size: 1.1rem; font-weight: 600; flex: 1; }
.back-btn { background: none; border: none; color: var(--accent); font-size: 1rem; cursor: pointer; padding: 8px 0; white-space: nowrap; }
.progress-badge { background: var(--accent-dim); color: var(--accent); border-radius: 20px; padding: 4px 12px; font-size: 0.8rem; font-weight: 600; white-space: nowrap; }

/* Body */
.screen-body { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 20px; -webkit-overflow-scrolling: touch; }

/* Home role grid */
.role-grid { display: flex; flex-direction: column; gap: 16px; padding: 20px; flex: 1; justify-content: center; }
.role-btn { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px 24px; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; cursor: pointer; transition: border-color 0.15s, background 0.15s; text-align: left; }
.role-btn:active { background: var(--surface2); border-color: var(--accent); }
.role-icon { font-size: 2rem; }
.role-label { font-size: 1.25rem; font-weight: 700; color: var(--text); }
.role-sub { font-size: 0.875rem; color: var(--text-sub); }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.card h3 { font-size: 1rem; font-weight: 600; color: var(--text-sub); text-transform: uppercase; letter-spacing: 0.05em; display: flex; align-items: center; gap: 8px; }

/* Fields */
.field-group { display: flex; flex-direction: column; gap: 8px; }
.field-group label { font-size: 0.85rem; color: var(--text-sub); font-weight: 500; }
.field-group input, .field-group textarea, .field-group select { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); font-size: 1rem; padding: 14px 16px; width: 100%; outline: none; transition: border-color 0.15s; -webkit-appearance: none; }
.field-group input:focus, .field-group textarea:focus, .field-group select:focus { border-color: var(--accent); }
.field-group select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23888' stroke-width='1.5' fill='none'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }
.field-row { display: flex; gap: 12px; }
.flex-1 { flex: 1; }
.flex-3 { flex: 3; }
.optional { color: var(--text-sub); font-weight: 400; }

/* Stepper */
.stepper { display: flex; align-items: center; gap: 0; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; width: fit-content; }
.stepper-btn { background: none; border: none; color: var(--accent); font-size: 1.5rem; width: 56px; height: 52px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.stepper-btn:active { background: var(--accent-dim); }
#admin-event-count { font-size: 1.5rem; font-weight: 700; min-width: 48px; text-align: center; }

/* Event config rows */
.event-config-row { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.event-config-row .event-num { font-size: 0.8rem; color: var(--accent); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.btn-clear-event { background: transparent; color: var(--danger); border: 1px solid var(--danger); border-radius: var(--radius-sm); font-size: 0.8rem; font-weight: 600; padding: 6px 12px; cursor: pointer; align-self: flex-end; }
.btn-clear-event:active { opacity: 0.7; }
.event-config-fields { display: flex; gap: 12px; align-items: flex-end; }
.event-config-fields .field-group { flex: 1; }

/* Buttons */
.btn-primary { background: var(--accent); color: #000; border: none; border-radius: var(--radius-sm); font-size: 1rem; font-weight: 700; padding: 16px 24px; cursor: pointer; transition: opacity 0.15s; }
.btn-primary:active { opacity: 0.8; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 1rem; font-weight: 600; padding: 16px 24px; cursor: pointer; }
.btn-secondary:active { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; border: none; border-radius: var(--radius-sm); font-size: 1rem; font-weight: 700; padding: 16px 24px; cursor: pointer; }
.btn-danger:active { opacity: 0.8; }
.btn-warning { background: var(--warning); color: #fff; border: none; border-radius: var(--radius-sm); font-size: 1rem; font-weight: 700; padding: 16px 24px; cursor: pointer; }
.btn-certify { background: var(--success); color: #fff; border: none; border-radius: var(--radius-sm); font-size: 1.1rem; font-weight: 700; padding: 20px 24px; cursor: pointer; margin-top: 8px; }
.btn-certify:active { opacity: 0.8; }
.btn-full { width: 100%; }

/* Messages */
.msg { font-size: 0.9rem; min-height: 20px; padding: 4px 0; }
.msg.error { color: #e74c3c; }
.msg.success { color: var(--success); }

/* Badge */
.badge { background: var(--accent-dim); color: var(--accent); border-radius: 12px; padding: 2px 10px; font-size: 0.8rem; font-weight: 700; }
.badge-locked { background: rgba(85,85,85,0.3); color: var(--locked); }

/* Participant list */
.participant-list { display: flex; flex-direction: column; gap: 8px; }
.participant-row { display: flex; align-items: center; gap: 12px; background: var(--surface2); border-radius: var(--radius-sm); padding: 12px 16px; }
.participant-entry { font-size: 1.1rem; font-weight: 700; color: var(--accent); min-width: 48px; }
.participant-name { flex: 1; font-size: 1rem; }
.participant-delete { background: none; border: none; color: var(--danger); font-size: 1.3rem; cursor: pointer; padding: 4px 8px; line-height: 1; }
.empty-state { color: var(--text-sub); font-size: 0.95rem; text-align: center; padding: 20px 0; }

/* Event status list (office) */
.event-status-list { display: flex; flex-direction: column; gap: 8px; }
.event-status-row { display: flex; align-items: center; gap: 12px; background: var(--surface2); border-radius: var(--radius-sm); padding: 14px 16px; }
.event-status-name { flex: 1; font-size: 1rem; font-weight: 600; }
.status-pill { font-size: 0.78rem; font-weight: 700; border-radius: 12px; padding: 4px 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.status-open { background: rgba(39,174,96,0.2); color: var(--success); }
.status-locked { background: rgba(85,85,85,0.3); color: var(--locked); }
.unlock-btn { background: none; border: 1px solid var(--warning); color: var(--warning); border-radius: var(--radius-sm); font-size: 0.8rem; font-weight: 600; padding: 6px 12px; cursor: pointer; white-space: nowrap; }

/* Judge event buttons */
.event-btn-list { display: flex; flex-direction: column; gap: 16px; padding: 20px; }
.event-btn { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px 20px; display: flex; flex-direction: column; gap: 6px; cursor: pointer; text-align: left; width: 100%; }
.event-btn:active { border-color: var(--accent); background: var(--surface2); }
.event-btn.locked { opacity: 0.5; cursor: default; border-color: var(--locked); }
.event-btn-name { font-size: 1.25rem; font-weight: 700; color: var(--text); }
.event-btn-meta { font-size: 0.875rem; color: var(--text-sub); display: flex; gap: 12px; align-items: center; }
.event-btn-status { font-size: 0.78rem; font-weight: 700; border-radius: 12px; padding: 3px 10px; }

/* Rider list (scoring) */
.rider-list { display: flex; flex-direction: column; gap: 10px; }
.rider-row { display: flex; align-items: center; gap: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 16px; cursor: pointer; transition: border-color 0.15s; }
.rider-row:active { border-color: var(--accent); }
.rider-row.scored { border-color: rgba(39,174,96,0.4); }
.rider-entry { font-size: 1.2rem; font-weight: 800; color: var(--accent); min-width: 52px; }
.rider-info { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.rider-name { font-size: 1rem; font-weight: 600; }
.rider-score-summary { font-size: 0.85rem; color: var(--text-sub); }
.rider-check { font-size: 1.3rem; color: var(--success); }
.rider-arrow { color: var(--text-sub); font-size: 1rem; }

/* Score entry */
.rider-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px 20px; text-align: center; }
.rider-entry-num { font-size: 2rem; font-weight: 800; color: var(--accent); }
.rider-name-display { font-size: 1.4rem; font-weight: 700; margin-top: 6px; }

/* Rank input */
.rank-input-wrap { display: flex; flex-direction: column; gap: 12px; }
.rank-label { font-size: 0.85rem; color: var(--text-sub); font-weight: 500; }
.rank-big-input { background: var(--surface2); border: 2px solid var(--border); border-radius: var(--radius-sm); color: var(--text); font-size: 2.5rem; font-weight: 800; padding: 20px; width: 100%; text-align: center; outline: none; -webkit-appearance: none; }
.rank-big-input:focus { border-color: var(--accent); }
.rank-hint { font-size: 0.85rem; color: var(--text-sub); text-align: center; }
.points-preview { text-align: center; font-size: 1rem; color: var(--success); font-weight: 600; min-height: 24px; }

/* Points mode */
.points-input-wrap { display: flex; flex-direction: column; gap: 12px; }
.points-big-input { background: var(--surface2); border: 2px solid var(--border); border-radius: var(--radius-sm); color: var(--text); font-size: 2.5rem; font-weight: 800; padding: 20px; width: 100%; text-align: center; outline: none; -webkit-appearance: none; }
.points-big-input:focus { border-color: var(--accent); }

.score-actions { display: flex; gap: 12px; }
.score-actions .btn-secondary, .score-actions .btn-primary { flex: 1; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.75); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px 24px; max-width: 400px; width: 100%; display: flex; flex-direction: column; gap: 16px; }
.modal h3 { font-size: 1.2rem; font-weight: 700; }
.modal p { font-size: 0.95rem; color: var(--text-sub); line-height: 1.5; }
.modal-actions { display: flex; gap: 12px; margin-top: 8px; }
.modal-actions button { flex: 1; }

/* Sync indicator */
#sync-indicator { position: fixed; top: 12px; right: 12px; font-size: 0.75rem; padding: 4px 10px; border-radius: 12px; background: var(--surface2); color: var(--text-sub); z-index: 50; display: none; }
#sync-indicator.visible { display: block; }
#sync-indicator.syncing { color: var(--accent); }
#sync-indicator.error { color: var(--danger); }
