/* Competition Live View - Clean, data-focused design */
/* Design system matching training_live.css */

/* ============================================
   CSS Variables - Design Tokens
   ============================================ */
:root {
    /* Neutral palette */
    --color-bg: #f8f9fa;
    --color-surface: #ffffff;
    --color-surface-elevated: #ffffff;
    --color-border: #e5e7eb;
    --color-border-subtle: #f3f4f6;

    /* Text hierarchy */
    --color-text-primary: #111827;
    --color-text-secondary: #6b7280;
    --color-text-tertiary: #9ca3af;
    --color-text-inverse: #ffffff;

    /* Semantic colors */
    --color-accent: #2563eb;
    --color-accent-light: #dbeafe;
    --color-success: #059669;
    --color-success-light: #d1fae5;
    --color-warning: #d97706;
    --color-warning-light: #fef3c7;
    --color-error: #dc2626;
    --color-error-light: #fee2e2;

    /* Position colors */
    --color-gold: #b8860b;
    --color-gold-bg: #fef9e7;
    --color-silver: #6b7280;
    --color-silver-bg: #f9fafb;
    --color-bronze: #92400e;
    --color-bronze-bg: #fef7ed;

    /* Live indicator */
    --color-live: #dc2626;
    --color-live-pulse: #fecaca;

    /* Typography */
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'SF Mono', SFMono-Regular, ui-monospace, Menlo, Monaco, 'Cascadia Mono', monospace;

    /* Spacing scale */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;

    /* Border radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark mode */
[data-theme="dark"] {
    --color-bg: #111827;
    --color-surface: #1f2937;
    --color-surface-elevated: #374151;
    --color-border: #374151;
    --color-border-subtle: #1f2937;

    --color-text-primary: #f9fafb;
    --color-text-secondary: #d1d5db;
    --color-text-tertiary: #9ca3af;

    --color-accent: #3b82f6;
    --color-accent-light: #1e3a5f;
    --color-success-light: #064e3b;
    --color-warning-light: #78350f;
    --color-error-light: #7f1d1d;

    --color-gold-bg: #292524;
    --color-silver-bg: #1f2937;
    --color-bronze-bg: #292524;

    --color-live-pulse: #7f1d1d;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --color-bg: #111827;
        --color-surface: #1f2937;
        --color-surface-elevated: #374151;
        --color-border: #374151;
        --color-border-subtle: #1f2937;

        --color-text-primary: #f9fafb;
        --color-text-secondary: #d1d5db;
        --color-text-tertiary: #9ca3af;

        --color-accent: #3b82f6;
        --color-accent-light: #1e3a5f;
        --color-success-light: #064e3b;
        --color-warning-light: #78350f;
        --color-error-light: #7f1d1d;

        --color-gold-bg: #292524;
        --color-silver-bg: #1f2937;
        --color-bronze-bg: #292524;

        --color-live-pulse: #7f1d1d;
    }
}

/* ============================================
   Base Styles
   ============================================ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

.live-view {
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   Live Container
   ============================================ */
.live-container {
    max-width: 64rem;
    margin: 0 auto;
    padding: var(--space-4);
    padding-bottom: calc(5rem + env(safe-area-inset-bottom, var(--space-4)));
}

/* ============================================
   Live Header
   ============================================ */
.live-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: var(--space-4) 0;
    margin-bottom: var(--space-4);
    border-bottom: 1px solid var(--color-border);
}

.event-info-bar h1 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
    color: var(--color-text-primary);
}

.live-time-container {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.live-status {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    background: var(--color-surface);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
}

.status-text {
    font-size: 0.625rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--color-live);
}

.live-time {
    font-size: 1rem;
    font-weight: 500;
    font-family: var(--font-mono);
    color: var(--color-text-secondary);
    background: var(--color-surface);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
}

.viewer-count {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--color-text-tertiary);
    background: var(--color-surface);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
}

.viewer-icon {
    width: 0.75rem;
    height: 0.75rem;
    opacity: 0.7;
}

.viewer-count #viewerCountNum {
    font-family: var(--font-mono);
    font-weight: 600;
    min-width: 1rem;
    text-align: center;
}

/* Status Indicator */
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.status-live {
    background: var(--color-success);
    animation: pulse-live 2s ease-in-out infinite;
}

.status-updating {
    background: var(--color-warning);
    animation: pulse-live 1s ease-in-out infinite;
}

