:root {
    --head-w: 200px;
    --lane-h: 46px;
    --ruler-h: 56px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
}

body {
    background: radial-gradient(circle at 30% 0%, #101020 0%, #050507 70%);
    color: #e7e7ef;
    font-family: 'Noto Sans', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    overflow: hidden;
    touch-action: manipulation;
}

/* Collapsible timecode column (collapsed by default on mobile) */
body.tl-head-collapsed {
    --head-w: 0px;
}

body.tl-head-collapsed .tl-corner,
body.tl-head-collapsed .tl-head-cell {
    padding-left: 0;
    padding-right: 0;
    border-right: 0;
    overflow: hidden;
}

body.tl-head-collapsed .tl-head-cell > * {
    display: none;
}

body.tl-head-collapsed .tl-head-toggle-text {
    display: none;
}

/* ===== Brand bar (mirrors /map) ===== */
.mt-brand-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 8px 16px;
    background: linear-gradient(135deg, rgba(10, 10, 18, 0.92), rgba(28, 26, 46, 0.92));
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(6px);
}

.mt-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
}

.mt-brand-logo {
    width: 42px;
    height: 42px;
    object-fit: contain;
}

.mt-brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    color: #fff;
}

.mt-brand-text strong {
    font-size: 1rem;
    letter-spacing: 0.5px;
}

.mt-brand-text small {
    font-size: 0.72rem;
    opacity: 0.75;
    letter-spacing: 0.4px;
}

.mt-brand-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.mt-brand-nav a {
    color: #ddd;
    text-decoration: none;
    font-size: 0.85rem;
    padding: 6px 12px;
    border-radius: 999px;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.mt-brand-nav a:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

/* ===== App shell ===== */
.tl-app {
    position: absolute;
    inset: 0;
    padding-top: 59px;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* ===== Toolbar ===== */
.tl-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(12, 12, 20, 0.7);
    flex: 0 0 auto;
}

.tl-toolbar-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.tl-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #191926;
    color: #d6d6e6;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    padding: 6px 11px;
    font-size: 0.82rem;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.tl-btn:hover {
    background: #24243a;
    border-color: rgba(61, 139, 253, 0.6);
    color: #fff;
}

.tl-btn:active {
    transform: translateY(1px);
}

.tl-btn.is-active {
    background: #24243a;
    border-color: rgba(61, 139, 253, 0.7);
    color: #fff;
}

.tl-readout {
    font-size: 0.78rem;
    color: #9a9ab5;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
    padding-left: 4px;
}

.tl-hint {
    margin-left: auto;
    font-size: 0.74rem;
    color: #7c7c95;
}

.tl-hint i {
    color: #5f8fe0;
}

/* ===== Scroll viewport ===== */
.tl-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
}

/* ===== Ruler (timecode) ===== */
.tl-head {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    height: var(--ruler-h);
    background: linear-gradient(#13131f, #0c0c15);
    border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.tl-corner {
    flex: 0 0 var(--head-w);
    display: flex;
    align-items: flex-end;
    padding: 0 12px 10px;
    font-size: 0.66rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: #83839b;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.tl-ruler-wrap {
    flex: 1 1 auto;
    position: relative;
    overflow: hidden;
    cursor: grab;
}

.tl-ruler-wrap:active {
    cursor: grabbing;
}

.tl-ruler {
    display: block;
    width: 100%;
    height: var(--ruler-h);
    touch-action: none;
}

/* ===== Lanes ===== */
.tl-lanes {
    position: relative;
    min-height: 100%;
    /* Vertical drags scroll the track list natively; horizontal drags are
       left to the pointer handlers so the track body pans the timeline. */
    touch-action: pan-y;
}

.tl-grid {
    position: absolute;
    top: 0;
    bottom: 0;
    left: var(--head-w);
    right: 0;
    pointer-events: none;
    z-index: 0;
}

.tl-grid-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    background: rgba(255, 255, 255, 0.055);
}

.tl-row {
    position: relative;
    z-index: 1;
    display: flex;
    height: var(--lane-h);
}

.tl-head-cell {
    flex: 0 0 var(--head-w);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 10px;
    background: #0c0c15;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    user-select: none;
    position: relative;
    z-index: 2;
    transition: background-color 0.12s ease;
}

.tl-row:hover .tl-head-cell {
    background: #15151f;
}

.tl-row.drag-over .tl-head-cell {
    box-shadow: inset 0 2px 0 #3d8bfd;
}

.tl-drag {
    cursor: grab;
    color: #5a5a72;
    padding: 2px 0;
    touch-action: none;
}

.tl-drag:active {
    cursor: grabbing;
}

.tl-color {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    flex: 0 0 auto;
    box-shadow: 0 0 6px currentColor;
    background: currentColor;
}

.tl-track-label {
    font-size: 0.82rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tl-lane {
    flex: 1 1 auto;
    position: relative;
    overflow: hidden;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(255, 255, 255, 0.012);
}

/* ===== Clips ===== */
.tl-clip {
    position: absolute;
    top: 6px;
    height: calc(var(--lane-h) - 12px);
    border-radius: 6px;
    padding: 0 8px;
    display: flex;
    align-items: center;
    overflow: hidden;
    font-size: 0.72rem;
    line-height: 1;
    color: #fff;
    white-space: nowrap;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
    border: 1px solid transparent;
    cursor: default;
}

.tl-clip.is-point {
    top: 0;
    bottom: 0;
    height: auto;
    width: 0;
    min-width: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: none;
    box-shadow: none;
    overflow: visible;
}

.tl-point-dot {
    position: absolute;
    left: -5px;
    bottom: 7px;
    width: 10px;
    height: 10px;
    transform: rotate(45deg);
    border-radius: 2px;
    border: 1px solid rgba(0, 0, 0, 0.45);
    box-shadow: 0 0 8px currentColor, 0 1px 3px rgba(0, 0, 0, 0.6);
}

.tl-point-flag {
    position: absolute;
    bottom: 24px;
    left: 0;
    transform: translateX(-50%);
    max-width: 220px;
    padding: 3px 8px;
    border-radius: 6px;
    background: rgba(18, 18, 29, 0.98);
    color: #e7e7ef;
    font-size: 0.7rem;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.55);
    pointer-events: none;
}

.tl-point-flag::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid rgba(18, 18, 29, 0.98);
}

