:root {
    --bg-color: #0f172a;
    --panel-bg: rgba(30, 41, 59, 0.7);
    --panel-border: rgba(255, 255, 255, 0.1);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    --color-n: #00e5ff;
    --color-a: #ff007f;
    --color-na: #b026ff;
    --color-sup: #ffeb3b;
    --color-s1: #ffd700;
    --color-s2: #ef4444;
    --color-s3: #38bdf8;
    --color-c0: #ff5722;
    --color-c2: #00b0ff;
    --track-bg: #0b0f19;
}

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

body {
    font-family: 'Inter', sans-serif;
    background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 20px;
    gap: 15px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

header {
    text-align: center;
    padding-top: 5px;
}

header h1 {
    font-size: 2.2rem;
    font-weight: 800;
    background: linear-gradient(to right, var(--color-n), var(--color-a), var(--color-na));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 20px rgba(255,255,255,0.1);
}

header p {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-top: 4px;
}

main {
    display: flex;
    flex-direction: column;
    gap: 15px;
    flex-grow: 1;
    min-height: 0; 
}

.glass-panel {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 15px;
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
}

.plot-container {
    flex-grow: 1;
    display: flex;
    padding: 10px 15px;
    position: relative;
    min-height: 300px;
}

#d3-plot {
    width: 100%;
    height: 100%;
}

.controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
}

.stats {
    display: flex;
    gap: 30px;
    font-size: 1.2rem;
    font-weight: 600;
}

.blue { color: var(--color-n); text-shadow: 0 0 8px rgba(0,229,255,0.5); }
.pink { color: var(--color-a); text-shadow: 0 0 8px rgba(255,0,127,0.5); }
.violet { color: var(--color-na); text-shadow: 0 0 8px rgba(176,38,255,0.5); }

.buttons {
    display: flex;
    gap: 10px;
}

button {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--panel-border);
    color: var(--text-main);
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

button:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

button.active {
    background: rgba(255, 255, 255, 0.25);
    border-color: var(--text-main);
    box-shadow: 0 0 15px rgba(255,255,255,0.1);
}

.race-container {
    height: auto;
    gap: 3px;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    position: relative;
    padding: 5px 30px 5px 10px;
}

.track {
    background: var(--track-bg);
    height: 14px;
    border-radius: 7px;
    position: relative;
    display: flex;
    align-items: center;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.8);
    border: 1px solid rgba(255,255,255,0.05);
}

.horse {
    position: absolute;
    font-size: 16px;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: left 0.1s linear;
    z-index: 10;
}

.horse span {
    position: absolute;
    right: 100%;
    white-space: nowrap;
    font-size: 9px;
    background: rgba(0,0,0,0.8);
    padding: 1px 4px;
    border-radius: 4px;
    margin-right: 4px;
    font-weight: 800;
    border: 1px solid rgba(255,255,255,0.15);
}

#horse-1 span { color: var(--color-n); border-color: rgba(0,229,255,0.3); }
#horse-2 span { color: var(--color-a); border-color: rgba(255,0,127,0.3); }
#horse-3 span { color: var(--color-na); border-color: rgba(176,38,255,0.3); }
#horse-4 span { color: var(--color-sup); border-color: rgba(255,235,59,0.3); }
#horse-5 span { color: var(--color-c0); border-color: rgba(255,87,34,0.3); }
#horse-6 span { color: var(--color-c2); border-color: rgba(0,176,255,0.3); }

.finish-line {
    position: absolute;
    right: 20px;
    top: 15px;
    bottom: 15px;
    width: 6px;
    background: repeating-linear-gradient(
        to bottom,
        #fff,
        #fff 10px,
        #000 10px,
        #000 20px
    );
    opacity: 0.7;
    border-radius: 3px;
    box-shadow: 0 0 10px rgba(255,255,255,0.2);
}

/* D3 SVG Styling */
.axis path,
.axis line {
    stroke: var(--panel-border);
}

.axis text {
    fill: var(--text-muted);
    font-family: 'Inter', sans-serif;
    font-size: 11px;
}

.grid-line {
    stroke: rgba(255, 255, 255, 0.05);
}

