:root {
  --bg-dark: #121212;
  --bg-panel: #1e1e1e;
  --text-main: #e0e0e0;
  --accent: #2196f3;
  --fencer-left: #d32f2f;
  --fencer-right: #388e3c;
}

body {
  margin: 0;
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: 'Segoe UI', sans-serif;
  height: 100vh;
  overflow: hidden;
}

.app-container {
  display: grid;
  height: 100%;
  grid-template-rows: 50px 1fr 120px 80px; 
  grid-template-columns: 1fr;
}

/* HEADER */
.top-bar {
  background-color: var(--bg-panel);
  border-bottom: 1px solid #333;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}
.brand { font-weight: 700; color: var(--accent); letter-spacing: 1px; }
.file-controls button {
  background: #333; border: 1px solid #444; color: white;
  padding: 6px 12px; border-radius: 4px; cursor: pointer; margin-left: 10px;
}

/* MAIN STAGE */
.main-stage-flex {
  display: flex;
  height: 100%;
  background: black;
  overflow: hidden;
}

.sidebar-left, .sidebar-right {
  background: #181818;
  border-right: 1px solid #333;
  border-left: 1px solid #333;
  display: flex; flex-direction: column; padding: 10px;
  z-index: 20;
}
.sidebar-left { width: 50px; align-items: center; }
.sidebar-right { width: 250px; background: #1e1e1e; }

/* VIDEO AREA (Layout Engine Targets) */
.video-center {
  flex: 1;
  background: black;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 20px;
  overflow: hidden;
}

#videoWrapper {
  position: relative;
  box-shadow: 0 0 30px rgba(0,0,0,0.5);
  /* Dimensions set by JS */
}

/* LAYER STACKING: Video Bottom, Canvas Top */
#mainVideo {
  display: block;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0; left: 0;
  z-index: 1;
}

/* Target Fabric's wrapper div explicitly */
.canvas-container {
  position: absolute !important;
  top: 0; left: 0;
  width: 100% !important;
  height: 100% !important;
  z-index: 10;
}

/* TOOLS */
.tools-container { display: flex; flex-direction: column; gap: 15px; margin-top: 20px; }
.tool-btn {
  width: 40px; height: 40px; background: #333; border: 1px solid #444;
  border-radius: 6px; cursor: pointer; font-size: 1.2rem;
}
.tool-btn.active { background: var(--accent); border-color: var(--accent); }
.color-picker-wrapper input { width: 40px; height: 30px; border: none; background: none; }

/* RIGHT PANEL & PLAYLIST */
.panel-box { margin-bottom: 20px; }
.panel-label { font-size: 0.75rem; color: #888; font-weight: bold; margin-bottom: 8px; }

.score-display {
  display: flex; justify-content: space-between; align-items: center;
  background: #000; padding: 10px; border-radius: 6px; border: 1px solid #333;
}
.score-digit { font-size: 2rem; font-weight: 700; font-family: monospace; }
.score-digit.left { color: var(--fencer-left); }
.score-digit.right { color: var(--fencer-right); }

/* Playlist Styling Updates */
.playlist-controls .btn-small { width: 100%; padding: 5px; cursor: pointer; }

.playlist-list { 
  list-style: none; 
  padding: 5px; 
  margin: 10px 0 0 0; 
  max-height: 200px; 
  min-height: 50px; /* Ensure drop target exists when empty */
  overflow-y: auto; 
  border: 2px solid transparent; /* Reserve space for border */
  border-radius: 4px;
  transition: all 0.2s;
}

/* Only the list gets the highlight now */
.playlist-list.highlight {
  border-color: var(--accent);
  background: rgba(33, 150, 243, 0.1);
}

.playlist-item {
  padding: 8px; background: #252525; margin-bottom: 4px; font-size: 0.85rem; cursor: grab;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-left: 3px solid transparent;
}
.playlist-item.active { background: #333; border-left-color: var(--accent); }
.playlist-item.missing { color: #d32f2f; }
.playlist-item.dragging { opacity: 0.5; background: #444; }


/* TIMELINE & FOOTER */
.timeline-area {
  background: #181818; border-top: 1px solid #333; border-bottom: 1px solid #333;
  position: relative; height: 100%; width: 100%;
}
#visualization { width: 100%; height: 100%; }

/* Vis.js overrides */
.vis-item.vis-range { border-radius: 2px; font-size: 10px; opacity: 0.8; }
.vis-item.type-annotation { background-color: rgba(255, 235, 59, 0.4); border-color: #fbc02d; color: #fff; }
.vis-item.type-annotation.vis-selected { background-color: rgba(255, 235, 59, 0.7); border-color: white; }
.vis-item.type-video-bg { background-color: #333; border-color: #555; color: #888; font-size: 10px; z-index: -1; }
.vis-item.type-left { background-color: var(--fencer-left); border-color: var(--fencer-left); color: white; }
.vis-item.type-right { background-color: var(--fencer-right); border-color: var(--fencer-right); color: white; }
.vis-item.type-double { background-color: #2196f3; border-color: #2196f3; color: white; }

.controls-deck {
  background: var(--bg-panel); display: flex; justify-content: space-between; align-items: center; padding: 0 30px;
}
.group-fencer { display: flex; gap: 10px; }
.btn-touch { padding: 10px 20px; font-weight: bold; border: none; border-radius: 4px; color: white; cursor: pointer; }
.btn-touch.red { background: var(--fencer-left); }
.btn-touch.green { background: var(--fencer-right); }
.group-transport { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.jog-controls { display: flex; gap: 15px; align-items: center; }
.btn-play { font-size: 1.2rem; width: 40px; height: 40px; border-radius: 50%; border: none; cursor: pointer; }