:root {
    --bg: #121212;
    --panel: #1e1e1e;
    --border: #333;
    --sidebar-width: 20%;
    --ruler-height: 35px;
    --row-height: 50px;
    --row-height-expanded: 100px;
}

* { box-sizing: border-box; }
body, html {
    margin: 0;
    padding: 0;
    background: var(--main-background);
    color: var(--col-1);
    font-family: 'Segoe UI', sans-serif;
    overflow: hidden;
    height: 100vh;
}

.screen1 {
    display: flex;
    width: 100%;
    flex-direction: row;
}

.leftbar {
    display: flex;
    flex-direction: column;
    padding: 15px;
    border-right: 1px solid var(--col-2);
    width: 62px;
}

.leftbar img {
    width: 32px;
    height: 32px;
    margin-bottom: 20px;
    opacity: 0.6;
    transition: all 0.3s ease;
}

.leftbar img:hover {
    opacity: 1;
    cursor: pointer;
    transition: all 0.3s ease;
}

.controlbar {
    display: none;
    flex-direction: column;
    padding: 15px;
    border-right: 2px solid var(--col-4);
    background-color: var(--main-background);
    width: 20vw;
    position: absolute;
    left: 62px;
    z-index: 1000000;
    height: 100%;
}

.controlbar h2 {
    margin: 0;
    font-size: var(--font-title);
}

.connect_data {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.connectQR {
    width: auto !important;
}

.connectQR button { 
    flex: 1;
    padding: 10px; 
    border: none; 
    border-radius: 4px; 
    cursor: pointer; 
    font-weight: bold; 
    font-size: 12px; 
}

#connect_description {
    font-size: 11px;
    color: var(--col-3);
}

.controlbar a {
    text-decoration: none;
    color: var(--col-1);
}

.controlbar p {
    color: var(--col-1);
    font-size: var(--font-normal);
}

.connect_link_span {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
}

.controlbar_connect span {
    display: flex;
    flex-direction: row;
    gap: 5px;
    align-items: center;
}

.connect_img {
    width: 28px;
    height: 28px;
    border-radius: 5px;
    padding: 5px;
    transition: all 0.3s ease;
}

.connect_img:hover {
    background-color: var(--col-2);
    transition: all 0.3s ease;
    cursor: pointer;
}

.controlbar-scenes {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.controlbar-scenes-item {
    display: flex;
    padding: 10px;
    align-items: center;
    gap: 15px;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.controlbar-scenes-item.active {
    background-color: var(--col-5);
}

.controlbar-scenes-item:hover {
    background-color: var(--col-2);
    transition: all 0.3s ease;
    cursor: pointer;
}

.controlbar-scenes-item {
    cursor: grab;
    user-select: none;
}

.controlbar-scenes-item:active {
    cursor: grabbing;
}

/* Style for the item being moved */
.sortable-ghost {
    opacity: 0.4;
    background-color: var(--col-2) !important;
}

.controlbar-scenes-item span {
    font-weight: bold;
    color: var(--col-1);
    background-color: var(--accent);
    width: 40px;
    height: 40px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.controlbar-panel {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.controlbar-panel label {
    font-size: var(--font-label);
    color: var(--col-4);
    margin-bottom: -10px;
}

.controlbar-panel input, .controlbar-panel select {
    color: var(--col-4);
    padding: 10px;
    border: 2px solid var(--col-4);
    border-radius: 5px;
    width: 100%;
    font-size: var(--font-normal);
    background-color: var(--main-background);
}

.controlbar-panel h4 {
    margin-top: 20px;
    font-size: var(--font-subtitle);
    color: var(--col-1);
}

.controlbar-panel button {
    padding: 8px 16px;
    cursor: pointer;
    background: var(--col-5);
    color: var(--col-1);
    border: none;
    border-radius: 4px;
    font-weight: bold;
    width: 100%;
    transition: all 0.3s ease;
}

.controlbar-panel button:hover {
    background-color: var(--col-2);
}

#switchspan {
    display: flex;
    justify-content: space-between;
}

#switchspan p {
    font-size: var(--font-normal);
    color: var(--col-4);
}

#sync-status-text {
    margin-top: -5px;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--col-2);
  transition: .4s;
  border-radius: 20px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: var(--col-1);
  transition: .4s;
  border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--accent);
}

