/* Bansida (/track/{id}) och destinationens banor (/track?venue={id}) — mobil först */

.tv { display: flex; flex-direction: column; gap: var(--space-md); max-width: 960px; margin: 0 auto; }

/* ---------- Rubrik ---------- */
.tv-head { display: flex; flex-direction: column; gap: var(--space-2xs); }
.tv-back {
    display: inline-flex; align-items: center; gap: 2px; align-self: flex-start;
    min-height: 32px; font-size: 0.85rem; font-weight: 600;
    color: var(--color-text-secondary); text-decoration: none;
}
.tv-back svg { width: 18px; height: 18px; margin-left: -4px; }
.tv-title {
    display: flex; align-items: center; gap: var(--space-xs);
    margin: 0; font-family: var(--font-heading); font-size: clamp(1.5rem, 6vw, 2.25rem);
    line-height: 1.1; color: var(--color-text-primary);
}
.tv-grade {
    width: 14px; height: 14px; flex-shrink: 0; border-radius: var(--radius-full);
    background: var(--grade); box-shadow: 0 0 0 2px var(--color-bg-page), 0 0 0 3px var(--grade);
}
.tv-tags { display: flex; flex-wrap: wrap; gap: var(--space-2xs); }
.tv-tags > * {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 10px; border-radius: var(--radius-full);
    background: var(--color-bg-hover); color: var(--color-text-secondary);
    font-size: 0.78rem; font-weight: 600; text-decoration: none;
}
.tv-tags svg { width: 13px; height: 13px; }

/* ---------- Siffror (sveper i sidled på mobil) ---------- */
.tv-stats {
    display: grid; grid-auto-flow: column; grid-auto-columns: minmax(92px, 1fr);
    gap: var(--space-xs); overflow-x: auto; scroll-snap-type: x proximity;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.tv-stats::-webkit-scrollbar { display: none; }
.tv-stat {
    display: flex; flex-direction: column; gap: 2px; scroll-snap-align: start;
    padding: var(--space-sm); border-radius: var(--radius-md);
    background: var(--color-bg-card); border: 1px solid var(--color-border);
}
.tv-stat-v { font-family: var(--font-heading); font-size: 1.25rem; line-height: 1.1; color: var(--color-text-primary); white-space: nowrap; }
.tv-stat-l { font-size: 0.7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--color-text-muted); }

/* ---------- Karta ---------- */
.tv-map-card {
    position: relative; overflow: hidden;
    border-radius: var(--radius-lg); border: 1px solid var(--color-border);
    background: var(--color-bg-surface);
}
.tv-map { width: 100%; height: clamp(320px, 58vh, 620px); touch-action: none; }
.tv-map-card.is-full {
    position: fixed; inset: 0; z-index: 10050; border-radius: 0; border: 0;
}
.tv-map-card.is-full .tv-map { height: 100%; height: 100dvh; }
html.tv-noscroll, html.tv-noscroll body { overflow: hidden; }

