:root {
  /* Color System - Modern Slate & Indigo */
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-soft: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: #eff6ff;
  
  --success: #10b981;
  --success-soft: #ecfdf5;
  --danger: #ef4444;
  --danger-soft: #fef2f2;
  --warning: #f59e0b;
  --warning-soft: #fffbeb;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
  color-scheme: light;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font: inherit;
}

button, a {
  -webkit-tap-highlight-color: transparent;
}

/* Header Navbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: 0 32px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(12px);
}

.brand {
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  text-decoration: none;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.system-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.state-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
}

.system-state.ready .state-dot {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.system-state.error .state-dot {
  background: var(--danger);
}

/* Main Area */
main {
  width: min(1200px, calc(100% - 48px));
  margin: 0 auto;
  padding: 32px 0 64px;
}

.workspace {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow 0.2s ease;
}

.workspace-heading,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.workspace-heading {
  padding: 24px 28px 16px;
}

h1, h2, p {
  margin: 0;
}

h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

#uploadHint {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

/* Upload Drop Zone */
.drop-zone {
  display: flex;
  min-height: 200px;
  margin: 0 28px 24px;
  padding: 32px 20px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface-soft);
  cursor: pointer;
  transition: all 0.2s ease-in-out;
}

.drop-zone:hover,
.drop-zone:focus-within,
.drop-zone.dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-2px);
}

.drop-zone strong {
  font-size: 16px;
  font-weight: 600;
}

.drop-zone > span:last-child {
  color: var(--muted);
  font-size: 13px;
}

.upload-symbol {
  display: grid;
  width: 52px;
  height: 52px;
  margin-bottom: 4px;
  place-items: center;
  border-radius: 50%;
  color: var(--accent);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 22px;
  font-weight: 700;
  transition: transform 0.2s ease;
}

.drop-zone:hover .upload-symbol {
  transform: translateY(-3px);
}

/* Buttons */
.button {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  padding: 6px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: #ffffff;
  background: var(--accent);
  text-decoration: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: all 0.15s ease;
  box-shadow: var(--shadow-sm);
}

.button:hover {
  background: var(--accent-strong);
  box-shadow: var(--shadow);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  box-shadow: none;
}

.button-secondary {
  border-color: var(--border);
  color: var(--text);
  background: var(--surface);
}

.button-secondary:hover {
  border-color: var(--border-strong);
  background: var(--surface-soft);
}

.button-danger {
  border-color: transparent;
  color: var(--danger);
  background: var(--danger-soft);
}

.button-danger:hover {
  color: #ffffff;
  background: var(--danger);
}

.button-quiet {
  min-height: 32px;
  padding: 4px 10px;
  color: var(--muted);
  background: transparent;
  box-shadow: none;
}

.button-quiet:hover {
  color: var(--text);
  background: var(--surface-soft);
}

/* Sections & Cards */
.jobs-section {
  margin-top: 36px;
}

.section-heading {
  margin-bottom: 16px;
}

.section-heading-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.jobs-list {
  display: grid;
  gap: 16px;
}

.job-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.job-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow);
}

.job-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 20px;
  padding: 18px 20px;
}

.job-summary {
  display: flex;
  min-width: 0;
  align-items: flex-start;
  gap: 14px;
}

.job-summary-content {
  min-width: 0;
  flex: 1 1 auto;
}

/* FROZEN COVER UI: do not change this width or 9:16 ratio. */
.job-source-thumbnail {
  width: 32px;
  flex: 0 0 32px;
  aspect-ratio: 9 / 16;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  object-fit: cover;
}