.status-offline {
    background: var(--color-error);
    animation: none;
}

@keyframes pulse-live {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.round-live-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-success);
    display: inline-block;
    margin-left: 4px;
    vertical-align: middle;
    animation: pulse-live 2s ease-in-out infinite;
}

/* ============================================
   Controls Top - Round Tabs + Actions
   ============================================ */
.controls-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
    position: relative;
}

.round-tabs-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    flex: 1;
}

.round-tabs-container::-webkit-scrollbar {
    display: none;
}

.round-tabs {
    display: inline-flex;
    gap: var(--space-2);
    padding: 2px;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    min-width: max-content;
}

.round-short { display: none; }

/* Tab button — reuse .tab class from JS but style as round-tab */
.round-tab,
.tab {
    display: inline-flex;
    align-items: center;
    background: transparent;
    color: var(--color-text-secondary);
    border: none;
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    transition: all var(--transition-fast);
    min-height: 2.25rem;
}

.round-tab:hover,
.tab:hover {
    background: var(--color-border-subtle);
    color: var(--color-text-primary);
}

.round-tab.active,
.tab.active {
    background: var(--color-accent);
    color: var(--color-text-inverse);
    box-shadow: var(--shadow-sm);
}

.controls-actions {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    flex-shrink: 0;
}

.controls-top.hide-controls .controls-actions {
    display: none;
}

.icon-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--color-text-secondary);
    transition: all var(--transition-fast);
}

.icon-button:hover {
    background: var(--color-border-subtle);
    color: var(--color-text-primary);
}

.icon-button.active {
    background: var(--color-accent-light);
    color: var(--color-accent);
    border-color: var(--color-accent);
}

/* Theme toggle icons - show moon by default (light mode), sun in dark mode */
.theme-icon-sun { display: none; }
.theme-icon-moon { display: block; }

/* ============================================
   Search Container
   ============================================ */
.search-container {
    display: none;
    margin-bottom: var(--space-3);
}

.search-container.active {
    display: block;
}

.search-field {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: var(--space-3);
    color: var(--color-text-tertiary);
    pointer-events: none;
}

.search-field input {
    width: 100%;
    padding: var(--space-3) var(--space-3) var(--space-3) 2.5rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    font-size: 0.9375rem;
    background: var(--color-surface);
    color: var(--color-text-primary);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.search-field input:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-accent-light);
}

.close-search {
    position: absolute;
    right: var(--space-2);
    background: none;
    border: none;
    padding: var(--space-2);
    cursor: pointer;
    color: var(--color-text-tertiary);
    font-size: 1.25rem;
    line-height: 1;
}

.close-search:hover {
    color: var(--color-text-primary);
}

/* ============================================
   Filter Dropdown
   ============================================ */
.filter-dropdown {
    display: none;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    margin-bottom: var(--space-3);
    box-shadow: var(--shadow-md);
    z-index: 50;
}

.filter-dropdown.active {
    display: block;
}

.filter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-3);
}

.filter-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text-primary);
}

.filter-close {
    background: none;
    border: none;
    padding: var(--space-1);
    cursor: pointer;
    font-size: 1.25rem;
    line-height: 1;
    color: var(--color-text-tertiary);
}

.filter-close:hover {
    color: var(--color-text-primary);
}

.filter-group {
    margin-bottom: var(--space-3);
}

.filter-group:last-child {
    margin-bottom: 0;
}

.selected-classes {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
}

.class-tag {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    background: var(--color-accent-light);
    color: var(--color-accent);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-full);
    font-size: 0.8125rem;
    font-weight: 500;
}

.class-tag button {
    border: none;
    background: none;
    padding: 0;
    cursor: pointer;
    color: var(--color-accent);
    font-size: 1.125rem;
    line-height: 1;
}

.class-tag button:hover {
    color: var(--color-error);
}

select {
    width: 100%;
    padding: var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 0.9375rem;
    background-color: var(--color-surface);
    color: var(--color-text-primary);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%236b7280'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1.25rem;
    padding-right: 2.5rem;
    cursor: pointer;
    transition: border-color var(--transition-fast);
}

select:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-accent-light);
}

select:hover {
    border-color: var(--color-accent);
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    cursor: pointer;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    color: var(--color-text-primary);
    transition: background var(--transition-fast);
}

.toggle-label:hover {
    background: var(--color-border-subtle);
}

