:root { 
  --panel: #0f1a2a; 
  --muted: rgba(255,255,255,0.65); 
  --accent: #7c5cff;
  --success: #4ade80;
  --danger: #ff6b6b;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', system-ui, Roboto, Arial, sans-serif;
  color: #e9eef8;
  background: linear-gradient(180deg, #051022, #07121a);
  overflow: hidden;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Header */
header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

/* Main Content Grid */
.content {
  display: grid;
  grid-template-columns: 420px 1fr 380px;
  gap: 12px;
  padding: 12px;
  flex: 1;
  overflow: hidden;
}

.panel {
  background: var(--panel);
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 6px 18px rgba(2,6,23,0.6);
  border: 1px solid rgba(255,255,255,0.02);
  overflow: auto;
  display: flex;
  flex-direction: column;
}

/* Buttons */
.controls {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

button.btn {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.2s;
}

button.btn:hover {
  background: #8c6cff;
  transform: translateY(-1px);
}

button.btn:active {
  transform: translateY(0);
}

button.ghost {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--muted);
}

button.ghost:hover {
  background: rgba(255,255,255,0.05);
  border-color: rgba(255,255,255,0.2);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Model Selection */
.model-select {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.model-select select {
  flex: 1;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(0,0,0,0.2);
  color: #fff;
}

/* Subtitle List */
.subtitle-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
}

.subtitle-list::-webkit-scrollbar {
  width: 8px;
}

.subtitle-list::-webkit-scrollbar-track {
  background: rgba(0,0,0,0.2);
  border-radius: 4px;
}

.subtitle-list::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 4px;
}

.subtitle-list::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.2);
}

.line {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.06);
  background: rgba(255,255,255,0.02);
  transition: all 0.2s;
  cursor: pointer;
}

.line:hover {
  background: rgba(255,255,255,0.05);
  border-color: rgba(255,255,255,0.1);
}

.line.selected {
  outline: 2px solid rgba(124,92,255,0.6);
  background: rgba(124,92,255,0.1);
}

.line-index {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  padding-top: 4px;
}

.line-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.line-row input[type="text"] {
  flex: 1;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(0,0,0,0.3);
  color: #fff;
  font-size: 14px;
  transition: all 0.2s;
}

.line-row input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(0,0,0,0.4);
}

.time-edit {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.time-edit > div {
  flex: 1;
}

.time-edit label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.time-edit input {
  width: 100%;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(0,0,0,0.3);
  color: #fff;
  font-size: 13px;
  font-family: 'Courier New', monospace;
}

.time-edit input:focus {
  outline: none;
  border-color: var(--accent);
}

/* Video Section */
.video-wrap {
  background: #000;
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  justify-content: center;
  flex: 1;
}

.video-container {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
}

video#preview {
  width: 100%;
  max-height: 60vh;
  background: #000;
  border-radius: 6px;
  display: block;
}

.video-controls {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: 8px;
}

/* Subtitle Overlay (Impact Pop Animation) */
#subtitleOverlay {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  text-align: center;
  pointer-events: none;
  font-family: 'Montserrat', sans-serif;
  font-weight: 800;
  display: none;
  z-index: 10;
}

#subtitleOverlay .layer {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  margin: auto;
  white-space: pre-wrap;
  word-break: break-word;
  transform-origin: center center;
  will-change: transform, opacity;
}

#subtitleOverlay .stroke {
  color: transparent;
  -webkit-text-stroke: 0;
  paint-order: stroke fill;
  --s: calc(var(--stroke-size, 2px));
  text-shadow:
    0 0 var(--s) var(--stroke-color, #000),
    var(--s) 0 var(--s) var(--stroke-color, #000),
    calc(-1 * var(--s)) 0 var(--s) var(--stroke-color, #000),
    0 var(--s) var(--s) var(--stroke-color, #000),
    0 calc(-1 * var(--s)) var(--s) var(--stroke-color, #000),
    var(--s) var(--s) var(--s) var(--stroke-color, #000),
    calc(-1 * var(--s)) var(--s) var(--s) var(--stroke-color, #000),
    var(--s) calc(-1 * var(--s)) var(--s) var(--stroke-color, #000),
    calc(-1 * var(--s)) calc(-1 * var(--s)) var(--s) var(--stroke-color, #000);
}

.fill {
  color: #fff;
}

/* Impact Pop Animation */
#subtitleOverlay.anim-start .layer {
  transform: scale(0.92);
  opacity: 1;
  transition: none;
}

#subtitleOverlay.anim-in .layer {
  transform: scale(1);
  opacity: 1;
  transition: transform 0.4s cubic-bezier(0.05, 0.95, 0.15, 1);
}

/* ==========================================
   Draggable Caption Positioning
   ========================================== */

/* Make overlay interactive when visible */
#subtitleOverlay.draggable {
  pointer-events: auto;
  cursor: grab;
}

#subtitleOverlay.draggable:active {
  cursor: grabbing;
}

/* Selection box around caption when clicked */
#subtitleOverlay.selected {
  outline: 2px dashed rgba(124, 92, 255, 0.8);
  outline-offset: 8px;
  border-radius: 4px;
}

/* Snap guide lines */
.snap-guide {
  position: absolute;
  z-index: 20;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.snap-guide.visible {
  opacity: 1;
}

.snap-guide-v {
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(124, 92, 255, 0.6);
  transform: translateX(-0.5px);
}

.snap-guide-h {
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: rgba(124, 92, 255, 0.6);
  transform: translateY(-0.5px);
}

/* Ensure video container is the positioning reference */
.video-container {
  position: relative;
}

/* Style Controls */
.style-group {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.style-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.slider-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.slider-group input[type="range"] {
  flex: 1;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: rgba(255,255,255,0.1);
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  transition: all 0.2s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  background: #8c6cff;
  transform: scale(1.1);
}

input[type="color"] {
  width: 100%;
  height: 40px;
  padding: 4px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
  background: transparent;
  cursor: pointer;
}

select {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(0,0,0,0.2);
  color: #fff;
  cursor: pointer;
}

.value-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  min-width: 35px;
  text-align: right;
}

/* Export Section */
.export-section {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.export-btn {
  width: 100%;
  padding: 14px;
  font-size: 15px;
  background: var(--success);
}

.export-btn:hover {
  background: #22c55e;
}

.export-btn:disabled {
  background: rgba(74, 222, 128, 0.3);
}

/* Progress Bar */
.progress-bar {
  width: 100%;
  height: 32px;
  background: rgba(0,0,0,0.3);
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  margin-top: 12px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #8c6cff);
  transition: width 0.3s ease;
  width: 0%;
}

.progress-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

/* Footer */
footer {
  padding: 10px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  border-top: 1px solid rgba(255,255,255,0.05);
  font-size: 12px;
}

/* Overlay (for generation progress) */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(5,16,34,0.95);
  backdrop-filter: blur(10px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlay-content {
  background: var(--panel);
  padding: 40px;
  border-radius: 16px;
  width: 500px;
  max-width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.1);
}

.overlay-content h2 {
  margin: 0 0 24px 0;
  text-align: center;
  font-size: 24px;
}

/* Utility */
.small {
  font-size: 13px;
  color: var(--muted);
}

.error {
  color: var(--danger);
  font-weight: 600;
}

.success {
  color: var(--success);
  font-weight: 600;
}

code {
  background: rgba(255,255,255,0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 12px;
}