:root {
  --bg-dark: #07090e;
  --bg-panel: rgba(13, 20, 30, 0.75);
  --bg-panel-frosted: rgba(13, 20, 30, 0.85);
  --accent-orange: #FE7F2D;
  --accent-orange-glow: rgba(254, 127, 45, 0.25);
  --text-main: #EAECF0;
  --text-muted: rgba(234, 236, 240, 0.5);
  --panel-border: rgba(234, 236, 240, 0.08);
  --radius-lg: 14px;
  --radius-md: 8px;
  --radius-sm: 5px;
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body, html {
  width: 100%;
  height: 100%;
  background: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-sans);
  overflow: hidden;
  user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
}

/* SLEEK BAR DESIGN */
#appHeader {
  height: 52px;
  background: rgba(7, 9, 14, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 50;
  transition: opacity 0.3s ease;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand svg {
  color: var(--accent-orange);
}
.brand h1 {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-main);
}
.meta-status {
  display: flex;
  align-items: center;
  gap: 10px;
}
.meta-chip {
  background: rgba(234, 236, 240, 0.04);
  border: 1px solid var(--panel-border);
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}
.meta-chip.active {
  border-color: var(--accent-orange);
  color: var(--accent-orange);
  background: rgba(254, 127, 45, 0.06);
}

.btn-header {
  background: rgba(234, 236, 240, 0.06);
  border: 1px solid var(--panel-border);
  color: var(--text-main);
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  transition: all 0.2s ease;
}
.btn-header:hover {
  background: var(--accent-orange);
  border-color: var(--accent-orange);
  color: var(--bg-dark);
  box-shadow: 0 0 12px var(--accent-orange-glow);
}

/* DROP ZONE FOR MEDIA */
#dropzone {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  border: 2px dashed rgba(234, 236, 240, 0.15);
  margin: 30px;
  border-radius: var(--radius-lg);
  background: rgba(13, 20, 30, 0.4);
  backdrop-filter: blur(10px);
  transition: all 0.25s ease;
  cursor: pointer;
}
#dropzone:hover, #dropzone.drag {
  border-color: var(--accent-orange);
  background: rgba(254, 127, 45, 0.02);
}
#dropzone .icon-container {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(234, 236, 240, 0.02);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--panel-border);
  transition: transform 0.2s ease;
}
#dropzone:hover .icon-container {
  transform: scale(1.05);
  background: rgba(254, 127, 45, 0.08);
  border-color: var(--accent-orange);
}
#dropzone h2 {
  font-size: 18px;
  font-weight: 600;
  color: #fff;
}
#dropzone p {
  color: var(--text-muted);
  font-size: 12px;
  max-width: 400px;
  text-align: center;
  line-height: 1.5;
}
#fileInput { display: none; }

/* PLAYER STAGE CONTAINER */
#playerWrap {
  flex: 1;
  position: relative;
  display: none;
  background: var(--bg-dark);
  overflow: hidden;
  touch-action: none;
}
#stage {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: var(--bg-dark);
}

video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transform-origin: center center;
  z-index: 1;
}
#canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  z-index: 2;
}

/* HOT SWAP OVERLAYS */
#dragSwapOverlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(7, 9, 14, 0.95);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  z-index: 100;
  pointer-events: none;
  border: 3px dashed var(--accent-orange);
}
#dragSwapOverlay.active { display: flex; }
#dragSwapOverlay h3 {
  font-size: 20px;
  color: var(--accent-orange);
  margin-top: 12px;
}

#status {
  position: absolute;
  top: 20px;
  left: 20px;
  background: var(--bg-panel);
  border: 1px solid var(--panel-border);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  color: var(--text-main);
  display: none;
  z-index: 30;
  font-family: var(--font-mono);
}
#errBox {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(28, 16, 16, 0.95);
  border: 1px solid var(--accent-orange);
  padding: 20px 28px;
  border-radius: var(--radius-lg);
  display: none;
  z-index: 40;
  max-width: 440px;
  text-align: center;
}
#errBox h3 { color: var(--accent-orange); margin-bottom: 10px; font-size: 16px; }
#errBox p { font-size: 12px; color: #cbd5e1; line-height: 1.5; }

#toast {
  position: absolute;
  bottom: 120px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-panel);
  border: 1px solid var(--panel-border);
  color: #fff;
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, bottom 0.25s;
}
#toast.show { opacity: 1; bottom: 130px; }

