:root {
            /* Colors */
            --bg-color: #0f1117;
            --surface-color: #1a1d27;
            --text-color: #ffffff;
            --text-muted: #8a8d97;
            --accent-red: #e84040;
            --accent-amber: #f5a623;
            
            /* Player Colors */
            --p1: #e84040; /* Red */
            --p2: #4ade80; /* Green */
            --p3: #a855f7; /* Purple */
            --p4: #f5a623; /* Amber */
            --p5: #3b82f6; /* Blue */
            --p6: #ec4899; /* Pink */
            --p7: #06b6d4; /* Cyan */
            --p8: #facc15; /* Yellow */
            --p9: #f97316; /* Orange */
            --p10: #8b5cf6; /* Violet */
            --p11: #10b981; /* Emerald */
            --p12: #6366f1; /* Indigo */
            --p13: #f43f5e; /* Rose */
            --p14: #84cc16; /* Lime */
            --p15: #14b8a6; /* Teal */
            --p16: #0ea5e9; /* Sky */
            --p17: #d946ef; /* Fuchsia */
            --p18: #64748b; /* Slate */
            
            /* Spacing & Sizing */
            --safe-area-inset-bottom: env(safe-area-inset-bottom, 20px);
            --radius: 8px;
        }

        * {
            box-sizing: border-box;
            -webkit-tap-highlight-color: transparent;
        }

        body {
            margin: 0;
            padding: 0;
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
            background-color: var(--bg-color);
            color: var(--text-color);
            display: flex;
            justify-content: center;
            min-height: 100vh;
            overflow-x: hidden;
        }

        #app {
            width: 100%;
            max-width: 420px;
            display: flex;
            flex-direction: column;
            position: relative;
            min-height: 100vh;
        }

        /* Screens */
        .screen {
            display: none;
            padding: 20px;
            height: 100%;
            flex-direction: column;
            justify-content: flex-start;
            padding-top: 60px;
        }

        .screen.active {
            display: flex;
        }

        #scoreboard-screen.active {
            justify-content: flex-start;
        }

        /* Typography */
        h1 { font-weight: 500; font-size: 24px; margin: 0 0 24px 0; }
        h2 { font-weight: 500; font-size: 18px; margin: 0 0 16px 0; }
        p { font-weight: 400; font-size: 14px; color: var(--text-muted); }

        /* Buttons & Inputs */
        button {
            border: none;
            border-radius: var(--radius);
            font-size: 16px;
            font-weight: 500;
            padding: 14px;
            cursor: pointer;
            transition: opacity 0.2s;
        }

        button:active {
            opacity: 0.8;
        }

        .btn-primary {
            background-color: var(--accent-red);
            color: white;
        }

        .btn-ghost {
            background: transparent;
            color: var(--text-muted);
            border: 1px solid #2a2d37;
        }

        .btn-share {
            background-color: #3b82f6; /* Blue */
            color: white;
        }

        input {
            background: var(--surface-color);
            border: 1px solid #2a2d37;
            border-radius: var(--radius);
            color: white;
            padding: 16px; /* Increased from 12px */
            font-size: 18px; /* Increased from 16px */
            outline: none;
            width: 100%;
        }

        .init-input {
            text-transform: uppercase;
            font-weight: 800;
            letter-spacing: 1px;
            text-align: center;
        }

        .score-input {
            font-size: 20px !important;
            font-weight: 600 !important;
            text-align: center;
        }

        /* Hide number spinners */
        .score-input::-webkit-outer-spin-button,
        .score-input::-webkit-inner-spin-button {
            -webkit-appearance: none;
            margin: 0;
        }
        .score-input[type=number] {
            -moz-appearance: textfield;
        }

        /* Setup Screen Specifics */
        #setup-screen .player-input-group {
            display: flex;
            flex-direction: column;
            gap: 12px;
            margin-bottom: 24px;
        }

        .player-row-setup {
            display: flex;
            gap: 12px;
            align-items: center;
        }

        .color-dot {
            width: 5px;
            height: 20px;
            border-radius: 1px;
            flex-shrink: 0;
            position: relative;
        }

        .starter-dot-absolute {
            position: absolute;
            top: -4px;
            right: -6px;
            width: 10px;
            height: 10px;
            background-color: var(--accent-red);
            border: 2px solid var(--bg-color);
            border-radius: 50%;
            box-shadow: 0 0 8px var(--accent-red);
            z-index: 2;
        }

        .player-name {
            font-weight: 800;
            font-size: 15px;
            letter-spacing: 0.5px;
            text-transform: uppercase;
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
        }


        .starter-label-dot {
            width: 6px;
            height: 6px;
            background-color: var(--accent-red);
            border-radius: 50%;
            display: inline-block;
            margin-right: 4px;
            box-shadow: 0 0 5px var(--accent-red);
        }

        /* Scoreboard Screen */
        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }

        .scoreboard-table-container {
            overflow-x: auto;
            margin: 0 -20px;
            padding: 0 20px 0 0; /* Only right padding; left padding shifted into the sticky cell to prevent scroll bleeding */
            -webkit-overflow-scrolling: touch;
            white-space: nowrap;
        }

        table {
            border-collapse: separate; /* Required for sticky borders */
            border-spacing: 0;
            width: 100%;
            min-width: 380px;
        }

        th, td {
            padding: 12px 16px; /* A bit more horizontal padding since it's a wide table now */
            text-align: center;
            border-bottom: 1px solid #2a2d37;
            font-size: 14px;
            background-color: var(--bg-color); /* Need background color for sticky to block underlying cells */
        }

        td {
            color: var(--text-color);
        }

        th {
            background-color: var(--bg-color);
            position: sticky;
            top: 0;
            z-index: 10;
            font-weight: 600;
            color: var(--text-muted);
            border-bottom: 2px solid #2a2d37; /* Stronger header border */
        }
        
        /* Sticky Column 1: Player Name */
        th:first-child, td:first-child {
            position: sticky;
            left: 0;
            z-index: 12; /* Needs to be above normal THs */
            text-align: left;
            padding-left: 20px; /* Embed screen gap directly into the sticky element */
            width: 95px;
            min-width: 95px;
            max-width: 95px;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        th:first-child { z-index: 15; } /* Top-left corner needs highest z-index */

        /* Sticky Column 2: Total */
        th:nth-child(2), td:nth-child(2) {
            position: sticky;
            left: 95px; 
            z-index: 12;
            width: 75px;
            min-width: 75px;
            max-width: 75px;
            border-right: 1px solid rgba(255,255,255,0.1);
            background-color: var(--bg-color);
        }
        th:nth-child(2) { z-index: 15; }


        .total-col {
            font-weight: 500;
            width: 60px;
            text-align: center;
            transition: color 0.3s, transform 0.3s;
        }

        .total-updated {
            color: var(--accent-amber);
            transform: scale(1.1);
        }

        .round-col {
            color: var(--text-muted);
            width: 40px;
            text-align: center;
        }

        /* Totals Highlight (Separated) */
        #totals-bar {
            background-color: #1e2230;
            border-radius: var(--radius);
            margin-bottom: 16px;
            padding: 16px;
            display: flex;
            align-items: center;
            gap: 12px;
            position: sticky;
            top: 53px;
            z-index: 11;
        }

        .total-item {
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 8px;
        }

        /* Circular Progress CSS */
        .progress-circle {
            position: relative;
            width: 48px;
            height: 48px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            background: conic-gradient(var(--progress-color) var(--progress), #2a2d37 0deg);
            margin: 0 auto;
        }

        .progress-circle::after {
            content: '';
            position: absolute;
            width: 38px;
            height: 38px;
            background: var(--bg-color);
            border-radius: 50%;
        }

        .progress-text {
            position: relative;
            z-index: 1;
            font-size: 14px;
            font-weight: 600;
        }

        /* Winner Banner (Golden Box) */
        #winner-banner {
            display: none;
            background-color: var(--surface-color);
            border: 2px solid var(--accent-amber);
            box-shadow: 0 0 30px rgba(245, 166, 35, 0.15);
            padding: 32px 20px 20px;
            border-radius: 16px;
            margin-bottom: 24px;
            text-align: center;
            animation: bounceIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
            position: relative;
        }

        @keyframes bounceIn {
            0% { transform: scale(0.9); opacity: 0; }
            100% { transform: scale(1); opacity: 1; }
        }

        #winner-banner h2 { 
            margin: 0; 
            font-size: 24px; 
            color: var(--accent-amber);
            letter-spacing: 1px;
            font-weight: 800;
        }
        
        #winner-banner p { 
            margin: 12px 0 20px; 
            font-size: 16px; 
            color: #ffffff;
            font-weight: 500;
        }

        .banner-divider {
            width: 40px;
            height: 1px;
            background: rgba(255, 255, 255, 0.1);
            margin: 0 auto 16px;
        }

        .banner-url {
            font-size: 13px;
            color: var(--text-muted);
            letter-spacing: 0.5px;
            font-weight: 500;
        }

        /* End Screen Content (Everything outside the box) */
        #end-screen-content {
            padding-bottom: 40px;
        }

        #game-highlights {
            margin-top: 8px;
        }

        #end-chart-container h3 {
            font-weight: 700;
            color: var(--text-muted);
            font-size: 11px;
            margin-bottom: 12px;
        }

        #live-race-chart {
            width: 100%;
            height: 200px;
            display: block;
        }

        .footer-credit {
            margin-top: 24px;
            padding-top: 16px;
            border-top: 1px solid rgba(255, 255, 255, 0.05);
            font-size: 10px;
            color: var(--text-muted);
            text-align: center;
            opacity: 0.6;
            letter-spacing: 1px;
            text-transform: uppercase;
            font-weight: 700;
        }

        .round-progress {
            width: 32px;
            height: 32px;
        }

        .round-progress::after {
            width: 24px;
            height: 24px;
            background: var(--bg-color); /* Matches table body background */
        }

        .round-progress .progress-text {
            font-size: 11px;
            font-weight: 500;
        }

        /* Bottom Sheet */
        #bottom-sheet-overlay {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0,0,0,0.6);
            display: none;
            z-index: 100;
        }

        #bottom-sheet {
            position: fixed;
            bottom: 0;
            left: 50%;
            transform: translateX(-50%) translateY(100%);
            width: 100%;
            max-width: 420px;
            background: var(--surface-color);
            padding: 24px 20px calc(24px + var(--safe-area-inset-bottom));
            border-radius: 20px 20px 0 0;
            transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            z-index: 101;
            max-height: 85vh;
            display: flex;
            flex-direction: column;
        }

        #bottom-sheet.open {
            transform: translateX(-50%) translateY(0);
        }

        .sheet-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 24px;
        }

        .sheet-header h2 {
            margin: 0 !important;
        }

        button:disabled {
            opacity: 0.3;
            cursor: not-allowed;
            filter: grayscale(1);
        }

        /* Winner Modal */
        #winner-screen {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: var(--bg-color);
            display: none;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            z-index: 200;
            text-align: center;
            padding: 40px;
        }

        #winner-screen.active {
            display: flex;
        }

        .winner-name {
            font-size: 48px;
            font-weight: 500;
            color: var(--accent-amber);
            margin: 20px 0;
        }

        .sheet-handle {
            width: 40px;
            height: 4px;
            background: #2a2d37;
            border-radius: 2px;
            margin: -12px auto 20px;
        }

        /* F7 Info Banner */
        #f7-info-banner {
            display: none;
            background: rgba(245, 166, 35, 0.1);
            border: 1px solid rgba(245, 166, 35, 0.3);
            border-radius: 12px;
            padding: 12px 16px;
            margin-bottom: 20px;
            align-items: center;
            gap: 12px;
            animation: slideDown 0.3s ease-out;
        }

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

        .f7-banner-text {
            font-size: 13px;
            color: var(--accent-amber);
            line-height: 1.4;
            flex: 1;
        }

        .f7-icon-small {
            font-size: 18px;
        }

        /* PWA Banner Redesign */
        #install-banner {
            display: none;
            background: #1e2230;
            border-bottom: 1px solid #2a2d37;
            padding: 8px 16px;
            font-size: 13px;
            color: var(--text-muted);
            position: sticky;
            top: 0;
            z-index: 50;
            align-items: center;
            gap: 12px;
        }

        #install-banner-text {
            flex: 1;
        }

        #pwa-install-btn {
            background: var(--accent-amber);
            color: #0f1117;
            padding: 6px 12px;
            font-size: 12px;
            font-weight: 600;
            border-radius: 6px;
            white-space: nowrap;
        }

        #install-dismiss-btn {
            background: none;
            border: none;
            color: var(--text-muted);
            font-size: 24px;
            padding: 4px;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            line-height: 1;
        }

        /* iOS-Specific Banner Adjustments */
        .ios-banner {
            flex-direction: column !important;
            align-items: flex-start !important;
            padding: 16px 20px !important;
            gap: 12px !important;
            height: auto !important;
            text-align: left !important;
        }

        .ios-banner #install-dismiss-btn {
            position: absolute;
            top: 10px;
            right: 10px;
        }

        .ios-steps {
            display: flex;
            flex-direction: column;
            gap: 6px;
            color: var(--text-color);
        }

        .ios-steps strong {
            display: block;
            margin-bottom: 4px;
            color: var(--accent-amber);
            font-size: 14px;
        }

        .ios-steps .step {
            font-size: 13px;
            color: var(--text-muted);
            line-height: 1.4;
        }

        .share-icon {
            font-size: 18px;
            vertical-align: middle;
            color: var(--text-color);
            margin: 0 2px;
        }

        /* 12-12 Button (The Joke) */
        .double-btn {
            background: transparent;
            color: var(--text-muted);
            border: 1px solid #2a2d37;
            padding: 8px 12px; /* Reduced from 12px 16px */
            font-size: 16px; /* Increased icon font size slightly */
            white-space: nowrap;
        }

        /* Compact styles for modifiers in the sheet */
        #round-entry-list .btn-ghost {
            padding: 8px 10px; /* Thinner buttons */
            font-size: 13px; /* Slightly smaller text for Bust/F7 */
        }

        #round-entry-list .score-input {
            width: 60px !important; /* Narrower input */
            padding: 12px 8px !important;
            font-size: 18px !important;
        }

        .double-btn.active {
            background: rgba(255, 255, 255, 0.05);
            border-color: #ffffff;
            color: #ffffff;
            animation: pulse-white 2s infinite;
        }

        @keyframes pulse-white {
            0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.2); }
            70% { box-shadow: 0 0 0 6px rgba(255, 255, 255, 0); }
            100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0); }
        }

        .double-12-text {
            color: #ffffff;
            font-weight: 600;
            font-size: 13px;
        }

        /* 12 Curse Banner (Disappearing Toast) */
        .toast-banner {
            position: fixed;
            top: 20px;
            left: 50%;
            transform: translateX(-50%) translateY(-100px);
            background: #ffffff;
            color: #000000;
            padding: 12px 24px;
            border-radius: 40px;
            display: flex;
            align-items: center;
            gap: 10px;
            font-weight: 600;
            font-size: 14px;
            z-index: 1000;
            box-shadow: 0 10px 30px rgba(0,0,0,0.5);
            transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
            pointer-events: none;
            white-space: nowrap;
        }

        .toast-banner.show {
            transform: translateX(-50%) translateY(0);
        }

        .curse-icon {
            font-size: 20px;
        }

        /* Footer Credits */
        .footer-credit {
            margin-top: 32px;
            padding: 16px 0;
            font-size: 11px;
            color: var(--text-muted);
            text-align: center;
            opacity: 0.5;
            letter-spacing: 0.5px;
            text-transform: uppercase;
        }

        .footer-credit a {
            color: var(--text-muted);
            text-decoration: none;
            font-weight: 600;
            transition: color 0.2s;
        }

        .footer-credit a:hover {
            color: var(--accent-amber);
        }

        /* Adjustments for setup screen to ensure footer is at bottom */
        #setup-screen {
            justify-content: space-between;
        }

        .setup-content {
            flex: 1;
            display: flex;
            flex-direction: column;
        }

        /* Modals (History) */
        /* Modals (History) */
        .modal-overlay {
            position: fixed;
            top: 0; left: 0; right: 0; bottom: 0;
            background: rgba(0, 0, 0, 0.9);
            display: none;
            z-index: 200;
            backdrop-filter: blur(8px);
        }

        .modal {
            position: fixed;
            top: 50%; left: 50%;
            transform: translate(-50%, -50%) scale(0.95);
            width: 92%;
            max-width: 400px;
            background: var(--surface-color);
            border: 1px solid rgba(255, 255, 255, 0.08);
            border-radius: 24px;
            display: none;
            flex-direction: column;
            max-height: 85vh;
            z-index: 201;
            opacity: 0;
            transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
            box-shadow: 0 20px 50px rgba(0,0,0,0.5);
        }

        .modal.open {
            display: flex;
            transform: translate(-50%, -50%) scale(1);
            opacity: 1;
        }

        .modal-header {
            padding: 24px 24px 16px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .modal-header h2 { 
            margin: 0; 
            font-size: 20px;
            font-weight: 700;
        }

        .close-btn {
            background: rgba(255,255,255,0.05);
            color: var(--text-muted);
            font-size: 20px;
            width: 32px;
            height: 32px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 0;
            line-height: 1;
        }

        .history-list {
            overflow-y: auto;
            flex: 1;
            padding: 0 20px 20px;
        }

        .history-item {
            padding: 12px 14px;
            background: rgba(255, 255, 255, 0.03);
            border: 1px solid rgba(255, 255, 255, 0.05);
            border-radius: 12px;
            margin-bottom: 8px;
            display: flex;
            flex-direction: column;
            gap: 6px;
        }

        .history-top {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .history-winner-compact {
            font-size: 14px;
            font-weight: 700;
            color: var(--accent-amber);
            display: flex;
            align-items: center;
            gap: 6px;
        }

        .history-info-compact {
            font-size: 10px;
            color: var(--text-muted);
            text-transform: uppercase;
            letter-spacing: 0.4px;
        }

        .history-details {
            display: flex;
            align-items: center;
            font-size: 12px;
            border-top: 1px solid rgba(255,255,255,0.05);
            padding-top: 8px;
            margin-top: 2px;
        }

        .history-scores-full {
            width: 100%;
            color: var(--text-color);
            font-weight: 500;
            font-variant-numeric: tabular-nums;
            font-size: 11px;
            display: flex;
            justify-content: center;
            gap: 12px;
            flex-wrap: wrap;
        }

        .score-pill {
            background: rgba(255,255,255,0.05);
            padding: 2px 8px;
            border-radius: 6px;
            white-space: nowrap;
        }

        .modal-footer {
            padding: 16px 20px;
            background: rgba(0,0,0,0.2);
            border-radius: 0 0 24px 24px;
        }

        .clear-btn-styled {
            background: rgba(232, 64, 64, 0.05);
            border: 1px solid rgba(232, 64, 64, 0.2);
            color: #ff5c5c;
            width: 100%;
            padding: 14px;
            border-radius: 14px;
            font-size: 14px;
            font-weight: 600;
            transition: all 0.2s ease;
        }

        .clear-btn-styled:active {
            background: rgba(232, 64, 64, 0.15);
            transform: scale(0.98);
        }

        .empty-history {
            padding: 60px 20px;
            text-align: center;
            opacity: 0.5;
        }
        
        .empty-history span {
            display: block;
            font-size: 40px;
            margin-bottom: 16px;
        }