.tl-clip.is-point.no-label .tl-point-flag {
    visibility: hidden;
}

.tl-clip .tl-clip-label {
    overflow: hidden;
    text-overflow: ellipsis;
}

.tl-clip.no-label .tl-clip-label {
    display: none;
}

/* Sub-lane overflow indicator (events hidden by the lane cap). */
.tl-overflow-badge {
    position: absolute;
    top: 4px;
    right: 6px;
    z-index: 3;
    padding: 1px 7px;
    border-radius: 999px;
    background: rgba(18, 18, 29, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #b9b9d0;
    font-size: 0.66rem;
    line-height: 1.5;
    font-variant-numeric: tabular-nums;
    cursor: help;
}

/* Ongoing conflicts extend to the present: caution stripes + a continuation arrow. */
.tl-clip.is-ongoing {
    padding-right: 18px;
}

.tl-clip.is-ongoing::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: repeating-linear-gradient(
        -45deg,
        rgba(255, 255, 255, 0.16) 0 5px,
        rgba(255, 255, 255, 0) 5px 10px
    );
    pointer-events: none;
}

.tl-clip.is-ongoing::after {
    content: '\2192';
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.72rem;
    opacity: 0.9;
}

/* ===== Clip hover tooltip ===== */
.tl-tip {
    position: fixed;
    z-index: 1300;
    pointer-events: none;
    background: rgba(18, 18, 29, 0.97);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-left-width: 3px;
    border-radius: 8px;
    padding: 7px 10px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.55);
    color: #e7e7ef;
    font-size: 0.78rem;
    line-height: 1.35;
    max-width: 280px;
    white-space: normal;
}

.tl-tip[hidden] {
    display: none;
}

.tl-tip-title {
    font-weight: 600;
    margin-bottom: 2px;
}

.tl-tip-meta {
    color: #9a9ab5;
    font-variant-numeric: tabular-nums;
}

/* ===== Playhead ===== */
.tl-playhead {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 0;
    z-index: 4;
    pointer-events: none;
}

.tl-playhead::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: -1px;
    width: 2px;
    background: #ffd166;
    box-shadow: 0 0 8px rgba(255, 209, 102, 0.85);
}

.tl-playhead-grip {
    position: absolute;
    top: 0;
    bottom: 0;
    left: -9px;
    width: 18px;
    cursor: ew-resize;
    pointer-events: auto;
    touch-action: none;
}

.tl-playhead-marker {
    position: absolute;
    bottom: 0;
    left: 0;
    z-index: 6;
    display: flex;
    flex-direction: column;
    align-items: center;
    transform: translateX(-50%);
    pointer-events: auto;
    cursor: ew-resize;
    touch-action: none;
}

.tl-playhead-label {
    background: #ffd166;
    color: #1a1400;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    padding: 2px 7px;
    border-radius: 5px;
    white-space: nowrap;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.55);
}

.tl-playhead-caret {
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid #ffd166;
}

.tl-btn-now {
    border-color: rgba(255, 209, 102, 0.4);
}

.tl-btn-now:hover {
    border-color: #ffd166;
    color: #ffd166;
}

/* ===== Tracks modal ===== */
.modal {
    z-index: 1200;
}

.modal-backdrop {
    z-index: 1190;
}

.tl-modal {
    background: #12121d;
    color: #e7e7ef;
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}

.tl-modal .modal-header,
.tl-modal .modal-footer {
    border-color: rgba(255, 255, 255, 0.1);
}

.tl-modal .btn-close {
    filter: invert(1) grayscale(1) brightness(1.8);
    opacity: 0.7;
}

.tl-modal .btn-close:hover {
    opacity: 1;
}

.tl-modal-hint {
    font-size: 0.82rem;
    color: #9a9ab5;
    margin: 0 0 12px;
}

.tl-track-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tl-track-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.07);
}

.tl-track-item-label {
    flex: 1 1 auto;
    font-size: 0.88rem;
}

.tl-track-item .form-check-input {
    width: 2.2em;
    height: 1.2em;
    cursor: pointer;
    background-color: #2a2a3d;
    border-color: rgba(255, 255, 255, 0.2);
}

.tl-track-item .form-check-input:checked {
    background-color: #3d8bfd;
    border-color: #3d8bfd;
}

.tl-track-item .form-check-input:focus {
    box-shadow: 0 0 0 0.2rem rgba(61, 139, 253, 0.35);
}

/* ===== Mobile landscape: drop the brand bar for more vertical room =====
   Targeted at short/phone landscape viewports (max-height) so desktop
   browsers in landscape keep the header. */
@media (orientation: landscape) and (max-height: 600px) {
    .mt-brand-bar {
        display: none;
    }

    .tl-app {
        padding-top: 0;
    }
}
