:root {
  --bg: #1c1d1f;
  --panel: #26282b;
  --canvas: #111214;
  --ink: #ececec;
  --muted: #b4b8be;
  --faint: #8b9098;
  --line: #3a3d42;
  --line-strong: #52565c;
  --accent: #6fbf2a;
  --accent-hover: #5ea621;
  --accent-soft: #2c3a1e;
  --clip: #d4b12a;
  --clip-text: #1c1a0a;
  --clip-active: #f0d24a;
  --ok: #7dcea0;
  --danger: #e07a72;
  --danger-soft: #3a2220;
  --warn: #e0c36a;
  --warn-soft: #3a3318;
  --shadow: none;
  --sans: "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  --mono: Consolas, "Cascadia Mono", monospace;
  --radius: 6px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.4;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.brand {
  display: flex;
  flex-direction: column;
  margin-right: 8px;
}

h1 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 650;
}

.version {
  color: var(--faint);
  font-size: 11px;
}

.pills {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

.pill {
  border: 1px solid var(--line);
  background: #1c1d1f;
  color: var(--muted);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
}

.pill[data-kind="webgpu"] {
  color: var(--ok);
  border-color: #355c45;
}

.pill[data-kind="wasm"] {
  color: #9ec0e0;
}

.file-meta {
  margin: 0;
  max-width: 220px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-meta:empty {
  display: none;
}

.inline-field {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.inline-field span {
  white-space: nowrap;
}

.toolbar-status {
  min-width: 160px;
  flex: 1 1 160px;
}

#status {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.toolbar-export {
  display: flex;
  gap: 6px;
}

.stage {
  flex: 1 1 auto;
  min-height: 160px;
  padding: 12px 14px 8px;
  background: var(--bg);
}

.canvas {
  position: relative;
  display: grid;
  place-items: center;
  height: 100%;
  min-height: 220px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--canvas);
  cursor: pointer;
}

.canvas.has-file {
  cursor: default;
}

.canvas-empty {
  padding: 24px;
  text-align: center;
}

.canvas.has-file .canvas-empty {
  display: none;
}

.drop-title {
  margin: 0 0 6px;
  font-size: 1.05rem;
  font-weight: 650;
}

.drop-sub,
.hint {
  margin: 0;
  color: var(--faint);
  font-size: 13px;
}

.canvas:hover:not(.has-file),
.canvas.is-dragover {
  border-color: var(--accent);
  outline: none;
}

.canvas.is-disabled {
  pointer-events: none;
  opacity: 0.6;
}

#file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.player {
  position: absolute;
  inset: 0;
  background: #000;
}

.player video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  background: #000;
  pointer-events: none;
}

.subtitle-overlay {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 88%;
  max-width: 90%;
  padding: 5px 10px;
  border-radius: 5px;
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
  text-shadow: 0 1px 2px #000, 0 0 8px #000;
  background: rgba(0, 0, 0, 0.55);
  transform: translate(-50%, -100%);
  pointer-events: none;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  user-select: none;
  touch-action: none;
}

.subtitle-overlay:not(.is-empty) {
  pointer-events: auto;
  cursor: grab;
}

.subtitle-overlay.is-dragging {
  cursor: grabbing;
}

.subtitle-overlay.is-nowrap {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  overflow-wrap: normal;
  word-break: normal;
}

.subtitle-overlay.is-empty {
  padding: 0;
  background: transparent !important;
  text-shadow: none;
  pointer-events: none;
}

.transport {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}

.play-btn {
  min-width: 72px;
  background: var(--accent);
  color: #132006;
  font-weight: 750;
}

.play-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.clock {
  min-width: 92px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 13px;
}

.style-panel {
  position: relative;
  margin-left: auto;
}

.style-panel summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.style-grid {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  z-index: 8;
  display: grid;
  grid-template-columns: repeat(2, minmax(140px, 1fr));
  gap: 10px 12px;
  width: min(420px, 90vw);
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #303338;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

.style-grid input[type="range"],
.style-grid input[type="color"] {
  width: 100%;
  height: 28px;
  padding: 0;
  border: 0;
  background: transparent;
}

.style-grid input[type="color"] {
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #1c1d1f;
}

.style-checks {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  grid-column: 1 / -1;
}

.check {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
}

.check input {
  width: auto;
}

.field label,
label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

select,
.mono,
.inspector-text textarea,
.cue-times input,
.cue textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #1c1d1f;
  color: var(--ink);
  border-radius: 6px;
  padding: 7px 10px;
  font: inherit;
}