.toggle-label input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: var(--color-accent);
}

.clear-filters {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-2) var(--space-4);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.clear-filters:hover {
    background: var(--color-border-subtle);
    color: var(--color-text-primary);
}

/* ============================================
   Latest Finisher Banner
   ============================================ */
.latest-finisher {
    background: linear-gradient(135deg, var(--color-accent) 0%, #1e40af 100%);
    color: var(--color-text-inverse);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-3);
    animation: slideIn 0.3s ease;
}

.latest-label {
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.85;
    margin-bottom: var(--space-1);
    font-weight: 600;
}

.latest-content {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
}

.latest-pos {
    font-size: 1.5rem;
    font-weight: bold;
    min-width: 2rem;
}

.latest-number {
    background: rgba(255,255,255,0.2);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    font-weight: bold;
    font-family: var(--font-mono);
}

.latest-name {
    font-weight: 600;
    flex: 1;
    min-width: 100px;
}

.latest-time {
    font-size: 1.25rem;
    font-weight: bold;
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

.latest-gap {
    opacity: 0.85;
    font-size: 0.875rem;
}

.latest-class {
    font-size: 0.75rem;
    opacity: 0.85;
    background: rgba(255,255,255,0.15);
    padding: 0.125rem var(--space-2);
    border-radius: var(--radius-sm);
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeOut {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(-8px); }
}

/* ============================================
   On Track Section
   ============================================ */
.on-track-section {
    background: var(--color-warning-light);
    border: 1px solid var(--color-warning);
    border-left-width: 4px;
    border-radius: var(--radius-lg);
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-3);
}

.on-track-section h3 {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--color-warning);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0 0 var(--space-2) 0;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.on-track-section h3::before {
    content: '';
    width: 0.5rem;
    height: 0.5rem;
    background: var(--color-warning);
    border-radius: var(--radius-full);
    animation: pulse-live 1.5s ease-in-out infinite;
}

.on-track-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

/* On-track card style (used by JS-rendered content) */
.on-track-card {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    background: var(--color-surface);
    border-radius: var(--radius-md);
    padding: var(--space-2) var(--space-3);
    box-shadow: var(--shadow-sm);
}

.on-track-card .car-number {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text-primary);
    font-family: var(--font-mono);
    min-width: 2.5rem;
}

.on-track-card .driver-name {
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.on-track-card .class-name {
    font-size: 0.75rem;
    color: var(--color-text-tertiary);
    background: var(--color-border-subtle);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
}

/* Legacy on-track table style (fallback) */
.on-track-section table,
.on-track table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.on-track-section table td,
.on-track-section table th,
.on-track table td,
.on-track table th {
    padding: var(--space-2) var(--space-3);
    text-align: left;
    border-bottom: 1px solid var(--color-border-subtle);
}

.on-track-section table tr,
.on-track table tr {
    background: var(--color-surface);
}

/* ============================================
   Results Section - Leaderboard Table
   ============================================ */
.results-section {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    overflow: hidden;
    margin-bottom: var(--space-3);
}

/* The JS-generated results-table */
#results-table {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Results table styling */
.results-table,
#results-table table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.results-table thead th,
#results-table table thead th {
    background: var(--color-border-subtle);
    color: var(--color-text-tertiary);
    padding: var(--space-1) var(--space-2);
    text-align: left;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 1;
}

.results-table td,
#results-table table td {
    padding: var(--space-1) var(--space-2);
    border-bottom: 1px solid var(--color-border-subtle);
    vertical-align: middle;
}

.results-table tbody tr:last-child td,
#results-table table tbody tr:last-child td {
    border-bottom: none;
}

.results-table tbody tr:hover,
#results-table table tbody tr:hover {
    background: var(--color-border-subtle);
}

/* Position column */
.pos-col {
    width: 1.75rem;
    text-align: center;
    font-weight: 700;
    font-size: 0.875rem;
}

/* Car number column */
.num-col {
    width: 2.25rem;
    font-weight: 600;
    font-family: var(--font-mono);
    color: var(--color-text-primary);
}

/* Time column */
.time,
.time-cell {
    font-family: var(--font-mono);
    font-weight: 600;
    white-space: nowrap;
}

/* Gap */
.gap-time {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    color: var(--color-text-tertiary);
    white-space: nowrap;
}