input:checked + .slider:before {
    transform: translateX(14px);
}

.app-container { 
    display: flex; 
    flex-direction: column; 
    height: 100vh; 
    width: 100%;
    overflow: hidden; 
}

.main-viewport-top {
    flex: 1;
    display: flex;
    flex-direction: row;
    overflow: hidden;
}

.main-viewport { 
    flex: 1; /* This takes all space except for the controls and timeline */
    display: flex; 
    flex-direction: column; 
    min-height: 0; /* Important for inner scrolling */
}

.side-panel {
    width: 30vw;
    background: var(--main-background);
    padding: 15px;
    border-right: 1px solid var(--col-2);
    overflow-y: auto;
}

.side-panel input, .side-panel select {
    color: var(--col-4);
    padding: 10px;
    border: 2px solid var(--col-4);
    border-radius: 5px;
    width: 100%;
    font-size: var(--font-normal);
    background-color: var(--main-background);
}

.side-panel label {
    font-size: var(--font-label);
    color: var(--col-4);
    margin-bottom: -10px;
}

.control-btn {
    background: var(--accent);
    color: var(--col-1);
    padding: 10px; 
    border: none; 
    border-radius: 4px; 
    cursor: pointer; 
    font-weight: bold; 
    font-size: 12px; 
}

.option-group {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.track-option-btn {
    padding: 4px 12px;
    cursor: pointer;
    color: var(--col-1);
    border: none;
    border-radius: 4px;
    font-weight: bold;
    opacity: 0.8;
    transition: all 0.3s ease;
}

.track-option-btn:hover {
    opacity: 1;
    transition: all 0.3s ease;
}

.track-controls {
    display: flex;
    gap: 5px;
    margin-top: 10px;
}

.track-controls-img {
    width: 28px;
    height: 28px;
    border-radius: 5px;
    padding: 5px;
    transition: all 0.3s ease;
}

.track-controls-img:hover {
    background-color: var(--col-2);
    transition: all 0.3s ease;
    cursor: pointer;
}

.admin-panel {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px dashed var(--col-4);
}

.admin-panel h4 {
    font-size: 11px;
    color: var(--col-1);
    margin-bottom: 10px;
}

.admin-panel input, .admin-panel select {
    width: 100%;
    margin-bottom: 5px;
    background: var(--main-background);
    border: 2px solid var(--col-4);
    color: var(--col-1);
    padding: 5px;
    border-radius: 4px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 20px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.panel-section {
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.panel-section.active-inspector {
    background: var(--main-background);
}

.controls {
    display: flex;
    justify-content: space-between;
    padding: 10px;
    background: var(--main-background);
    border-top: 1px solid var(--col-2);
    border-bottom: 1px solid var(--col-2);
    z-index: 10;
}

.controls_left {
    display: flex;
    gap: 15px;
}

.controls-img {
    height: 35px;
    width: 35px;
    border-radius: 5px;
    padding: 5px;
    transition: all 0.3s ease;
}

.controls-img:hover {
    background-color: var(--col-2);
    transition: all 0.3s ease;
    cursor: pointer;
}

#scene-switcher-container select {
    color: var(--col-4);
    padding: 10px;
    border: 2px solid var(--col-4);
    border-radius: 5px;
    width: 100%;
    font-size: var(--font-normal);
    background-color: var(--main-background);
}

.controls_center {
    flex-shrink: 0;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

.track-row {
    cursor: grab;
    transition: transform 0.2s ease;
}

.track-row:active {
    cursor: grabbing;
}

.placeholder-player {
    display: flex;
    gap: 10px;
}

.video-preview {
    display: grid;
    /* This automatically creates as many columns as needed */
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    grid-auto-rows: 1fr; 
    gap: 10px;
    padding: 10px;
    background: var(--main-background);
    height: 400px; /* Or whatever fixed height fits your layout */
    width: 100%;
    box-sizing: border-box;
    overflow-y: auto; /* Scroll if there are too many tracks */
}

.track-slot {
    background: var(--main-background);
    position: relative;
    min-height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.track-slot video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.track-slot:has(video[src=""]) .preview-layer {
    background: repeating-linear-gradient(
      45deg,
      #111,
      #111 10px,
      #181818 10px,
      #181818 20px
    );
}

.slot-label {
    position: absolute;
    top: 5px;
    left: 5px;
    font-size: 10px;
    color: var(--col-4);
    text-transform: uppercase;
}

.preview-layer {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: var(--main-background);
}

.transport-bar {
    display: flex;
    gap: 10px;
}

/* Timeline Logic */
.timeline-container { 
    height: 350px; /* Adjust this to your preferred timeline height */
    flex-shrink: 0;
    background: var(--main-background);
    overflow: hidden;
}

.timeline-view {
    display: flex;
    height: 100%;
    overflow: hidden;
}

.sidebar-labels {
    width: var(--sidebar-width);
    flex-shrink: 0;
    z-index: 1000;
    background: var(--main-background);
    border-right: 1px solid var(--col-2);
}

.ruler-header {
    height: var(--ruler-height);
    background: var(--main-background);
    border-bottom: 1px solid var(--col-2);
    display: flex;
    align-items: center;
    padding-left: 15px;
    font-size: 11px;
    font-weight: bold;
    color: var(--col-4);
    position: absolute;
    width: inherit;
    z-index: 2;
}

.track-label {
    height: var(--row-height);
    display: flex;
    align-items: center;
    padding-left: 15px;
    border-bottom: 1px solid var(--col-2);
    transition: height 0.15s;
    justify-content: space-between;
    padding-right: 10px;
}

.track-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
}
.track-label.expanded { height: var(--row-height-expanded); }

.track-btn {
    background: var(--col-4);
    border: none;
    color: var(--col-1);
    padding: 4px 8px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 10px;
    margin-right: 4px;
}

.sort-controls {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sort-controls button {
    background: var(--col-3);
    border: 2px solid var(--col-4);
    color: var(--col-1);
    font-size: 8px;
    padding: 2px 4px;
    cursor: pointer;
    border-radius: 2px;
}

.sort-controls button:hover {
    background: var(--accent);
}

.track-btn.active-mute { background: #d32f2f; }
.track-btn.active-hide { background: #7b1fa2; }

.track-name-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mini-edit-btn { 
    background: transparent;
    border: none;
    cursor: pointer;
    opacity: 0.3;
    font-size: 12px;
    color: var(--col-1);
}

.track-label:hover .mini-edit-btn { opacity: 1; }

/* Moving Viewport Logic */
.timeline-viewport {
    flex-grow: 1;
    position: relative;
    overflow-x: hidden;
    overflow-y: auto;
    background: var(--main-background);
}

.timeline-viewport::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Opera */
}

.timeline-viewport {
  -ms-overflow-style: none; /* Edge, IE */
  scrollbar-width: none; /* Firefox */
}

.scrubber {
    position: absolute;
    left: 50%;
    top: 0;
    width: 2px;
    height: 100%;
    background: #ff4444;
    z-index: 100;
    pointer-events: none;
}

.scrubber::after {
    content: '';
    position: absolute;
    top: 0;
    left: -5px;
    width: 12px;
    height: 12px;
    background: #ff4444;
    clip-path: polygon(0% 0%, 100% 0%, 50% 100%);
}

#moving-canvas {
    position: absolute;
    top: var(--ruler-height);
    left: 0;
    min-height: calc(100% - var(--ruler-height));
    will-change: transform;
}

.ruler-tick {
    position: absolute;
    border-left: 2px solid var(--col-4);
    height: 12px;
    font-size: 10px;
    color: var(--col-4);
    bottom: 0;
    padding-left: 3px;
    pointer-events: none;
}

.time-ruler {
    position: relative;
    height: var(--ruler-height);
    background: var(--main-background);
    border-bottom: 1px solid var(--col-2);
    width: 50000px;
}

#time-ruler {
    height: var(--ruler-height);
    background: var(--main-background);
    border-bottom: 1px solid var(--col-2);
    position: sticky;
    top: 0;
    z-index: 50;
    width: 50000px;
}

#tracks-container {
    position: relative;
    width: 1000000px;
}

.track {
    height: var(--row-height);
    border-bottom: 1px solid var(--col-2);
    position: relative;
    transition: height 0.15s;
    display: flex;
    align-items: center;
}
.track.expanded { 
    height: var(--row-height-expanded); 
}

.track-content-wrapper {
    position: relative;
    height: 100%;
}

.block {
    position: absolute;
    height: 70%; 
    border-radius: 6px; 
    border-left: 2px solid rgba(0,0,0,0);
    border-right: 2px solid rgba(0,0,0,0);
    background-clip: padding-box;
    color: var(--col-1);
    font-size: 11px;
    display: flex;
    align-items: center;
    padding: 0 8px;
    cursor: pointer;
    box-sizing: border-box;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.1);
}

.block-content {
    display: flex;
    align-items: center;
    padding: 0 8px;
    height: 100%;
    overflow: hidden; /* Hide overflow */
    white-space: nowrap; /* Keep everything on one line */
    gap: 15px; /* The space gap you requested */
    margin: 0 10px;
    pointer-events: none;
}

.block-name {
    font-weight: bold;
    flex-shrink: 0; /* Don't let the name get squished */
}

.block-desc {
    font-weight: normal;
    opacity: 0.7;
    font-size: 0.9em;
    overflow: hidden;
    text-overflow: ellipsis; /* Adds '...' if words are cut off */
    flex-shrink: 1; /* Let the description shrink/disappear first */
}

.block:hover { filter: brightness(1.2); }
.block:active {
    outline: 2px solid var(--col-1);
    z-index: 100;
}
.track.expanded .block { height: 80%; }

/* Add a second resizer to the left */
.resizer-left {
    position: absolute;
    left: 0;
    top: 0;
    width: 8px;
    height: 100%;
    cursor: ew-resize;
    z-index: 10;
}
/* Existing resizer is on the right */
.resizer-right {
    position: absolute;
    right: 0;
    top: 0;
    width: 8px;
    height: 100%;
    cursor: ew-resize;
    z-index: 10;
}

/* --- CENTERED UNIFIED POPUP --- */
.context-menu {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%); /* Centers exactly in viewport */
    background: var(--main-background);
    border: none;
    padding: 20px;
    border-radius: 10px;
    z-index: 5000;
    box-shadow: 0 15px 40px rgba(0,0,0,0.6);
    width: 320px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

#menu-title { 
    font-size: 14px; 
    color: var(--main-background); 
    margin-bottom: 4px; 
    font-weight: bold; 
    text-align: center;
    border-bottom: 2px solid var(--col-4);
    padding-bottom: 10px;
}