.mono {
  width: 118px;
  font-family: var(--mono);
  font-size: 12px;
}

select {
  appearance: none;
  width: 150px;
  background: #1c1d1f
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath fill='%23b4b8be' d='M0 0l6 8 6-8z'/%3E%3C/svg%3E")
    no-repeat right 10px center;
  padding-right: 30px;
}

select:focus,
.mono:focus,
textarea:focus,
button:focus-visible {
  outline: 2px solid #6f8f3a;
  border-color: var(--accent);
}

button {
  font: inherit;
  border: 0;
  border-radius: 6px;
  padding: 7px 12px;
  cursor: pointer;
}

#generate-btn,
#export-video {
  background: var(--accent);
  color: #132006;
  font-weight: 750;
}

#generate-btn:hover:not(:disabled),
#export-video:hover:not(:disabled) {
  background: var(--accent-hover);
}

#generate-btn:disabled,
#export-video:disabled,
#play-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ghost {
  background: #1c1d1f;
  color: var(--ink);
  border: 1px solid var(--line-strong);
}

.ghost:hover {
  background: #32353a;
}

.progress {
  margin-top: 4px;
}

.progress-track {
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: #3a3d42;
}

.progress-fill {
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 0.2s ease-out;
}

#progress-label {
  display: block;
  margin-top: 3px;
  color: var(--faint);
  font-size: 11px;
}

.error,
.warning {
  margin: 0;
  padding: 8px 12px;
  font-size: 13px;
}

.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.warning {
  background: var(--warn-soft);
  color: var(--warn);
}

.timeline-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 12px 12px;
  background: #222428;
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}

.inspector {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px 10px;
}

.inspector-text {
  flex: 1 1 240px;
  margin: 0;
}

.inspector-text textarea {
  width: 100%;
  min-height: 52px;
  resize: vertical;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.inspector-hint {
  flex: 1 1 100%;
  margin: 0;
}

.cue-remove {
  background: #1c1d1f;
  color: var(--danger);
  border: 1px solid #6a3a36;
  padding: 7px 10px;
}

.cue-remove:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.timeline {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #1a1b1d;
}

.timeline-ruler {
  position: relative;
  height: 22px;
  border-bottom: 1px solid var(--line);
  background: #202226;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 10px;
}

.ruler-tick {
  position: absolute;
  top: 0;
  height: 100%;
  padding-left: 4px;
  border-left: 1px solid #3f4349;
  line-height: 22px;
  white-space: nowrap;
}

.timeline-track {
  display: grid;
  grid-template-columns: 76px 1fr;
  min-height: 56px;
}

.track-label {
  display: flex;
  align-items: center;
  padding: 0 8px;
  border-right: 1px solid var(--line);
  background: #25272b;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.timeline-body {
  position: relative;
  min-height: 56px;
  overflow: hidden;
  background: repeating-linear-gradient(
    to right,
    #1a1b1d 0,
    #1a1b1d calc(12.5% - 1px),
    #23252a calc(12.5% - 1px),
    #23252a 12.5%
  );
}

.timeline-clips {
  position: absolute;
  inset: 8px 0;
}

.tl-clip {
  position: absolute;
  top: 0;
  display: flex;
  align-items: stretch;
  height: 40px;
  overflow: hidden;
  border: 1px solid #8d7618;
  border-radius: 3px;
  background: var(--clip);
  color: var(--clip-text);
  font-size: 11px;
  font-weight: 650;
  padding: 0;
  cursor: grab;
  touch-action: none;
}

.tl-clip.is-active {
  background: var(--clip-active);
  box-shadow: 0 0 0 2px #fff6;
}

.tl-clip.is-dragging {
  cursor: grabbing;
  z-index: 2;
}

.tl-label {
  flex: 1 1 auto;
  overflow: hidden;
  padding: 0 6px;
  line-height: 38px;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

.tl-handle {
  flex: 0 0 8px;
  cursor: ew-resize;
  background: rgba(0, 0, 0, 0.18);
}

.empty {
  margin: 0;
  padding: 16px;
  color: var(--faint);
  font-size: 12px;
}

.playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 3;
  width: 2px;
  margin-left: -1px;
  background: var(--accent);
  pointer-events: none;
}

.playhead::before {
  content: "";
  position: absolute;
  top: -1px;
  left: -5px;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 8px solid var(--accent);
}

@media (max-width: 900px) {
  .stage {
    min-height: 180px;
  }

  .pills,
  .style-panel {
    margin-left: 0;
  }

  .style-grid {
    position: static;
    width: 100%;
  }
}