/* Points */
.points {
    font-weight: 700;
    text-align: center;
    width: 2.5rem;
    background: var(--color-border-subtle);
}

.gap-cell {
    color: var(--color-text-secondary);
    font-size: 0.8125rem;
}

/* Class header rows */
.class-header td {
    background: var(--color-border-subtle);
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--color-text-primary);
    padding: var(--space-1) var(--space-2);
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

/* Recent finisher highlight */
.recent-finisher {
    background: var(--color-success-light) !important;
    position: relative;
}

.recent-finisher td:first-child {
    border-left: 3px solid var(--color-success);
}

.new-badge {
    display: inline-block;
    background: var(--color-success);
    color: var(--color-text-inverse);
    font-size: 0.5625rem;
    font-weight: 700;
    padding: 0.0625rem 0.375rem;
    border-radius: var(--radius-full);
    margin-left: var(--space-2);
    vertical-align: middle;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Position change indicators - REMOVED (was causing the bug) */
/* Position changes are no longer shown to avoid confusion */

/* Error message */
.error-message {
    text-align: center;
    color: var(--color-text-tertiary);
    padding: var(--space-10);
    font-size: 0.9375rem;
}

/* ============================================
   Penalties Section
   ============================================ */
.penalties-section {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    overflow: hidden;
    margin-bottom: var(--space-3);
}

.penalties-section h2,
#penalties-section h2 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text-primary);
    padding: var(--space-4);
    margin: 0;
    border-bottom: 1px solid var(--color-border);
}

#penalties-table table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

#penalties-table th {
    background: var(--color-border-subtle);
    color: var(--color-text-tertiary);
    padding: var(--space-3);
    text-align: left;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--color-border);
}

#penalties-table td {
    padding: var(--space-3);
    border-bottom: 1px solid var(--color-border-subtle);
}

#penalties-table tbody tr:hover {
    background: var(--color-border-subtle);
}

.dnf-row td:nth-child(4),
.dsq-row td:nth-child(4) {
    color: var(--color-error);
    font-weight: 600;
}

.dns-row td:nth-child(4) {
    color: var(--color-warning);
    font-weight: 600;
}

.penalty-row td:nth-child(5) {
    font-family: var(--font-mono);
}

/* Inline penalty badge shown next to times */
.penalty-badge {
    display: inline-block;
    margin-left: 4px;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--color-error);
    background: var(--color-error-light);
    vertical-align: middle;
    line-height: 1.4;
}

/* ============================================
   Footer
   ============================================ */
.live-footer {
    font-style: italic;
    color: var(--color-text-tertiary);
    font-size: 0.8125rem;
    padding: var(--space-6) 0 var(--space-4);
    text-align: center;
}

/* ============================================
   Fixed Bottom Overlay (Recent Finish Toast)
   ============================================ */
.recent-overlay {
    position: fixed;
    bottom: env(safe-area-inset-bottom, 0);
    left: var(--space-2);
    right: var(--space-2);
    max-width: 36rem;
    margin: 0 auto var(--space-2);
    background: var(--color-surface-elevated);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    transition: transform var(--transition-base), opacity var(--transition-base);
    z-index: 100;
}

.recent-overlay.hidden {
    transform: translateY(calc(100% + 2rem));
    opacity: 0;
    pointer-events: none;
}

.recent-label {
    font-size: 0.5625rem;
    font-weight: 600;
    color: var(--color-text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    width: 2.5rem;
    flex-shrink: 0;
    text-align: center;
    line-height: 1.2;
}

.recent-content {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex: 1;
    min-width: 0;
}

.recent-pos {
    font-size: 1.125rem;
    font-weight: 700;
    min-width: 1.75rem;
    color: var(--color-text-primary);
}

.recent-gap {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    font-family: var(--font-mono);
}

.recent-car {
    font-size: 0.9375rem;
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--color-text-primary);
}

.recent-driver {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-text-primary);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.recent-class {
    font-size: 0.6875rem;
    color: var(--color-text-tertiary);
    background: var(--color-border-subtle);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    white-space: nowrap;
}

.recent-time {
    font-size: 1rem;
    font-family: var(--font-mono);
    font-weight: 700;
    color: var(--color-success);
    white-space: nowrap;
}

/* Pulse animation for overlay on new finisher */
.recent-overlay.updated {
    animation: overlayPulse 0.5s ease;
}

