/* ============================================================================
   Bremswerk — app.css
   Component styles: masthead/wordmark, hero empty-state, native <dialog>
   upload modal + dropzone, and the data "deck" (lap rail + stage panels).
   ========================================================================= */

/* ── Masthead ───────────────────────────────────────────────────────────── */
.masthead {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .9rem clamp(1rem, 4vw, 2.4rem);
    border-bottom: 1px solid var(--edge);
    background: rgba(8, 10, 12, .72);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}
.masthead__nav { display: flex; align-items: center; gap: 1rem; }

.wordmark { display: inline-flex; align-items: center; gap: .65rem; color: var(--ink); }
.wordmark:hover { text-decoration: none; }
.logomark { width: 30px; height: 30px; flex: 0 0 auto; }
.wordmark__text {
    font-family: var(--cond);
    font-weight: 600;
    font-size: 1.12rem;
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: .34em;
    padding-left: .08em;          /* optical: balance the wide tracking */
    color: var(--ink-hi);
}

.meta-chip {
    font-family: var(--mono);
    font-size: .72rem;
    color: var(--ink-2);
    border: 1px solid var(--edge);
    border-radius: 999px;
    padding: .3em .85em;
    white-space: nowrap;
}
.meta-chip b { color: var(--accent); font-weight: 600; }

/* ── Hero / empty state ─────────────────────────────────────────────────── */
.hero { position: relative; max-width: 720px; }
.eyebrow {
    font-family: var(--cond);
    text-transform: uppercase;
    letter-spacing: .34em;
    font-size: .74rem;
    color: var(--accent);
    margin: 0 0 1.2rem;
}
.hero__title {
    font-family: var(--cond);
    font-weight: 600;
    font-size: clamp(2.6rem, 7vw, 4.5rem);
    line-height: .98;
    letter-spacing: -.01em;
    margin: 0 0 1.3rem;
    color: var(--ink-hi);
}
.hero__title em { font-style: normal; color: var(--accent); }
.hero__lead {
    font-size: .98rem;
    line-height: 1.75;
    color: var(--ink-2);
    max-width: 58ch;
    margin: 0 0 2.1rem;
}
.hero__cta { display: flex; align-items: center; gap: 1.1rem; flex-wrap: wrap; }
.hero__hint { font-size: .78rem; color: var(--ink-2); letter-spacing: .06em; }

/* Decorative telemetry trace, faint, behind/around the hero copy. */
.hero__trace {
    position: absolute;
    right: -2%;
    top: 6%;
    width: min(42vw, 440px);
    color: var(--edge);
    opacity: .8;
    pointer-events: none;
    z-index: -1;
}
.hero__trace .pulse { stroke: var(--accent); opacity: .5; }
@media (max-width: 760px) { .hero__trace { display: none; } }

/* ── Upload modal (native <dialog>) ─────────────────────────────────────── */
dialog.modal {
    width: min(560px, calc(100vw - 2rem));
    padding: 0;
    border: 1px solid var(--edge);
    border-radius: var(--r-lg);
    background: linear-gradient(180deg, var(--surface-1), var(--surface-0));
    color: var(--ink);
    box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .85);
    overflow: hidden;
}
dialog.modal::backdrop {
    background: rgba(4, 6, 8, .66);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
}
dialog.modal[open] { animation: rise .26s cubic-bezier(.2, .7, .2, 1) both; }

.modal__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.05rem 1.3rem;
    border-bottom: 1px solid var(--edge);
}
.modal__head h2 {
    font-family: var(--cond);
    text-transform: uppercase;
    letter-spacing: .18em;
    font-size: .95rem;
    margin: 0;
    color: var(--ink-hi);
}
.modal__x {
    background: none; border: none; cursor: pointer;
    color: var(--ink-2); font-size: 1.05rem; line-height: 1;
    padding: .3rem .4rem; border-radius: var(--r-sm);
}
.modal__x:hover { color: var(--ink); background: rgba(255, 255, 255, .06); }