/* COMPACT DASHBOARD CONSOLE */
#controls {
  position: absolute;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  bottom: 24px;
  width: calc(100% - 40px);
  max-width: 1120px;
  background: var(--bg-panel-frosted);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 12px 18px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.05);
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
}
#playerWrap.show-ui #controls {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, 0);
}

/* TIMELINE DECK */
#seekRow {
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
}
.timeline-wrapper {
  position: relative;
  flex: 1;
  height: 16px;
  display: flex;
  align-items: center;
}
#seek {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(234, 236, 240, 0.12);
  border-radius: 4px;
  cursor: pointer;
  outline: none;
  position: relative;
  z-index: 10;
  transition: all 0.2s ease;
}
#seek:hover {
  height: 6px;
}
#seek::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent-orange);
  border: 1.5px solid var(--text-main);
  transition: transform 0.1s ease;
}
#seek::-webkit-slider-thumb:hover {
  transform: scale(1.3);
}

#ab-track-highlight {
  position: absolute;
  height: 4px;
  background: rgba(254, 127, 45, 0.3);
  border: 1px solid var(--accent-orange);
  border-radius: 4px;
  z-index: 5;
  display: none;
  pointer-events: none;
}
.ab-marker {
  position: absolute;
  width: 6px;
  height: 12px;
  top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 1px;
  z-index: 15;
  pointer-events: none;
  display: none;
}
.marker-a { background: var(--accent-orange); }
.marker-b { background: var(--text-main); }

#curTime, #timeLbl {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-main);
}
#timeLbl {
  color: var(--text-muted);
  min-width: 90px;
  text-align: right;
}

/* DYNAMIC DRAWER CONFIGURATIONS */
#controlsDrawer {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s cubic-bezier(0.16, 1, 0.3, 1), padding 0.3s;
  border-bottom: 1px solid transparent;
  display: flex;
  flex-direction: column;
}
#controlsDrawer.open {
  max-height: 240px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--panel-border);
}
.drawer-panel {
  display: none;
  gap: 16px;
  flex-wrap: wrap;
  align-items: center;
  animation: panelFade 0.2s ease;
}
.drawer-panel.active {
  display: flex;
}
@keyframes panelFade {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel-item-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.panel-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}
.slider-val {
  font-family: var(--font-mono);
  color: var(--accent-orange);
  margin-left: 4px;
}
.fx-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100px;
  height: 4px;
  background: rgba(234, 236, 240, 0.12);
  border-radius: 2px;
  outline: none;
}
.fx-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-orange);
  cursor: pointer;
}

/* SYSTEM CONTROL ROW */
#controlsMainRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.main-row-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 180px;
}
.main-row-center {
  display: flex;
  align-items: center;
  gap: 4px;
}
.main-row-right {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
  min-width: 260px;
}

.ctrl-group {
  display: flex;
  align-items: center;
  gap: 3px;
  background: rgba(0, 0, 0, 0.2);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--panel-border);
}

.ctrlBtn {
  background: transparent;
  border: none;
  color: var(--text-main);
  cursor: pointer;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}
.ctrlBtn:hover {
  background: rgba(234, 236, 240, 0.05);
  color: var(--accent-orange);
}
.ctrlBtn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}
.ctrlBtn.active {
  background: var(--accent-orange);
  color: var(--bg-dark) !important;
}
.ctrlBtn.active-pink {
  background: var(--text-main);
  color: var(--bg-dark) !important;
}

.sep {
  width: 1px;
  height: 20px;
  background: var(--panel-border);
  margin: 0 2px;
}

/* SELECT ELEMENT MATRICES */
select {
  background: rgba(13, 20, 30, 0.9);
  color: var(--text-main);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s ease;
}
select:hover {
  border-color: var(--accent-orange);
}

.stretch-info {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  min-width: 32px;
  text-align: center;
}

/* FLOATING VOLUME METER */
#volWrap {
  display: flex;
  align-items: center;
  gap: 6px;
}
#vol {
  width: 50px;
  height: 3px;
  -webkit-appearance: none;
  background: rgba(234, 236, 240, 0.15);
  border-radius: 2px;
  outline: none;
}
#vol::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-orange);
  cursor: pointer;
}