.line-n { stroke: var(--color-n); stroke-width: 2.5; fill: none; opacity: 0.9; }
.line-a { stroke: var(--color-a); stroke-width: 2.5; fill: none; opacity: 0.8; }
.line-na { stroke: var(--color-na); stroke-width: 2.5; fill: none; opacity: 0.8; }
.line-sup { stroke: var(--color-sup); stroke-width: 2.5; fill: none; opacity: 0.8; stroke-dasharray: 4 4; }
.line-c0 { stroke: var(--color-c0); stroke-width: 2.5; fill: none; opacity: 0.8; stroke-dasharray: 2 2; }
.line-c2 { stroke: var(--color-c2); stroke-width: 2.5; fill: none; opacity: 0.8; stroke-dasharray: 2 2; }

@keyframes pop {
    0% { transform: translateX(-50%) scale(1); }
    50% { transform: translateX(-50%) scale(1.4) translateY(-10px); text-shadow: 0 0 20px var(--color-sup); }
    100% { transform: translateX(-50%) scale(1); }
}

.horse.celebrate {
    animation: pop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    z-index: 100;
}

@keyframes text-pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.5); color: #fff; text-shadow: 0 0 15px var(--color-sup); }
    100% { transform: scale(1); }
}

.val.celebrate-text {
    display: inline-block;
    animation: text-pop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.cash-out-btn:hover {
    background: rgba(251, 192, 45, 0.4) !important;
    color: #fff !important;
    transform: translateY(-2px);
    box-shadow: 0 0 15px rgba(251, 192, 45, 0.5);
}
.cash-out-btn:active {
    transform: translateY(0);
}

/* Horizontal scrolling sequence visualizer */
#seq-wrapper {
    position: absolute;
    left: 75px;
    right: 15px;
    top: 15px;
    bottom: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-behavior: auto; /* Fast updates need auto scroll, not smooth */
    scrollbar-width: none; /* Hide scrollbar for Firefox */
    -ms-overflow-style: none; /* Hide scrollbar for IE/Edge */
}
#seq-wrapper::-webkit-scrollbar {
    display: none; /* Hide scrollbar for Chrome/Safari */
}

.seq-num {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 36px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    color: var(--text-main);
    font-weight: 700;
    font-size: 14px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    transition: background-color 0.2s, border-color 0.2s, box-shadow 0.2s;
    backdrop-filter: blur(4px);
}

.seq-num.active {
    background: rgba(255, 0, 127, 0.15) !important;
    border-color: var(--color-a) !important;
    color: var(--color-a) !important;
    box-shadow: 0 0 12px rgba(255, 0, 127, 0.4) !important;
}

.seq-num.record {
    border-color: var(--color-sup) !important;
    box-shadow: 0 0 10px rgba(255, 235, 59, 0.3);
}

.seq-star {
    font-size: 10px;
    position: absolute;
    top: -6px;
    right: -2px;
    text-shadow: 0 0 8px var(--color-sup);
}

/* Track layout adjustments for janky-cute horse emojis */
.spectator-track {
    position: relative;
    height: 35px;
    background: var(--track-bg);
    border-radius: 12px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.8);
    border: 1px solid rgba(255,255,255,0.05);
    margin-bottom: 5px;
}

.spec-track-label {
    height: 35px;
    font-size: 14px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.spec-limit-label {
    position: absolute;
    bottom: 2px;
    font-size: 11px;
    font-weight: 800;
    color: var(--text-muted);
    opacity: 0.6;
    background: rgba(11, 15, 25, 0.7);
    padding: 1px 4px;
    border-radius: 3px;
    pointer-events: none;
    z-index: 5;
}

.spec-limit-min {
    left: 8px;
}

.spec-limit-max {
    right: 8px;
}

/* Telemetry Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 15px;
    width: 100%;
}

.telemetry-card {
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: all 0.2s ease;
}

.telemetry-card:hover {
    border-color: rgba(255, 255, 255, 0.15);
    background: rgba(15, 23, 42, 0.6);
}

.telemetry-label {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

.telemetry-value {
    font-size: 1.4rem;
    font-weight: 700;
    font-family: monospace;
}

/* Controls structure */
.control-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    gap: 20px;
}

/* Centerline for track convergence */
.track-centerline {
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 1px;
    border-left: 1px dashed rgba(255, 255, 255, 0.15);
    z-index: 2;
    pointer-events: none;
}

