:root {
  --bg-dark: #0f0f0f;
  --bg-panel: #181818;
  --bg-panel-alt: #222222;
  --border-color: #333333;
  --accent: #7c4dff;
  --accent-hover: #9575cd;
  --text-main: #e0e0e0;
  --text-dim: #a0a0a0;
  --sidebar-width: 72px;
  --inspector-width: 320px;
  --timeline-height: 280px;
  --header-height: 48px;
  --transition-speed: 0.2s;
}

body.light-mode {
  --bg-dark: #f0f0f0;
  --bg-panel: #ffffff;
  --bg-panel-alt: #f5f5f5;
  --border-color: #e0e0e0;
  --accent: #6200ea;
  --accent-hover: #7c4dff;
  --text-main: #212121;
  --text-dim: #757575;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: "Lexend", sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  user-select: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  transition: all var(--transition-speed);
}

.editor-root {
  display: grid;
  grid-template-areas:
    "header header header"
    "sidebar main inspector"
    "sidebar timeline inspector";
  grid-template-columns: var(--sidebar-width) 1fr var(--inspector-width);
  grid-template-rows: var(--header-height) 1fr var(--timeline-height);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

.mobile-toolbar {
  display: none;
}

header {
  grid-area: header;
  background-color: var(--bg-panel);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  z-index: 100;
  width: 100%;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-family: "Archivo Black", sans-serif;
  font-size: 1.1rem;
  letter-spacing: 1px;
  flex-shrink: 0;
}

.brand .accent {
  color: var(--accent);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.file-info {
  font-size: 0.75rem;
  color: var(--text-dim);
  background: var(--bg-panel-alt);
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 768px) {
  .file-info,
  header .primary-btn {
    display: none;
  }
}

.sidebar-left {
  grid-area: sidebar;
  background-color: var(--bg-panel);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem 0;
  gap: 1.5rem;
}

.tool-btn {
  width: 48px;
  height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 0.65rem;
  gap: 4px;
}

.tool-btn svg {
  width: 24px;
  height: 24px;
}

.tool-btn:hover,
.tool-btn.active {
  color: var(--text-main);
  background: var(--bg-panel-alt);
}

.tool-btn.active {
  color: var(--accent);
}

.main-content {
  grid-area: main;
  background-color: var(--bg-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow: hidden;
}

.preview-container {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  background: #000;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  border-radius: 4px;
  overflow: hidden;
}

video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.preview-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.2);
  opacity: 0;
  transition: opacity 0.2s;
  cursor: pointer;
}

.preview-overlay:hover {
  opacity: 1;
}

.play-pause-overlay {
  width: 64px;
  height: 64px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(4px);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.inspector {
  grid-area: inspector;
  background-color: var(--bg-panel);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.inspector-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.inspector-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.segment-card {
  background: var(--bg-panel-alt);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
  transition: border-color 0.2s;
}

.segment-card:hover {
  border-color: var(--accent);
}

.segment-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.segment-name {
  font-size: 0.85rem;
  font-weight: 600;
}

.segment-time-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.time-input-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.time-input-group label {
  font-size: 0.65rem;
  color: var(--text-dim);
  text-transform: uppercase;
}

.time-input-group input {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.8rem;
  width: 100%;
}

.segment-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.small-btn {
  padding: 0.25rem 0.5rem;
  font-size: 0.7rem;
  border-radius: 4px;
  background: var(--bg-dark);
}

.delete-btn {
  color: #ff5252;
}

.delete-btn:hover {
  background: rgba(255, 82, 82, 0.1);
}

@media (max-width: 768px) {
  html,
  body {
    overflow-x: hidden;
    width: 100%;
    position: relative;
  }
}

.timeline-area {
  grid-area: timeline;
  background-color: var(--bg-panel);
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.timeline-toolbar {
  height: 44px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  width: 100%;
  box-sizing: border-box;
  flex-wrap: nowrap;
}

@media (max-width: 480px) {
  .timeline-toolbar {
    gap: 0.5rem;
  }
  .time-display {
    font-size: 0.8rem;
  }
}

.time-display {
  font-family: monospace;
  font-size: 0.9rem;
  color: var(--accent);
  letter-spacing: 1px;
  flex-shrink: 0;
}

.timeline-controls {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-shrink: 0;
}

.timeline-action-btn {
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  white-space: nowrap;
}

.timeline-action-btn:hover {
  color: var(--text-main);
}

.timeline-action-btn.primary {
  color: var(--accent);
}

.timeline-view {
  flex: 1;
  position: relative;
  overflow-x: hidden;
  overflow-y: hidden;
  background-image:
    linear-gradient(var(--border-color) 1px, transparent 1px),
    linear-gradient(90deg, var(--border-color) 1px, transparent 1px);
  background-size:
    100px 40px,
    100px 40px;
  -webkit-overflow-scrolling: touch;
}

.timeline-view:active {
  cursor: default;
}

.timeline-ruler,
.timeline-track {
  width: 100% !important;
  min-width: 100%;
  position: relative;
}

.timeline-ruler {
  height: 24px;
  background: var(--bg-panel-alt);
  border-bottom: 1px solid var(--border-color);
}

.timeline-track {
  height: 60px;
  margin: 10px 0;
  background: rgba(255, 255, 255, 0.03);
}

.clip-block {
  position: absolute;
  height: 40px;
  top: 10px;
  background: var(--accent);
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  padding: 0 0.5rem;
  font-size: 0.7rem;
  color: white;
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  z-index: 5;
}

.clip-block.selected {
  outline: 2px solid white;
  box-shadow: 0 0 15px rgba(255, 255, 255, 0.5);
  z-index: 10;
}

.playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #ff5252;
  z-index: 50;
  pointer-events: none;
}

.playhead::after {
  content: "";
  position: absolute;
  top: 0;
  left: -5px;
  width: 12px;
  height: 12px;
  background: #ff5252;
  clip-path: polygon(0% 0%, 100% 0%, 50% 100%);
  z-index: 51;
}

.timeline-scrubber {
  position: absolute;
  top: 24px;
  left: 0;
  height: 80px;
  z-index: 20;
  opacity: 0;
  cursor: pointer;
  -webkit-appearance: none;
  background: transparent;
  width: 100%;
}

.primary-btn {
  background: var(--accent);
  color: white;
  padding: 0.6rem 1.2rem;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.85rem;
}

.primary-btn:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.primary-btn:disabled {
  background: var(--bg-panel-alt);
  color: var(--text-dim);
  cursor: not-allowed;
  transform: none;
}

.icon-btn-circle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  flex-shrink: 0;
}

.icon-btn-circle:hover {
  background: var(--bg-panel-alt);
  color: var(--text-main);
}

.empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  text-align: center;
  padding: 2rem;
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 1rem;
  opacity: 0.3;
}

@media (max-width: 1024px) {
  .editor-root {
    grid-template-columns: var(--sidebar-width) 1fr 240px;
  }
}

@media (max-width: 768px) {
  .editor-root {
    grid-template-areas:
      "header"
      "main"
      "timeline"
      "toolbar";
    grid-template-columns: 1fr;
    grid-template-rows: var(--header-height) 1.2fr 1fr 64px;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
  }

  .sidebar-left,
  .inspector {
    display: none;
  }

  .mobile-toolbar {
    grid-area: toolbar;
    background: var(--bg-panel);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-around;
    align-items: center;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 64px;
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 1000;
  }

  .timeline-area {
    height: auto;
    flex-grow: 1;
  }
}

.loader-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-dark);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.loader-content {
  text-align: center;
  max-width: 400px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--bg-panel-alt);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 1.5rem;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.progress-container {
  width: 100%;
  height: 6px;
  background: var(--bg-panel-alt);
  border-radius: 3px;
  overflow: hidden;
  margin: 1.5rem 0;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s;
}

.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translate(-50%, 100px);
  background: var(--bg-panel);
  color: var(--text-main);
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  transition: transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
  z-index: 3000;
  font-size: 0.9rem;
}

.toast.show {
  transform: translate(-50%, 0);
}