/* COLLAPSIBLE TAB DIRECTIVES */
.drawer-toggles {
  display: flex;
  align-items: center;
  gap: 3px;
  background: rgba(0, 0, 0, 0.25);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--panel-border);
}
.drawer-toggle-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  transition: all 0.15s ease;
}
.drawer-toggle-btn:hover {
  color: var(--text-main);
  background: rgba(234, 236, 240, 0.04);
}
.drawer-toggle-btn.active {
  background: var(--accent-orange);
  color: var(--bg-dark) !important;
  box-shadow: 0 0 10px var(--accent-orange-glow);
}

#fileNameLbl {
  font-size: 10px;
  color: var(--text-muted);
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
  background: rgba(254, 127, 45, 0.05);
  border: 1px solid rgba(254, 127, 45, 0.15);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
}

#subtitleOverlay {
  position: absolute;
  bottom: 120px;
  left: 50%;
  transform: translateX(-50%);
  color: #ffffff;
  font-size: 18px;
  font-weight: 600;
  text-shadow: 0 2px 4px rgba(0,0,0,0.95), 0 0 10px rgba(0,0,0,0.5);
  background-color: rgba(13, 20, 30, 0.9);
  padding: 8px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--panel-border);
  text-align: center;
  pointer-events: none;
  z-index: 45;
  display: none;
  max-width: 80%;
  white-space: pre-wrap;
  transition: bottom 0.25s;
}
#playerWrap.show-ui #subtitleOverlay {
  bottom: 145px;
}

/* MODALS */
#helpModal {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  max-width: 520px;
  background: rgba(13, 20, 30, 0.96);
  border: 1px solid var(--panel-border);
  box-shadow: 0 20px 50px rgba(0,0,0,0.6);
  border-radius: var(--radius-lg);
  padding: 20px;
  z-index: 110;
  display: none;
  backdrop-filter: blur(15px);
}
#helpModal h3 {
  font-size: 16px;
  margin-bottom: 12px;
  color: var(--accent-orange);
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 8px;
}
.help-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  font-size: 11px;
}
.help-item {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  border-bottom: 1px solid rgba(234, 236, 240, 0.02);
}
.kbd {
  background: rgba(234, 236, 240, 0.08);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: var(--font-mono);
  color: var(--accent-orange);
  font-size: 10px;
}

.modal-close {
  background: var(--accent-orange);
  border: none;
  color: var(--bg-dark);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  margin-top: 14px;
  float: right;
}

*::-webkit-scrollbar { width: 5px; height: 5px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: rgba(234, 236, 240, 0.1); border-radius: 10px; }

/* OPTIMIZED RESPONSIVE LAYOUT FOR MOBILE SCREENS */
@media (max-width: 768px) {
  #controls {
    width: calc(100% - 16px);
    bottom: 8px;
    padding: 8px 12px;
  }
  #controlsMainRow {
    flex-direction: column;
    gap: 8px;
    align-items: stretch;
  }
  .main-row-left {
    justify-content: center;
    min-width: unset;
  }
  .main-row-center {
    justify-content: center;
  }
  .main-row-right {
    justify-content: center;
    min-width: unset;
    flex-wrap: wrap;
    gap: 8px;
  }
  #controlsDrawer.open {
    max-height: 320px;
    overflow-y: auto;
  }
  .drawer-panel {
    justify-content: center;
    gap: 12px;
  }
  .panel-item-group {
    align-items: center;
    text-align: center;
  }
  
  /* Thumb size expansion for high mobile usability */
  #seek::-webkit-slider-thumb {
    width: 20px;
    height: 20px;
  }
  #vol::-webkit-slider-thumb {
    width: 16px;
    height: 16px;
  }
  .ctrlBtn {
    width: 36px;
    height: 36px;
  }
  .ctrlBtn svg {
    width: 18px;
    height: 18px;
  }
  .drawer-toggle-btn {
    padding: 8px 12px;
    font-size: 12px;
  }
  #subtitleOverlay {
    font-size: 14px;
    padding: 6px 12px;
    bottom: 160px;
  }
  #playerWrap.show-ui #subtitleOverlay {
    bottom: 240px;
  }
  .help-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  #appHeader {
    padding: 0 10px;
  }
  .brand h1 {
    font-size: 12px;
  }
  .btn-header span {
    display: none; /* Keep icons only on small portrait layouts */
  }
  .btn-header {
    padding: 5px 8px;
  }
}