.tv-map-ui {
    position: absolute; top: 0; left: 0; right: 0;
    display: flex; justify-content: space-between; align-items: flex-start;
    padding: var(--space-sm); padding-top: max(var(--space-sm), env(safe-area-inset-top));
    pointer-events: none;
}
.tv-map-ui > * { pointer-events: auto; }
.tv-seg {
    display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.92); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
    -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.tv-seg button {
    min-width: 48px; min-height: 34px; padding: 0 14px; border: 0; border-radius: var(--radius-full);
    background: transparent; font: inherit; font-weight: 700; font-size: 0.85rem; color: #33404d; cursor: pointer;
}
.tv-seg button.is-on { background: var(--color-accent); color: #fff; }
.tv-map-btns { display: flex; flex-direction: column; gap: var(--space-xs); }
.tv-round {
    width: 44px; height: 44px; display: grid; place-items: center;
    border: 0; border-radius: var(--radius-full); cursor: pointer;
    background: rgba(255, 255, 255, 0.92); color: #1f2a36;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
    -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.tv-round svg { width: 20px; height: 20px; }
.tv-round.is-on { background: var(--color-accent); color: #fff; }
.tv-map-card .maplibregl-ctrl-bottom-right { bottom: 4px; }
.tv-map-card.is-full .maplibregl-ctrl-bottom-right { bottom: calc(4px + env(safe-area-inset-bottom)); }

.tv-map-segs { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-xs); }

/* Spelaren i botten (som Trailforks): play/paus + reglage att dra med tummen */
.tv-player {
    position: absolute; left: var(--space-sm); right: 60px; bottom: var(--space-sm);
    display: flex; align-items: center; gap: var(--space-sm);
    padding: 6px 14px 6px 6px; border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.94); box-shadow: 0 2px 12px rgba(0, 0, 0, 0.22);
    -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.tv-map-card.is-full .tv-player { bottom: calc(var(--space-sm) + env(safe-area-inset-bottom)); }
.tv-play {
    width: 44px; height: 44px; flex-shrink: 0; display: grid; place-items: center;
    border: 0; border-radius: 50%; cursor: pointer;
    background: var(--color-accent); color: #fff;
}
.tv-play svg { width: 20px; height: 20px; fill: currentColor; }
.tv-player-track { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.tv-player-info {
    font-size: 0.75rem; font-weight: 600; color: #33404d;
    font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tv-scrub {
    --p: 0%;
    width: 100%; height: 28px; margin: 0; background: transparent; cursor: pointer;
    -webkit-appearance: none; appearance: none; touch-action: pan-x;
}
.tv-scrub::-webkit-slider-runnable-track {
    height: 6px; border-radius: 3px;
    background: linear-gradient(to right, var(--color-accent) var(--p), #d5dbe3 var(--p));
}
.tv-scrub::-moz-range-track { height: 6px; border-radius: 3px; background: #d5dbe3; }
.tv-scrub::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--color-accent); }
.tv-scrub::-webkit-slider-thumb {
    -webkit-appearance: none; width: 24px; height: 24px; margin-top: -9px; border-radius: 50%;
    background: #fff; border: 3px solid var(--color-accent); box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
}
.tv-scrub::-moz-range-thumb {
    width: 18px; height: 18px; border-radius: 50%;
    background: #fff; border: 3px solid var(--color-accent); box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
}

/* Lutningsfärgerna, under höjdprofilen */
.tv-legend {
    display: flex; flex-wrap: wrap; gap: 4px var(--space-sm);
    padding: 0 var(--space-md) var(--space-xs);
    font-size: 0.72rem; font-weight: 600; color: var(--color-text-secondary);
}
.tv-legend span { display: inline-flex; align-items: center; gap: 4px; }
.tv-legend span::before { content: ''; width: 14px; height: 5px; border-radius: 3px; background: var(--c); }

.tv-pin { width: 18px; height: 18px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 6px rgba(0, 0, 0, .35); }
.tv-pin--start { background: #16a34a; }
.tv-pin--end { background: #111827; }
.tv-dot {
    width: 22px; height: 22px; border-radius: 50%;
    background: #16a34a; border: 4px solid #fff;
    box-shadow: 0 0 0 7px rgba(22, 163, 74, 0.3), 0 2px 8px rgba(0, 0, 0, .45);
}
.tv-popup { display: block; padding: 4px 2px; font-weight: 700; color: var(--color-accent); text-decoration: none; }

.tv-empty {
    display: flex; flex-direction: column; align-items: center; gap: var(--space-xs);
    padding: var(--space-xl) var(--space-md); text-align: center;
    border: 1px dashed var(--color-border-strong); border-radius: var(--radius-lg); color: var(--color-text-muted);
}
.tv-empty svg { width: 32px; height: 32px; }
.tv-empty p { margin: 0; }

/* ---------- Kort ---------- */
.tv-card {
    border-radius: var(--radius-lg); border: 1px solid var(--color-border);
    background: var(--color-bg-card); overflow: hidden;
}
.tv-card-head {
    display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md) 0;
}
.tv-card-head h2 { margin: 0; font-family: var(--font-heading); font-size: 1.1rem; color: var(--color-text-primary); }
.tv-readout {
    font-size: 0.85rem; font-weight: 600; color: var(--color-text-secondary);
    font-variant-numeric: tabular-nums; white-space: nowrap;
}
.tv-note { margin: 0; padding: 0 var(--space-md) var(--space-sm); font-size: 0.75rem; color: var(--color-text-muted); }

/* ---------- Höjdprofil ---------- */
.tv-profile {
    height: 190px; margin: var(--space-xs) 0; cursor: crosshair;
    touch-action: pan-y; -webkit-user-select: none; user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.tv-profile svg { display: block; }
.tv-area { opacity: 0.55; }
.tv-line { fill: none; stroke: var(--color-text-primary); stroke-width: 1.75; stroke-linejoin: round; }
.tv-grid line { stroke: var(--color-border); stroke-dasharray: 3 4; }
.tv-axis text { font-size: 10px; fill: var(--color-text-muted); font-family: var(--font-body); }
.tv-cursor { stroke: var(--color-accent); stroke-width: 1.5; }
.tv-cursor-dot { fill: var(--color-accent); stroke: #fff; stroke-width: 2; }
.tv-profile.is-active .tv-cursor-dot { r: 7; }

/* ---------- Filmer ---------- */
.tv-video-list { display: grid; gap: var(--space-md); padding: var(--space-sm) var(--space-md) var(--space-md); }
@media (min-width: 768px) { .tv-video-list { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); } }

/* ---------- Beskrivning, betyg, länkar ---------- */
.tv-desc { padding: var(--space-md); color: var(--color-text-secondary); line-height: 1.6; }
.tv-scores { display: grid; gap: var(--space-xs); padding: 0 var(--space-md) var(--space-md); }
.tv-desc + .tv-scores { padding-top: 0; }
.tv-card > .tv-scores:first-child { padding-top: var(--space-md); }
.tv-score { display: grid; grid-template-columns: 64px minmax(0, 1fr) 24px; align-items: center; gap: var(--space-sm); font-size: 0.85rem; }
.tv-score span { color: var(--color-text-secondary); }
.tv-score b { text-align: right; color: var(--color-text-primary); }
.tv-bar { height: 8px; border-radius: var(--radius-full); background: var(--color-bg-hover); overflow: hidden; }
.tv-bar i { display: block; height: 100%; border-radius: inherit; background: var(--color-accent); }
.tv-links { display: flex; flex-wrap: wrap; gap: var(--space-xs); padding: 0 var(--space-md) var(--space-md); }
.tv-card > .tv-links:first-child { padding-top: var(--space-md); }
.tv-links a {
    display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 14px;
    border-radius: var(--radius-full); border: 1px solid var(--color-border-strong);
    color: var(--color-text-primary); font-size: 0.85rem; font-weight: 600; text-decoration: none;
}
.tv-links svg { width: 15px; height: 15px; }

/* ---------- Listor ---------- */
.tv-list { list-style: none; margin: var(--space-xs) 0 0; padding: 0; }
.tv-card > .tv-list:first-child { margin-top: 0; }
.tv-list li + li { border-top: 1px solid var(--color-border); }
.tv-list a {
    display: flex; align-items: center; gap: var(--space-sm);
    min-height: 52px; padding: var(--space-xs) var(--space-md);
    color: var(--color-text-primary); text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}
.tv-list a:active, .tv-list li.is-active a { background: var(--color-bg-hover); }
.tv-list-date { font-size: 0.8rem; color: var(--color-text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tv-list-name { flex: 1; min-width: 0; font-weight: 600; }
.tv-list-name small { display: block; font-weight: 400; font-size: 0.78rem; color: var(--color-text-muted); }
.tv-list a > svg:last-child { width: 18px; height: 18px; color: var(--color-text-muted); flex-shrink: 0; }
.tv-list .track-spark { width: 90px; height: 28px; flex-shrink: 0; }
.track-spark-fill { fill: var(--color-accent-light); }
.track-spark-line { fill: none; stroke: var(--color-accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }

.tv-credit { margin: 0; font-size: 0.7rem; color: var(--color-text-muted); text-align: center; }

/* ---------- Mobil: kant till kant ---------- */
@media (max-width: 767px) {
    .tv { gap: var(--space-sm); }
    .tv-stats { margin: 0 -16px; padding: 0 16px; }
    .tv-map-card, .tv-card, .tv-empty {
        margin-left: -16px; margin-right: -16px;
        border-radius: 0; border-left: 0; border-right: 0;
    }
    .tv-map { height: 62vh; height: 62svh; min-height: 300px; }
    .tv-profile { height: 170px; }
    .tv-video-list { padding-left: 0; padding-right: 0; }
    .tv-video-list .vv-player { border-radius: 0; }
    .tv-video-list .vv-title, .tv-video-list .vv-chapters { padding-left: var(--space-md); padding-right: var(--space-md); }
}

/* ---------- Redigera: penna i listan, justera längd ---------- */
.tv-track-list li:has(.tv-list-edit) { display: flex; align-items: stretch; }
.tv-track-list li:has(.tv-list-edit) > a:first-child { flex: 1; min-width: 0; }
.tv-list .tv-list-edit {
    flex: 0 0 52px; justify-content: center; padding: 0;
    border-left: 1px solid var(--color-border); color: var(--color-text-secondary);
}
.tv-list .tv-list-edit svg { width: 18px; height: 18px; }

.tv-trim-hint {
    position: absolute; left: 50%; bottom: var(--space-sm); transform: translateX(-50%);
    max-width: calc(100% - 2 * var(--space-md)); padding: 6px var(--space-sm);
    border-radius: var(--radius-full); background: rgba(17, 24, 39, .8); color: #fff;
    font-size: 0.78rem; font-weight: 600; text-align: center; pointer-events: none;
}
.tv-pin--drag { width: 30px; height: 30px; border-width: 4px; cursor: grab; touch-action: none; }
.tv-pin--drag:active { cursor: grabbing; transform: scale(1.12); }

.tv-trim-range { --a: 0%; --b: 100%; position: relative; height: 36px; margin: var(--space-xs) var(--space-md) 0; }
.tv-trim-range::before {
    content: ''; position: absolute; left: 0; right: 0; top: 15px; height: 6px; border-radius: 3px;
    background: linear-gradient(to right, #d5dbe3 var(--a), var(--color-accent) var(--a), var(--color-accent) var(--b), #d5dbe3 var(--b));
}
.tv-trim-range input {
    position: absolute; inset: 0; width: 100%; height: 36px; margin: 0;
    background: transparent; pointer-events: none; -webkit-appearance: none; appearance: none;
}
.tv-trim-range input::-webkit-slider-runnable-track { height: 36px; background: transparent; }
.tv-trim-range input::-moz-range-track { background: transparent; }
.tv-trim-range input::-webkit-slider-thumb {
    -webkit-appearance: none; pointer-events: auto; width: 28px; height: 28px; margin-top: 4px; border-radius: 50%;
    border: 4px solid #fff; box-shadow: 0 1px 5px rgba(0, 0, 0, .35); cursor: pointer;
}
.tv-trim-range input::-moz-range-thumb {
    pointer-events: auto; width: 20px; height: 20px; border-radius: 50%;
    border: 4px solid #fff; box-shadow: 0 1px 5px rgba(0, 0, 0, .35); cursor: pointer;
}
#tvTrimStart::-webkit-slider-thumb { background: #16a34a; }
#tvTrimStart::-moz-range-thumb { background: #16a34a; }
#tvTrimEnd::-webkit-slider-thumb { background: #111827; }
#tvTrimEnd::-moz-range-thumb { background: #111827; }
.tv-trim-vals {
    display: flex; justify-content: space-between; padding: 0 var(--space-md) var(--space-xs);
    font-size: 0.8rem; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--color-text-secondary);
}
.tv-trim-actions { display: flex; flex-wrap: wrap; gap: var(--space-xs); padding: 0 var(--space-md) var(--space-sm); }
.tv-trim-actions .btn { min-height: 44px; }
.tv-trim-msg { margin: 0; padding: 0 var(--space-md) var(--space-sm); font-size: 0.85rem; font-weight: 600; }
.tv-trim-msg:empty { display: none; }
.tv-trim-msg.is-ok { color: var(--color-success); }
.tv-trim-msg.is-err { color: var(--color-error); }
@media (max-width: 599px) {
    .tv-trim-actions .btn { flex: 1 1 auto; justify-content: center; }
}

/* Variant av ett spår: indragen under originalet */
.tv-list li.tv-variant > a:first-child { padding-left: calc(var(--space-md) + 18px); }

/* På tävling: statistik + snabbaste åkare */
.tv-runs-stats { padding: var(--space-sm) var(--space-md) !important; margin: 0 !important; }
.tv-best { color: var(--color-warning); }
.tv-top { list-style: none; margin: 0; padding: 0; }
.tv-top li { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; align-items: center; gap: var(--space-sm); padding: var(--space-xs) var(--space-md); border-top: 1px solid var(--color-border); }
.tv-top-pos { font-family: var(--font-heading); color: var(--color-text-muted); text-align: center; }
.tv-top-pos.is-first { color: var(--color-warning); }
.tv-top-name { color: var(--color-text-primary); text-decoration: none; font-weight: 500; font-family: var(--font-body); font-size: .9rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tv-top-name small { display: block; font-weight: 400; font-size: .75rem; color: var(--color-text-muted); overflow: hidden; text-overflow: ellipsis; }
.tv-top-time { font-variant-numeric: tabular-nums; font-weight: 500; font-family: var(--font-body); text-align: right; }
.tv-top-time small { display: block; font-weight: 400; font-size: .72rem; color: var(--color-text-muted); }

.tv-list-name { font-weight: 500; font-family: var(--font-body); }