.dropzone {
    margin: 1.3rem;
    padding: 2.4rem 1.5rem;
    border: 1.5px dashed #2b353d;
    border-radius: var(--r-lg);
    background: rgba(255, 255, 255, .012);
    text-align: center;
    cursor: pointer;
    transition: border-color .16s ease, background .16s ease, box-shadow .16s ease;
}
.dropzone:hover, .dropzone:focus-visible { border-color: #3a464f; background: rgba(255, 255, 255, .025); outline: none; }
.dropzone.is-dragover {
    border-color: var(--accent);
    background: rgba(213, 0, 28, .06);
    box-shadow: inset 0 0 44px -12px rgba(213, 0, 28, .35);
}
.dropzone__icon { width: 46px; height: 46px; color: var(--ink-3); margin: 0 auto .9rem; transition: color .16s ease, transform .16s ease; }
.dropzone.is-dragover .dropzone__icon { color: var(--accent); transform: translateY(-2px); }
.dropzone__title { font-family: var(--cond); text-transform: uppercase; letter-spacing: .12em; font-size: .95rem; color: var(--ink); margin: 0 0 .35rem; }
.dropzone__sub { font-size: .82rem; color: var(--ink-2); margin: 0 0 .8rem; }
.dropzone__types { font-size: .72rem; color: var(--ink-2); letter-spacing: .06em; margin: 0; }
.dropzone__types.is-error { color: var(--err); }

.filelist { list-style: none; margin: 0 1.3rem; padding: 0; display: flex; flex-direction: column; gap: .5rem; max-height: 210px; overflow: auto; }
.filerow { display: flex; align-items: center; gap: .8rem; padding: .55rem .75rem; border: 1px solid var(--edge); border-radius: var(--r-md); background: var(--surface-0); }
.filerow__name { flex: 1; font-size: .82rem; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filerow__size { font-size: .74rem; color: var(--ink-2); white-space: nowrap; }
.filerow__rm { background: none; border: none; cursor: pointer; color: var(--ink-3); padding: .2rem .35rem; border-radius: var(--r-sm); }
.filerow__rm:hover { color: var(--err); background: rgba(255, 85, 85, .1); }

/* Format badge (VBO / TPA / CSV) */
.badge {
    font-family: var(--cond); font-weight: 600;
    font-size: .64rem; letter-spacing: .1em; text-transform: uppercase;
    padding: .28em .5em; border-radius: 3px; flex: 0 0 auto;
}
.badge--tpa { background: rgba(213, 0, 28, .16);  color: #ff6b6b;      border: 1px solid rgba(213, 0, 28, .4); }
.badge--vbo { background: rgba(127, 178, 230, .14); color: var(--link); border: 1px solid rgba(127, 178, 230, .35); }
.badge--csv { background: rgba(227, 171, 55, .14); color: var(--gold);  border: 1px solid rgba(227, 171, 55, .35); }
.badge--other { background: rgba(140,170,180,.1); color: var(--ink-2); border: 1px solid var(--edge); }

.modal__foot { display: flex; justify-content: flex-end; gap: .7rem; padding: 1.1rem 1.3rem; border-top: 1px solid var(--edge); margin-top: 1.3rem; }
.modal__note { margin: 0 1.3rem; font-size: .72rem; color: var(--ink-2); line-height: 1.5; }

/* ── Data deck (shown once sessions exist) ──────────────────────────────── */
.deck { display: grid; grid-template-columns: 300px 1fr; gap: 1.2rem; align-items: start; }
@media (max-width: 860px) { .deck { grid-template-columns: 1fr; } }

.rail { border: 1px solid var(--edge); border-radius: var(--r-lg); background: linear-gradient(180deg, var(--surface-1), var(--surface-0)); overflow: hidden; }
.rail__head { display: flex; align-items: center; justify-content: space-between; padding: .85rem 1rem; border-bottom: 1px solid var(--edge); }
.rail__head h2 { font-family: var(--cond); text-transform: uppercase; letter-spacing: .18em; font-size: .85rem; margin: 0; color: var(--ink); }
.sort { font-family: var(--mono); font-size: .72rem; color: var(--ink-2); background: none; border: 1px solid var(--edge); border-radius: var(--r-sm); padding: .25em .6em; cursor: pointer; }
.sort:hover { color: var(--ink); border-color: #2a343d; }
.sort:disabled { opacity: .4; cursor: default; }
.sort:disabled:hover { color: var(--ink-2); border-color: var(--edge); }

.session-list { list-style: none; margin: 0; padding: .6rem; display: flex; flex-direction: column; gap: .5rem; }
.session-card {
    border: 1px solid var(--edge);
    border-left: 3px solid var(--accent);
    border-radius: var(--r-md);
    padding: .7rem .8rem;
    background: var(--surface-0);
    transition: transform .16s ease, border-color .16s ease;
}
.session-card:hover { transform: translateY(-2px); border-color: #2a343d; border-left-color: var(--accent); }
.session-card__top { display: flex; align-items: center; gap: .6rem; margin-bottom: .35rem; }
.session-card__name { flex: 1; font-size: .82rem; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-card__meta { font-size: .72rem; color: var(--ink-2); }
.session-card__rm { background: none; border: none; cursor: pointer; color: var(--ink-3); padding: .15rem .3rem; border-radius: var(--r-sm); }
.session-card__rm:hover { color: var(--err); background: rgba(255, 85, 85, .1); }

.stage { display: flex; flex-direction: column; gap: 1.2rem; }
.panel {
    position: relative;
    border: 1px solid var(--edge);
    border-radius: var(--r-lg);
    background: linear-gradient(180deg, var(--surface-1), var(--surface-0));
    padding: 1rem;
    min-height: 240px;
}
.panel--map { min-height: 340px; }
.panel__label { position: absolute; top: .85rem; left: 1rem; font-family: var(--cond); text-transform: uppercase; letter-spacing: .18em; font-size: .72rem; color: var(--ink-2); }
.panel__ph { display: grid; place-items: center; min-height: 200px; height: 100%; text-align: center; color: var(--ink-2); font-size: .82rem; line-height: 1.7; }
.panel__ph svg { width: 40px; height: 40px; margin-bottom: .6rem; opacity: .6; }

/* Instrument corner-ticks on panels */
.panel::before, .panel::after { content: ""; position: absolute; width: 10px; height: 10px; border: 1px solid var(--edge); }
.panel::before { top: 6px; left: 6px; border-right: 0; border-bottom: 0; }
.panel::after  { bottom: 6px; right: 6px; border-left: 0; border-top: 0; }

/* selected session */
.session-card.is-selected { border-color: var(--accent); border-left-color: var(--accent); background: rgba(213, 0, 28, .06); }
.session-card { cursor: pointer; }

/* ── Summary strip ──────────────────────────────────────────────────────── */
.summary {
    border: 1px solid var(--edge);
    border-radius: var(--r-lg);
    background: linear-gradient(180deg, var(--surface-1), var(--surface-0));
    padding: 1.1rem 1.2rem;
}
.summary__title { font-family: var(--cond); text-transform: uppercase; letter-spacing: .08em; font-size: 1.3rem; margin: 0; color: var(--ink-hi); }
.summary__sub { font-size: .8rem; color: var(--ink-2); margin: .25rem 0 0; }
.stat-row { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1.1rem; }
.stat {
    flex: 1 1 92px;
    border: 1px solid var(--edge);
    border-radius: var(--r-md);
    background: var(--surface-0);
    padding: .6rem .7rem;
}
.stat__val { font-family: var(--mono); font-size: 1.15rem; font-weight: 600; color: var(--ink-hi); line-height: 1.1; }
.stat__label { font-family: var(--cond); text-transform: uppercase; letter-spacing: .12em; font-size: .64rem; color: var(--ink-2); margin-top: .3rem; }

/* ── Racing-line map ────────────────────────────────────────────────────── */
.map-fig { display: grid; place-items: center; padding-top: 1.4rem; }
.racingline { width: 100%; height: auto; max-height: 360px; display: block; }
.racingline__path { stroke: var(--accent); stroke-width: 2.25; fill: none; stroke-linejoin: round; stroke-linecap: round; filter: drop-shadow(0 0 6px rgba(213, 0, 28, .35)); }
.racingline__start { fill: var(--ink-hi); stroke: var(--accent); stroke-width: 1.5; }

/* ── Lap table ──────────────────────────────────────────────────────────── */
.panel--laps .panel__label { margin-bottom: .2rem; }
.lap-table { margin-top: 1.7rem; display: flex; flex-direction: column; gap: .15rem; }
.lap-head, .lap-row {
    display: grid;
    /* column track sizing lives in the 8-col rule below (checkbox … play) */
    gap: .6rem;
    align-items: baseline;
    padding: .5rem .7rem;
}
.lap-head { padding-top: 0; padding-bottom: .5rem; margin-bottom: .3rem; border-bottom: 1px solid var(--edge); }
.lap-h { font-family: var(--cond); text-transform: uppercase; letter-spacing: .1em; font-size: .62rem; color: var(--ink-3); }
.lap-h--delta { text-align: right; }   /* line the Δ header up over its right-aligned values */
/* sortable column headers */
.lap-h--sortable { cursor: pointer; user-select: none; transition: color .14s ease; }
.lap-h--sortable:hover { color: var(--ink); }
.lap-h--sortable:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
.lap-h.is-sorted { color: var(--ink-hi); }
.lap-h__ind { margin-left: .25em; color: var(--accent); font-size: .9em; }
.lap-row {
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: background .14s ease, border-color .14s ease;
}
.lap-row:hover { background: rgba(255, 255, 255, .03); }
.lap-row.is-current { border-color: var(--edge); background: rgba(255, 255, 255, .04); }
.lap-c { font-family: var(--mono); font-size: .84rem; color: var(--ink); white-space: nowrap; }
.lap-c--num { font-family: var(--cond); text-transform: uppercase; letter-spacing: .06em; }
.lap-c--start, .lap-c--max, .lap-c--maxlat { color: var(--ink-2); font-size: .78rem; }
/* fastest-lap medals beside the Lap # (shown in both wide and compact views) */
.lap-c--num { display: inline-flex; align-items: center; gap: .4em; }
/* circular minted rank badge (1/2/3), placed AFTER the lap number */
.lap-medal {
    flex: 0 0 auto;
    display: inline-grid; place-items: center;
    width: 18px; height: 18px; border-radius: 50%;
    font-family: var(--mono); font-weight: 700; font-size: .62rem; line-height: 1;
    color: #1a1a1a;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .4), 0 1px 2px rgba(0, 0, 0, .55);
}
.lap-medal--1 { background: linear-gradient(145deg, #ffe07a, #d4af37); }
.lap-medal--2 { background: linear-gradient(145deg, #f0f0f0, #b8b8b8); }
.lap-medal--3 { background: linear-gradient(145deg, #e8b07a, #b87333); }
.lap-c--time { color: var(--ink-hi); font-size: .92rem; }
.lap-c--delta { text-align: right; color: var(--ink-2); font-size: .76rem; }
.lap-row.is-best .lap-c--num,
.lap-row.is-best .lap-c--time,
.lap-row.is-best .lap-c--delta { color: var(--accent); }
.lap-row.is-best .lap-c--delta { font-weight: 600; }

/* ── Telemetry traces ───────────────────────────────────────────────────── */
.legend { display: flex; gap: 1.1rem; margin-top: 1.5rem; font-family: var(--mono); font-size: .72rem; color: var(--ink-2); }
.legend__item { display: flex; align-items: center; gap: .45rem; }
.legend__dot { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }
.legend__item--sp .legend__dot { background: var(--ink-hi); }
.legend__item--th .legend__dot { background: #4ade80; }
.legend__item--br .legend__dot { background: var(--accent); }
.trace-fig { padding-top: .5rem; }
.traces { width: 100%; height: auto; display: block; }
.traces__axis { stroke: var(--edge); stroke-width: 1; }
.traces__throttle { fill: rgba(74, 222, 128, .16); stroke: rgba(74, 222, 128, .55); stroke-width: 1; }
.traces__brake { fill: rgba(213, 0, 28, .16); stroke: rgba(213, 0, 28, .6); stroke-width: 1; }
.traces__speed { stroke: var(--ink-hi); stroke-width: 1.75; fill: none; stroke-linejoin: round; }

/* ── Dockable panels parked in the left rail ────────────────────────────── */
#railPanels { padding: 0 .6rem .7rem; display: flex; flex-direction: column; gap: .6rem; }
#railPanels .panel { min-height: 0; }
#railPanels .panel::before, #railPanels .panel::after { display: none; } /* skip corner ticks at this size */
.panel--track .map-fig { padding-top: 1.5rem; padding-bottom: .2rem; }
.panel--track .racingline { max-height: 210px; }

/* Track badge (logo + name) */
.track-badge { display: flex; align-items: center; gap: .55rem; margin-top: .7rem; padding: .4rem .55rem; border: 1px solid var(--edge); border-radius: var(--r-md); background: var(--surface-0); }
.track-badge__logo { height: 20px; width: auto; max-width: 120px; background: #fff; border-radius: 3px; padding: 2px 5px; }
.track-badge__name { font-family: var(--cond); text-transform: uppercase; letter-spacing: .06em; font-size: .64rem; color: var(--ink-2); line-height: 1.2; }

/* Track length caption on the map card (constant per session) */
.track-dist {
    margin-top: .5rem; text-align: center;
    font-family: var(--mono); font-size: .74rem; letter-spacing: .04em;
    color: var(--ink-2);
}

/* dock toggle (← minimize to rail / → expand to main) */
.panel__dock {
    position: absolute; top: .7rem; right: .8rem; z-index: 2;
    width: 22px; height: 22px; display: grid; place-items: center;
    border: 1px solid var(--edge); border-radius: 4px;
    background: rgba(255, 255, 255, .04); color: var(--ink-2);
    font-size: .82rem; line-height: 1; cursor: pointer;
}
.panel__dock:hover { color: var(--ink-hi); border-color: #2a343d; background: rgba(255, 255, 255, .09); }

/* lap action bar + play/compare controls */
.lap-actions { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 1.5rem 0 .1rem; }
.lap-actions__hint { font-family: var(--mono); font-size: .73rem; color: var(--ink-2); }
.btn--sm { font-size: .68rem; padding: .42em .8em; }
.lap-head, .lap-row { grid-template-columns: 26px 84px 62px 88px 76px 76px 1fr 30px; }   /* +checkbox, +play */
.lap-c--check { width: 15px; height: 15px; margin: 0; accent-color: var(--accent); cursor: pointer; align-self: center; }
.lap-c--play {
    align-self: center; justify-self: end; width: 26px; height: 22px;
    border: 1px solid var(--edge); border-radius: 4px; background: none;
    color: var(--accent); font-size: .82rem; line-height: 1; cursor: pointer; padding: 0;
    transition: color .14s ease, border-color .14s ease, background .14s ease;
}
.lap-c--play:hover { color: #fff; border-color: var(--accent); background: var(--accent); }

/* compact lap table (when docked to the narrow rail): checkbox · Lap · Time · play */
.lap-table--compact .lap-actions { display: none; }
.lap-table--compact .lap-head, .lap-table--compact .lap-row { grid-template-columns: 22px 1fr auto 26px; }
.lap-table--compact .lap-c--start, .lap-table--compact .lap-c--max,
.lap-table--compact .lap-c--maxlat, .lap-table--compact .lap-c--delta,
.lap-table--compact .lap-h:nth-child(3), .lap-table--compact .lap-h:nth-child(5),
.lap-table--compact .lap-h:nth-child(6), .lap-table--compact .lap-h:nth-child(7) { display: none; }

/* ── Replay / study modal ───────────────────────────────────────────────── */
dialog.modal--replay {
    width: min(1400px, 96vw); height: min(92vh, 1000px); max-width: none;
    padding: 0; display: flex; flex-direction: column; overflow: hidden;
}
.replay__head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .75rem 1.1rem; border-bottom: 1px solid var(--edge); }
.replay__title { font-family: var(--cond); text-transform: uppercase; letter-spacing: .1em; font-size: 1rem; margin: 0; color: var(--ink-hi); }
.replay__tools { display: flex; gap: .5rem; align-items: center; }
.rbtn {
    font-family: var(--cond); text-transform: uppercase; letter-spacing: .1em; font-size: .7rem;
    padding: .42em .8em; border: 1px solid var(--edge); border-radius: 4px;
    background: rgba(255, 255, 255, .03); color: var(--ink); cursor: pointer;
}
.rbtn:hover { border-color: #2a343d; background: rgba(255, 255, 255, .08); }
.rbtn.is-on { background: var(--accent); border-color: var(--accent); color: #fff; }
.rbtn--x { color: var(--ink-2); font-size: .85rem; padding: .35em .6em; }
.replay__map { position: relative; flex: 1 1 auto; min-height: 0; background: #0f1318; }
.replay__gauges { position: absolute; left: 1rem; bottom: 1rem; z-index: 650; }
.replay__gg { position: absolute; right: 1rem; bottom: 1rem; z-index: 650; width: 158px; height: 158px; }
.replay__delta.is-ahead { color: #4ade80; }
.replay__delta.is-behind { color: #ff5c5c; }
.replay__transport { display: flex; align-items: center; gap: 1.1rem; padding: .6rem 1.1rem; border-top: 1px solid var(--edge); }
.replay__play {
    width: 44px; height: 44px; border-radius: 50%; border: none; flex: 0 0 auto;
    background: var(--accent); color: #fff; cursor: pointer; display: grid; place-items: center;
    box-shadow: 0 6px 20px -6px rgba(213, 0, 28, .6);
}
.replay__play:hover { background: var(--accent-hi); }
.replay__play svg { width: 20px; height: 20px; }
.replay__clock { font-family: var(--mono); font-size: .9rem; color: var(--ink-hi); white-space: nowrap; }
.replay__delta { font-family: var(--mono); font-size: .78rem; color: var(--ink-2); white-space: nowrap; }

/* YouTube-style scrub bar */
.replay__scrubwrap { position: relative; flex: 1 1 auto; display: flex; align-items: center; min-width: 120px; }
.replay__scrub {
    width: 100%; height: 5px; -webkit-appearance: none; appearance: none;
    background: #2a323a; border-radius: 3px; outline: none; cursor: pointer; margin: 0;
}
.replay__scrub::-webkit-slider-thumb {
    -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%;
    background: var(--accent); cursor: pointer; box-shadow: 0 0 0 3px rgba(213, 0, 28, .25);
}
.replay__scrub::-moz-range-thumb { width: 14px; height: 14px; border: none; border-radius: 50%; background: var(--accent); cursor: pointer; }
.replay__scrub:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px rgba(213, 0, 28, .4); }
.replay__end { position: absolute; top: 50%; width: 3px; height: 13px; transform: translate(-50%, -50%); border-radius: 1px; pointer-events: none; }

/* stacked timelines (primary + secondary) */
.replay__timelines { flex: 0 0 auto; display: flex; flex-direction: column; border-top: 1px solid var(--edge); max-height: 46vh; }
.replay__timeline { height: 196px; flex: 0 0 auto; overflow: hidden; }
.replay__timeline + .replay__timeline:not([hidden]) { border-top: 1px solid var(--edge); }

[hidden] { display: none !important; }