.context-menu input, .context-menu select, .context-menu textarea { 
    width: 100%; 
    background: var(--main-background); 
    border: 2px solid var(--col-4); 
    color: var(--col-1); 
    padding: 10px; 
    border-radius: 4px; 
    font-size: 13px;
}

.context-menu label {
    font-size: var(--font-label);
    color: var(--col-4);
    margin-bottom: -10px;
}

/* Helper to hide options you can't edit */
.hide-field {
    display: none !important;
}

.menu-actions { 
    display: flex; 
    flex-direction: row; 
    justify-content: space-between;
    gap: 8px; 
    margin-top: 10px;
}

.menu-actions button { 
    flex: 1;
    padding: 10px; 
    border: none; 
    border-radius: 4px; 
    cursor: pointer; 
    font-weight: bold; 
    font-size: 12px; 
}

.save-btn {
    background: var(--accent);
    color: var(--col-1);
    padding: 10px; 
    border: none; 
    border-radius: 4px; 
    cursor: pointer; 
    font-weight: bold; 
    font-size: 12px; 
}
.delete-btn { 
    background: #d7000085 !important; 
    color: var(--col-1);
    transition: all 0.3s ease;
}
.delete-btn:hover {
    background: #d70000 !important;
    transition: all 0.3s ease;
}
.close-btn {
    background: var(--col-2);
    color: var(--col-1);
}

/* Optional: Dim background when popup is open */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0,0,0,0.5);
    z-index: 4999;
}


#pop-color {
    padding: 0;
}

.track-label-item {
    margin: 0; /* Remove margins for accurate drag math */
    padding: 10px;
    border-bottom: 2px solid var(--col-4); /* Use border for separation */
    cursor: grab;
}

.track-label-item.dragging {
    opacity: 0.4;
    background: var(--col-2);
    border: 2px solid var(--col-4);
}

/* Make sure the container doesn't collapse */
#labels-content {
    display: flex;
    flex-direction: column;
    min-height: 50px;
    overflow: hidden;
    margin-top: var(--ruler-height);
}