.job-title-row {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

.job-name {
  overflow: hidden;
  font-weight: 600;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-badge {
  flex: 0 0 auto;
  padding: 2px 8px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 12px;
  font-weight: 500;
}

.status-badge.converting,
.status-badge.queued,
.status-badge.uploading {
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.status-badge.completed {
  color: var(--success);
  background: var(--success-soft);
}

.status-badge.failed {
  color: var(--danger);
  background: var(--danger-soft);
}

.job-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.progress-track {
  height: 6px;
  margin-top: 14px;
  border-radius: 999px;
  background: var(--surface-soft);
  overflow: hidden;
}

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

.job-card.failed .progress-bar { background: var(--danger); }
.job-card.completed .progress-bar { background: var(--success); }

.job-stage {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.job-error {
  display: none;
  max-height: 90px;
  margin-top: 8px;
  padding: 8px 12px;
  overflow: auto;
  border-radius: var(--radius-sm);
  color: var(--danger);
  background: var(--danger-soft);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
  white-space: pre-wrap;
}

.job-error.visible { display: block; }

.job-actions {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.result-panel {
  display: none;
}

.result-panel.visible {
  display: grid;
  grid-template-columns: minmax(60px, 87px) minmax(0, 1fr);
  align-items: start;
  gap: 12px 18px;
  padding: 16px 20px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-soft);
}

/* FROZEN COVER UI: do not change this width or 9:16 ratio. */
.video-poster {
  position: relative;
  display: block;
  width: 87px;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #e2e8f0;
  cursor: pointer;
  justify-self: start;
  aspect-ratio: 9 / 16;
}

.video-poster img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s ease;
}

.video-poster:hover img {
  transform: scale(1.025);
}

.video-poster-play {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  color: #ffffff;
  background: rgba(15, 23, 42, 0.78);
  font-size: 12px;
  font-weight: 600;
  backdrop-filter: blur(4px);
}

.compact-job-actions {
  display: flex;
  min-width: 0;
  flex-wrap: wrap;
  gap: 8px;
}

.share-panel {
  display: grid;
  min-width: 0;
  gap: 12px;
  grid-column: 2;
  grid-row: 1 / span 2;
}

.share-panel-heading {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.share-panel-heading strong,
.share-address-group > strong {
  font-size: 13px;
  font-weight: 700;
}

.share-state {
  flex: 0 0 auto;
  padding: 2px 8px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface);
  font-size: 11px;
  font-weight: 600;
}

.share-state.enabled {
  color: var(--success);
  background: var(--success-soft);
}

.share-disabled-panel {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.share-disabled-text {
  color: var(--muted);
  font-size: 12px;
}

.share-address-group {
  display: grid;
  min-width: 0;
  gap: 8px;
}

.share-address-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  min-width: 0;
  align-items: end;
  gap: 8px;
}

.share-address-info {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.share-address-info > strong {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.manifest-url {
  width: 100%;
  min-width: 0;
  min-height: 34px;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  background: var(--surface);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 11px;
  outline: none;
}

.manifest-url:focus {
  border-color: var(--accent);
}

.share-show-all {
  justify-self: start;
}

.share-panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.share-modal-list {
  display: grid;
  gap: 10px;
}

.empty-state {
  display: flex;
  min-height: 200px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--surface);
}

.empty-state.hidden { display: none; }

.empty-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 50%;
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 12px;
  font-weight: 700;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 50;
  max-width: min(380px, calc(100% - 48px));
  padding: 12px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: #ffffff;
  background: #0f172a;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 760px) {
  .topbar { padding: 0 16px; }
  main { width: min(100% - 24px, 1200px); padding-top: 20px; }
  .workspace-heading { padding: 18px; }
  .drop-zone { margin: 0 18px 18px; min-height: 160px; }
  .job-main { grid-template-columns: 1fr; }
  .result-panel.visible {
    grid-template-columns: minmax(0, 1fr);
    padding: 14px 16px 16px;
  }
  .share-panel {
    grid-column: 1;
    grid-row: auto;
  }
}

@media (max-width: 620px) {
  .topbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
  }

  .brand,
  .topbar-actions {
    min-width: 0;
  }

  .topbar-actions {
    flex: 1 1 100%;
    flex-wrap: wrap;
    justify-content: space-between;
  }

  .user-chip {
    flex: 1 1 220px;
    min-width: 0;
  }

  .user-chip strong {
    min-width: 0;
  }

  .job-actions {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .job-actions .button {
    flex: 1 1 120px;
  }

  .share-disabled-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .share-address-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
  }

  .share-address-info {
    grid-column: 1 / -1;
  }

  .share-address-row .button {
    width: 100%;
  }
}