@keyframes overlayPulse {
    0%, 100% { box-shadow: var(--shadow-lg); }
    50% { box-shadow: 0 0 0 4px var(--color-accent-light), var(--shadow-lg); }
}

/* ============================================
   Responsive - Mobile
   ============================================ */
@media (max-width: 639px) {
    .live-container {
        padding: var(--space-2);
        padding-bottom: calc(4rem + env(safe-area-inset-bottom, var(--space-2)));
    }

    .live-header {
        padding: var(--space-2) 0;
        margin-bottom: var(--space-2);
    }

    .event-info-bar h1 {
        font-size: 1rem;
    }

    .viewer-count {
        font-size: 0.5625rem;
        padding: 0.125rem 0.375rem;
    }

    .viewer-icon {
        width: 0.625rem;
        height: 0.625rem;
    }

    .live-status {
        padding: 2px var(--space-1);
    }

    .status-text {
        font-size: 0.5625rem;
    }

    .live-time {
        font-size: 0.8125rem;
        padding: var(--space-1) var(--space-2);
    }

    .controls-top {
        margin-bottom: var(--space-2);
        gap: var(--space-2);
    }

    .round-tab,
    .tab {
        padding: var(--space-1) var(--space-2);
        font-size: 0.8125rem;
        min-height: 2rem;
    }

    .round-full { display: none; }
    .round-short { display: inline; }

    .icon-button {
        width: 2rem;
        height: 2rem;
    }

    .icon-button svg {
        width: 16px;
        height: 16px;
    }

    /* Results table compact */
    .results-table thead th,
    #results-table table thead th {
        padding: 2px 4px;
        font-size: 0.5625rem;
    }

    .results-table td,
    #results-table table td {
        padding: 3px 4px;
        font-size: 0.75rem;
    }

    .pos-col {
        width: 1.25rem;
        font-size: 0.75rem;
    }

    .num-col {
        width: 1.5rem;
        font-size: 0.75rem;
    }

    .time,
    .time-cell {
        font-size: 0.75rem;
    }

    .gap-time {
        font-size: 0.6875rem;
    }

    .points {
        width: 2rem;
        font-size: 0.6875rem;
    }

    .hide-mobile {
        display: none;
    }

    .hide-tablet {
        display: none;
    }

    /* On-track compact */
    .on-track-section {
        padding: var(--space-2);
        margin-bottom: var(--space-2);
    }

    .on-track-card {
        padding: var(--space-2);
        gap: var(--space-2);
    }

    .on-track-card .car-number {
        font-size: 0.875rem;
        min-width: 2rem;
    }

    .on-track-card .driver-name {
        font-size: 0.75rem;
    }

    /* Latest finisher compact */
    .latest-finisher {
        padding: var(--space-2) var(--space-3);
        margin-bottom: var(--space-2);
    }

    .latest-pos {
        font-size: 1.25rem;
    }

    .latest-time {
        font-size: 1rem;
    }

    /* Bottom overlay compact */
    .recent-overlay {
        padding: var(--space-2) var(--space-3);
    }

    .recent-pos {
        font-size: 1rem;
    }

    .recent-class {
        display: none;
    }

    .recent-driver {
        max-width: 6rem;
    }

    /* Filter dropdown as bottom sheet on mobile */
    .filter-dropdown.active {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 80vh;
        overflow-y: auto;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        margin: 0;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
        z-index: 200;
    }
}

/* Tablet */
@media (min-width: 640px) and (max-width: 1023px) {
    .hide-tablet {
        display: none;
    }
}

/* Desktop */
@media (min-width: 640px) {
    .live-container {
        padding: var(--space-6);
    }

    .live-header {
        padding: var(--space-6) 0;
    }

    .event-info-bar h1 {
        font-size: 1.5rem;
    }

    .live-time {
        font-size: 1.125rem;
    }

    .results-table thead th,
    #results-table table thead th,
    .results-table td,
    #results-table table td {
        padding: var(--space-2) var(--space-3);
    }
}

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

/* ============================================
   Print Styles
   ============================================ */
@media print {
    .live-view {
        background: white;
    }

    .controls-top .controls-actions,
    .search-container,
    .filter-dropdown,
    .on-track-section,
    .recent-overlay,
    .latest-finisher,
    .live-status,
    .live-time {
        display: none !important;
    }

    .results-section {
        border: 1px solid #ccc;
        box-shadow: none;
    }
}
